Pathologic was missing because of a .git folder inside.
[yaffs-website] / web / modules / contrib / advagg / advagg.admin.js
1 /**
2  * @file
3  * Used to toggle the AdvAgg Bypass Cookie client side.
4  */
5
6 /* global Drupal:false */
7
8 /**
9  * Test to see if the given string contains unicode.
10  *
11  * @param int interval
12  *   String to test.
13  * @param int granularity
14  *   String to test.
15  * @param string langcode
16  *   Language used in translation.
17  *
18  * @return
19  *   true if string contains non ASCII characters.
20  *   false if string only contains ASCII characters.
21  */
22 Drupal.formatInterval = function (interval, granularity, langcode) {
23   'use strict';
24   granularity = typeof granularity !== 'undefined' ? granularity : 2;
25   var output = '';
26
27   while (granularity > 0) {
28     var value = 0;
29     if (interval >= 31536000) {
30       value = 31536000;
31       output += (output.length ? ' ' : '') + Drupal.formatPlural(Math.floor(interval / value), '1 year', '@count years');
32     }
33     else if (interval >= 2592000) {
34       value = 2592000;
35       output += (output.length ? ' ' : '') + Drupal.formatPlural(Math.floor(interval / value), '1 month', '@count months');
36     }
37     else if (interval >= 604800) {
38       value = 604800;
39       output += (output.length ? ' ' : '') + Drupal.formatPlural(Math.floor(interval / value), '1 week', '@count weeks');
40     }
41     else if (interval >= 86400) {
42       value = 86400;
43       output += (output.length ? ' ' : '') + Drupal.formatPlural(Math.floor(interval / value), '1 day', '@count days');
44     }
45     else if (interval >= 3600) {
46       value = 3600;
47       output += (output.length ? ' ' : '') + Drupal.formatPlural(Math.floor(interval / value), '1 hour', '@count hours');
48     }
49     else if (interval >= 60) {
50       value = 60;
51       output += (output.length ? ' ' : '') + Drupal.formatPlural(Math.floor(interval / value), '1 min', '@count min');
52     }
53     else if (interval >= 1) {
54       value = 1;
55       output += (output.length ? ' ' : '') + Drupal.formatPlural(Math.floor(interval / value), '1 sec', '@count sec');
56     }
57
58     interval %= value;
59     granularity--;
60   }
61
62   return output.length ? output : Drupal.t('0 sec', {});
63 };
64
65 /**
66  * Test to see if the given string contains unicode.
67  *
68  * @param str
69  *   String to test.
70  *
71  * @return
72  *   true if string contains non ASCII characters.
73  *   false if string only contains ASCII characters.
74  */
75 function advagg_is_unicode(str) {
76   'use strict';
77   for (var i = 0, n = str.length; i < n; i++) {
78     if (str.charCodeAt(i) > 255) {
79       return true;
80     }
81   }
82   return false;
83 }
84
85 /**
86  * Toggle the advagg cookie.
87  *
88  * @return
89  *   true if hostname contains unicode.
90  *   false so the form does not get submitted.
91  */
92 function advagg_toggle_cookie() {
93   'use strict';
94   // Fallback to submitting the form for Unicode domains like ".рф".
95   if (advagg_is_unicode(document.location.hostname)) {
96     return true;
97   }
98
99   var cookie_name = 'AdvAggDisabled';
100
101   // See if the cookie exists.
102   var cookie_pos = document.cookie.indexOf(cookie_name + '=' + drupalSettings.advagg.key);
103
104   // If the cookie does exist then remove it.
105   if (cookie_pos !== -1) {
106     document.cookie = cookie_name + '=;'
107       + 'expires=Thu, 01 Jan 1970 00:00:00 GMT;'
108       + ' path=' + drupalSettings.path.baseUrl + ';'
109       + ' domain=.' + document.location.hostname + ';';
110     alert(Drupal.t('AdvAgg Bypass Cookie Removed'));
111   }
112   // If the cookie does not exist then set it.
113   else {
114     var bypass_length = document.getElementById('edit-timespan').value, expire_date = new Date(new Date().getTime() + bypass_length * 1000);
115
116     document.cookie = cookie_name + '=' + drupalSettings.advagg.key + ';'
117       + ' expires=' + expire_date.toGMTString() + ';'
118       + ' path=' + drupalSettings.path.baseUrl + ';'
119       + ' domain=.' + document.location.hostname + ';';
120     alert(Drupal.t('AdvAgg Bypass Cookie Set for @time.', {'@time' : Drupal.formatInterval(bypass_length)}));
121   }
122
123   // Must return false, if returning true then form gets submitted.
124   return false;
125 }