Created
October 30, 2010 13:34
-
-
Save azu/655300 to your computer and use it in GitHub Desktop.
検索結果のタブを一つのタブにまとめるプラグイン
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* twicli plugin (http://twicli.neocat.jp/) | |
* switchViewedSearches.js | |
* 検索結果のタブを一覧表示するタブを作る - サイドバーなど狭い場所で使ってる人向け | |
* Pluginsに https://gist.github.com/655300.txt を読み込む | |
*/ | |
registerPlugin({ | |
init: function(tab) { | |
if (tws_list.length > 1 && !$('viewed_searches')) { | |
var hashTags = tws_list;// ハッシュタグの配列 ["#clipex", "#twicliJP"] | |
var hashTabs = []; | |
var menu = $("menu2"); | |
var aTags = menu.getElementsByTagName("a"); | |
for (var i = aTags.length - 1; 0 < i; i--) { | |
var aContent = aTags[i].textContent || aTags[i].innerText; | |
if (hashTags.indexOf(aContent) !== -1) { | |
hashTabs.push(menu.removeChild(aTags[i])); | |
} | |
} | |
var div = document.createElement("div"); | |
div.id = "efcl_hash_list"; | |
var ul = document.createElement("ul"); | |
ul.setAttribute("style", "list-style:none;padding: 3px 20px;") | |
for (var i = 0,len = hashTabs.length; i < len; i++) (function(hash) { | |
var li = document.createElement("li"); | |
li.appendChild(hashTabs[i]); | |
ul.appendChild(li); | |
})(hashTabs[i]); | |
div.appendChild(ul); | |
var isMouseover = false; | |
var onmouseover = function() { | |
isMouseover = true; | |
var hash_list = $("efcl_hash_list"); | |
hash_list.style.display = "block"; | |
} | |
div.onmouseover = onmouseover; | |
var onmouseout = debounce(function() { | |
var hash_list = $("efcl_hash_list"); | |
if (!isMouseover && hash_list.style.display === "block") { | |
hash_list.style.display = "none"; | |
} | |
}, 300); | |
div.onmouseout = function() { | |
isMouseover = false; | |
onmouseout(); | |
} | |
var newTab = document.createElement('a'); | |
newTab.onmouseover = function(evt) { | |
var hash_list = $("efcl_hash_list"); | |
if (hash_list.style.display !== "block") { | |
var pos = getMousePositon(evt); | |
hash_list.style.display = "block"; | |
div.style.top = pos.y + 20; | |
div.style.left = pos.x + 25; | |
} | |
} | |
newTab.onmouseout = onmouseout; | |
newTab.id = 'viewed_searches'; | |
newTab.innerHTML = '#Tags' | |
// CSS + element | |
addCSS("#efcl_hash_list{" + | |
"position:absolute;" + | |
"top:80px;" + | |
"left:10px;" + | |
"background:#fff;" + | |
"display:none;" + | |
"z-index:100;" + | |
"}"); | |
$("misc").parentNode.insertBefore(newTab, $("misc").nextSibling); | |
document.body.appendChild(div); | |
} | |
} | |
}); | |
// http://d.hatena.ne.jp/brazil/20110131/1296419283 | |
function debounce(fnArg, threshold) { | |
var me = fnArg; | |
var timeout; | |
return function() { | |
var self = this; | |
var args = arguments; | |
if (timeout) { | |
clearTimeout(timeout); | |
} | |
timeout = setTimeout(function() { | |
me.apply(self, args); | |
timeout = null; | |
}, threshold || 100); | |
}; | |
} | |
function getMousePositon(event) { | |
if (!event) { | |
event = window.event; | |
} | |
var hx, hy; | |
if (document.all) { // for IE | |
hx = event.offsetX; | |
hy = event.offsetY; | |
} else { | |
hx = event.layerX; | |
hy = event.layerY; | |
} | |
return { | |
x:hx, | |
y:hy | |
} | |
} | |
function addCSS(css) { | |
if (document.createStyleSheet) { // for IE | |
var sheet = document.createStyleSheet(); | |
sheet.cssText = css; | |
return sheet; | |
} else { | |
var sheet = document.createElement('style'); | |
sheet.type = 'text/css'; | |
var _root = document.getElementsByTagName('head')[0] || document.documentElement; | |
sheet.textContent = css; | |
return _root.appendChild(sheet).sheet; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment