com web/shared: Include common javascripts: js/common.js js/external/mousetrap.min.js templates/footer.inc templates/header.inc
| From: | Hannes Magnusson | Date: | Tue, 31 Dec 2013 20:49:16 +0000 |
| Subject: | com web/shared: Include common javascripts: js/common.js js/external/mousetrap.min.js templates/footer.inc templates/header.inc | ||
| Groups: | php.webmaster | ||
| Request: | Send a blank email to php-webmaster+get-17958@lists.php.net to get a copy of this message | ||
Commit: 647a05aecee6529c4ba1f2d53b0f93782a7426ad
Author: Hannes Magnusson <bjori@mongodb.com> Tue, 31 Dec 2013 12:49:16 -0800
Parents: 3a2966b6a092a67480c3b6bee9f9c80ca2b18a18
Branches: master
Link: http://git.php.net/?p=web/shared.git;a=commitdiff;h=647a05aecee6529c4ba1f2d53b0f93782a7426ad
Log:
Include common javascripts
Changed paths:
A js/common.js
A js/external/mousetrap.min.js
M templates/footer.inc
M templates/header.inc
diff --git a/js/common.js b/js/common.js new file mode 100755 index 0000000..d038158 --- /dev/null +++ b/js/common.js @@ -0,0 +1,129 @@ +function cycle(to, from) { + from.removeClass("current"); + to.addClass("current"); + $(window).scrollTop(to.offset().top); +} +function getNextOrPreviousSibling(node, forward) { + if (forward) { + return node.next(); + } + return node.prev(); +} +function cycleMenuItems(current, forward) { + if (getNextOrPreviousSibling(current, forward).length) { + cycle(getNextOrPreviousSibling(current, forward), current); + curr.children("a").first().focus().css({outline: "none"}); + } +} +function cycleHeaders(matches, forward) { + /* forward=1 next match + * forward=0 previous match + */ + var gotmatch = 0; + + matches.each(function(k, item) { + if ($(item).hasClass("current")) { + if ($(matches[forward ? k+1 : k-1]).length) { + cycle($(matches[forward ? k+1 : k-1]), $(item)); + gotmatch = 1; + return false; + } + } + }); + if (!gotmatch) { + cycle($(matches[forward ? 0 : matches.length-1]), $(matches[forward ? matches.length-1 : 0])); + } +} +Mousetrap.bind('up up down down left right left right b a enter', function() { + $(".home img").attr("src", "//php.net/images/php_konami.gif"); + $(window).scrollTop(0); +}); +Mousetrap.bind("?", function() { + $("#megadropdown").slideToggle(); +}); +Mousetrap.bind("esc", function() { + $("#megadropdown").slideUp(); + $("#goto").slideUp(); + + $("html").off("keydown"); + $("html").off("keypress"); +}); +Mousetrap.bind("G", function() { + var n = $(document).height(); + $(window).scrollTop(n, 10); +}); +Mousetrap.bind("g h", function() { + window.location.href = "/"; +}); +Mousetrap.bind("g g", function() { + $(window).scrollTop(0, 10); +}); +Mousetrap.bind("g p", function() { + var link = $("link[rel=prev]").attr("href"); + if (link) { + window.location.href = link; + } +}); +Mousetrap.bind("g n", function() { + var link = $("link[rel=next]").attr("href"); + if (link) { + window.location.href = link; + } +}); + +Mousetrap.bind("j", function() { + /* Doc page */ + var node = $(".layout-menu .current"); + if (node.length) { + cycleMenuItems(node, 1); + } + else { + /* Cycle through headers on normal pages */ + var matches = $("section.fullscreen h1, section.fullscreen h2, section.fullscreen h3"); + cycleHeaders(matches, 1); + } +}); +Mousetrap.bind("k", function() { + var node = $(".layout-menu .current"); + if (node.length) { + cycleMenuItems(node, 0); + } + else { + /* Cycle through headers on normal pages */ + var matches = $("section.fullscreen h1, section.fullscreen h2, section.fullscreen h3"); + cycleHeaders(matches, 0); + } +}); +Mousetrap.bind("/", function(e) { + e.preventDefault(); + $("input[type=search]").focus() +}); +var rotate = 0; +Mousetrap.bind("r o t a t e enter", function(e) { + rotate += 90; + if (rotate > 360) { + rotate = 0; + } + $("html").css("-webkit-transform", "rotate(" + rotate + "deg)"); + $("html").css("-moz-transform", "rotate(" + rotate + "deg)"); + $("html").css("-o-transform", "rotate(" + rotate + "deg)"); + $("html").css("-ms-transform", "rotate(" + rotate + "deg)"); + $("html").css("transform", "rotate(" + rotate + "deg)"); +}); +var scale = 1; +Mousetrap.bind("m i r r o r enter", function(e) { + scale *= -1; + $("html").css("-webkit-transform", "scaleX(" + scale + ")"); + $("html").css("-moz-transform", "scaleX(" + scale + ")"); + $("html").css("-o-transform", "scaleX(" + scale + ")"); + $("html").css("-ms-transform", "scaleX(" + scale + ")"); + $("html").css("transform", "scaleX(" + scale + ")"); +}); +Mousetrap.bind("l o g o enter", function(e) { + var time = new Date().getTime(); + $(".home img").attr("src", "//php.net/images/logo.php?refresh&time=" + time); + $(window).scrollTop(0); +}); + + +// vim: set ts=4 sw=4 et: diff --git a/js/external/mousetrap.min.js b/js/external/mousetrap.min.js new file mode 100644 index 0000000..5a99439 --- /dev/null +++ b/js/external/mousetrap.min.js @@ -0,0 +1,10 @@ +/* mousetrap v1.4.6 craig.is/killing/mice */ +(function(J,r,f){function s(a,b,d){a.addEventListener?a.addEventListener(b,d,!1):a.attachEvent("on"+b,d)}function A(a){if("keypress"==a.type){var b=String.fromCharCode(a.which);a.shiftKey||(b=b.toLowerCase());return b}return h[a.which]?h[a.which]:B[a.which]?B[a.which]:String.fromCharCode(a.which).toLowerCase()}function t(a){a=a||{};var b=!1,d;for(d in n)a[d]?b=!0:n[d]=0;b||(u=!1)}function C(a,b,d,c,e,v){var g,k,f=[],h=d.type;if(!l[a])return[];"keyup"==h&&w(a)&&(b=[a]);for(g=0;g<l[a].length;++g)if(k= +l[a][g],!(!c&&k.seq&&n[k.seq]!=k.level||h!=k.action||("keypress"!=h||d.metaKey||d.ctrlKey)&&b.sort().join(",")!==k.modifiers.sort().join(","))){var m=c&&k.seq==c&&k.level==v;(!c&&k.combo==e||m)&&l[a].splice(g,1);f.push(k)}return f}function K(a){var b=[];a.shiftKey&&b.push("shift");a.altKey&&b.push("alt");a.ctrlKey&&b.push("ctrl");a.metaKey&&b.push("meta");return b}function x(a,b,d,c){m.stopCallback(b,b.target||b.srcElement,d,c)||!1!==a(b,d)||(b.preventDefault?b.preventDefault():b.returnValue=!1,b.stopPropagation? +b.stopPropagation():b.cancelBubble=!0)}function y(a){"number"!==typeof a.which&&(a.which=a.keyCode);var b=A(a);b&&("keyup"==a.type&&z===b?z=!1:m.handleKey(b,K(a),a))}function w(a){return"shift"==a||"ctrl"==a||"alt"==a||"meta"==a}function L(a,b,d,c){function e(b){return function(){u=b;++n[a];clearTimeout(D);D=setTimeout(t,1E3)}}function v(b){x(d,b,a);"keyup"!==c&&(z=A(b));setTimeout(t,10)}for(var g=n[a]=0;g<b.length;++g){var f=g+1===b.length?v:e(c||E(b[g+1]).action);F(b[g],f,c,a,g)}}function E(a,b){var d, +c,e,f=[];d="+"===a?["+"]:a.split("+");for(e=0;e<d.length;++e)c=d[e],G[c]&&(c=G[c]),b&&"keypress"!=b&&H[c]&&(c=H[c],f.push("shift")),w(c)&&f.push(c);d=c;e=b;if(!e){if(!p){p={};for(var g in h)95<g&&112>g||h.hasOwnProperty(g)&&(p[h[g]]=g)}e=p[d]?"keydown":"keypress"}"keypress"==e&&f.length&&(e="keydown");return{key:c,modifiers:f,action:e}}function F(a,b,d,c,e){q[a+":"+d]=b;a=a.replace(/\s+/g," ");var f=a.split(" ");1<f.length?L(a,f,b,d):(d=E(a,d),l[d.key]=l[d.key]||[],C(d.key,d.modifiers,{type:d.action}, +c,a,e),l[d.key][c?"unshift":"push"]({callback:b,modifiers:d.modifiers,action:d.action,seq:c,level:e,combo:a}))}var h={8:"backspace",9:"tab",13:"enter",16:"shift",17:"ctrl",18:"alt",20:"capslock",27:"esc",32:"space",33:"pageup",34:"pagedown",35:"end",36:"home",37:"left",38:"up",39:"right",40:"down",45:"ins",46:"del",91:"meta",93:"meta",224:"meta"},B={106:"*",107:"+",109:"-",110:".",111:"/",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},H={"~":"`","!":"1", +"@":"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/templates/footer.inc b/templates/footer.inc index 04f7272..d4cdfdd 100644 --- a/templates/footer.inc +++ b/templates/footer.inc @@ -29,6 +29,9 @@ $ROOT = substr($_SERVER["SERVER_NAME"], -8) == ".php.net" ? "//shared.php.net" : </nav> </footer> +<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> +<script src="<?php echo $ROOT?>/js/external/mousetrap.min.js"></script> +<script src="<?php echo $ROOT?>/js/common.js"></script> <?php foreach($JS as $script) :?> <?php if (strncmp($script, "//", 2) == 0): ?> <script type="text/javascript" src="<?php echo $script?>"></script> diff --git a/templates/header.inc b/templates/header.inc index 13d615e..155b808 100644 --- a/templates/header.inc +++ b/templates/header.inc @@ -70,6 +70,7 @@ $ROOT = substr($_SERVER["SERVER_NAME"], -8) == ".php.net" ? "//shared.php.net" : <?php endif ?> </nav> </header> +<div id="flash-message"></div> <nav id="megadropdown"></nav> <section class="fullscreen">
diff --git a/js/common.js b/js/common.js new file mode 100755 index 0000000..d038158 --- /dev/null +++ b/js/common.js @@ -0,0 +1,129 @@ +function cycle(to, from) { + from.removeClass("current"); + to.addClass("current"); + $(window).scrollTop(to.offset().top); +} +function getNextOrPreviousSibling(node, forward) { + if (forward) { + return node.next(); + } + return node.prev(); +} +function cycleMenuItems(current, forward) { + if (getNextOrPreviousSibling(current, forward).length) { + cycle(getNextOrPreviousSibling(current, forward), current); + curr.children("a").first().focus().css({outline: "none"}); + } +} +function cycleHeaders(matches, forward) { + /* forward=1 next match + * forward=0 previous match + */ + var gotmatch = 0; + + matches.each(function(k, item) { + if ($(item).hasClass("current")) { + if ($(matches[forward ? k+1 : k-1]).length) { + cycle($(matches[forward ? k+1 : k-1]), $(item)); + gotmatch = 1; + return false; + } + } + }); + if (!gotmatch) { + cycle($(matches[forward ? 0 : matches.length-1]), $(matches[forward ? matches.length-1 : 0])); + } +} +Mousetrap.bind('up up down down left right left right b a enter', function() { + $(".home img").attr("src", "//php.net/images/php_konami.gif"); + $(window).scrollTop(0); +}); +Mousetrap.bind("?", function() { + $("#megadropdown").slideToggle(); +}); +Mousetrap.bind("esc", function() { + $("#megadropdown").slideUp(); + $("#goto").slideUp(); + + $("html").off("keydown"); + $("html").off("keypress"); +}); +Mousetrap.bind("G", function() { + var n = $(document).height(); + $(window).scrollTop(n, 10); +}); +Mousetrap.bind("g h", function() { + window.location.href = "/"; +}); +Mousetrap.bind("g g", function() { + $(window).scrollTop(0, 10); +}); +Mousetrap.bind("g p", function() { + var link = $("link[rel=prev]").attr("href"); + if (link) { + window.location.href = link; + } +}); +Mousetrap.bind("g n", function() { + var link = $("link[rel=next]").attr("href"); + if (link) { + window.location.href = link; + } +}); + +Mousetrap.bind("j", function() { + /* Doc page */ + var node = $(".layout-menu .current"); + if (node.length) { + cycleMenuItems(node, 1); + } + else { + /* Cycle through headers on normal pages */ + var matches = $("section.fullscreen h1, section.fullscreen h2, section.fullscreen h3"); + cycleHeaders(matches, 1); + } +}); +Mousetrap.bind("k", function() { + var node = $(".layout-menu .current"); + if (node.length) { + cycleMenuItems(node, 0); + } + else { + /* Cycle through headers on normal pages */ + var matches = $("section.fullscreen h1, section.fullscreen h2, section.fullscreen h3"); + cycleHeaders(matches, 0); + } +}); +Mousetrap.bind("/", function(e) { + e.preventDefault(); + $("input[type=search]").focus() +}); +var rotate = 0; +Mousetrap.bind("r o t a t e enter", function(e) { + rotate += 90; + if (rotate > 360) { + rotate = 0; + } + $("html").css("-webkit-transform", "rotate(" + rotate + "deg)"); + $("html").css("-moz-transform", "rotate(" + rotate + "deg)"); + $("html").css("-o-transform", "rotate(" + rotate + "deg)"); + $("html").css("-ms-transform", "rotate(" + rotate + "deg)"); + $("html").css("transform", "rotate(" + rotate + "deg)"); +}); +var scale = 1; +Mousetrap.bind("m i r r o r enter", function(e) { + scale *= -1; + $("html").css("-webkit-transform", "scaleX(" + scale + ")"); + $("html").css("-moz-transform", "scaleX(" + scale + ")"); + $("html").css("-o-transform", "scaleX(" + scale + ")"); + $("html").css("-ms-transform", "scaleX(" + scale + ")"); + $("html").css("transform", "scaleX(" + scale + ")"); +}); +Mousetrap.bind("l o g o enter", function(e) { + var time = new Date().getTime(); + $(".home img").attr("src", "//php.net/images/logo.php?refresh&time=" + time); + $(window).scrollTop(0); +}); + + +// vim: set ts=4 sw=4 et: diff --git a/js/external/mousetrap.min.js b/js/external/mousetrap.min.js new file mode 100644 index 0000000..5a99439 --- /dev/null +++ b/js/external/mousetrap.min.js @@ -0,0 +1,10 @@ +/* mousetrap v1.4.6 craig.is/killing/mice */ +(function(J,r,f){function s(a,b,d){a.addEventListener?a.addEventListener(b,d,!1):a.attachEvent("on"+b,d)}function A(a){if("keypress"==a.type){var b=String.fromCharCode(a.which);a.shiftKey||(b=b.toLowerCase());return b}return h[a.which]?h[a.which]:B[a.which]?B[a.which]:String.fromCharCode(a.which).toLowerCase()}function t(a){a=a||{};var b=!1,d;for(d in n)a[d]?b=!0:n[d]=0;b||(u=!1)}function C(a,b,d,c,e,v){var g,k,f=[],h=d.type;if(!l[a])return[];"keyup"==h&&w(a)&&(b=[a]);for(g=0;g<l[a].length;++g)if(k= +l[a][g],!(!c&&k.seq&&n[k.seq]!=k.level||h!=k.action||("keypress"!=h||d.metaKey||d.ctrlKey)&&b.sort().join(",")!==k.modifiers.sort().join(","))){var m=c&&k.seq==c&&k.level==v;(!c&&k.combo==e||m)&&l[a].splice(g,1);f.push(k)}return f}function K(a){var b=[];a.shiftKey&&b.push("shift");a.altKey&&b.push("alt");a.ctrlKey&&b.push("ctrl");a.metaKey&&b.push("meta");return b}function x(a,b,d,c){m.stopCallback(b,b.target||b.srcElement,d,c)||!1!==a(b,d)||(b.preventDefault?b.preventDefault():b.returnValue=!1,b.stopPropagation? +b.stopPropagation():b.cancelBubble=!0)}function y(a){"number"!==typeof a.which&&(a.which=a.keyCode);var b=A(a);b&&("keyup"==a.type&&z===b?z=!1:m.handleKey(b,K(a),a))}function w(a){return"shift"==a||"ctrl"==a||"alt"==a||"meta"==a}function L(a,b,d,c){function e(b){return function(){u=b;++n[a];clearTimeout(D);D=setTimeout(t,1E3)}}function v(b){x(d,b,a);"keyup"!==c&&(z=A(b));setTimeout(t,10)}for(var g=n[a]=0;g<b.length;++g){var f=g+1===b.length?v:e(c||E(b[g+1]).action);F(b[g],f,c,a,g)}}function E(a,b){var d, +c,e,f=[];d="+"===a?["+"]:a.split("+");for(e=0;e<d.length;++e)c=d[e],G[c]&&(c=G[c]),b&&"keypress"!=b&&H[c]&&(c=H[c],f.push("shift")),w(c)&&f.push(c);d=c;e=b;if(!e){if(!p){p={};for(var g in h)95<g&&112>g||h.hasOwnProperty(g)&&(p[h[g]]=g)}e=p[d]?"keydown":"keypress"}"keypress"==e&&f.length&&(e="keydown");return{key:c,modifiers:f,action:e}}function F(a,b,d,c,e){q[a+":"+d]=b;a=a.replace(/\s+/g," ");var f=a.split(" ");1<f.length?L(a,f,b,d):(d=E(a,d),l[d.key]=l[d.key]||[],C(d.key,d.modifiers,{type:d.action}, +c,a,e),l[d.key][c?"unshift":"push"]({callback:b,modifiers:d.modifiers,action:d.action,seq:c,level:e,combo:a}))}var h={8:"backspace",9:"tab",13:"enter",16:"shift",17:"ctrl",18:"alt",20:"capslock",27:"esc",32:"space",33:"pageup",34:"pagedown",35:"end",36:"home",37:"left",38:"up",39:"right",40:"down",45:"ins",46:"del",91:"meta",93:"meta",224:"meta"},B={106:"*",107:"+",109:"-",110:".",111:"/",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},H={"~":"`","!":"1", +"@":"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/templates/footer.inc b/templates/footer.inc index 04f7272..d4cdfdd 100644 --- a/templates/footer.inc +++ b/templates/footer.inc @@ -29,6 +29,9 @@ $ROOT = substr($_SERVER["SERVER_NAME"], -8) == ".php.net" ? "//shared.php.net" : </nav> </footer> +<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> +<script src="<?php echo $ROOT?>/js/external/mousetrap.min.js"></script> +<script src="<?php echo $ROOT?>/js/common.js"></script> <?php foreach($JS as $script) :?> <?php if (strncmp($script, "//", 2) == 0): ?> <script type="text/javascript" src="<?php echo $script?>"></script> diff --git a/templates/header.inc b/templates/header.inc index 13d615e..155b808 100644 --- a/templates/header.inc +++ b/templates/header.inc @@ -70,6 +70,7 @@ $ROOT = substr($_SERVER["SERVER_NAME"], -8) == ".php.net" ? "//shared.php.net" : <?php endif ?> </nav> </header> +<div id="flash-message"></div> <nav id="megadropdown"></nav> <section class="fullscreen">