From edd450502f74dcbe8175dfddee8b50d14424a390 Mon Sep 17 00:00:00 2001 From: hukl Date: Sat, 13 Jun 2009 15:42:13 +0200 Subject: added js search widget with clickable results that will take the user to the brand new "show" version of the page. so the user doesn't create new revisions and locks all the time when he / she only wants to take a look at it. --- public/javascripts/admin_interface.js | 7 +- public/javascripts/admin_search.js | 62 +++++---- public/javascripts/jquery.hotkeys.js | 244 ++++++++++++++++++++++++++++++++++ 3 files changed, 287 insertions(+), 26 deletions(-) create mode 100755 public/javascripts/jquery.hotkeys.js (limited to 'public/javascripts') diff --git a/public/javascripts/admin_interface.js b/public/javascripts/admin_interface.js index 5fe91a2..f890afb 100644 --- a/public/javascripts/admin_interface.js +++ b/public/javascripts/admin_interface.js @@ -1,5 +1,10 @@ $(document).ready(function () { - admin_search.initialize(); + $("#search_widget").hide(); + + $(document).bind("keydown", 'Alt+f', function(){ + admin_search.display_toggle(); + return false; + }); $("#metadata").attr("style", "display: none;"); diff --git a/public/javascripts/admin_search.js b/public/javascripts/admin_search.js index d645cca..ba52bb5 100644 --- a/public/javascripts/admin_search.js +++ b/public/javascripts/admin_search.js @@ -1,28 +1,40 @@ admin_search = { - initialize : function() { - $("#search_term").bind("keyup", function() { - if ($(this).attr("value")) { - $.ajax({ - type: "GET", - url: "/admin/search", - data: "search_term=" + $(this).attr("value"), - dataType: "json", - success : function(results) { - admin_search.show_results(results); - } - }); - } - else { - $('#results').empty(); - } - }); - }, - - show_results : function(results) { - $('#results').empty(); - for (result in results) { - $('#results').append("

" + results[result].title + "

"); + display_toggle : function() { + if ($('#search_widget').css("display") != "none") { + $('#search_widget').fadeOut(); } - } -} \ No newline at end of file + else { + $('#search_widget').fadeIn(); + $('#search_term').attr("value", ""); + $('#search_term').focus(); + } + + $("#search_term").bind("keyup", function() { + if ($(this).attr("value")) { + $.ajax({ + type: "GET", + url: "/admin/search", + data: "search_term=" + $(this).attr("value"), + dataType: "json", + success : function(results) { + admin_search.show_results(results); + } + }); + } + else { + $('#search_results').slideUp(); + $('#search_results').empty(); + } + }); + }, + + show_results : function(results) { + $('#search_results').empty(); + for (result in results) { + $('#search_results').append("

" + results[result].title + "

"); + } + $('#search_results').slideDown(); + } + + } \ No newline at end of file diff --git a/public/javascripts/jquery.hotkeys.js b/public/javascripts/jquery.hotkeys.js new file mode 100755 index 0000000..9a8f2de --- /dev/null +++ b/public/javascripts/jquery.hotkeys.js @@ -0,0 +1,244 @@ +/* +(c) Copyrights 2007 - 2008 + +Original idea by by Binny V A, http://www.openjs.com/scripts/events/keyboard_shortcuts/ + +jQuery Plugin by Tzury Bar Yochay +tzury.by@gmail.com +http://evalinux.wordpress.com +http://facebook.com/profile.php?id=513676303 + +Project's sites: +http://code.google.com/p/js-hotkeys/ +http://github.com/tzuryby/hotkeys/tree/master + +License: same as jQuery license. + +USAGE: + // simple usage + $(document).bind('keydown', 'Ctrl+c', function(){ alert('copy anyone?');}); + + // special options such as disableInIput + $(document).bind('keydown', {combi:'Ctrl+x', disableInInput: true} , function() {}); + +Note: + This plugin wraps the following jQuery methods: $.fn.find, $.fn.bind and $.fn.unbind +*/ + +(function (jQuery){ + // keep reference to the original $.fn.bind, $.fn.unbind and $.fn.find + jQuery.fn.__bind__ = jQuery.fn.bind; + jQuery.fn.__unbind__ = jQuery.fn.unbind; + jQuery.fn.__find__ = jQuery.fn.find; + + var hotkeys = { + version: '0.7.9', + override: /keypress|keydown|keyup/g, + triggersMap: {}, + + specialKeys: { 27: 'esc', 9: 'tab', 32:'space', 13: 'return', 8:'backspace', 145: 'scroll', + 20: 'capslock', 144: 'numlock', 19:'pause', 45:'insert', 36:'home', 46:'del', + 35:'end', 33: 'pageup', 34:'pagedown', 37:'left', 38:'up', 39:'right',40:'down', + 109: '-', + 112:'f1',113:'f2', 114:'f3', 115:'f4', 116:'f5', 117:'f6', 118:'f7', 119:'f8', + 120:'f9', 121:'f10', 122:'f11', 123:'f12', 191: '/'}, + + shiftNums: { "`":"~", "1":"!", "2":"@", "3":"#", "4":"$", "5":"%", "6":"^", "7":"&", + "8":"*", "9":"(", "0":")", "-":"_", "=":"+", ";":":", "'":"\"", ",":"<", + ".":">", "/":"?", "\\":"|" }, + + newTrigger: function (type, combi, callback) { + // i.e. {'keyup': {'ctrl': {cb: callback, disableInInput: false}}} + var result = {}; + result[type] = {}; + result[type][combi] = {cb: callback, disableInInput: false}; + return result; + } + }; + // add firefox num pad char codes + //if (jQuery.browser.mozilla){ + // add num pad char codes + hotkeys.specialKeys = jQuery.extend(hotkeys.specialKeys, { 96: '0', 97:'1', 98: '2', 99: + '3', 100: '4', 101: '5', 102: '6', 103: '7', 104: '8', 105: '9', 106: '*', + 107: '+', 109: '-', 110: '.', 111 : '/' + }); + //} + + // a wrapper around of $.fn.find + // see more at: http://groups.google.com/group/jquery-en/browse_thread/thread/18f9825e8d22f18d + jQuery.fn.find = function( selector ) { + this.query = selector; + return jQuery.fn.__find__.apply(this, arguments); + }; + + jQuery.fn.unbind = function (type, combi, fn){ + if (jQuery.isFunction(combi)){ + fn = combi; + combi = null; + } + if (combi && typeof combi === 'string'){ + var selectorId = ((this.prevObject && this.prevObject.query) || (this[0].id && this[0].id) || this[0]).toString(); + var hkTypes = type.split(' '); + for (var x=0; x