[Pkg-mozext-commits] [wot] 28/226: #7 Ninja donuts
David Prévot
taffit at moszumanska.debian.org
Fri May 1 00:35:31 UTC 2015
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository wot.
commit 97f0ecf7238b6d9a2cf6ad8f6e8e1c49b305f670
Author: Sergey Andryukhin <sorgoz at yandex.com>
Date: Mon Jun 11 11:55:17 2012 +0300
#7 Ninja donuts
---
content/search.js | 66 ++++++++++++++++++++++++++++++++++++++++++++++---------
1 file changed, 56 insertions(+), 10 deletions(-)
diff --git a/content/search.js b/content/search.js
index ea68b38..52719e9 100644
--- a/content/search.js
+++ b/content/search.js
@@ -532,32 +532,78 @@ var wot_search =
addrating: function(target, content, link, rule)
{
- var is_ninja = rule.ninja && wot_prefs.ninja_donuts;
-
- dump("ninja_donuts: " + wot_prefs.ninja_donuts + "\n");
- dump("is ninja: " + is_ninja + "\n");
- dump("rule" + JSON.stringify(rule) + "\n");
-
try {
+ // ninja - is experimental feature to make donuts on the SERP hidden
+ var is_ninja = rule.ninja && wot_prefs.ninja_donuts;
+
var elem = content.createElement("div");
if (elem) {
+
+ var link_parent = link.parentNode;
+
elem.setAttribute(this.attribute, target);
- elem.setAttribute("style",
- "display: inline-block; " +
- "cursor: pointer; " +
+ var initial_style = "cursor: pointer; " +
"width: 16px; " +
- "height: 16px;");
+ "height: 16px;" +
+ "display: inline-block;";
+
+ if(is_ninja)
+ initial_style += "visibility: hidden !important;";
+
+ elem.setAttribute("style", initial_style);
elem.innerHTML = " ";
elem.addEventListener("click", this.onclick, false);
+ if(is_ninja) {
+
+ var ninja_timer = null,
+ visibility = null;
+
+ // clojure
+ function set_visibility() {
+ var style = elem.getAttribute("style");
+
+ // simply replace "visibility" value
+ var new_style = style.replace(/(visibility:) (hidden|visible) (!important)/g,
+ function(str, g1, g2, g3, s) { return g1 + visibility + g3 });
+
+ elem.setAttribute("style", new_style)
+ }
+
+ function do_ninja(event) {
+ // It needs to be called as clojure to access "elem"
+
+ if (ninja_timer) clearTimeout(ninja_timer);
+
+ if(event.type == "mouseout") {
+
+ visibility = " hidden ";
+ // delay, to prevent premature hiding causes by bubled events from element's children
+ ninja_timer = setTimeout(set_visibility, 100);
+ return;
+ } else {
+ visibility = " visible ";
+ }
+
+ set_visibility();
+ }
+
+ // use parent to avoid hiding donut when cursor moves to it but goes out of the link
+ link_parent.addEventListener("mouseover", do_ninja, false);
+ link_parent.addEventListener("mouseout", do_ninja, false);
+ }
+
+
if (link.nextSibling) {
link.parentNode.insertBefore(elem, link.nextSibling);
} else {
link.parentNode.appendChild(elem);
}
+
+ initial_style = undefined; // clean up
}
} catch (e) {
dump("wot_search.addrating: failed with " + e + "\n");
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/wot.git
More information about the Pkg-mozext-commits
mailing list