From 518311ff61e6de169ca806f0b6cec519b32c5ddf Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Sat, 30 Nov 2013 00:09:15 +0100 Subject: [PATCH] Optimalization: some JS tweaks - Removed redundant function - Using .preventDefault instead of return calls in some places --- public_html/media/js/core.js | 33 +++++++-------------------------- 1 file changed, 7 insertions(+), 26 deletions(-) diff --git a/public_html/media/js/core.js b/public_html/media/js/core.js index eb760fcf..2d7123c5 100644 --- a/public_html/media/js/core.js +++ b/public_html/media/js/core.js @@ -38,23 +38,6 @@ $.fn.hasAttr = function(name) return this.attr(name) !== undefined; }; -if ($.when.all === undefined) -{ - $.when.all = function(deferreds) - { - var deferred = new $.Deferred(); - $.when.apply($, deferreds).then(function() - { - deferred.resolve(Array.prototype.slice.call(arguments, 0)); - }, function() - { - deferred.fail(Array.prototype.slice.call(arguments, 0)); - }); - - return deferred; - } -} - //safety trigger @@ -220,19 +203,19 @@ $(function() response($.map(data.tags, function(tag) { return { label: tag.name + ' (' + tag.count + ')', value: tag.name }; })); }); }, - focus: function() + focus: function(e) { // prevent value inserted on focus - return false; + e.preventDefault(); }, - select: function(event, ui) + select: function(e, ui) { + e.preventDefault(); var terms = split(this.value); terms.pop(); terms.push(ui.item.value); terms.push(''); this.value = terms.join(' '); - return false; } }; @@ -248,12 +231,10 @@ $(function() var searchInput = $(this); searchInput // don't navigate away from the field on tab when selecting an item - .bind('keydown', function(event) + .bind('keydown', function(e) { - if (event.keyCode === $.ui.keyCode.TAB && $(this).data('autocomplete').menu.active) - { - event.preventDefault(); - } + if (e.keyCode === $.ui.keyCode.TAB && $(this).data('autocomplete').menu.active) + e.preventDefault(); }).autocomplete(options); }); });