Security update to Drupal 8.4.6
[yaffs-website] / web / core / misc / drupal.js
1 /**
2 * DO NOT EDIT THIS FILE.
3 * See the following change record for more information,
4 * https://www.drupal.org/node/2815083
5 * @preserve
6 **/
7
8 window.Drupal = { behaviors: {}, locale: {} };
9
10 (function (Drupal, drupalSettings, drupalTranslations) {
11   Drupal.throwError = function (error) {
12     setTimeout(function () {
13       throw error;
14     }, 0);
15   };
16
17   Drupal.attachBehaviors = function (context, settings) {
18     context = context || document;
19     settings = settings || drupalSettings;
20     var behaviors = Drupal.behaviors;
21
22     for (var i in behaviors) {
23       if (behaviors.hasOwnProperty(i) && typeof behaviors[i].attach === 'function') {
24         try {
25           behaviors[i].attach(context, settings);
26         } catch (e) {
27           Drupal.throwError(e);
28         }
29       }
30     }
31   };
32
33   Drupal.detachBehaviors = function (context, settings, trigger) {
34     context = context || document;
35     settings = settings || drupalSettings;
36     trigger = trigger || 'unload';
37     var behaviors = Drupal.behaviors;
38
39     for (var i in behaviors) {
40       if (behaviors.hasOwnProperty(i) && typeof behaviors[i].detach === 'function') {
41         try {
42           behaviors[i].detach(context, settings, trigger);
43         } catch (e) {
44           Drupal.throwError(e);
45         }
46       }
47     }
48   };
49
50   Drupal.checkPlain = function (str) {
51     str = str.toString().replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&#39;');
52     return str;
53   };
54
55   Drupal.formatString = function (str, args) {
56     var processedArgs = {};
57
58     for (var key in args) {
59       if (args.hasOwnProperty(key)) {
60         switch (key.charAt(0)) {
61           case '@':
62             processedArgs[key] = Drupal.checkPlain(args[key]);
63             break;
64
65           case '!':
66             processedArgs[key] = args[key];
67             break;
68
69           default:
70             processedArgs[key] = Drupal.theme('placeholder', args[key]);
71             break;
72         }
73       }
74     }
75
76     return Drupal.stringReplace(str, processedArgs, null);
77   };
78
79   Drupal.stringReplace = function (str, args, keys) {
80     if (str.length === 0) {
81       return str;
82     }
83
84     if (!Array.isArray(keys)) {
85       keys = [];
86       for (var k in args) {
87         if (args.hasOwnProperty(k)) {
88           keys.push(k);
89         }
90       }
91
92       keys.sort(function (a, b) {
93         return a.length - b.length;
94       });
95     }
96
97     if (keys.length === 0) {
98       return str;
99     }
100
101     var key = keys.pop();
102     var fragments = str.split(key);
103
104     if (keys.length) {
105       for (var i = 0; i < fragments.length; i++) {
106         fragments[i] = Drupal.stringReplace(fragments[i], args, keys.slice(0));
107       }
108     }
109
110     return fragments.join(args[key]);
111   };
112
113   Drupal.t = function (str, args, options) {
114     options = options || {};
115     options.context = options.context || '';
116
117     if (typeof drupalTranslations !== 'undefined' && drupalTranslations.strings && drupalTranslations.strings[options.context] && drupalTranslations.strings[options.context][str]) {
118       str = drupalTranslations.strings[options.context][str];
119     }
120
121     if (args) {
122       str = Drupal.formatString(str, args);
123     }
124     return str;
125   };
126
127   Drupal.url = function (path) {
128     return drupalSettings.path.baseUrl + drupalSettings.path.pathPrefix + path;
129   };
130
131   Drupal.url.toAbsolute = function (url) {
132     var urlParsingNode = document.createElement('a');
133
134     try {
135       url = decodeURIComponent(url);
136     } catch (e) {}
137
138     urlParsingNode.setAttribute('href', url);
139
140     return urlParsingNode.cloneNode(false).href;
141   };
142
143   Drupal.url.isLocal = function (url) {
144     var absoluteUrl = Drupal.url.toAbsolute(url);
145     var protocol = location.protocol;
146
147     if (protocol === 'http:' && absoluteUrl.indexOf('https:') === 0) {
148       protocol = 'https:';
149     }
150     var baseUrl = protocol + '//' + location.host + drupalSettings.path.baseUrl.slice(0, -1);
151
152     try {
153       absoluteUrl = decodeURIComponent(absoluteUrl);
154     } catch (e) {}
155     try {
156       baseUrl = decodeURIComponent(baseUrl);
157     } catch (e) {}
158
159     return absoluteUrl === baseUrl || absoluteUrl.indexOf(baseUrl + '/') === 0;
160   };
161
162   Drupal.formatPlural = function (count, singular, plural, args, options) {
163     args = args || {};
164     args['@count'] = count;
165
166     var pluralDelimiter = drupalSettings.pluralDelimiter;
167     var translations = Drupal.t(singular + pluralDelimiter + plural, args, options).split(pluralDelimiter);
168     var index = 0;
169
170     if (typeof drupalTranslations !== 'undefined' && drupalTranslations.pluralFormula) {
171       index = count in drupalTranslations.pluralFormula ? drupalTranslations.pluralFormula[count] : drupalTranslations.pluralFormula.default;
172     } else if (args['@count'] !== 1) {
173       index = 1;
174     }
175
176     return translations[index];
177   };
178
179   Drupal.encodePath = function (item) {
180     return window.encodeURIComponent(item).replace(/%2F/g, '/');
181   };
182
183   Drupal.theme = function (func) {
184     var args = Array.prototype.slice.apply(arguments, [1]);
185     if (func in Drupal.theme) {
186       return Drupal.theme[func].apply(this, args);
187     }
188   };
189
190   Drupal.theme.placeholder = function (str) {
191     return '<em class="placeholder">' + Drupal.checkPlain(str) + '</em>';
192   };
193 })(Drupal, window.drupalSettings, window.drupalTranslations);