com web/php: Have some fun with current-page search (keyboard shortcut: g s): include/header.inc js/common.js js/ext/mousetrap.min.js
styles/theme-base.css
| From: | Hannes Magnusson | Date: | Sun, 29 Dec 2013 03:01:40 +0000 |
| Subject: | com web/php: Have some fun with current-page search (keyboard shortcut: g s): include/header.inc js/common.js js/ext/mousetrap.min.js styles/theme-base.css |
||
| Groups: | php.webmaster | ||
| Request: | Send a blank email to php-webmaster+get-17867@lists.php.net to get a copy of this message | ||
Commit: 41ae81049082668c4f8bf883db739484081b2c08
Author: Hannes Magnusson <bjori@mongodb.com> Sat, 28 Dec 2013 19:01:40 -0800
Parents: c251f3f393baaab6f9205d0d164b60ccd3e8e24b
Branches: master
Link: http://git.php.net/?p=web/php.git;a=commitdiff;h=41ae81049082668c4f8bf883db739484081b2c08
Log:
Have some fun with current-page search (keyboard shortcut: g s)
Changed paths:
M include/header.inc
M js/common.js
M js/ext/mousetrap.min.js
M styles/theme-base.css
Diff:
diff --git a/include/header.inc b/include/header.inc
index c015d5d..770a2d0 100755
--- a/include/header.inc
+++ b/include/header.inc
@@ -102,6 +102,12 @@ if ($config["cache"]) {
<div class="headsup"><?php echo $config["headsup"]?></div>
<?php endif ?>
<nav id="trick"><div><?php doc_toc("en")
?></div></nav>
+<div id="goto">
+ <div class="search">
+ <div class="text"></div>
+ <div class="results"><ul></ul></div>
+ </div>
+</div>
<?php if (!empty($config['breadcrumbs'])): ?>
<div id="breadcrumbs">
diff --git a/js/common.js b/js/common.js
index d370169..4378a5e 100755
--- a/js/common.js
+++ b/js/common.js
@@ -61,6 +61,10 @@ Mousetrap.bind("?", function() {
});
Mousetrap.bind("esc", function() {
$("#trick").slideUp();
+ $("#goto").slideUp();
+
+ $("html").off("keydown");
+ $("html").off("keypress");
});
/*
Mousetrap.bind("j", function() {
@@ -155,6 +159,62 @@ Mousetrap.bind("k", function() {
cycleHeaders(matches, 0);
}
});
+$.expr[":"].icontains = $.expr.createPseudo(function(arg) {
+ return function( elem ) {
+ return $(elem).text().toUpperCase().indexOf(arg.toUpperCase()) >= 0;
+ };
+});
+function lookfor(txt) {
+ var retval = $("#layout a:icontains('" + txt + "')");
+ $("#goto .results ul").empty();
+ $(retval).each(function(k, val) {
+ $("#goto .results ul").append("<li><a href='" +
$(val).attr("href") + "'>" + $(val).text()
+"</a></li>");
+ });
+ $("#goto .results a:first").focus();
+}
+Mousetrap.bind("g s", function(e) {
+ $("#goto").slideToggle();
+ lookfor($("#goto .text").text());
+
+ $("html").on("keydown", function(e) {
+ switch(e.which || e.keyCode) {
+ /* Backspace */
+ case 8:
+ var txt = $("#goto .text").text();
+ txt = txt.substring(0, txt.length - 1);
+ $("#goto .text").text(txt);
+ lookfor(txt);
+ e.preventDefault();
+ break;
+
+ /* Enter */
+ case 13:
+ Mousetrap.unpause();
+ Mousetrap.trigger('esc');
+ return true;
+
+ /* Tab */
+ case 9:
+ $(document.activeElement).parent().next().first().focus();
+ break;
+ case 27:
+ Mousetrap.unpause();
+ Mousetrap.trigger('esc');
+ }
+ });
+ $("html").on("keypress", function(e) {
+ if (e.which == 13) {
+ return true;
+ }
+ e.preventDefault();
+ var letter = String.fromCharCode(e.which || e.keyCode);
+ $("#goto .text").append(letter);
+ var txt = $("#goto .text").text().trim();
+ lookfor(txt);
+ });
+
+ Mousetrap.pause();
+});
Mousetrap.bind("/", function(e) {
if (e.preventDefault) {
e.preventDefault();
diff --git a/js/ext/mousetrap.min.js b/js/ext/mousetrap.min.js
index 114a222..5a99439 100644
--- a/js/ext/mousetrap.min.js
+++ b/js/ext/mousetrap.min.js
@@ -7,3 +7,4 @@
c,a,e),l[d.key][c?"unshift":"push"]({callback:b,modifiers:d.modifiers,action:d.a
"@":"2","#":"3",$:"4","%":"5","^":"6","&":"7","*":"8","(":"9",")":"0",_:"-","+":"=",":":";",'"':"'","<":",",">":".","?":"/","|":"\\"},G={option:"alt",command:"meta","return":"enter",escape:"esc",mod:/Mac|iPod|iPhone|iPad/.test(navigator.platform)?"meta":"ctrl"},p,l={},q={},n={},D,z=!1,I=!1,u=!1;for(f=1;20>f;++f)h[111+f]="f"+f;for(f=0;9>=f;++f)h[f+96]=f;s(r,"keypress",y);s(r,"keydown",y);s(r,"keyup",y);var
m={bind:function(a,b,d){a=a instanceof Array?a:[a];for(var c=0;c<a.length;++c)F(a[c],b,d);return
this},
unbind:function(a,b){return
m.bind(a,function(){},b)},trigger:function(a,b){if(q[a+":"+b])q[a+":"+b]({},a);return
this},reset:function(){l={};q={};return this},stopCallback:function(a,b){return-1<("
"+b.className+" ").indexOf(" mousetrap
")?!1:"INPUT"==b.tagName||"SELECT"==b.tagName||"TEXTAREA"==b.tagName||b.isContentEditable},handleKey:function(a,b,d){var
c=C(a,b,d),e;b={};var
f=0,g=!1;for(e=0;e<c.length;++e)c[e].seq&&(f=Math.max(f,c[e].level));for(e=0;e<c.length;++e)c[e].seq?c[e].level==f&&(g=!0,
b[c[e].seq]=1,x(c[e].callback,d,c[e].combo,c[e].seq)):g||x(c[e].callback,d,c[e].combo);c="keypress"==d.type&&I;d.type!=u||w(a)||c||t(b);I=g&&"keydown"==d.type}};J.Mousetrap=m;"function"===typeof
define&&define.amd&&define(m)})(window,document);
+Mousetrap=function(a){var c=a.stopCallback,b=!0;a.stopCallback=function(a,d,e){return
b?c(a,d,e):!0};a.pause=function(){b=!1};a.unpause=function(){b=!0};return a}(Mousetrap);
diff --git a/styles/theme-base.css b/styles/theme-base.css
index 3fbd6b2..81c9db3 100755
--- a/styles/theme-base.css
+++ b/styles/theme-base..css
@@ -1583,6 +1583,7 @@ div.soft-deprecation-notice blockquote.sidebar {
#intro .container,
.navbar-inner,
#breadcrumbs,
+ #goto div,
#trick div,
#layout {
width:1170px;
@@ -1592,6 +1593,7 @@ div.soft-deprecation-notice blockquote.sidebar {
#intro .container,
.navbar-inner,
#breadcrumbs,
+ #goto div,
#trick div,
#layout {
width:1440px;
@@ -1725,6 +1727,27 @@ div.soft-deprecation-notice blockquote.sidebar {
}
}
+#goto {
+ display: none;
+ background-color: #333;
+ height: 100%;
+ width: 100%;
+ opacity: 0.9;
+ position: fixed;
+ top: 50px;
+ z-index: 5000;
+ color: #eee;
+}
+#goto .search .results {
+ text-shadow: 0px 2px 3px #555;
+ font-size: 2em;
+ line-height: 1;
+}
+#goto .search .text {
+ color: #222;
+ text-shadow: 0px 2px 3px #555;
+ font-size: 10em;
+}
#trick {
display: none;
background-color: #333;
@@ -1735,6 +1758,7 @@ div.soft-deprecation-notice blockquote.sidebar {
top: 50px;
z-index: 5000;
}
+#goto div,
#trick div {
margin: 0 auto;
}