diff options
author | Adrian C. (anrxc) <anrxc@sysphere.org> | 2009-10-29 22:52:27 +0100 |
---|---|---|
committer | Adrian C. (anrxc) <anrxc@sysphere.org> | 2009-10-29 22:54:54 +0100 |
commit | ab1018041700e50e56ed04b4782dbc36086938e2 (patch) | |
tree | 1eaa0aa2c0c111a47c3391d70477606aa6ab1000 | |
parent | 10f8310c7e02aebbfda45bd953a0c972f1c4952d (diff) | |
download | dotfiles-ab1018041700e50e56ed04b4782dbc36086938e2.tar.xz |
vimperator: add buftabs plugin
Buftabs plugin from Lucas de Vries provides a tabbar replacement,
integrated into the statusbar. Original plugin is hosted on:
http://git.glacicle.com/configs/
-rw-r--r-- | vimperator/plugin/buftabs.js | 191 | ||||
-rw-r--r-- | vimperatorrc | 5 |
2 files changed, 195 insertions, 1 deletions
diff --git a/vimperator/plugin/buftabs.js b/vimperator/plugin/buftabs.js new file mode 100644 index 0000000..cb3adcf --- /dev/null +++ b/vimperator/plugin/buftabs.js @@ -0,0 +1,191 @@ +// PLUGIN_INFO {{{ +let PLUGIN_INFO = +<VimperatorPlugin> + <name>Buftabs</name> + <description>Add buffer tabs to the statusline to save space.</description> + <version>1.0</version> + <author mail="lucas@tuple-typed.org" homepage="http://tuple-typed.org/">GGLucas</author> + <license>WTFPL version 2 (http://sam.zoy.org/wtfpl/)</license> + <minVersion>2.2</minVersion> + <maxVersion>2.2</maxVersion> + <detail><![CDATA[ + + == Usage == + When the script is loaded it hijacks the statusline to display a list of tabs, + you can use the "buftabs" option to toggle it on or off. + + == Styling == + You can style the buftabs with: + + :style * .buftab { <CSS> } + + and + + :style * .buftab_selected { <CSS> } + + == Length == + You can set the max length of a title before it is cut off with the buftabs_maxlength + option. It is set to 25 by default. + + ]]></detail> +</VimperatorPlugin>; +// }}} + +buftabs = { + // Update the tabs + updateUrl: function (url) + { + // Get buftabbar + var buftabs = document.getElementById("liberator-statusline-buftabs"); + var urlWidget = document.getElementById("liberator-statusline-field-url"); + var maxlength = options.get("buftabs_maxlength").get(); + var tabvalue, position=0, selpos; + + //// Empty the tabbar + while (buftabs.lastChild != null) + buftabs.removeChild(buftabs.lastChild); + + // Create the new tabs + for (let [i, browser] in tabs.browsers) + { + // Title + if (browser.webProgress.isLoadingDocument) + tabvalue = "Loading..."; + else + tabvalue = browser.contentTitle || "Untitled"; + + // Check length + if (tabvalue.length > maxlength) + tabvalue = tabvalue.substr(0, maxlength-3)+"..."; + + // Bookmark icon + if (liberator.has("bookmarks")) + if (bookmarks.isBookmarked(browser.contentDocument.location.href)) + tabvalue += "\u2764"; + + // Brackets and index + tabvalue = "["+(i+1)+"-"+tabvalue+"]"; + + // Create label + var label = document.createElement("label"); + label.tabpos = i; + label.setAttribute("value", tabvalue); + buftabs.appendChild(label); + + label.onclick = function () + { + tabs.select(this.tabpos); + } + + if (tabs.index() == i) + { + selpos = [position, label.clientWidth+position]; + label.className = "buftab_selected"; + } else { + label.className = "buftab"; + } + + position += label.clientWidth; + } + + // Scroll + if (selpos[0] < buftabs.scrollLeft || selpos[1] > buftabs.scrollLeft+buftabs.clientWidth) + buftabs.scrollLeft = selpos[0]; + + // Show the entire line if possible + if (buftabs.scrollWidth == buftabs.clientWidth) + buftabs.scrollLeft = 0; + + // Empty url label + urlWidget.value = ""; + }, + + // Create the horizontal box for adding the tabs to + createBar: function() + { + var statusline = document.getElementById("liberator-statusline"); + var buftabs = document.getElementById("liberator-statusline-buftabs"); + var urlWidget = document.getElementById("liberator-statusline-field-url"); + + // Only create if it doesn't exist yet + if (!buftabs) + { + buftabs = document.createElement("hbox"); + buftabs.setAttribute("id", "liberator-statusline-buftabs"); + buftabs.setAttribute("flex", "1"); + buftabs.style.overflow = "hidden" + + statusline.insertBefore(buftabs, urlWidget); + } + }, + + destroyBar: function() + { + var statusline = document.getElementById("liberator-statusline"); + var buftabs = document.getElementById("liberator-statusline-buftabs"); + + if (buftabs) + statusline.removeChild(buftabs); + } +} + +var tabContainer = tabs.getBrowser().mTabContainer; +buftabs._statusline_updateUrl = statusline.updateUrl; + +tabContainer.addEventListener("TabMove", function (event) { + if (options.get("buftabs").get()) + statusline.updateUrl(); +}, false); +tabContainer.addEventListener("TabOpen", function (event) { + if (options.get("buftabs").get()) + statusline.updateUrl(); +}, false); +tabContainer.addEventListener("TabClose", function (event) { + if (options.get("buftabs").get()) + setTimeout(statusline.updateUrl, 0); +}, false); +tabContainer.addEventListener("TabSelect", function (event) { + if (options.get("buftabs").get()) + statusline.updateUrl(); +}, false); + +/// Options +options.add(["buftabs", "buftabs"], + "Control whether to use buftabs in the statusline", + "number", "1", + { + setter: function (value) + { + if (value) + { + buftabs.createBar(); + buftabs.updateUrl(null); + + statusline.updateUrl = buftabs.updateUrl; + } else { + buftabs.destroyBar(); + statusline.updateUrl = buftabs._statusline_updateUrl; + } + + return value; + }, + + completer: function (context) + [ + ["0", "Don't show buftabs, show the url"], + ["1", "Show buftabs"] + ], + + validator: Option.validateCompleter + }); + +options.add(["buftabs_maxlength", "buftabs_maxlength"], + "Max length of an entry in the buftabs list", + "number", "25", + { + setter: function (value) + { + buftabs.updateUrl(); + return value; + } + }); diff --git a/vimperatorrc b/vimperatorrc index 72536dd..c87d2c3 100644 --- a/vimperatorrc +++ b/vimperatorrc @@ -33,7 +33,7 @@ set history=10000 "set go+=T " Show the tab bar only if more then one tab is open -set showtabline=1 +set showtabline=0 " Focus the content after a page has loaded set focuscontent @@ -258,6 +258,9 @@ noremap <silent> <Leader>p :noscript popup<CR> " TinyURL :map <silent> <Leader>t :exe ":tinyurl "+getBrowser().contentWindow.location.href<CR> +" Buftabs +"set buftabs=0 + " {{{ Javascript functions " |