mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-21 20:17:58 +01:00
changed vimperator.open() to accept postdata, makes the design a little uncleaner, but supports _all_ firefox search engines now.
This commit is contained in:
@@ -197,11 +197,13 @@ function Bookmarks() //{{{
|
|||||||
return keywords;
|
return keywords;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if the engine name is null, it uses the default search engine
|
// if @param engine_name is null, it uses the default search engine
|
||||||
// @returns the url for the search string
|
// @returns the url for the search string
|
||||||
|
// if the search also requires a postdata, [url, postdata] is returned
|
||||||
this.getSearchURL = function(text, engine_name)
|
this.getSearchURL = function(text, engine_name)
|
||||||
{
|
{
|
||||||
var url = null;
|
var url = null;
|
||||||
|
var postdata = null;
|
||||||
if (!engine_name || engine_name == "")
|
if (!engine_name || engine_name == "")
|
||||||
engine_name = vimperator.options["defsearch"];
|
engine_name = vimperator.options["defsearch"];
|
||||||
|
|
||||||
@@ -210,7 +212,11 @@ function Bookmarks() //{{{
|
|||||||
if (engine)
|
if (engine)
|
||||||
{
|
{
|
||||||
if (text)
|
if (text)
|
||||||
url = engine.getSubmission(text, null).uri.spec;
|
{
|
||||||
|
var submission = engine.getSubmission(text, null);
|
||||||
|
url = submission.uri.spec;
|
||||||
|
postdata = submission.postData;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
url = engine.searchForm;
|
url = engine.searchForm;
|
||||||
}
|
}
|
||||||
@@ -232,7 +238,10 @@ function Bookmarks() //{{{
|
|||||||
}
|
}
|
||||||
|
|
||||||
// if we came here, the engine_name is neither a search engine or URL
|
// if we came here, the engine_name is neither a search engine or URL
|
||||||
return url;
|
if (postdata)
|
||||||
|
return [url, postdata];
|
||||||
|
else
|
||||||
|
return url; // can be null
|
||||||
}
|
}
|
||||||
|
|
||||||
this.list = function(filter, fullmode)
|
this.list = function(filter, fullmode)
|
||||||
|
|||||||
@@ -1207,6 +1207,7 @@ String.prototype.toURLArray = function()
|
|||||||
var urls = this.split(/\s*\,\s+/);
|
var urls = this.split(/\s*\,\s+/);
|
||||||
begin: for (var url = 0; url < urls.length; url++)
|
begin: for (var url = 0; url < urls.length; url++)
|
||||||
{
|
{
|
||||||
|
// FIXME: not really that good (doesn't handle .. in the middle), also problems with trailing slashes
|
||||||
// check for ./ and ../ (or even .../) to go to a file in the upper directory
|
// check for ./ and ../ (or even .../) to go to a file in the upper directory
|
||||||
if (urls[url].match(/^(\.$|\.\/\S*)/))
|
if (urls[url].match(/^(\.$|\.\/\S*)/))
|
||||||
{
|
{
|
||||||
@@ -1253,7 +1254,7 @@ String.prototype.toURLArray = function()
|
|||||||
text = matches[3];
|
text = matches[3];
|
||||||
|
|
||||||
var search_url = vimperator.bookmarks.getSearchURL(text, alias);
|
var search_url = vimperator.bookmarks.getSearchURL(text, alias);
|
||||||
if (search_url && search_url.length >= 1)
|
if (search_url/* && search_url.length >= 1*/)
|
||||||
{
|
{
|
||||||
urls[url] = search_url;
|
urls[url] = search_url;
|
||||||
continue;
|
continue;
|
||||||
@@ -1261,7 +1262,7 @@ String.prototype.toURLArray = function()
|
|||||||
else // the first word was not a search engine, search for the whole string in the default engine
|
else // the first word was not a search engine, search for the whole string in the default engine
|
||||||
{
|
{
|
||||||
search_url = vimperator.bookmarks.getSearchURL(urls[url], null);
|
search_url = vimperator.bookmarks.getSearchURL(urls[url], null);
|
||||||
if (search_url && search_url.length >= 1)
|
if (search_url/* && search_url.length >= 1*/)
|
||||||
{
|
{
|
||||||
urls[url] = search_url;
|
urls[url] = search_url;
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
@@ -252,6 +252,9 @@ const vimperator = (function() //{{{
|
|||||||
// open one or more URLs
|
// open one or more URLs
|
||||||
//
|
//
|
||||||
// @param urls: either a string or an array of urls
|
// @param urls: either a string or an array of urls
|
||||||
|
// The array can look like this:
|
||||||
|
// ["url1", "url2", "url3", ...] or:
|
||||||
|
// [["url1", postdata1], ["url2", postdata2], ...]
|
||||||
// @param where: if ommited, CURRENT_TAB is assumed
|
// @param where: if ommited, CURRENT_TAB is assumed
|
||||||
// @param callback: not implemented, will be allowed to specify a callback function
|
// @param callback: not implemented, will be allowed to specify a callback function
|
||||||
// which is called, when the page finished loading
|
// which is called, when the page finished loading
|
||||||
@@ -269,17 +272,21 @@ const vimperator = (function() //{{{
|
|||||||
if (!where)
|
if (!where)
|
||||||
where = vimperator.CURRENT_TAB;
|
where = vimperator.CURRENT_TAB;
|
||||||
|
|
||||||
|
var url = typeof urls[0] == "string" ? urls[0] : urls[0][0];
|
||||||
|
var postdata = typeof urls[0] == "string" ? null : urls[0][1];
|
||||||
|
//alert(postdata);
|
||||||
|
|
||||||
// decide where to load the first tab
|
// decide where to load the first tab
|
||||||
if (where == vimperator.CURRENT_TAB)
|
if (where == vimperator.CURRENT_TAB)
|
||||||
getBrowser().loadURI(urls[0]);
|
/*getBrowser().*/loadURI(url, null, postdata);
|
||||||
else if (where == vimperator.NEW_TAB)
|
else if (where == vimperator.NEW_TAB)
|
||||||
{
|
{
|
||||||
var firsttab = getBrowser().addTab(urls[0]);
|
var firsttab = getBrowser().addTab(url, null, null, postdata);
|
||||||
getBrowser().selectedTab = firsttab;
|
getBrowser().selectedTab = firsttab;
|
||||||
}
|
}
|
||||||
else if (where == vimperator.NEW_BACKGROUND_TAB)
|
else if (where == vimperator.NEW_BACKGROUND_TAB)
|
||||||
{
|
{
|
||||||
getBrowser().addTab(urls[0]);
|
getBrowser().addTab(url, null, null, postdata);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -288,8 +295,12 @@ const vimperator = (function() //{{{
|
|||||||
}
|
}
|
||||||
|
|
||||||
// all other URLs are always loaded in background
|
// all other URLs are always loaded in background
|
||||||
for (var url=1; url < urls.length; url++)
|
for (var i=1; i < urls.length; i++)
|
||||||
getBrowser().addTab(urls[url]);
|
{
|
||||||
|
url = typeof urls[i] == "string" ? urls[i] : urls[i][0];
|
||||||
|
postdata = typeof urls[i] == "string" ? null : urls[i][1];
|
||||||
|
getBrowser().addTab(url, null, null, postdata);
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: register callbacks
|
// TODO: register callbacks
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user