X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fcore%2Fmisc%2Fdrupal.js;h=4e3389358e14ddc3acc33c4220ad0cb1e80b9639;hb=0bf8d09d2542548982e81a441b1f16e75873a04f;hp=f0c2b72243f75a53877b093f9d2dbe0076fde103;hpb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;p=yaffs-website diff --git a/web/core/misc/drupal.js b/web/core/misc/drupal.js index f0c2b7224..4e3389358 100644 --- a/web/core/misc/drupal.js +++ b/web/core/misc/drupal.js @@ -19,15 +19,15 @@ window.Drupal = { behaviors: {}, locale: {} }; settings = settings || drupalSettings; var behaviors = Drupal.behaviors; - for (var i in behaviors) { - if (behaviors.hasOwnProperty(i) && typeof behaviors[i].attach === 'function') { + Object.keys(behaviors || {}).forEach(function (i) { + if (typeof behaviors[i].attach === 'function') { try { behaviors[i].attach(context, settings); } catch (e) { Drupal.throwError(e); } } - } + }); }; Drupal.detachBehaviors = function (context, settings, trigger) { @@ -36,15 +36,15 @@ window.Drupal = { behaviors: {}, locale: {} }; trigger = trigger || 'unload'; var behaviors = Drupal.behaviors; - for (var i in behaviors) { - if (behaviors.hasOwnProperty(i) && typeof behaviors[i].detach === 'function') { + Object.keys(behaviors || {}).forEach(function (i) { + if (typeof behaviors[i].detach === 'function') { try { behaviors[i].detach(context, settings, trigger); } catch (e) { Drupal.throwError(e); } } - } + }); }; Drupal.checkPlain = function (str) { @@ -55,23 +55,21 @@ window.Drupal = { behaviors: {}, locale: {} }; Drupal.formatString = function (str, args) { var processedArgs = {}; - for (var key in args) { - if (args.hasOwnProperty(key)) { - switch (key.charAt(0)) { - case '@': - processedArgs[key] = Drupal.checkPlain(args[key]); - break; + Object.keys(args || {}).forEach(function (key) { + switch (key.charAt(0)) { + case '@': + processedArgs[key] = Drupal.checkPlain(args[key]); + break; - case '!': - processedArgs[key] = args[key]; - break; + case '!': + processedArgs[key] = args[key]; + break; - default: - processedArgs[key] = Drupal.theme('placeholder', args[key]); - break; - } + default: + processedArgs[key] = Drupal.theme('placeholder', args[key]); + break; } - } + }); return Drupal.stringReplace(str, processedArgs, null); }; @@ -82,12 +80,7 @@ window.Drupal = { behaviors: {}, locale: {} }; } if (!Array.isArray(keys)) { - keys = []; - for (var k in args) { - if (args.hasOwnProperty(k)) { - keys.push(k); - } - } + keys = Object.keys(args || {}); keys.sort(function (a, b) { return a.length - b.length; @@ -142,12 +135,12 @@ window.Drupal = { behaviors: {}, locale: {} }; Drupal.url.isLocal = function (url) { var absoluteUrl = Drupal.url.toAbsolute(url); - var protocol = location.protocol; + var protocol = window.location.protocol; if (protocol === 'http:' && absoluteUrl.indexOf('https:') === 0) { protocol = 'https:'; } - var baseUrl = protocol + '//' + location.host + drupalSettings.path.baseUrl.slice(0, -1); + var baseUrl = protocol + '//' + window.location.host + drupalSettings.path.baseUrl.slice(0, -1); try { absoluteUrl = decodeURIComponent(absoluteUrl); @@ -181,9 +174,14 @@ window.Drupal = { behaviors: {}, locale: {} }; }; Drupal.theme = function (func) { - var args = Array.prototype.slice.apply(arguments, [1]); if (func in Drupal.theme) { - return Drupal.theme[func].apply(this, args); + var _Drupal$theme; + + for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { + args[_key - 1] = arguments[_key]; + } + + return (_Drupal$theme = Drupal.theme)[func].apply(_Drupal$theme, args); } };