active_frontend 14.1.1 → 14.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1c3b97b53a0ddbad1b889259ec427f701c00201d
4
- data.tar.gz: e17f9b1a1570aebd11bcdc8747d262612df52340
3
+ metadata.gz: 54ae884c7b36e63cd8093ebd2b95d713c7e99eb4
4
+ data.tar.gz: 5b27ffda4450e3e1fd1417aee92463a7b2caea81
5
5
  SHA512:
6
- metadata.gz: 023c3a747ff9f1f52c371ac921a4a0b5900497711185abcc2445fbff03df7ae4c125ebd372c720e223d90299b7af459c2e36d4a9d3864c1874801aa5b7a86ea6
7
- data.tar.gz: bc5106115322f6f64a2a746fd9da5179fcb8deecd153b89431f4dc1b23cbb75feb556fa6c3a7a7a66b15cc74b34a17c0c1e28ba68631c232fa456bff447ef8d0
6
+ metadata.gz: 67a1f2577e4d40d8d12feb427de798aeb0fb4c3cfe2bd0ef9ddf2890bdb21c7534ea6d020c4a077a43d40e553c10fd94514180f1e62cdeed535fae2aa91c0142
7
+ data.tar.gz: eddc376a922967285c7b7cea2b0a9b4471987a7f2f0ce3bdddb1c84d12e85e35b436451bf138a132b68dd3e479a5bee9c84e45ad7f6c2b0734d319e02e6b1431
@@ -1,3 +1,3 @@
1
1
  module ActiveFrontend
2
- VERSION = '14.1.1'.freeze
2
+ VERSION = '14.1.2'.freeze
3
3
  end
@@ -39,6 +39,7 @@
39
39
  //
40
40
  // Extensions Imports
41
41
  // ==================================================
42
+ //= require extensions/_antiblocker
42
43
  //= require extensions/_calendar
43
44
  //= require extensions/_chart
44
45
  //= require extensions/_cohort
@@ -39,6 +39,7 @@
39
39
  //
40
40
  // Extensions Imports
41
41
  // ==================================================
42
+ //= require extensions/_antiblocker
42
43
  //= require extensions/_calendar
43
44
  //= require extensions/_chart
44
45
  //= require extensions/_cohort
@@ -0,0 +1,255 @@
1
+ (function (window) {
2
+ var AntiBlocker = function (options) {
3
+ this._options = {
4
+ checkOnLoad: false,
5
+ resetOnEnd: false,
6
+ loopCheckTime: 50,
7
+ loopMaxNumber: 5,
8
+ baitClass: 'pub_300x250 pub_300x250m pub_728x90 text-ad textAd text_ad text_ads text-ads text-ad-links _ads',
9
+ baitStyle: 'width: 1px !important; height: 1px !important; position: absolute !important; left: -10000px !important; top: -1000px !important;',
10
+ debug: false
11
+ };
12
+ this._var = {
13
+ version: '1.0.0',
14
+ bait: null,
15
+ checking: false,
16
+ loop: null,
17
+ loopNumber: 0,
18
+ event: {
19
+ detected: [],
20
+ notDetected: []
21
+ }
22
+ };
23
+
24
+ if (options !== undefined) this.setOption(options);
25
+
26
+ var self = this;
27
+ var eventCallback = function () {
28
+ setTimeout(function () {
29
+ if (self._options.checkOnLoad === true) {
30
+ if (self._options.debug === true) {
31
+ self._log('onload -> eventCallback', 'A check loading is launched');
32
+ }
33
+ if (self._var.bait === null) {
34
+ self._creatBait();
35
+ }
36
+ setTimeout(function () {
37
+ self.check();
38
+ }, 1);
39
+ }
40
+ }, 1);
41
+ };
42
+
43
+ if (window.addEventListener !== undefined) {
44
+ window.addEventListener('load', eventCallback, false);
45
+ } else {
46
+ window.attachEvent('onload', eventCallback);
47
+ }
48
+ };
49
+
50
+ AntiBlocker.prototype._options = null;
51
+ AntiBlocker.prototype._var = null;
52
+ AntiBlocker.prototype._bait = null;
53
+
54
+ AntiBlocker.prototype._log = function (method, message) {
55
+ console.log('[AntiBlocker][' + method + '] ' + message);
56
+ };
57
+
58
+ AntiBlocker.prototype.setOption = function (options, value) {
59
+ if (value !== undefined) {
60
+ var key = options;
61
+ options = {};
62
+ options[key] = value;
63
+ }
64
+
65
+ for(var option in options) {
66
+ this._options[option] = options[option];
67
+
68
+ if (this._options.debug === true) {
69
+ this._log('setOption', 'The option "' + option + '" was assigned to "' + options[option] + '"');
70
+ }
71
+ }
72
+
73
+ return this;
74
+ };
75
+
76
+ AntiBlocker.prototype._creatBait = function () {
77
+ var bait = document.createElement('div');
78
+ bait.setAttribute('class', this._options.baitClass);
79
+ bait.setAttribute('style', this._options.baitStyle);
80
+ this._var.bait = window.document.body.appendChild(bait);
81
+
82
+ this._var.bait.offsetParent;
83
+ this._var.bait.offsetHeight;
84
+ this._var.bait.offsetLeft;
85
+ this._var.bait.offsetTop;
86
+ this._var.bait.offsetWidth;
87
+ this._var.bait.clientHeight;
88
+ this._var.bait.clientWidth;
89
+
90
+ if (this._options.debug === true) {
91
+ this._log('_creatBait', 'Bait has been created');
92
+ }
93
+ };
94
+
95
+ AntiBlocker.prototype._destroyBait = function () {
96
+ window.document.body.removeChild(this._var.bait);
97
+ this._var.bait = null;
98
+
99
+ if (this._options.debug === true) {
100
+ this._log('_destroyBait', 'Bait has been removed');
101
+ }
102
+ };
103
+
104
+ AntiBlocker.prototype.check = function (loop) {
105
+ if (loop === undefined) {
106
+ loop = true;
107
+ }
108
+
109
+ if (this._options.debug === true) {
110
+ this._log('check', 'An audit was requested ' + (loop ===true ? 'with a' : 'without') + ' loop');
111
+ }
112
+
113
+ if (this._var.checking === true) {
114
+ if (this._options.debug === true) {
115
+ this._log('check', 'A check was canceled because there is already an ongoing check');
116
+ }
117
+
118
+ return false;
119
+ }
120
+
121
+ this._var.checking = true;
122
+
123
+ if (this._var.bait === null) this._creatBait();
124
+
125
+ var self = this;
126
+ this._var.loopNumber = 0;
127
+
128
+ if (loop === true) {
129
+ this._var.loop = setInterval(function () {
130
+ self._checkBait(loop);
131
+ }, this._options.loopCheckTime);
132
+ }
133
+
134
+ setTimeout(function () {
135
+ self._checkBait(loop);
136
+ }, 1);
137
+ if (this._options.debug === true) {
138
+ this._log('check', 'A check is in progress ...');
139
+ }
140
+
141
+ return true;
142
+ };
143
+
144
+ AntiBlocker.prototype._checkBait = function (loop) {
145
+ var detected = false;
146
+
147
+ if (this._var.bait === null) this._creatBait();
148
+
149
+ if (window.document.body.getAttribute('abp') !== null ||
150
+ this._var.bait.offsetParent === null ||
151
+ this._var.bait.offsetHeight === 0 ||
152
+ this._var.bait.offsetLeft === 0 ||
153
+ this._var.bait.offsetTop === 0 ||
154
+ this._var.bait.offsetWidth === 0 ||
155
+ this._var.bait.clientHeight === 0 ||
156
+ this._var.bait.clientWidth === 0) {
157
+ detected = true;
158
+ }
159
+
160
+ if (window.getComputedStyle !== undefined) {
161
+ var baitTemp = window.getComputedStyle(this._var.bait, null);
162
+
163
+ if (baitTemp && (baitTemp.getPropertyValue('display') == 'none' || baitTemp.getPropertyValue('visibility') == 'hidden')) {
164
+ detected = true;
165
+ }
166
+ }
167
+
168
+ if (this._options.debug === true) {
169
+ this._log('_checkBait', 'A check ('+(this._var.loopNumber+1)+'/'+this._options.loopMaxNumber+' ~'+(1+this._var.loopNumber*this._options.loopCheckTime)+'ms) was conducted and detection is '+(detected===true?'positive':'negative'));
170
+ }
171
+
172
+ if (loop === true) {
173
+ this._var.loopNumber++;
174
+
175
+ if (this._var.loopNumber >= this._options.loopMaxNumber) this._stopLoop();
176
+ }
177
+
178
+ if (detected === true) {
179
+ this._stopLoop();
180
+ this._destroyBait();
181
+ this.emitEvent(true);
182
+
183
+ if (loop === true) {
184
+ this._var.checking = false;
185
+ }
186
+ } else if (this._var.loop === null || loop === false) {
187
+ this._destroyBait();
188
+ this.emitEvent(false);
189
+
190
+ if (loop === true) {
191
+ this._var.checking = false;
192
+ }
193
+ }
194
+ };
195
+
196
+ AntiBlocker.prototype._stopLoop = function (detected) {
197
+ clearInterval(this._var.loop);
198
+ this._var.loop = null;
199
+ this._var.loopNumber = 0;
200
+
201
+ if (this._options.debug === true) {
202
+ this._log('_stopLoop', 'A loop has been stopped');
203
+ }
204
+ };
205
+
206
+ AntiBlocker.prototype.emitEvent = function (detected) {
207
+ if (this._options.debug === true) {
208
+ this._log('emitEvent', 'An event with a ' + (detected === true ? 'positive' : 'negative') + ' detection was called');
209
+ }
210
+
211
+ var fns = this._var.event[(detected === true ? 'detected' : 'notDetected')];
212
+
213
+ for(var i in fns) {
214
+ if (this._options.debug === true) {
215
+ this._log('emitEvent', 'Call function '+(parseInt(i)+1)+'/'+fns.length);
216
+ }
217
+
218
+ if (fns.hasOwnProperty(i)) {
219
+ fns[i]();
220
+ }
221
+ }
222
+
223
+ if (this._options.resetOnEnd === true) this.clearEvent();
224
+ return this;
225
+ };
226
+
227
+ AntiBlocker.prototype.clearEvent = function () {
228
+ this._var.event.detected = [];
229
+ this._var.event.notDetected = [];
230
+
231
+ if (this._options.debug === true) {
232
+ this._log('clearEvent', 'The event list has been cleared');
233
+ }
234
+ };
235
+
236
+ AntiBlocker.prototype.on = function (detected, fn) {
237
+ this._var.event[(detected === true ? 'detected' : 'notDetected')].push(fn);
238
+
239
+ if (this._options.debug === true) {
240
+ this._log('on', 'A type of event "'+(detected === true ? 'detected' : 'notDetected') + '" was added');
241
+ }
242
+
243
+ return this;
244
+ };
245
+
246
+ AntiBlocker.prototype.onDetected = function (fn) {
247
+ return this.on(true, fn);
248
+ };
249
+
250
+ AntiBlocker.prototype.onNotDetected = function (fn) {
251
+ return this.on(false, fn);
252
+ };
253
+
254
+ window.AntiBlocker = AntiBlocker;
255
+ })(window);
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_frontend
3
3
  version: !ruby/object:Gem::Version
4
- version: 14.1.1
4
+ version: 14.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juan Gomez
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-06-22 00:00:00.000000000 Z
11
+ date: 2017-06-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -246,6 +246,7 @@ files:
246
246
  - vendor/assets/javascripts/base/_tour.js
247
247
  - vendor/assets/javascripts/base/_transition.js
248
248
  - vendor/assets/javascripts/base/_typeahead.js
249
+ - vendor/assets/javascripts/extensions/_antiblocker.js
249
250
  - vendor/assets/javascripts/extensions/_calendar.js
250
251
  - vendor/assets/javascripts/extensions/_chart.js
251
252
  - vendor/assets/javascripts/extensions/_cohort.js