From 050cc3dab1bc17afa48821b1cfa7a7e424e6192e Mon Sep 17 00:00:00 2001 From: teramako Date: Sun, 19 Sep 2010 13:40:17 +0000 Subject: add context menu git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@38497 d0d07461-0603-4401-acd4-de1884942a52 --- twittperator/twlist-win.tw | 206 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 197 insertions(+), 9 deletions(-) diff --git a/twittperator/twlist-win.tw b/twittperator/twlist-win.tw index 92ecc55..0de48ef 100644 --- a/twittperator/twlist-win.tw +++ b/twittperator/twlist-win.tw @@ -96,7 +96,196 @@ let winXML = tab.label = tab.label.substr(1); } } + function getCurrentListBox(){ + return tabBox.tabpanels.selectedPanel.firstChild; + } + function getParent(node, class){ + let elm = node; + while (elm != document.documentElement){ + if (elm instanceof class) + return elm; + elm = elm.parentNode; + } + return null; + } + var gActions = (function(){ + function getItemIndex(listbox, arg){ + let index = 0, currentIndex = listbox.selectedIndex; + switch (arg) { + case "0": + return 0; + case "$": + return listbox.itemCount - 1; + case "+1": + if (currentIndex == listbox.itemCount - 1) + return null; + return currentIndex + 1; + case "-1": + if (currentIndex == -1) + return null; + return currentIndex - 1; + default: + return null; + } + } + function getCopyItem(target){ + let listbox = getCurrentListBox(); + let item = listbox.selectedItem; + if (!item) + return null; + switch (target){ + case "ID": + return item.value; + case "SCREENNAME": + return item.querySelector(".twlist-screenname").textContent; + case "TEXT": + return item.querySelector(".twlist-text").textContent; + case "SELECTION": + return window.getSelection().toString(); + case "URL": + let node = document.popupNode; + if (node) { + let elm = getParent(node, HTMLAnchorElement); + if (elm) + return elm.getAttribute("href"); + } + } + return null; + } + var self = { + copy: function(target){ + let text = getCopyItem(target); + if (text) { + liberator.modules.util.copyToClipboard(text, true); + } + }, + select: function(arg){ + let listbox = getCurrentListBox(); + let index = getItemIndex(listbox, arg); + listbox.ensureIndexIsVisible( listbox.selectedIndex = index ); + }, + reply: function(){ + let listbox = getCurrentListBox(); + let item = listbox.selectedItem; + if (!item) + return; + twlist.onReply(item.querySelector(".twlist-reply"), (listbox == dmBox)); + }, + retweet: function(){ + let listbox = getCurrentListBox(); + if (listbox == dmBox) + return; + let item = listbox.selectedItem; + if (!item) + return; + twlist.onRetweet(item.querySelector(".twlist-retweet")); + }, + fav: function(){ + let listbox = getCurrentListBox(); + if (listbox == dmBox) + return; + let item = listbox.selectedItem; + if (!item) + return; + twlist.onFav(item.querySelector(".twlist-fav")); + } + }; + return self; + })(); + var gContext = (function(){ + var popupNode = null, anchor; + function showItem (item, show, text){ + if (show){ + if (item.hasAttribute("hidden")) + item.removeAttribute("hidden"); + if (text) + item.setAttribute("tooltiptext", text); + } else { + item.setAttribute("hidden", true); + if (item.hasAttribute("tooltiptext")) + item.removeAttribute("tooltiptext"); + } + } + function getSelText(text){ + if (text.length > 20) + return text.substr(20) + "..."; + return text; + } + var self = { + showing: function gContextShowing(){ + let listbox = getCurrentListBox(); + if (!listbox.selectedItem) + return false; + popupNode = document.popupNode; + let openLinkMenu = $("twlist-menuitem-openlink"), + openLinkTabMenu = $("twlist-menuitem-openlinktab"), + copyURLMenu = $("twlist-menuitem-copy-url"), + isAnchor = false, + href = null; + anchor = getParent(popupNode, HTMLAnchorElement); + if (anchor){ + isAnchor = true; + href = anchor.getAttribute("href"); + } + showItem(openLinkMenu, isAnchor, href); + showItem(openLinkTabMenu, isAnchor, href); + showItem(copyURLMenu, isAnchor, href); + let sel = window.getSelection(), + selectMenu = $("twlist-menuitem-copy-selection"); + showItem(selectMenu, (sel.toString() != ""), getSelText(sel.toString())); + return true; + }, + hiding: function gContextHiding(){ + anchor = null; + }, + openLink: function(newTab) { + if (popupNode instanceof HTMLAnchorElement) { + liberator.open(popupNode.getAttribute("href"), + {where: (newTab ? liberator.NEW_TAB : liberator.CURRENT_TAB) }); + } + } + }; + return self; + })(); ]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -104,9 +293,9 @@ let winXML = - + - @@ -149,15 +338,13 @@ function setStyleSheet() { padding: 2px 5px; margin: 0; -moz-border-radius: 4px; } - .twlist-reply, .twlist-retweet { + .twlist-reply, .twlist-retweet, .twlist-fav { color: white; font-weight: bold; background-color: gray; padding: 2px; margin:0; -moz-border-radius: 2px; } .twlist-fav { - color: yellow; background-color: #E0E0E0; - padding: 2px; margin:0; - -moz-border-radius: 2px; + color: yellow; } .twlist-text { margin: 2px 1em; } .twlist-text>label { margin: 1px 2px 2px 2px !important; } @@ -194,7 +381,7 @@ function getItemXML(msg) { - {formatText(msg.direct_message.text)} + {formatText(msg.direct_message.text.replace(/[\01-\10\14\16-\37]/g,""))} @@ -221,7 +408,7 @@ function getItemXML(msg) { - {formatText(msg.retweeted_status.text)} + {formatText(msg.retweeted_status.text.replace(/[\01-\10\14\16-\37]/g,""))} @@ -247,7 +434,7 @@ function getItemXML(msg) { - {formatText(msg.text)} + {formatText(msg.text.replace(/[\01-\10\14\16-\37]/g,""))} @@ -354,6 +541,7 @@ function getRedirectedURL (aURI, aElement, aCallback){ } function onSelect (evt) { let item = evt.target.selectedItem; + if (!item) return; let links = item.querySelectorAll("a.twlist-url"); function detectMedia (uri) { -- cgit v1.2.3