From 9bc3f3cf304c300c758743f2e460beb1fee3ecac Mon Sep 17 00:00:00 2001 From: kondou Date: Sat, 1 Mar 2014 02:46:27 +0100 Subject: [PATCH] Scrutinizer cleanup --- core/js/avatar.js | 4 ++- core/js/compatibility.js | 3 +- core/js/eventsource.js | 12 ++++---- core/js/jquery.ocdialog.js | 16 +++++++++-- core/js/js.js | 14 +++++---- core/js/listview.js | 8 +++--- core/js/multiselect.js | 46 +++++++++++++++++++----------- core/js/oc-dialogs.js | 18 ++++++++++-- core/js/octemplate.js | 11 +++++--- core/js/setup.js | 5 +++- core/js/share.js | 50 +++++++++++++++++++-------------- core/js/singleselect.js | 4 +-- core/js/tags.js | 34 ++++++++++++++++++---- core/js/tests/specHelper.js | 3 +- core/js/tests/specs/coreSpec.js | 14 ++++----- core/js/visitortimezone.js | 3 +- 16 files changed, 166 insertions(+), 79 deletions(-) diff --git a/core/js/avatar.js b/core/js/avatar.js index 67d6b9b7b9..6835f6ef0a 100644 --- a/core/js/avatar.js +++ b/core/js/avatar.js @@ -7,7 +7,9 @@ $(document).ready(function(){ } }; - $('#header .avatardiv').avatar(OC.currentUser, 32, undefined, true, callback); + $('#header .avatardiv').avatar( + OC.currentUser, 32, undefined, true, callback + ); // Personal settings $('#avatar .avatardiv').avatar(OC.currentUser, 128); } diff --git a/core/js/compatibility.js b/core/js/compatibility.js index c07288857f..ac942d202e 100644 --- a/core/js/compatibility.js +++ b/core/js/compatibility.js @@ -42,8 +42,9 @@ if (!Array.prototype.filter) { for (var i = 0; i < len; i++) { if (i in this) { var val = this[i]; // in case fun mutates this - if (fun.call(thisp, val, i, this)) + if (fun.call(thisp, val, i, this)) { res.push(val); + } } } return res; diff --git a/core/js/eventsource.js b/core/js/eventsource.js index 70f4a2a9aa..4834653dda 100644 --- a/core/js/eventsource.js +++ b/core/js/eventsource.js @@ -20,10 +20,12 @@ */ /** - * Wrapper for server side events (http://en.wikipedia.org/wiki/Server-sent_events) + * Wrapper for server side events + * (http://en.wikipedia.org/wiki/Server-sent_events) * includes a fallback for older browsers and IE * - * Use server side events with caution, too many open requests can hang the server + * use server side events with caution, to many open requests can hang the + * server */ /** @@ -43,7 +45,7 @@ OC.EventSource=function(src,data){ dataStr+='requesttoken='+oc_requesttoken; if(!this.useFallBack && typeof EventSource !='undefined'){ var joinChar = '&'; - if(src.indexOf('?') == -1) { + if(src.indexOf('?') === -1) { joinChar = '?'; } this.source=new EventSource(src+joinChar+dataStr); @@ -60,13 +62,13 @@ OC.EventSource=function(src,data){ this.iframe.hide(); var joinChar = '&'; - if(src.indexOf('?') == -1) { + if(src.indexOf('?') === -1) { joinChar = '?'; } this.iframe.attr('src',src+joinChar+'fallback=true&fallback_id='+OC.EventSource.iframeCount+'&'+dataStr); $('body').append(this.iframe); this.useFallBack=true; - OC.EventSource.iframeCount++ + OC.EventSource.iframeCount++; } //add close listener this.listen('__internal__',function(data){ diff --git a/core/js/jquery.ocdialog.js b/core/js/jquery.ocdialog.js index e2433f5f98..af32591ce5 100644 --- a/core/js/jquery.ocdialog.js +++ b/core/js/jquery.ocdialog.js @@ -35,11 +35,18 @@ }); $(document).on('keydown keyup', function(event) { - if(event.target !== self.$dialog.get(0) && self.$dialog.find($(event.target)).length === 0) { + if ( + event.target !== self.$dialog.get(0) && + self.$dialog.find($(event.target)).length === 0 + ) { return; } // Escape - if(event.keyCode === 27 && event.type === 'keydown' && self.options.closeOnEscape) { + if ( + event.keyCode === 27 && + event.type === 'keydown' && + self.options.closeOnEscape + ) { event.stopImmediatePropagation(); self.close(); return false; @@ -52,7 +59,10 @@ return false; } // If no button is selected we trigger the primary - if(self.$buttonrow && self.$buttonrow.find($(event.target)).length === 0) { + if ( + self.$buttonrow && + self.$buttonrow.find($(event.target)).length === 0 + ) { var $button = self.$buttonrow.find('button.primary'); if($button) { $button.trigger('click'); diff --git a/core/js/js.js b/core/js/js.js index a859034ed0..51878cb913 100644 --- a/core/js/js.js +++ b/core/js/js.js @@ -1,7 +1,7 @@ /** * Disable console output unless DEBUG mode is enabled. * Add - * define('DEBUG', true); + * define('DEBUG', true); * To the end of config/config.php to enable debug mode. * The undefined checks fix the broken ie8 console */ @@ -23,7 +23,10 @@ if (typeof oc_webroot === "undefined") { oc_webroot = oc_webroot.substr(0, oc_webroot.lastIndexOf('/')); } } -if (oc_debug !== true || typeof console === "undefined" || typeof console.log === "undefined") { +if ( + oc_debug !== true || typeof console === "undefined" || + typeof console.log === "undefined" +) { if (!window.console) { window.console = {}; } @@ -37,7 +40,8 @@ if (oc_debug !== true || typeof console === "undefined" || typeof console.log == function initL10N(app) { if (!( t.cache[app] )) { $.ajax(OC.filePath('core', 'ajax', 'translations.php'), { - async: false,//todo a proper solution for this without sync ajax calls + // TODO a proper solution for this without sync ajax calls + async: false, data: {'app': app}, type: 'POST', success: function (jsondata) { @@ -75,8 +79,8 @@ function initL10N(app) { /* We used to use eval, but it seems IE has issues with it. * We now use "new Function", though it carries a slightly * bigger performance hit. - var code = 'function (n) { var plural; var nplurals; '+pf+' return { "nplural" : nplurals, "plural" : (plural === true ? 1 : plural ? plural : 0) }; };'; - Gettext._locale_data[domain].head.plural_func = eval("("+code+")"); + var code = 'function (n) { var plural; var nplurals; '+pf+' return { "nplural" : nplurals, "plural" : (plural === true ? 1 : plural ? plural : 0) }; };'; + Gettext._locale_data[domain].head.plural_func = eval("("+code+")"); */ var code = 'var plural; var nplurals; '+pf+' return { "nplural" : nplurals, "plural" : (plural === true ? 1 : plural ? plural : 0) };'; t.plural_function[app] = new Function("n", code); diff --git a/core/js/listview.js b/core/js/listview.js index 18d0bdeaf7..239792d634 100644 --- a/core/js/listview.js +++ b/core/js/listview.js @@ -46,7 +46,7 @@ ListView.prototype={ $.each(this.hoverElement,function(index,collumn){ $.each(collumn,function(index,element){ var html=''; - var element=$(html); + element=$(html); element.append($('')); element.click(element.callback); tr.children('td.'+collumn).append(element); @@ -59,9 +59,9 @@ ListView.prototype={ hoverHandelerOut:function(tr){ tr.find('*.hoverElement').remove(); }, - addHoverElement:function(collumn,icon,title,callback){ - if(!this.hoverElements[collumn]){ - this.hoverElements[collumn]=[]; + addHoverElement:function(column,icon,title,callback){ + if(!this.hoverElements[column]){ + this.hoverElements[column]=[]; } this.hoverElements[row].push({icon:icon,callback:callback,title:title}); }, diff --git a/core/js/multiselect.js b/core/js/multiselect.js index 02699636a2..03408033db 100644 --- a/core/js/multiselect.js +++ b/core/js/multiselect.js @@ -1,14 +1,19 @@ /** - * @param 'createCallback' A function to be called when a new entry is created. Two arguments are supplied to this function: - * The select element used and the value of the option. If the function returns false addition will be cancelled. If it returns - * anything else it will be used as the value of the newly added option. + * @param 'createCallback' A function to be called when a new entry is created. + * Two arguments are supplied to this function: + * The select element used and the value of the option. If the function + * returns false addition will be cancelled. If it returns + * anything else it will be used as the value of the newly added option. * @param 'createText' The placeholder text for the create action. * @param 'title' The title to show if no options are selected. - * @param 'checked' An array containing values for options that should be checked. Any options which are already selected will be added to this array. + * @param 'checked' An array containing values for options that should be + * checked. Any options which are already selected will be added to this array. * @param 'labels' The corresponding labels to show for the checked items. - * @param 'oncheck' Callback function which will be called when a checkbox/radiobutton is selected. If the function returns false the input will be unchecked. + * @param 'oncheck' Callback function which will be called when a + * checkbox/radiobutton is selected. If the function returns false the input will be unchecked. * @param 'onuncheck' @see 'oncheck'. - * @param 'singleSelect' If true radiobuttons will be used instead of checkboxes. + * @param 'singleSelect' If true radiobuttons will be used instead of + * checkboxes. */ (function( $ ){ var multiSelectId=-1; @@ -32,12 +37,18 @@ $.extend(settings,options); $.each(this.children(),function(i,option) { // If the option is selected, but not in the checked array, add it. - if($(option).attr('selected') && settings.checked.indexOf($(option).val()) === -1) { + if ( + $(option).attr('selected') && + settings.checked.indexOf($(option).val()) === -1 + ) { settings.checked.push($(option).val()); settings.labels.push($(option).text().trim()); } // If the option is in the checked array but not selected, select it. - else if(settings.checked.indexOf($(option).val()) !== -1 && !$(option).attr('selected')) { + else if ( + settings.checked.indexOf($(option).val()) !== -1 && + !$(option).attr('selected') + ) { $(option).attr('selected', 'selected'); settings.labels.push($(option).text().trim()); } @@ -104,7 +115,7 @@ var label=$('