PageSourceSearch

https://www.themoneypages.com/wp-content/plugins/yeloni-free-exit-popup/client/dist/client.min.js?ver=6.8.1

js themoneypages.com collected 2026-09-24 22:20:42 UTC 108,782 bytes, 2,632 lines download raw bytes

1var Autience = null
2
3window.defineAutience = function (autience_callback) {
4
5    var cycle = null,
6        lifecycle = null
7
8    var lifecycles = ['displayValidation', 'onPageLoad', 'render', 'postRender', 'display', 'beforeClose', 'close', 'afterClose']
9
10    if (Autience != null) {
11        return
12    }
13
14    Autience = {
15        lifecycle: {},
16        utils: {},
17        listeners: [],
18        emitted: {},
19        executors: {},
20        lifecycle_executed: false,
21        yeloniTriggerPopup: function (widget_id) {
22            var matching_widget = Autience.setup.widgets.filter(function (widget) {
23                return widget.code == widget_id
24            })
25            if (matching_widget.length > 0) {
26                matching_widget = matching_widget[0]
27            }
28            console.log('Triggering matching popup from customjs event')
29            Autience.executors.displayWidget(matching_widget)
30
31        },
32        yeloniTriggerAllPopups: function () {
33            console.log('Triggering all popups from customjs event')
34            Autience.setup.widgets.map(function (widget) {
35                Autience.executors.displayWidget(widget)
36            })
37        }
38    }
39
40    lifecycles.forEach(function (l) {
41
42        Autience.lifecycle[l] = [function () {
43            //console.log('in ' + l + ' lifecycle')
44            return true
45        }]
46    })
47
48
49
50    //simple functions with no dependencies
51    Autience.executors.defineUtils = function () {
52
53        //1. Ajax object - shifted to common
54
55        //2b. autience utils sendEvent
56        Autience.utils.sendEvent = function (event, data) {
57
58            return
59
60            //Disabled Event Logging
61            var now = Math.round(new Date().getTime() / 1000);
62            // var ten_minutes = 10 * 60
63            var six_hours = 6 * 60 * 60
64            var created = Autience.utils.nestedValue(Autience, ['setup', 'first_widget_time']);
65            var time_gap = now - created
66            var like_text = 'popup_day_'
67
68
69            //send popup liked event after 1 day
70            if (event == 'popup_liked') {
71                var one_day = 1 * 24 * 60 * 60,
72                    days_limit = 7,
73                    sent_array = []
74
75                var widget_time = data.widget_time
76                time_gap = now - widget_time
77                if (widget_time && time_gap > 0) {
78                    var day = Math.ceil(time_gap / one_day)
79                    //if day is not present in sent_array -> send event for the day and add it to the array
80                    if (sent_array.indexOf(day) < 0 && day <= days_limit) {
81                        window.yetience.sendEvent(like_text + day, Autience.setup.id, data)
82                        sent_array.push(day)
83                    }
84                }
85            } else {
86                //logging client events only for 10 minutes after popup creation
87                if (created && time_gap > 0 && time_gap < six_hours) {
88                    // console.log('fresh widget, sending event')
89                    if (Autience.setup && Autience.setup.id) {
90                        window.yetience.sendEvent(event, Autience.setup.id, data)
91                    }
92                }
93            }
94        }
95
96        //3a. emitAutienceEvent
97        Autience.utils.emitAutienceEvent = function (eventName, forget) {
98            eventName = "autience_" + eventName
99            //only emit if this event was not already emitted
100            if (!Autience.emitted[eventName]) {
101                var event; // The custom event that will be created
102                if (document.createEvent) {
103                    event = document.createEvent("HTMLEvents");
104                    event.initEvent(eventName, true, true);
105                } else {
106                    event = document.createEventObject();
107                    event.eventType = eventName;
108                }
109
110                event.eventName = eventName;
111
112                if (document.createEvent) {
113                    document.dispatchEvent(event);
114                } else {
115                    document.fireEvent("on" + event.eventType, event);
116                }
117                if (eventName == 'autience_load' || eventName == 'autience_exit') {
118                    //Autience.utils.sendEvent('client_' + eventName + '_triggered')
119                }
120
121                //console.log('emitting - '+eventName)
122                if (!forget) {
123                    //this event can happen only once on the page
124                    Autience.emitted[eventName] = true
125                }
126            }
127        }
128
129
130        //3b. listenAutienceEvent
131        Autience.utils.listenAutienceEvent = function (eventName, fn) {
132            var autience_event = "autience_" + eventName
133            Autience.utils.listen(document, autience_event, fn)
134        }
135
136        //3c. delayed Listener
137        Autience.utils.delayedListenAutienceEvent = function (autience_event, delay, fn) {
138            Autience.listenAutienceEvent(autience_event, function () {
139                setTimeout(fn, delay)
140            })
141        }
142
143        //4. getting document height
144        Autience.utils.getDocHeight = function () {
145            var D = document
146            return Math.max(
147                D.body.scrollHeight, D.documentElement.scrollHeight,
148                D.body.offsetHeight, D.documentElement.offsetHeight,
149                D.body.clientHeight, D.documentElement.clientHeight
150            )
151        }
152
153        //5. createCookies
154        Autience.utils.createCookie = function (name, value, permanent) {
155            var cookie = name + "=" + value + ";path=/"
156            if (permanent) {
157
158                var expiration_date = new Date();
159                expiration_date.setFullYear(expiration_date.getFullYear() + 5);
160                cookie = cookie + ";expires=" + expiration_date.toGMTString()
161            }
162            document.cookie = cookie
163        }
164
165        Autience.utils.readCookie = function (name) {
166            var nameEQ = name + "=";
167            var ca = document.cookie.split(';');
168            for (var i = 0; i < ca.length; i++) {
169                var c = ca[i];
170                while (c.charAt(0) == ' ') c = c.substring(1, c.length);
171                if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
172            }
173            return null;
174        }
175
176
177        //6. bind function on all elements with the clas
178        Autience.utils.executeOnClass = function (class_name, fn) {
179            var els = document.getElementsByClassName(class_name)
180            if (els) {
181                for (var i = 0; i < els.length; i++) {
182                    fn(els[i])
183                }
184            }
185        }
186
187        Autience.utils.executeOnId = function (id, fn) {
188            var el = document.getElementById(id)
189            if (el) {
190                fn(el)
191            }
192        }
193
194        Autience.utils.idListen = function (id, event, fn) {
195            Autience.utils.executeOnId(id, function (el) {
196                Autience.utils.listen(el, event, fn)
197            })
198        }
199
200
201        //7. Listen on elements by class name
202        Autience.utils.classListen = function (class_name, evt, fn) {
203            Autience.utils.executeOnClass(class_name, function (el) {
204                Autience.utils.listen(el, 'click', fn)
205            })
206        }
207
208        //8. Execute array of functions without input
209        Autience.utils.cycle = function (fn_array, widget) {
210
211            if (fn_array) {
212                for (var i = 0; i < fn_array.length; i++) {
213                    fn_array[i](widget)
214                }
215            }
216        }
217
218        //9. Execute validators in sequence and return true if all are valid
219        Autience.utils.checkCycle = function (fn_array, inp) {
220            if (fn_array) {
221                for (var i = 0; i < fn_array.length; i++) {
222                    if (!fn_array[i](inp)) {
223                        //console.log('in validateSequence ' + i + ' th function is returning false')
224                        return false
225                    }
226                }
227            }
228            return true
229        }
230
231        //10. get a smart setting value
232        Autience.utils.smartSetting = function (extension, key) {
233            if (autience_settings && autience_settings.smart && autience_settings.smart[extension]) {
234                return autience_settings.smart[extension][key]
235            }
236        }
237
238        //11. close widget
239        Autience.utils.closeWidget = function (widget) {
240            Autience.utils.cycle(Autience.lifecycle.close, widget)
241            Autience.utils.cycle(Autience.lifecycle.afterClose, widget)
242            Autience.utils.sendEvent('popup_closed');
243        }
244
245        //12. base64 decoding
246        Autience.utils.decode = function (s) {
247            if (window.atob) {
248                try {
249                    var decoded = window.atob(s)
250                    return decoded
251                } catch (err) {
252                    //console.log('Unable to to decode')
253                    //console.log(s)
254                    return alternateDecode(s)
255                }
256
257            }
258
259            function alternateDecode(s) {
260                if (!s || s.length == 0) {
261                    return ''
262                }
263                var e = {},
264                    i, b = 0,
265                    c, x, l = 0,
266                    a, r = '',
267                    w = String.fromCharCode,
268                    L = s.length;
269                var A = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
270                for (i = 0; i < 64; i++) {
271                    e[A.charAt(i)] = i;
272                }
273                for (x = 0; x < L; x++) {
274                    c = e[s.charAt(x)];
275                    b = (b << 6) + c;
276                    l += 6;
277                    while (l >= 8) {
278                        ((a = (b >>> (l -= 8)) & 0xff) || (x < (L - 2))) && (r += w(a));
279                    }
280                }
281                return r;
282            }
283
284        }
285
286        Autience.utils.nestedValue = function (obj, fields) {
287
288            var nested = obj
289            for (var i = 0; i < fields.length; i++) {
290                nested = nested[fields[i]]
291
292                if (typeof nested == 'undefined') {
293
294                    return null
295                }
296            }
297
298            return nested
299        }
300
301        Autience.utils.stripAndExecuteScript = function (text) {
302            var scripts = '';
303            var cleaned = text.replace(/<script[^>]*>([\s\S]*?)<\/script>/gi, function () {
304                scripts += arguments[1] + '\n';
305                return '';
306            });
307
308            if (window.execScript) {
309                window.execScript(scripts);
310            } else {
311                var head = document.getElementsByTagName('head')[0];
312                var scriptElement = document.createElement('script');
313                scriptElement.setAttribute('type', 'text/javascript');
314                scriptElement.innerText = scripts;
315                head.appendChild(scriptElement);
316                head.removeChild(scriptElement);
317            }
318            return cleaned;
319        }
320
321        Autience.utils.emitLinkClick = function (url, target, evt) {
322            Autience.current_link = url
323            Autience.current_target = target
324
325            var host = window.location.host
326            var host_without_www = host.replace('www.', '')
327            var host_with_www = 'www.' + host
328
329            //if the user clicks on a button which has js function, it has href = javascript. the popup should not show up
330            if (url.indexOf('javascript') > -1) {
331                return
332            }
333
334            if (url.indexOf(host) >= 0 || url.indexOf(host_with_www) >= 0 || url.indexOf(host_without_www) >= 0) {
335                emitAndDisableRedirect('internal')
336            } else {
337                emitAndDisableRedirect('external')
338            }
339
340            emitAndDisableRedirect('any')
341            emitAndDisableRedirect('custom')
342
343            function emitAndDisableRedirect(type) {
344                Autience.clickEvent = evt
345                Autience.utils.emitAutienceEvent('link_' + type, true)
346
347                if (Autience['disable_link_' + type]) {
348
349                    console.log('Disable link redirection for ', 'disable_link_' + type)
350
351                    //evt.preventDefault()
352                }
353            }
354        }
355
356        Autience.utils.redirect = function (url, target) {
357            if (!target) {
358                window.location = url
359            } else {
360                window.open(url, target);
361            }
362        }
363
364        Autience.utils.isDefined = function (a) {
365            return (typeof a != 'undefined')
366        }
367
368        Autience.utils.isMobile = function () {
369            if (/Mobi/.test(navigator.userAgent)) {
370                return true
371            }
372            return false
373        }
374
375        Autience.utils.randomString = function () {
376            var text = "";
377            var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
378
379            for (var i = 0; i < 5; i++)
380                text += possible.charAt(Math.floor(Math.random() * possible.length));
381
382            return text;
383        }
384
385        Autience.utils.hasFeature = function (feature) {
386            if (Autience.setup && Autience.setup.package_id != 'default') {
387                return true
388            }
389
390            //All features if premiumSubscription is present
391            if (Autience.utils.nestedValue(Autience, ['setup', 'extensions', 'premiumSubscription'])) {
392                return true
393            }
394
395            if (Autience.utils.nestedValue(Autience, ['setup', 'extensions', feature])) {
396                return true
397            }
398
399            return false
400        }
401    }
402
403
404    //define Listeners for the common events
405    Autience.executors.defineListeners = function () {
406        //console.log('defining autience listeners')
407        Autience.listeners = [{
408            target: document,
409            trigger: 'scroll',
410            reaction: function () {
411                var ratio = (window.innerHeight + window.scrollY) / (Autience.utils.getDocHeight());
412                var percentage = 25 * Math.floor(ratio * 4.1) //percentage is in multiples of 25
413                //console.log('percentage- ' + percentage)
414                Autience.utils.emitAutienceEvent('scroll_' + percentage)
415            },
416            target_name: 'document'
417        }, {
418            target: document.body,
419            trigger: 'mouseout',
420            reaction: function (e) {
421                e = e ? e : window.event;
422                var from = e.relatedTarget || e.toElement;
423                if ((!from || from.nodeName == "HTML") && (!e.clientY || (e.clientY <= 0))) {
424                    // console.log('exit is triggered')
425
426                    Autience.utils.emitAutienceEvent('exit')
427                }
428            },
429            target_name: 'body'
430        }, {
431            target: document.getElementsByTagName('a'),
432            trigger: 'click',
433            reaction: function (evt_obj, evt_name, el) {
434                Autience.utils.emitLinkClick(el.href, el.getAttribute('target'), evt_obj)
435            },
436            target_name: 'links'
437        }, {
438            target: window,
439            trigger: 'hashchange',
440            reaction: function (evt_obj, evt_name, el) {
441                //alert('in hashchange '+ window.location.hash )
442                if (Autience.hash_set) {
443                    //emit this event only after a hash has been set in the current cycle
444                    Autience.utils.emitAutienceEvent('back')
445                }
446
447            },
448            target_name: 'window'
449        }, {
450            target: window,
451            trigger: 'popstate',
452            reaction: function (evt_obj, evt_name, el) {
453                Autience.utils.emitAutienceEvent('back')
454            },
455            target_name: 'window'
456        }]
457    }
458
459
460
461    Autience.executors.bindListeners = function () {
462        //iterate through all the listeners and bind them
463        //console.log('binding autience listeners')
464        var listener = null,
465            triggers = null
466
467        Autience.listeners.forEach(function (listener) {
468
469            //if trigger is a string, put the single string in an array
470            if (typeof listener.trigger === 'string') {
471                triggers = [listener.trigger]
472            } else {
473                triggers = listener.trigger
474            }
475
476            triggers.forEach(function (trigger) {
477                if (listener.target.length) {
478
479                    //targets are an array of elements
480                    for (var i in listener.target) {
481
482                        Autience.utils.listen(listener.target[i], trigger, listener.reaction)
483                    }
484                } else {
485
486                    //target is a single element
487                    Autience.utils.listen(listener.target, trigger, listener.reaction, listener.target_name)
488                }
489            })
490        })
491    }
492
493    Autience.executors.displayWidget = function (widget) {
494        console.log('Call for displayWidget')
495        Autience.utils.cycle(Autience.lifecycle.display, widget)
496    }
497
498    Autience.executors.runWidgetCycle = function (widget) {
499
500        var cycle = Autience.utils.cycle
501
502        if (Autience.utils.checkCycle(lifecycle.displayValidation, widget)) {
503            cycle(lifecycle.onPageLoad, widget)
504
505            cycle(lifecycle.render, widget)
506
507            cycle(lifecycle.postRender, widget)
508        }
509    }
510
511    Autience.executors.runLifecycles = function () {
512        //console.log('Starting widget lifecycle')
513        if (Autience.lifecycle_executed) {
514            //ensure that this function is run only once
515            return
516        }
517        if (window.autience_setup) {
518            Autience.lifecycle_executed = true
519            //decode and convert setup to json
520            //Commented to avoid being marked for code obfuscation
521            Autience.setup = JSON.parse(decodeURIComponent(Autience.utils.decode(autience_setup))
521)
522            //Autience.setup = JSON.parse(decodeURIComponent(autience_setup))
523            // console.log(Autience.setup)
524            //console.log('yeloni client is loaded with ' + Autience.setup.widgets.length + ' widgets ')
525            //Autience.utils.sendEvent('client_script_loaded')
526
527            Autience.setup.widgets.forEach(function (widget) {
528                Autience.executors.runWidgetCycle(widget)
529            })
530        } else {
531            //console.log('window.autience_setup is not defined')
532        }
533    }
534
535    //execute defineUtils and defineListeners
536    //Everything else happens when some event occurs
537
538
539    lifecycle = Autience.lifecycle
540
541
542    function assignAutienceListen(callback) {
543        //console.log('inside assignAutienceListen')
544        if (window.autience_listen) {
545            ////console.log('Autience.utils.listen is assigned')
546            Autience.utils.listen = window.autience_listen
547            if (callback) {
548                callback()
549            }
550        } else {
551            setTimeout(function () {
552                assignAutienceListen(callback)
553            }, 500)
554        }
555    }
556
557    assignAutienceListen(function () {
558        //console.log('in callback of assignAutienceListen')
559        Autience.executors.defineUtils()
560        Autience.executors.defineListeners()
561        Autience.executors.bindListeners()
562        if (autience_callback) {
563            autience_callback()
564        }
565    })
566
567};
568window.defineAutienceWhen = function (yetience_callback) {
569
570    //log for popup displayed
571    Autience.lifecycle.display.push(function (widget) {
572        //checking if the popup code is present and sending popup_displayed event
573        if (document.getElementById(widget.code)) {
574            var code = document.getElementById(widget.code).innerHTML
575            if (code) {
576                Autience.utils.sendEvent('d_popup_displayed');
577                if (Autience.utils.nestedValue(widget, ['widget_time'])) {
578                    Autience.utils.sendEvent('popup_liked', {
579                        widget_time: widget.widget_time
580                    });
581                }
582            } else {
583                Autience.utils.sendEvent('popup_empty');
584            }
585        } else {
586            console.log('Widget ' + widget.code + ' is not loaded')
587        }
588
589    })
590
591    //Zopim related functionality
592    Autience.lifecycle.display.push(function (widget) {
593
594        if (Autience.utils.nestedValue(widget, ['components', 'zopimChat']) && typeof $zopim !== 'undefined') {
595            $zopim(function () {
596
597                var yel_body_height = window.innerHeight
598                var yel_body_width = window.innerWidth
599                var yel_zopim_height = 400
600                var yel_zopim_width = 310
601                var yel_popup_offset = 76
602
603                $zopim.livechat.window.show();
604                var yel_loc = document.getElementById("yel-chat-wrapper").getBoundingClientRect();
605                //console.log(yel_body_width)
606                //console.log(yel_loc.left)
607                //console.log(yel_loc.top)
608
609                $zopim.livechat.window.setOffsetHorizontal(yel_body_width - yel_zopim_width - yel_loc.left - 5);
610                $zopim.livechat.window.setOffsetVertical((yel_body_height - yel_zopim_height) - yel_popup_offset);
611
612                if (yel_body_width < 767) {
613                    $zopim.livechat.window.setOffsetVertical((yel_body_height - yel_zopim_height) - yel_loc.top);
614                    $zopim.livechat.window.setOffsetHorizontal((yel_body_width - yel_zopim_width) / 2);
615                }
616
617            });
618        }
619    })
620
621    //attach listener to display when the event occurs
622    Autience.lifecycle.onPageLoad.push(function (widget) {
623        // console.log('Attaching display on trigger')
624        //first check if the  widget is enabled
625        if (Autience.utils.nestedValue(widget, ['configuration', 'what', 'enable'])) {
626            var when = widget.configuration.when
627
628            var is_mobile = Autience.utils.isMobile()
629            // console.log('is mobile- ' + is_mobile)
630            var different_for_mobiles = when.smallDifferent
631            var device = 'large',
632                delay = 0,
633                links_to_match = null,
634                prevent_redirect = false
635
636
637            if (is_mobile && different_for_mobiles) {
638                device = 'small'
639            }
640
641            var trigger = when[device]
642            var autience_event = trigger
643            switch (trigger) {
644                //handle these trigger cases differently
645                case 'scroll':
646                    autience_event = 'scroll_' + when.scroll[device]
647                    break
648                case 'delay':
649                    autience_event = 'load'
650                    delay = when.delay[device]
651                    break
652                case 'link':
653                    var link_type = when.link[device]
654                    autience_event = 'link_' + link_type
655
656                    if (link_type == 'custom') {
657                        links_to_match = when.customLink[device]
658                    }
659                    //Autience['disable_link_' + link_type] = true
660                    prevent_redirect = true
661                    break
662            }
663
664            displayPopupOnEvent(autience_event, delay, links_to_match, prevent_redirect)
665            widget.trigger = {
666                trigger: trigger,
667                autience_event: autience_event,
668                delay: delay
669            }
670
671        } else {
672            Autience.utils.sendEvent('client_widget_disabled')
673            console.log('widget is disabled')
674        }
675
676        function displayPopupOnEvent(autience_event, delay, links_to_match, prevent_redirect) {
677            //Listen to the defined event and run the display lifecycle
678            //console.log('Attached Event Listener for Popup for event ', autience_event)
679            Autience.utils.listenAutienceEvent(autience_event, function (evt) {
680                // console.log('Autience event triggered ', autience_event)
681                // console.log('Autience event is' + autience_event + ' Check if the clicked link matches ', evt)
682
683                if (matchingLink(links_to_match)) {
684                    if (prevent_redirect && Autience.clickEvent) {
685                        //alert('preventDefault for clickEvent')
686                        Autience.clickEvent.preventDefault()
687                    }
688
689                    setTimeout(function () {
690                        Autience.utils.cycle(Autience.lifecycle.display, widget)
691                        // console.log('Popup is triggered')
692                        //Autience.utils.sendEvent('popup_triggered')
693                    }, delay * 1000)
694                }
695                //alert('hold on')
696
697
698            })
699        }
700
701        function matchingLink(links) {
702            //check links with Autience.current_link
703            if (!links) {
704                //there is no link, so no need to check
705                return true
706            }
707
708            var matched = false
709            links.split(',').map(function (link) {
710                link = link.trim()
711
712                matched = matched || directMatch(Autience.current_link, link) || matchWithoutProtocol(Autience.current_link, link) || matchWithoutHost(Autience.current_link, link)
713            })
714
715            return matched
716
717            function directMatch(link1, link2) {
718                link1 = stripTrailingSlash(link1)
719                link2 = stripTrailingSlash(link2)
720                return link1 == link2
721            }
722
723            function matchWithoutProtocol(link1, link2) {
724                link1 = stripTrailingSlash(link1)
725                link2 = stripTrailingSlash(link2)
726                link1 = link1.replace('http://', '')
727                link1 = link1.replace('https://', '')
728                link2 = link2.replace('http://', '')
729                link2 = link2.replace('https://', '')
730                return link1 == link2
731            }
732
733            function matchWithoutHost(link1, link2) {
734                link1 = stripTrailingSlash(link1)
735                link2 = stripTrailingSlash(link2)
736                link1 = link1.replace('http://', '')
737                link1 = link1.replace('https://', '')
738                link2 = link2.replace('http://', '')
739                link2 = link2.replace('https://', '')
740                link1 = link1.replace('www.', '')
741                link2 = link2.replace('www.', '')
742                link1 = link1.replace(window.location.host, '')
743                link2 = link2.replace(window.location.host, '')
744
745                return link1 == link2
746            }
747
748            function stripTrailingSlash(str) {
749                if (str.substr(-1) === '/') {
750                    return str.substr(0, str.length - 1);
751                }
752                return str;
753            }
754        }
755
756    })
757
758
759    //adding the analytics tracking code to the body
760    Autience.lifecycle.display.push(function (widget) {
761
762
763        // if (widget.components.commonanalytics.values.measureAnalyticsBoolean && widget.components.commonanalytics.values.analyticsTrackingCode) {
764        if ((Autience.utils.nestedValue(widget, ['components', 'commonanalytics', 'values', 'measureAnalyticsBoolean'])) && (Autience.utils.nestedValue(widget, ['components', 'commonanalytics', 'values', 'analyticsTrackingCode']))) {
765
766            var yel_measure_analytics = widget.components.commonanalytics.values.measureAnalyticsBoolean;
767            var yel_tracking_code = widget.components.commonanalytics.values.analyticsTrackingCode;
768
769
770            //adding the analytics script
771            if (document.body != null) {
772                var tracking_code_div = document.createElement("script");
773                tracking_code_div.type = "text/javascript";
774
775                var yel_popup_name = 'Yeloni'
776
777                // if (widget.components.commonanalytics.values.analyticsPopupName)
778                if ((Autience.utils.nestedValue(widget, ['components', 'commonanalytics', 'values', 'analyticsPopupName']))) {
779                    var yel_temp_popup_name = widget.components.commonanalytics.values.analyticsPopupName;
780                    var yel_popup_name = 'Yeloni-' + yel_temp_popup_name.split(' ').join('-');
781                }
782
783
784                //removing <script> tags
785                yel_tracking_code = yel_tracking_code.replace("<script>", " ");
786                yel_tracking_code = yel_tracking_code.replace("</script>", " ");
787
788                //removing new lines
789                yel_tracking_code = yel_tracking_code.replace(/\n/g, " ");
790                //yel_tracking_code = yel_tracking_code.replace("pageview", "Page-Load");
791
792                //adding the code to the script
793                tracking_code_div.innerHTML = yel_tracking_code;
794
795
796                document.body.appendChild(tracking_code_div);
797
798                //send the popup display event
799                //sending the page load event
800                if (typeof ga === "function") {
801                    ga('send', 'event', yel_popup_name, 'Popup-Display');
802                }
803            }
804        }
805
806    })
807
808    Autience.lifecycle.render.push(function (widget) {
809        var extensions = Autience.utils.nestedValue(Autience, ['setup', 'extensions'])
810        //dont show for premium users
811        if (extensions && Object.keys(extensions).length > 0) {
812            return
813        }
814
815
816        // if (document.getElementsByClassName('logged-in').length > 0) {
817        //     return
818        // }
819
820        var widget_element = document.getElementById(widget.code)
821        var poweredBy = document.createElement('div')
822        var url = 'https://yeloni.com'
823        url = url + '?utm_source=' + window.location.hostname + '&utm_campaign=poweredby&from_site=' + window.location.hostname
824
825        var message = 'Get an <b>Email Optin</b> for your Website'
826        if (widget.goalType != 'subscribe') {
827            message = 'Powered by <b>Yeloni</b>'
828        }
829
830        poweredBy.innerHTML = "<a href='" + url + "' target='_blank'>" + message + "</a>"
831
832        var style = poweredBy.style,
833            astyle = poweredBy.getElementsByTagName('a')[0].style
834        Object.assign(style, {
835            color: 'white',
836            fontSize: '15px',
837            fontFamily: 'arial',
838            textAlign: 'center'
839        })
840        Object.assign(astyle, {
841            color: 'white'
842        })
843        widget_element.appendChild(poweredBy)
844    })
845    /*
846    //showing the affiliate link if applicable
847    Autience.lifecycle.render.push(function(widget) {
848
849        //console.log("show link-- "+Autience.setup.showAffiliateLink)
850
851
852        // if (Autience.setup.showAffiliateLink)         {
853        if ((Autience.utils.nestedValue(Autience, ['setup', 'poweredBy']))) {
854            var yelPopups = document.getElementsByClassName('yel-popup-template'),
855                noOfPopups = yelPopups.length,
856                shareMessage = 'Sharing Powered by <span style="text-decoration: underline;">Yeloni</span>',
857                emailMessage = 'Subscription Powered by <span style="text-decoration: underline;">Yeloni</span>',
858                message = 'Powered by <span style="text-decoration: underline;">Yeloni</span>'
859
860            while (noOfPopups--) {
861                //add an element at the end of the yel-popup-template div
862                var currentNode = yelPopups[noOfPopups]
863                var newNode = document.createElement("div")
864                newNode.className = "yel-powered"
865
866                if (widget.isSocial && widget.isSocial == true) {
867                    message = shareMessage
868                } else if (widget.isEmail && widget.isEmail == true) {
869                    message = emailMessage
870                } else {
871                    message = message
872                }
873
874                newNode.innerHTML = message
875
876                //so that powered by yeloni shows up only once per widget
877                if (!widget.insertedBranding) {
878                    currentNode.parentNode.insertBefore(newNode, currentNode.nextSibling)
879                    widget.insertedBranding = true
880                }
881                //Set the branding on bottom right
882                document.getElementsByClassName('yel-powered')[noOfPopups].style = 'float:right;margin-right:2%;position: absolute;right: 0px;bottom: 20px;';
883
884            }
885            //console.log("autience setup")
886            //console.dir(Autience.setup.affiliate_code)
887
888            Autience.utils.classListen('yel-powered', 'click', function() {
889                var linkhere = "?utm_source=" + Autience.setup.initial_domain + "&utm_medium=poweredBy"
890                var utmLink = "http://www.yeloni.com" + linkhere;
891                window.open(utmLink, '_blank');
892            })
893        }
894
895    })
896    */
897
898    if (yetience_callback) {
899        yetience_callback()
900    }
901};
902window.defineAutienceWhere = function (yetience_callback) {
903    // //for display by contain url
904    Autience.lifecycle.displayValidation.push(function (widget) {
905        //honor show on homepage condition
906        if (location.pathname == '/' && (Autience.utils.nestedValue(widget, ['configuration', 'where', 'home']) == true)) {
907            return true
908        }
909        if (Autience.utils.nestedValue(widget, ['configuration', 'where', 'show_contain_tags'])) {
910            var contain_tags = widget.configuration.where.show_contain_tags
911            if (contain_tags.length == 0) {
912                return true
913            }
914            console.log('location.pathname is ' + location.pathname)
915            for (var i = contain_tags.length - 1; i >= 0; i--) {
916
917                if (location.pathname.indexOf(contain_tags[i].text) > -1) {
918                    console.log(location.pathname + ' has ' + contain_tags[i].text)
919                    return true
920                }
921            }
922            // console.log('contain tags')
923            // console.log(contain_tags)
924        } else {
925
926            return true
927        }
928
929
930    })
931
932    //for show by match url
933    Autience.lifecycle.displayValidation.push(function (widget) {
934        // console.log('location.pathname is ' + location.pathname)
935        // console.log(widget.configuration.where)
936        if (Autience.utils.nestedValue(widget, ['configuration', 'where', 'show_match_tags'])) {
937            //honor show on homepage condition
938            if (location.pathname == '/' && (Autience.utils.nestedValue(widget, ['configuration', 'where', 'home']) == true)) {
939                return true
940            }
941            var match_tags = widget.configuration.where.show_match_tags
942            if (match_tags.length == 0) {
943                return true
944            }
945            // console.log('location.pathname is ' + location.pathname)
946            for (var i = match_tags.length - 1; i >= 0; i--) {
947                // console.log('------------------')
948                console.log(location.pathname + ' is /' + match_tags[i].name)
949                if (location.pathname.indexOf(match_tags[i].name) >= 0) {
950                    return true
951                }
952            }
953            // console.log('match tags')
954            // console.log(match_tags)
955        } else {
956            return true
957        }
958
959    })
960
961    Autience.lifecycle.displayValidation.push(function (widget) {
962        //return true = show, false = show
963        var showAdmin = widget.configuration.showAdmin
964
965        if (showAdmin != null) { //by default it's not defined
966            if (!showAdmin) { //if it is set to false - don't show to logged in users
967                if (is_logged_in) {
968                    // console.log('dont show popup to admin - logged in as admin')
969                    return false
970                } else {
971                    // console.log('dont show popup to admin - not logged in')
972                    return true
973                }
974            }
975        }
976        return true
977
978    })
979    // //for display by contain url
980    Autience.lifecycle.displayValidation.push(function (widget) {
981        //return true = show, false = hide
982        //honor show on homepage condition
983        if (location.pathname == '/' && (Autience.utils.nestedValue(widget, ['configuration', 'where', 'home']) == true)) {
984            return true
985        }
986        if (Autience.utils.nestedValue(widget, ['configuration', 'where', 'hide_contain_tags'])) {
987            //honor show on homepage condition
988            if (location.pathname == '/' && (Autience.utils.nestedValue(widget, ['configuration', 'where', 'home']) == true)) {
989                return true
990            }
991
992            var contain_tags = widget.configuration.where.hide_contain_tags
993            if (contain_tags.length == 0) {
994                return true
995            }
996            console.log('location.pathname is ' + location.pathname)
997            for (var i = contain_tags.length - 1; i >= 0; i--) {
998                if (location.pathname.indexOf(contain_tags[i].text) > -1) {
999                    console.log(location.pathname + ' has ' + contain_tags[i].text)
1000                    return false
1001                }
1002            }
1003            // console.log('contain tags')
1004            // console.log(contain_tags)
1005        }
1006        return true
1007
1008    })
1009
1010    //for hide by match url
1011    Autience.lifecycle.displayValidation.push(function (widget) {
1012        //return true = show, false = hide
1013        // console.log('location.pathname is ' + location.pathname)
1014        // console.log(widget.configuration.where)
1015        if (Autience.utils.nestedValue(widget, ['configuration', 'where', 'hide_match_tags'])) {
1016            //honor show on homepage condition
1017            if (location.pathname == '/' && (Autience.utils.nestedValue(widget, ['configuration', 'where', 'home']) == true)) {
1018                return true
1019            }
1020            var match_tags = widget.configuration.where.hide_match_tags
1021            if (match_tags.length == 0) {
1022                return true
1023            }
1024            console.log('location.pathname is ' + location.pathname)
1025            for (var i = match_tags.length - 1; i >= 0; i--) {
1026                console.log('------------------')
1027                console.log(location.pathname + ' is /' + match_tags[i].name)
1028                if (location.pathname.indexOf(match_tags[i].name) >= 0) {
1029                    return false
1030                }
1031            }
1032            // console.log('match tags')
1033            // console.log(match_tags)
1034        }
1035        return true
1036
1037    })
1038
1039    Autience.lifecycle.displayValidation.push(function (widget) {
1040        //return true = show, false = hide
1041        var showAdmin = widget.configuration.showAdmin
1042
1043        if (showAdmin != null) { //by default it's not defined
1044            if (!showAdmin) { //if it is set to false - don't show to logged in users
1045                if (is_logged_in) {
1046                    // console.log('dont show popup to admin - logged in as admin')
1047                    return false
1048                } else {
1049                    // console.log('dont show popup to admin - not logged in')
1050                    return true
1051                }
1052            }
1053        }
1054        return true
1055
1056    })
1057
1058    Autience.lifecycle.displayValidation.push(function (widget) {
1059        var isMobile = Autience.utils.isMobile()
1060
1061        if (isMobile && !Autience.utils.hasFeature('mobileScreens')) {
1062            console.log('Popup is not shown on mobile in lite version')
1063            return false
1064        }
1065        if (isMobile && Autience.utils.hasFeature('mobileScreens')) {
1066            if (Autience.utils.nestedValue(widget, ['configuration', 'when', 'smallEnabled'])) {
1067                console.log('enabled on small screen')
1068                return true
1069            } else {
1070                console.log('disabled on small screens')
1071                return false
1072            }
1073        }
1074        // console.log('default')
1075        return true
1076    })
1077
1078
1079    //show on specific pages
1080    Autience.lifecycle.displayValidation.push(function (widget) {
1081        var where = widget.configuration.where
1082        var cat = null
1083        var where_categories = widget.configuration.where_categories
1084        var where_titles = widget.configuration.where_titles
1085
1086        //sometimes the value given by wordpress is not correct
1087        autience_is_home = autience_is_home || (((window.location.pathname == '/') || (window.location.pathname == '')) && window.location.search.length == 0)
1088        if (autience_is_home) {
1089            //console.log('where.home is ', where.home)
1090            return where.home
1091        }
1092
1093        if (window.autience_page_name == 'checkout') {
1094            return where.checkout
1095        }
1096
1097        switch (where.other) {
1098            case 'all':
1099                return true
1100            case 'none':
1101                return false
1102            case 'specific':
1103                switch (where.specific.selector) {
1104                    case 'pageType':
1105                        switch (window.autience_post_type) {
1106                            case 'post':
1107                                return where.pageTypes.posts
1108                            case 'product':
1109                                return where.pageTypes.products
1110                            case 'page':
1111                                return where.pageTypes.pages
1112                        }
1113                        break;
1114                    case 'category':
1115
1116                        for (var i = 0; i < window.autience_categories.length; i++) {
1117                            cat = autience_categories[i].cat_ID
1118                            if (where_categories.indexOf(cat) >= 0 || where_categories.indexOf(cat.toString()) >= 0) {
1119
1120                                return true
1121                            }
1122                        }
1123
1124                        console.log('returning false')
1125                        return false
1126                        break;
1127                    case 'title':
1128
1129                        var index = where_titles.indexOf(window.autience_post_id)
1130
1131                        console.log('title at ' + index)
1132                        return (index >= 0)
1133                        break;
1134                    case 'url':
1135                        return true
1136                        break;
1137                    case 'custom':
1138                        //check if the current page type matches the custom page type
1139                        console.log('Current post type is ', window.autience_post_type)
1140                        console.log('post type to check is ', where.pageTypes.custom)
1141
1142                        return (window.autience_post_type.toLowerCase() == where.pageTypes.custom.toLowerCase())
1143                }
1144
1145        }
1146
1147        return true
1148    })
1149
1150    //for hide on specific pages
1151    Autience.lifecycle.displayValidation.push(function (widget) {
1152        var where = widget.configuration.where
1153        var cat = null
1154        var where_categories_hide = widget.configuration.where_categories_hide
1155        var where_titles_hide = widget.configuration.where_titles_hide
1156
1157        // console.log('widget is')
1158        // console.log(widget)
1159
1160        if (where.showOrHide == 'hide' && where.hideOn && where.hideOn.hideselector) {
1161            switch (where.hideOn.hideselector) {
1162                case 'pageType':
1163                    switch (window.autience_post_type) {
1164                        case 'post':
1165                            return !(where.pageTypes.posts)
1166                        case 'product':
1167                            return !(where.pageTypes.products)
1168                        case 'page':
1169                            return !(where.pageTypes.pages)
1170                    }
1171                    break;
1172                case 'category':
1173
1174                    for (var i = 0; i < window.autience_categories.length; i++) {
1175                        cat = autience_categories[i].cat_ID
1176                        if (where_categories_hide.indexOf(cat) >= 0 || where_categories_hide.indexOf(cat.toString()) >= 0) {
1177
1178                            return false
1179                        }
1180                    }
1181                    return true
1182                    break;
1183                case 'title':
1184
1185                    var index = where_titles_hide.indexOf(window.autience_post_id)
1186
1187                    // console.log('title at ' + index)
1188                    //return true - show
1189                    return (index < 0)
1190
1191                    break;
1192                case 'url':
1193                    //see the logic in first two displayValidation
1194                    return true
1195                case 'custom':
1196                    //check if the current page type matches the custom page type
1197                    console.log('Current post type is ', window.autience_post_type)
1198                    console.log('post type to check is ', where.pageTypes.custom)
1199
1200                    return !(window.autience_post_type.toLowerCase() == where.pageTypes.custom.toLowerCase())
1201
1202            }
1203
1204
1205
1206            return false
1207        } else {
1208            return true
1209        }
1210    })
1211
1212
1213
1214
1215    if (yetience_callback) {
1216        yetience_callback()
1217    }
1218};
1219window.defineAutienceHow = function (yetience_callback) {
1220    //Make sure that Action button shows up above anything else
1221    Autience.lifecycle.postRender.push(function (widget) {
1222        //console.log('Adding zindex to action buttons')
1223        var button_classes = ['yel-cta-wrapper', 'yel-arrow-wrapper', 'yel-circle-wrapper', 'yel-cta-button']
1224        button_classes.map(function (this_class) {
1225            //check if there is an element with this class.
1226            //if it exists, then assign the highest z index
1227            var els = document.getElementsByClassName(this_class)
1228            if (els && els.length > 0) {
1229                for (var i = 0; i < els.length; i++) {
1230                    els[i].style.zIndex = highestZIndex() + 1
1231                }
1232            }
1233        })
1234    })
1235
1236    //Make sure that Popups show up above anything else
1237    Autience.lifecycle.display.push(function (widget) {
1238        //core function which shows the popup
1239        if (document.getElementById(widget.code)) {
1240            document.getElementById(widget.code).style.visibility = 'visible'
1241            widget.default_display = document.getElementById(widget.code).style.display
1242            document.getElementById(widget.code).style.display = 'block'
1243            document.getElementById(widget.code).style.zIndex = (highestZIndex()) * 10
1244        } else {
1245            console.log('Widget ' + widget.code + ' is not loaded')
1246        }
1247
1248    })
1249
1250    function highestZIndex() {
1251        var highest = 1
1252        var types = ['div', 'nav', 'span']
1253        types.map(function (type) {
1254            var all_divs = document.getElementsByTagName(type)
1255            //console.log('elements of type ', type, all_divs.length)
1256            for (var i = 0; i < all_divs.length; i++) {
1257                var zIndex = getStyle(all_divs[i], 'z-index')
1258                //console.log('z Index ', zIndex)
1259                if (!isNaN(zIndex) && zIndex > highest) {
1260                    highest = parseInt(zIndex)
1261                }
1262            }
1263        })
1264
1265        console.log('highest z index ', highest)
1266        return highest
1267    }
1268
1269    function getStyle(el, styleProp) {
1270
1271        if (window.getComputedStyle) {
1272            var y = window.getComputedStyle(el, null).getPropertyValue(styleProp);
1273        } else if (el.currentStyle) {
1274            var y = el.currentStyle[styleProp];
1275        }
1276
1277        return y;
1278    }
1279
1280    //if analytics is enabled send an popup display event
1281    Autience.lifecycle.display.push(function (widget) {
1282
1283
1284        // if (widget.components.commonanalytics.values.measureAnalyticsBoolean)
1285        var yel_measure_analytics = Autience.utils.nestedValue(widget, ['components', 'commonanalytics', 'values', 'measureAnalyticsBoolean'])
1286        if (yel_measure_analytics) {
1287            var yel_popup_name = 'Yeloni'
1288
1289            // if (widget.components.commonanalytics.values.analyticsPopupName) {
1290            if (Autience.utils.nestedValue(widget, ['components', 'commonanalytics', 'values', 'analyticsPopupName'])) {
1291                var yel_temp_popup_name = widget.components.commonanalytics.values.analyticsPopupName;
1292                var yel_popup_name = 'Yeloni-' + yel_temp_popup_name.split(' ').join('-');
1293            }
1294        }
1295    })
1296
1297
1298
1299    //function to add widget rendered into a wrapper div
1300    Autience.lifecycle.render.push(function (widget) {
1301
1302        // console.log("WIDGET IS --")
1303        // console.dir(widget)
1304
1305        //create a new widget with a wrapper if it does not already exist
1306        if (!document.getElementById(widget.code) || true) {
1307
1308            //based on the type of widget render it differently.
1309            //types of widgets are selected by widget.widgetType
1310            //the list of all types is in widget_type_data.json - name field
1311
1312            var widgetDiv = document.createElement('div')
1313            widgetDiv.id = widget.code
1314            var typeOfWidget = widget.themeType;
1315
1316            //console.log("widget.placementType:"+ widget.placementType)
1317            // console.log('Type of Popup- ' + typeOfWidget)
1318
1319            switch (typeOfWidget) {
1320                case "Popups":
1321                    // console.log("THIS IS OF TYPE - Popups");
1322                    widgetDiv.style.visibility = 'hidden'
1323                    widgetDiv.className = "yel-popup-main-wrapper"
1324
1325                    var base64_decoded = Autience.utils.decode(widget.rendered)
1326                    //var base64_decoded = widget.rendered
1327
1328                    if (!base64_decoded || base64_decoded.length == 0) {
1329                        Autience.utils.sendEvent('client_template_empty')
1330                    }
1331                    var inner_html = Autience.utils.stripAndExecuteScript(decodeURIComponent(base64_decoded))
1332                    widgetDiv.innerHTML = inner_html
1333                    widgetDiv.style.background = "url('" + window.yetience.path + "/common/images/opaque-bg.png') top left repeat"
1334                    document.body.appendChild(widgetDiv)
1335                    break;
1336
1337                case "ActionButtons":
1338                    // console.log("THIS IS OF TYPE - ActionButtons");
1339                    widgetDiv.className = "yel-ab-main-wrapper"
1340
1341
1342                    var base64_decoded = Autience.utils.decode(widget.rendered)
1343                    //var base64_decoded = widget.rendered
1344                    if (!base64_decoded || base64_decoded.length == 0) {
1345                        Autience.utils.sendEvent('client_template_empty')
1346                    }
1347                    var inner_html = Autience.utils.stripAndExecuteScript(decodeURIComponent(base64_decoded))
1348                    widgetDiv.innerHTML = inner_html
1349                    widgetDiv.className = "yel-ab-main-wrapper";
1350                    document.body.appendChild(widgetDiv)
1351
1352                    //shift the elements to the right
1353                    if (document.getElementById("yel-main-box-wrapper")) {
1354                        document.getElementById("yel-main-box-wrapper").className = "yel-main-box-wrapper";
1355                        //hide the two boxes and show only the cta button
1356                        document.getElementById("yel-main-box-wrapper").style.display = "none"
1357                        document.getElementById("yel-main-box-wrapper").style.zIndex = highestZIndex() + 1
1358                    }
1359
1360                    if (document.getElementById("yel-circle-wrapper")) {
1361                        document.getElementById("yel-circle-wrapper").className = "yel-circle-wrapper";
1362
1363                        document.getElementById("yel-arrow-wrapper").style.display = "none"
1364                    }
1365
1366                    if (document.getElementById("yel-arrow-wrapper")) {
1367                        document.getElementById("yel-arrow-wrapper").className = "yel-arrow-wrapper";
1368                        //show the arrow box after 5 secs
1369                        setTimeout(function () {
1370                            document.getElementById("yel-arrow-wrapper").style.display = "block"
1371                        }, 5000);
1372                    }
1373
1374
1375
1376
1377
1378                    break;
1379
1380                case "InpostWidgets":
1381                    //code
1382                    //console.log("THIS IS OF TYPE - InpostWidgets");
1383
1384                    var articles = document.getElementsByTagName("article");
1385                    var x = articles[0].querySelectorAll("p");
1386
1387                    var numberOfElements = x.length;
1388                    var parentNode = x[0].parentNode;
1389
1390                    // if (widget.components.inpostPosition.values.postStart) {
1391                    if (Autience.utils.nestedValue(widget, ['components', 'inpostPosition', 'values', 'postStart'])) {
1392                        parentNode.insertBefore(ElemToInsert(widget), x[0]);
1393                    }
1394
1395                    // if (widget.components.inpostPosition.values.postCenter) {
1396                    if (Autience.utils.nestedValue(widget, ['components', 'inpostPosition', 'values', 'postCenter'])) {
1397                        console.log(numberOfElements)
1398                        console.log("center:" + (Math.round(numberOfElements / 2) - 1))
1399                        parentNode.insertBefore(ElemToInsert(widget), x[Math.round(numberOfElements / 2) - 1]);
1400                    }
1401
1402                    // if (widget.components.inpostPosition.values.postEnd) {
1403                    if (Autience.utils.nestedValue(widget, ['components', 'inpostPosition', 'values', 'postEnd'])) {
1404                        parentNode.insertBefore(ElemToInsert(widget), x[numberOfElements]);
1405                    }
1406
1407                    break;
1408
1409                case "Sliders":
1410                    // console.log("THIS IS OF TYPE - Sliders");
1411                    widgetDiv.className = "yel-slider-main-wrapper"
1412
1413                    var base64_decoded = Autience.utils.decode(widget.rendered)
1414                    //var base64_decoded = widget.rendered
1415                    if (!base64_decoded || base64_decoded.length == 0) {
1416                        Autience.utils.sendEvent('client_template_empty')
1417                    }
1418                    var inner_html = Autience.utils.stripAndExecuteScript(decodeURIComponent(base64_decoded))
1419                    widgetDiv.innerHTML = inner_html
1420                    widgetDiv.className = "yel-slider-main-wrapper yel-slider-left";
1421                    document.body.appendChild(widgetDiv)
1422
1423                    break;
1424
1425                case "Bars":
1426                    //console.log("THIS IS OF TYPE - Bars");
1427                    // widgetDiv.className = "yel-bars-main-wrapper"
1428
1429                    //THIS NEEDS TO BE WRITTEN BETTER HERE
1430                    // if (widget.components.barPosition.values.topscroll) {
1431                    if (Autience.utils.nestedValue(widget, ['components', 'barPosition', 'values', 'topscroll'])) {
1432                        widgetDiv.className = "yel-bars-main-wrapper yel-bar-template-render-top";
1433
1434                        var bodyclass = document.createAttribute("class");
1435                        bodyclass.value = "body-move";
1436                        document.getElementsByTagName("body")[0].setAttributeNode(bodyclass);
1437                        console.log("added class yel-bar-template-render");
1438
1439
1440                    }
1441                    // else if (widget.components.barPosition.values.topfixed) {
1442                    else if (Autience.utils.nestedValue(widget, ['components', 'barPosition', 'values', 'topfixed'])) {
1443                        widgetDiv.className = "yel-bars-main-wrapper yel-bar-template-render-top";
1444                        console.log("added class yel-bar-template-render")
1445                    }
1446                    // else if (widget.components.barPosition.values.bottomscroll) {
1447                    else if (Autience.utils.nestedValue(widget, ['components', 'barPosition', 'values', 'bottomscroll'])) {
1448                        widgetDiv.className = "yel-bars-main-wrapper yel-bar-template-render-bottom";
1449                        console.log("added class yel-bar-template-render")
1450                    }
1451                    // else if (widget.components.barPosition.values.bottomfixed) {
1452                    else if (Autience.utils.nestedValue(widget, ['components', 'barPosition', 'values', 'bottomfixed'])) {
1453                        widgetDiv.className = "yel-bars-main-wrapper yel-bar-template-render-bottom";
1454                        console.log("added class yel-bar-template-render")
1455                    }
1456
1457                    var base64_decoded = Autience.utils.decode(widget.rendered)
1458                    //var base64_decoded = widget.rendered
1459                    if (!base64_decoded || base64_decoded.length == 0) {
1460                        Autience.utils.sendEvent('client_template_empty')
1461                    }
1462
1463                    var inner_html = Autience.utils.stripAndExecuteScript(decodeURIComponent(base64_decoded))
1464                    widgetDiv.innerHTML = inner_html
1465                    document.body.insertBefore(widgetDiv, document.body.firstChild);
1466                    break;
1467
1468                case "Sidebar":
1469                    //code
1470                    // console.log("THIS IS OF TYPE - Sidebar");
1471                    break;
1472
1473                case "ContentGating":
1474                    //code
1475                    break;
1476
1477                case "Mats":
1478                    var base64_decoded = Autience.utils.decode(widget.rendered)
1479                    //var base64_decoded = widget.rendered
1480                    if (!base64_decoded || base64_decoded.length == 0) {
1481                        Autience.utils.sendEvent('client_template_empty')
1482                    }
1483                    var inner_html = Autience.utils.stripAndExecuteScript(decodeURIComponent(base64_decoded))
1484                    widgetDiv.innerHTML = inner_html
1485                    widgetDiv.className = "yel-mat-main-wrapper yel-mat-onload";
1486
1487                    var ydiv = document.createElement("div");
1488                    ydiv.id = "yel-wrap";
1489                    ydiv.className = "yel-wrap"
1490                    ydiv.appendChild(widgetDiv)
1491                    // Move the body's children into this wrapper
1492                    while (document.body.firstChild) {
1493                        ydiv.appendChild(document.body.firstChild);
1494                    }
1495
1496                    // Append the wrapper to the body
1497                    document.body.appendChild(ydiv);
1498
1499                    //check for scroll and hide the element after its outside viewport
1500                    yelTrackScroll(widgetDiv);
1501
1502                    break;
1503
1504                default:
1505                    console.log("WIDGET TYPE NOT DEFINED - DEFAULTING TO POPUPS")
1506                    //defaulting to popups
1507                    widgetDiv.style.visibility = 'hidden'
1508                    widgetDiv.className = "yel-popup-main-wrapper"
1509
1510                    var base64_decoded = Autience.utils.decode(widget.rendered)
1511                    //var base64_decoded = widget.rendered
1512
1513                    if (!base64_decoded || base64_decoded.length == 0) {
1514                        Autience.utils.sendEvent('client_template_empty')
1515                    }
1516                    var inner_html = Autience.utils.stripAndExecuteScript(decodeURIComponent(base64_decoded))
1517                    widgetDiv.innerHTML = inner_html
1518                    widgetDiv.style.background = "url('" + window.yetience.path + "/common/images/opaque-bg.png') top left repeat"
1519                    document.body.appendChild(widgetDiv)
1520                    break;
1521
1522            }
1523
1524
1525
1526
1527
1528            //document.body.appendChild(widgetDiv)
1529
1530
1531        } else {
1532            //console.log('widget with code ' + widget.code + ' already exists')
1533        }
1534
1535    })
1536
1537    function yelTrackScroll(widget) {
1538        //get the height of the widget
1539        var widgetHeight = document.getElementById(widget.id).style.height;
1540        console.log("Height:" + widgetHeight)
1541    }
1542
1543    function ElemToInsert(widget) {
1544        var widgetDiv = document.createElement('div')
1545        widgetDiv.className = "yel-inline-wrapper"
1546        widgetDiv.id = ""
1547        //var base64_decoded = Autience.utils.decode(widget.rendered)
1548        var base64_decoded = widget.rendered
1549        if (!base64_decoded || base64_decoded.length == 0) {
1550            Autience.utils.sendEvent('client_template_empty')
1551        }
1552        var inner_html = Autience.utils.stripAndExecuteScript(decodeURIComponent(base64_decoded))
1553        widgetDiv.innerHTML = inner_html
1554        widgetDiv.style.background = "url('" + window.yetience.path + "/common/images/opaque-bg.png') top left repeat"
1555
1556        return widgetDiv;
1557    }
1558
1559    // var giveMePopupBaby = function(widgetDiv) {
1560    //     console.log("THIS IS OF TYPE - Popups");
1561    //     widgetDiv.style.visibility = 'hidden'
1562    //     widgetDiv.className = "yel-popup-main-wrapper"
1563
1564    //     var base64_decoded = Autience.utils.decode(widget.rendered)
1565    //     if (!base64_decoded || base64_decoded.length == 0) {
1566    //         Autience.utils.sendEvent('client_template_empty')
1567    //     }
1568    //     var inner_html = Autience.utils.stripAndExecuteScript(decodeURIComponent(base64_decoded))
1569    //     widgetDiv.innerHTML = inner_html
1570    //     widgetDiv.style.background = "url('" + window.yetience.path + "/common/images/opaque-bg.png') top left repeat"
1571    //     document.body.appendChild(widgetDiv)
1572    // }
1573
1574    Autience.lifecycle.render.push(function (widget) {
1575        var styles_to_add = decodeURIComponent(Autience.utils.decode(widget.styles))
1576        //var styles_to_add = decodeURIComponent((widget.styles))
1577
1578        //addStyle(styles_to_add)
1579
1580
1581        var head = document.head || document.getElementsByTagName('head')[0]
1582        var style = document.createElement('style');
1583
1584        style.type = 'text/css';
1585        if (style.styleSheet) {
1586            style.styleSheet.cssText = styles_to_add;
1587        } else {
1588            style.appendChild(document.createTextNode(styles_to_add));
1589        }
1590
1591        head.appendChild(style);
1592    })
1593
1594    if (yetience_callback) {
1595        yetience_callback()
1596    }
1597};
1598window.defineAutienceWhom = function (yetience_callback) {
1599    if (Autience) {
1600        Autience.lifecycle.display.push(function (widget) {
1601            //create cookies as required
1602            Autience.utils.createCookie("autience-displayed-visitor-" + widget.code, true, true)
1603            Autience.utils.createCookie("autience-displayed-session-" 
1603+ widget.code, true)
1604
1605        })
1606
1607        Autience.lifecycle.displayValidation.push(function (widget) {
1608
1609            if ((Autience.utils.nestedValue(widget, ['configuration', 'whom', 'limitByReferrerSetting']))) {
1610                //console.log('limitByReferrerSetting is set to ' + widget.configuration.whom.limitByReferrerSetting)
1611                //this is fallback for the old version of plugin where the setting was set to default
1612                if (Autience.utils.nestedValue(widget, ['configuration', 'whom', 'limitByReferrerSetting']) == 'default') {
1613                    return true
1614                }
1615
1616                var return_value = null,
1617                    isFound = false
1618                if (Autience.utils.nestedValue(widget, ['configuration', 'whom', 'limitByReferrerSetting']) == 'show') {
1619                    return_value = true
1620                } else {
1621                    return_value = false
1622                }
1623
1624                var referrer_array = widget.configuration.whom.limitByReferrer_array
1625                if (referrer_array) {
1626                    for (var i = referrer_array.length - 1; i >= 0; i--) {
1627                        // console.log('comparing ' + referrer_array[i].text + ' to ' + document.referrer)
1628                        if (document.referrer.indexOf(referrer_array[i].text) > 0) {
1629                            // console.log('Disable on referrer is enabled for ' + referrer_array[i].text)
1630                            isFound = true
1631                        }
1632                    }
1633                }
1634
1635                if (isFound) {
1636                    return return_value
1637                } else {
1638                    return !return_value
1639                }
1640            }
1641            return true
1642        })
1643
1644
1645        Autience.lifecycle.displayValidation.push(function (widget) {
1646
1647
1648
1649            // if (widget.configuration.whom.cta == true)
1650            // if ((Autience.utils.nestedValue(widget, ['configuration', 'whom', 'cta'])) == true)
1651            //     console.log('cta is set to ' + widget.configuration.whom.cta)
1652
1653            if (Autience.utils.readCookie("autience-visitor-subscribed-" + widget.code)) {
1654                console.log('visitor subscribed, do not show popup')
1655                return false
1656            }
1657
1658            return true
1659        })
1660
1661
1662        Autience.lifecycle.displayValidation.push(function (widget) {
1663            if (Autience.utils.nestedValue(widget, ['configuration', 'whom', 'once'])) {
1664                // console.log('once is ' + widget.configuration.whom.once)
1665                switch (widget.configuration.whom.once) {
1666                    case 'visitor':
1667                        if (Autience.utils.readCookie("autience-displayed-visitor-" + widget.code)) {
1668                            //console.log('visitor cookie exists')
1669                            return false
1670                        }
1671                        break
1672                    case 'session':
1673                        if (Autience.utils.readCookie("autience-displayed-session-" + widget.code)) {
1674                            //console.log('session cookie exists')
1675                            return false
1676                        }
1677                        break
1678
1679                    case 'always':
1680                        return true
1681                        break
1682                }
1683            }
1684
1685            return true
1686        })
1687
1688        if (yetience_callback) {
1689            yetience_callback()
1690        }
1691    }
1692
1693
1694};
1695window.defineAutienceClose = function (yetience_callback) {
1696
1697    //this function changes the close image url based on the url's http or https
1698    Autience.lifecycle.postRender.push(function (widget) {
1699        //check the browser url to see if its http or https
1700        var yel_current_url = window.location.href
1701        if (yel_current_url.indexOf('https') >= 0) {
1702            //url is an https
1703            //console.log("a https url "+window.location.href)
1704            if (document.getElementsByClassName('yeloni-close-image-url')) {
1705                //get the current close button image
1706                var yel_div_list = document.getElementsByClassName('yeloni-close-image-url'),
1707                    yel_lt = yel_div_list.length;
1708                while (yel_lt--) {
1709                    var yel_img_url = yel_div_list[yel_lt].src;
1710                    if (yel_img_url.indexOf('https:') < 0) {
1711                        //image is from an http source
1712                        //console.log("url is https and image is from an http source ")
1713                        yel_div_list[yel_lt].src = yel_div_list[yel_lt].src.replace('http://', 'https://');
1714                    }
1715
1716                }
1717            }
1718        } else {
1719            //url is http - do nothing!
1720            //console.log("a http url " + window.location.href)
1721        }
1722    })
1723
1724    /*var yeloni_comment = 'This widget is powered by yeloni.com. Get one for your site today.'
1725    //show comments before widget
1726    Autience.lifecycle.postRender.push(function(widget) {
1727        if (document.getElementById(widget.code)) {
1728            var top_comment = document.createComment(yeloni_comment);
1729            // console.log(widget.themeType)
1730            var yel_widget_wrapper = wrapperClass(widget.themeType)
1731            var popup = document.getElementsByClassName(yel_widget_wrapper)[0]
1732            document.getElementById(widget.code).insertBefore(top_comment, popup);
1733        } else {
1734            console.log('Widget ' + widget.code + ' is not loaded')
1735        }
1736
1737    })*/
1738
1739    function wrapperClass(themeType) {
1740        if (themeType == 'ActionButtons') {
1741            return 'yel-cta-wrapper'
1742        } else {
1743            return 'yel-popup-template'
1744        }
1745    }
1746
1747    /*
1748    //show comments after widget
1749    Autience.lifecycle.postRender.push(function(widget) {
1750        var bottom_comment = document.createComment(yeloni_comment);
1751        if (document.getElementById(widget.code)) {
1752            document.getElementById(widget.code).appendChild(bottom_comment);
1753        } else {
1754            console.log('Widget ' + widget.code + ' is not loaded')
1755        }
1756    })
1757    */
1758
1759    //attach close functionality to the close button
1760    //close button has an id called autience-close-widget_id
1761    Autience.lifecycle.postRender.push(function (widget) {
1762        Autience.utils.classListen('autience-close-' + widget.code, 'click', function (el) {
1763            Autience.utils.closeWidget(widget)
1764        })
1765    })
1766
1767    Autience.lifecycle.postRender.push(function (widget) {
1768
1769        Autience.utils.idListen('autience-close-' + widget.code, 'click', function (el) {
1770            //if the user clicks the close button on a link trigger, check if we need to redirect
1771
1772            if (Autience.utils.nestedValue(widget, ['trigger', 'trigger']) == 'link' && Autience.utils.nestedValue(widget, ['configuration', 'when', 'link', 'close'])) {
1773                Autience.utils.redirect(Autience.current_link, Autience.current_target)
1774            }
1775        })
1776    })
1777
1778
1779    //hiding the facebook page like after popup close - only for facebook-page-like theme
1780    Autience.lifecycle.postRender.push(function (widget) {
1781
1782        Autience.utils.idListen('autience-close-' + widget.code, 'click', function (el) {
1783            if (document.getElementById("yel-facebook-popup")) {
1784                document.getElementById("yel-facebook-popup").display = "none";
1785            }
1786        })
1787    })
1788
1789    //for close clicking outside
1790    Autience.lifecycle.postRender.push(function (widget) {
1791        if (Autience.utils.nestedValue(widget, ['configuration', 'close', 'outside'])) {
1792            //console.log('close on clicking outside')
1793
1794            Autience.utils.classListen('yel-popup-main-wrapper', 'click', function () {
1795                //console.log('clicked outside')
1796                Autience.utils.closeWidget(widget)
1797            })
1798            Autience.utils.classListen('yel-popup-template', 'click', function (e) {
1799                e.stopPropagation();
1800            })
1801        }
1802    }) //close lifecycle
1803
1804
1805    //adding event listeners for analytics
1806    Autience.lifecycle.postRender.push(function (widget) {
1807
1808
1809        // if (widget.components.commonanalytics.values.measureAnalyticsBoolean) {
1810        if (Autience.utils.nestedValue(widget, ['components', 'commonanalytics', 'values', 'measureAnalyticsBoolean'])) {
1811            var yel_measure_analytics = widget.components.commonanalytics.values.measureAnalyticsBoolean;
1812
1813            var yel_popup_name = 'Yeloni'
1814
1815            // if (widget.components.commonanalytics.values.analyticsPopupName) {
1816            if (Autience.utils.nestedValue(widget, ['components', 'commonanalytics', 'values', 'analyticsPopupName'])) {
1817                var yel_temp_popup_name = widget.components.commonanalytics.values.analyticsPopupName;
1818                var yel_popup_name = 'Yeloni-' + yel_temp_popup_name.split(' ').join('-');
1819            }
1820
1821            if (typeof ga === "function") {
1822                //listening for linkedimage clicks
1823                Autience.utils.classListen('yel-atr-linked-image', 'click', function (el) {
1824                    //send the popup display event
1825                    //alert('pinterest follow clicked22')
1826                    ga('send', 'event', yel_popup_name, 'Linked-Image-Click');
1827                });
1828
1829                //listening for linkedtext clicks
1830                Autience.utils.classListen('yel-atr-linked-text', 'click', function (el) {
1831                    //send the popup display event
1832                    ga('send', 'event', yel_popup_name, 'Linked-Text-Click');
1833                });
1834
1835                //listening for button clicks
1836                //========do something for yes no buttons
1837                Autience.utils.classListen('yel-atr-button', 'click', function (el) {
1838                    //send the popup display event
1839                    ga('send', 'event', yel_popup_name, 'Button-Click');
1840                });
1841
1842                Autience.utils.classListen('yel-yes-button', 'click', function (el) {
1843                    //send the popup display event
1844                    ga('send', 'event', yel_popup_name, 'Yes-Button-Click');
1845                });
1846                Autience.utils.classListen('yel-no-button', 'click', function (el) {
1847                    //send the popup display event
1848                    ga('send', 'event', yel_popup_name, 'No-Button-Click');
1849                });
1850
1851                Autience.utils.classListen('yel-pinterest-follow-image', 'click', function (el) {
1852                    //send the popup display event
1853                    //alert('pinterest follow clicked')
1854                    ga('send', 'event', yel_popup_name, 'Pinterest-Follow-Click');
1855                });
1856
1857                //social share popup begin
1858                Autience.utils.idListen('autience-network-pinterest', 'click', function (el) {
1859                    //send the popup display event
1860                    ga('send', 'event', yel_popup_name, 'Pinterest-Follow-Click');
1861                });
1862                Autience.utils.idListen('autience-network-facebook', 'click', function (el) {
1863                    //send the popup display event
1864                    ga('send', 'event', yel_popup_name, 'facebook-Follow-Click');
1865                });
1866                Autience.utils.idListen('autience-network-twitter', 'click', function (el) {
1867                    //send the popup display event
1868                    ga('send', 'event', yel_popup_name, 'twitter-Follow-Click');
1869                });
1870                Autience.utils.idListen('autience-network-googleplus', 'click', function (el) {
1871                    //send the popup display event
1872                    ga('send', 'event', yel_popup_name, 'googleplus-Follow-Click');
1873                });
1874                Autience.utils.idListen('autience-network-linkedin', 'click', function (el) {
1875                    //send the popup display event
1876                    ga('send', 'event', yel_popup_name, 'linkedin-Follow-Click');
1877                });
1878                Autience.utils.idListen('autience-network-reddit', 'click', function (el) {
1879                    //send the popup display event
1880                    ga('send', 'event', yel_popup_name, 'reddit-Follow-Click');
1881                });
1882                Autience.utils.idListen('autience-network-whatsapp', 'click', function (el) {
1883                    //send the popup display event
1884                    ga('send', 'event', yel_popup_name, 'whatsapp-Follow-Click');
1885                });
1886                Autience.utils.idListen('autience-network-flipboard', 'click', function (el) {
1887                    //send the popup display event
1888                    ga('send', 'event', yel_popup_name, 'flipboard-Follow-Click');
1889                });
1890                Autience.utils.idListen('autience-network-baidu', 'click', function (el) {
1891                    //send the popup display event
1892                    ga('send', 'event', yel_popup_name, 'baidu-Follow-Click');
1893                });
1894                Autience.utils.idListen('autience-network-sinaweibo', 'click', function (el) {
1895                    //send the popup display event
1896                    ga('send', 'event', yel_popup_name, 'sinaweibo-Follow-Click');
1897                });
1898                Autience.utils.idListen('autience-network-slashdot', 'click', function (el) {
1899                    //send the popup display event
1900                    ga('send', 'event', yel_popup_name, 'slashdot-Follow-Click');
1901                });
1902                Autience.utils.idListen('autience-network-vkontakte', 'click', function (el) {
1903                    //send the popup display event
1904                    ga('send', 'event', yel_popup_name, 'vkontakte-Follow-Click');
1905                });
1906                //social share popup end
1907
1908                //email popup subscribe event
1909                Autience.utils.classListen('yel-ep-submit-button', 'click', function (el) {
1910                    //send the popup display event
1911                    ga('send', 'event', yel_popup_name, 'Subscribe-Button-Click');
1912                });
1913                Autience.utils.classListen('yel-email-popup-button-large', 'click', function (el) {
1914                    //send the popup display event
1915                    ga('send', 'event', yel_popup_name, 'Subscribe-Button-Click');
1916                });
1917                //email popup subscribe event end
1918            }
1919        }
1920
1921    })
1922
1923
1924
1925    Autience.lifecycle.close.push(function (widget) {
1926        document.getElementById(widget.code).style.visibility = 'hidden'
1927        if (widget.default_display) {
1928            document.getElementById(widget.code).style.display = widget.default_display
1929        }
1930    })
1931
1932
1933    //close the zopim window if needed
1934    Autience.lifecycle.close.push(function (widget) {
1935        if (typeof $zopim != 'undefined') {
1936            $zopim.livechat.window.hide();
1937        }
1938    })
1939
1940
1941    //send an analytics event is applicable
1942    Autience.lifecycle.close.push(function (widget) {
1943
1944
1945        // if (widget.components.commonanalytics.values.measureAnalyticsBoolean) {
1946        if (Autience.utils.nestedValue(widget, ['components', 'commonanalytics', 'values', 'measureAnalyticsBoolean'])) {
1947            var yel_measure_analytics = widget.components.commonanalytics.values.measureAnalyticsBoolean;
1948
1949
1950            var yel_popup_name = 'Yeloni'
1951
1952            // if (widget.components.commonanalytics.values.analyticsPopupName) 
1953
1954            if (Autience.utils.nestedValue(widget, ['components', 'commonanalytics', 'values', 'analyticsPopupName'])) {
1955                var yel_temp_popup_name = widget.components.commonanalytics.values.analyticsPopupName;
1956                var yel_popup_name = 'Yeloni-' + yel_temp_popup_name.split(' ').join('-');
1957            }
1958            if (typeof ga === "function") {
1959                //send the popup display event
1960                ga('send', 'event', yel_popup_name, 'Popup-Closed');
1961            }
1962        }
1963    })
1964
1965
1966    Autience.lifecycle.postRender.push(function (widget) {
1967        //Show an alertbox before the browser window closes
1968
1969
1970        if (Autience.utils.nestedValue(widget, ['configuration', 'close', 'alert'])) {
1971            window.onbeforeunload = function (e) {
1972                return Autience.utils.nestedValue(widget, ['configuration', 'close', 'message'])
1973            };
1974        }
1975    })
1976
1977    if (yetience_callback) {
1978        yetience_callback()
1979    }
1980};
1981window.defineAutienceEmail = function (yetience_callback) {
1982    //console.log('injecting email.js')
1983    if (Autience) {
1984
1985        email_json = {}
1986        Autience.lifecycle.postRender.push(function (widget) {
1987
1988
1989            var name = null,
1990                email = null,
1991                name_field_id = 'autience-emailform-name-' + widget.code,
1992                email_field_id = 'autience-emailform-email-' + widget.code,
1993                email_error_id = 'autience-emailform-email-error-' + widget.code,
1994                name_error_id = 'autience-emailform-name-error-' + widget.code,
1995                submit_field_id = 'autience-emailform-submit-' + widget.code
1996
1997            var values = Autience.utils.nestedValue(widget, ['components', 'emailSubscription', 'values'])
1998            if (!values) {
1999                return
2000            }
2001            // console.log(widget)
2002
2003            // if (widget.components.emailSubscription) {
2004
2005            if ((Autience.utils.nestedValue(widget, ['components', 'emailSubscription']))) {
2006
2007                Autience.utils.idListen(submit_field_id, 'click', function () {
2008                    //console.log("submit clicked")
2009
2010                    var default_thankyou_message = 'You have been subscribed',
2011                        custom_thankyou_message = null,
2012                        thankyou_message = ''
2013
2014                    if ((Autience.utils.nestedValue(widget, ['components', 'emailSubscription', 'values', 'customMessage']))) {
2015
2016                        custom_thankyou_message = (Autience.utils.nestedValue(widget, ['components', 'emailSubscription', 'values', 'customMessage']))
2017                    }
2018
2019                    if (custom_thankyou_message) {
2020                        thankyou_message = custom_thankyou_message
2021                    } else {
2022                        thankyou_message = default_thankyou_message
2023                    }
2024
2025                    var previous_submit_text = document.getElementById(submit_field_id).innerHTML
2026                    document.getElementById(submit_field_id).innerHTML = "Hold on.."
2027
2028                    name = document.getElementById(name_field_id).value
2029                    if (!validateName(name)) {
2030                        //console.log("Invalid name"+name_error_id)
2031                        document.getElementById(name_error_id).innerHTML = 'Invalid Name'
2032                        document.getElementById(name_error_id).style.display = 'block'
2033                        document.getElementById(submit_field_id).innerHTML = previous_submit_text
2034                        return;
2035                    } else {
2036                        document.getElementById(name_error_id).style.display = 'none'
2037                    }
2038
2039
2040                    email = document.getElementById(email_field_id).value
2041                    if (!validateEmail(email)) {
2042                        //console.log("Invalid email")
2043                        document.getElementById(email_error_id).innerHTML = 'Invalid Email'
2044                        document.getElementById(email_error_id).style.display = 'block'
2045                        document.getElementById(submit_field_id).innerHTML = previous_submit_text
2046                        return;
2047                    } else {
2048                        document.getElementById(email_error_id).style.display = 'none'
2049                    }
2050
2051
2052                    var provider = widget.components.emailSubscription.values.provider
2053                    var list = widget.components.emailSubscription.values.list
2054                    var verify = widget.components.emailSubscription.values.verify
2055                    var send_welcome_email = Autience.utils.nestedValue(widget, ['components', 'welcomeEmail', 'values', 'sendWelcomeEmail'])
2056
2057
2058                    // if(!welcome_email){
2059                    //     send_welcome_email = false
2060                    // }
2061
2062                    //creating a variable
2063                    var autience_user_details = {
2064                        "email": email,
2065                        "name": name,
2066                        "website_id": Autience.setup.id,
2067                        "provider": provider,
2068                        "list": list,
2069                        "verify": verify,
2070                        "send_welcome_email": send_welcome_email,
2071                        "widget_id": widget.code,
2072                        "website_domain": Autience.setup.initial_domain
2073                    }
2074
2075                    if ((Autience.utils.nestedValue(widget, ['components', 'welcomeEmail', 'values', 'removeSignatureFeature']))) {
2076                        autience_user_details.remove_email_signature = (Autience.utils.nestedValue(widget, ['components', 'welcomeEmail', 'values', 'removeEmailSignature']))
2077                    }
2078
2079                    Autience.utils.sendEvent('new_email_subscribed', autience_user_details);
2080                    //console.log("back from sendEvent")
2081
2082                    var autience_subscription_url = yetience.server + '/api/EmailSubscriptions/new_subscription';
2083                    console.log(autience_subscription_url)
2084
2085
2086                    //display if premium thankyou page is found or not
2087
2088                    // if (widget.components.emailSubscription.values.thankyou != 'yeloni') {
2089                    if ((Autience.utils.nestedValue(widget, ['components', 'emailSubscription', 'values', 'thankyou'])) != 'yeloni') {
2090                        console.log('premium thankyou page found')
2091                    } else {
2092                        console.log('default thankyou page')
2093                    }
2094
2095                    //function(url, method, data, success, failure)
2096                    window.yetience.ajax(autience_subscription_url, 'POST', autience_user_details,
2097                        function (status_response) {
2098                            //success
2099                            console.log('email response')
2100                            console.log(status_response)
2101                            var status = JSON.parse(status_response).status;
2102
2103                            if (status == "CREATED_SUBSCRIPTION") {
2104                                //create cookie if cta is selected - don't show popup after subscription feature
2105                                if (typeof window.yeloniSubscriptionCallback === 'function') {
2106                                    console.log('Found a subscription callback function ')
2107                                    window.yeloniSubscriptionCallback(autience_user_details)
2108                                }
2109
2110                                // if (widget.configuration.whom.cta == true) {
2111                                if ((Autience.utils.nestedValue(widget, ['configuration', 'whom', 'cta'])) == true) {
2112                                    Autience.utils.createCookie("autience-visitor-subscribed-" + widget.code, true, true)
2113                                }
2114
2115                                Autience.utils.sendEvent('provider_email_saved', autience_user_details);
2116
2117
2118                                //go to thankyou page, if it's enabled
2119
2120                                // if (widget.components.emailSubscription.values.thankyou == 'custom') {
2121                                if ((Autience.utils.nestedValue(widget, ['components', 'emailSubscription', 'values', 'thankyou'])) == 'custom') {
2122                                    console.log('custom redirect')
2123                                    setTimeout(function () {
2124                                        window.location = widget.components.emailSubscription.values.thankyouUrl
2125                                    }, 3000);
2126                                    return
2127                                } else {
2128                                    document.getElementById('yeloni-email-form').innerHTML = thankyou_message
2129                                    document.getElementById('yeloni-email-form').style.textAlign = "center"
2130                                    document.getElementById('yeloni-email-form').style.fontSize = "16px"
2131
2132                                    if (widget.themeType == "ActionButtons") {
2133                                        setTimeout(function () {
2134                                            document.getElementById('yel-main-box-wrapper').style.display = "none"
2135                                            document.getElementById('yel-arrow-wrapper').style.display = "none"
2136                                        }, 3000);
2137                                    } else {
2138                                        setTimeout(function () {
2139                                            Autience.utils.closeWidget(widget)
2140                                        }, 3000);
2141                                    }
2142                                    return
2143                                }
2144                                //ignore thankyou page if disabled, close the widget
2145
2146                                // window.location="http://yeloni.com/emails/subscription-thankyou.html"
2147                                return
2148                            }
2149
2150                            document.getElementById(submit_field_id).innerHTML = previous_submit_text
2151
2152                            if (status == "ALREADY_SUBSCRIBED" || status == "SUBSCRIPTION_ERROR") {
2153                                document.getElementById(email_error_id).innerHTML = 'Email is already subscribed'
2154                                document.getElementById(email_error_id).style.display = 'block'
2155                            }
2156
2157                            if (status == "SUBSCRIPTION_ERROR") {
2158                                document.getElementById(email_error_id).innerHTML = 'There was an error during susbcription'
2159                                document.getElementById(email_error_id).style.display = 'block'
2160                            }
2161
2162
2163                        },
2164                        function () {
2165                            //error
2166                            console.log("something went wrong")
2167                        });
2168
2169
2170                })
2171
2172            }
2173
2174
2175            function validateEmail(email) {
2176                if (!email || email.length < 2) {
2177                    return false
2178                }
2179                var re = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
2180                return re.test(email);
2181            }
2182
2183            function validateName(name) {
2184                if (typeof (Autience.utils.nestedValue(widget, ['components', 'emailSubscription', 'values', 'askName'])) != 'undefined') {
2185                    if (!(Autience.utils.nestedValue(widget, ['components', 'emailSubscription', 'values', 'askName']))) {
2186                        return true
2187                    }
2188                }
2189
2190                if (!(Autience.utils.nestedValue(widget, ['components', 'namePlaceholder', 'values', 'showName']))) {
2191                    return true
2192                }
2193
2194                if (!name || name.length < 2) {
2195                    return false
2196                }
2197
2198                //var r_name = new RegExp(/^[a-zA-Z. ]+$/);//check that only alphabets are allowed. This is disabled because european names can have other characters
2199                var r_name = new RegExp(/^([^0-9]*)$/) //dont allow numbers
2200
2201                var ret_reg = r_name.test(name)
2202
2203                return ret_reg
2204            }
2205
2206        })
2207
2208        if (yetience_callback) {
2209            yetience_callback()
2210        }
2211
2212    }
2213
2214
2215
2216};
2217window.defineAutienceGDPR = function (yetience_callback) {
2218    //console.log('injecting email.js')
2219    if (Autience) {
2220
2221        Autience.lifecycle.postRender.push(function (widget) {
2222            // console.log('Inside GDPR client side code')
2223            toggleSubmitButton(widget)
2224
2225            Autience.utils.classListen('yel-gdpr-checkbox-' + widget.code, 'click', function (el) {
2226                toggleSubmitButton(widget)
2227            })
2228        })
2229
2230
2231
2232        if (yetience_callback) {
2233            yetience_callback()
2234        }
2235
2236    }
2237
2238    function toggleSubmitButton(widget) {
2239        var submit_id = 'autience-emailform-submit-' + widget.code
2240        var gdpr_checkboxes = document.getElementsByClassName('yel-gdpr-checkbox-' + widget.code)
2241        var num_checked = 0
2242
2243        //  console.log('checkboxes ', gdpr_checkboxes)
2244
2245        var show_consent = Autience.utils.nestedValue(widget, ['components', 'gdprPlaceholder', 'values', 'showConsentCheckbox'])
2246        var show_terms = Autience.utils.nestedValue(widget, ['components', 'gdprPlaceholder', 'values', 'showTermsOfService']) || Autience.utils.nestedValue(widget, ['components', 'gdprPlaceholder', 'values', 'showPrivacyPolicy'])
2247        //  console.log("consent = ", show_consent, " show terms = ", show_terms);
2248        var num_to_be_checked = show_consent + show_terms
2249
2250
2251        for (var i = 0; i < gdpr_checkboxes.length; i++) {
2252            num_checked = num_checked + gdpr_checkboxes[i].checked
2253        }
2254        // console.log('num_to_be_checked ', num_to_be_checked, 'num_checked ', num_checked)
2255
2256        var submit_button = document.getElementById(submit_id)
2257        if (submit_button) {
2258            if (num_checked == num_to_be_checked) {
2259                //submit_button.style.visibility = 'visible'
2260                submit_button.classList.remove("yel-grayed-button");
2261            } else {
2262                //submit_button.style.visibility = 'hidden'
2263                submit_button.classList.add("yel-grayed-button");
2264            }
2265
2266        }
2267    }
2268
2269
2270
2271};
2272window.defineAutienceSocial = function(yetience_callback) {
2273    //console.log('injecting social.js')
2274    if (Autience) {
2275        //console.log('really injecting social.js')
2276        Autience.lifecycle.postRender.push(function(widget) {
2277
2278            Autience.setup.networks.forEach(function(N) {
2279                //console.log(N)
2280                bindAutienceShare(N.label, 'autience-network-' + N.label, N.sharing_link, N.sharing_param)
2281            })
2282
2283
2284            function bindAutienceShare(network, button_id, share_link, share_param) {
2285
2286                //console.log('binding ' + network + ' to ' + button_id)
2287
2288                var Config = {
2289                    Link: "a.share",
2290                    Width: 500,
2291                    Height: 500
2292                }
2293                var encoded_url = encodeURIComponent(window.location)
2294
2295                Autience.utils.idListen(button_id, 'click', PopupHandler)
2296
2297                function PopupHandler(e) {
2298                    console.log('clicked on ' + network)
2299
2300
2301                    console.log('share_link- ' + share_link)
2302                    console.log('share_param- ' + share_param)
2303
2304                    e = (e ? e : window.event);
2305                    var t = (e.target ? e.target : e.srcElement);
2306
2307                    // popup position
2308                    var
2309                        px = Math.floor(((screen.availWidth || 1024) - Config.Width) / 2),
2310                        py = Math.floor(((screen.availHeight || 700) - Config.Height) / 2);
2311
2312                    // open popup
2313                    var popup = window.open(share_link + '?' + share_param + '=' + encoded_url, "social",
2314                        "width=" + Config.Width + ",height=" + Config.Height +
2315                        ",left=" + px + ",top=" + py +
2316                        ",location=0,menubar=0,toolbar=0,status=0,scrollbars=1,resizable=1");
2317                    if (popup) {
2318                        popup.focus();
2319                        if (e.preventDefault) e.preventDefault();
2320                        e.returnValue = false;
2321                    }
2322
2323                    return !!popup;
2324                }
2325            }
2326
2327        })
2328
2329        if (yetience_callback) {
2330            yetience_callback()
2331        }
2332    }
2333};
2334window.defineAutienceRedirect = function(yetience_callback) {
2335    Autience.lifecycle.postRender.push(function(widget) {
2336
2337        var component_array = []
2338
2339        for (var tag in widget.components) {
2340            component_array.push({
2341                tag: tag,
2342                component: widget.components[tag]
2343            })
2344        }
2345
2346        component_array.forEach(function(item) {
2347            Autience.utils.executeOnClass('autience-redirect-' + item.tag, function(el) {
2348                console.log('found redirect button ' + item.tag)
2349
2350                Autience.utils.listen(el, 'click', function() {
2351                    //console.log('redirect button clicked')
2352                    //console.log(item.component)
2353                    var operation = item.component.values.operation
2354                    var url = null
2355                    switch (operation) {
2356                        case 'redirect':
2357                            url = item.component.values.redirectTo
2358                            break
2359                        case 'redirectClicked':
2360                            url = Autience.current_link
2361                            break
2362                    }
2363
2364                    console.log('redirect to ' + url)
2365                    switch (item.component.values.redirectOn) {
2366                        case 'same':
2367
2368                            Autience.utils.redirect(url)
2369                            break
2370
2371                        case 'new':
2372
2373                            Autience.utils.redirect(url, '_blank')
2374                            break
2375                    }
2376
2377                    Autience.utils.closeWidget(widget)
2378                })
2379            })
2380        })
2381
2382    })
2383
2384    if (yetience_callback) {
2385        yetience_callback()
2386    }
2387
2388
2389};
2390window.defineAutienceChat = function (yetience_callback) {
2391    if (Autience) {
2392        Autience.lifecycle.postRender.push(function (widget) {
2393
2394            Autience.setup.networks.forEach(function (N) {
2395                bindAutienceChat("zopim")
2396            })
2397
2398
2399            function bindAutienceChat(chatProvider) {
2400                //close popup
2401                Autience.utils.classListen('autience-open-chat', 'click', function () {
2402                    if (typeof zE != 'undefined' && typeof $zopim != 'undefined') {
2403                        zE.activate()
2404                        $zopim.livechat.window.show();
2405                        //$zopim.livechat.window.openPopout()
2406                    } else {
2407                        console.log('Zopim is not installed')
2408                    }
2409                })
2410
2411            }
2412        })
2413
2414
2415        Autience.lifecycle.display.push(function (widget) {
2416            if (typeof $zopim != 'undefined') {
2417                //for zopim popup to be shown as "in the popup"
2418                var yel_body_height = window.innerHeight;
2419                var yel_body_width = window.innerWidth;
2420                var yel_zopim_height = 400;
2421                var yel_zopim_width = 310;
2422                var yel_popup_offset = 76;
2423                var chat_wrapper = document.getElementById("yel-chat-wrapper")
2424
2425                if (chat_wrapper) {
2426                    var yel_loc = chat_wrapper.getBoundingClientRect();
2427
2428                    $zopim(function () {
2429                        //open the chat if it is closed
2430                        $zopim.livechat.window.show();
2431
2432                        //change location
2433                        $zopim.livechat.window.setOffsetHorizontal(yel_body_width - yel_zopim_width - yel_loc.left - 5);
2434                        $zopim.livechat.window.setOffsetVertical((yel_body_height - yel_zopim_height) - yel_popup_offset);
2435
2436                        /*var ua = navigator.userAgent.toLowerCase(),
2437                        platform = navigator.platform.toLowerCase();
2438                        platformName = ua.match(/ip(?:ad|od|hone)/) ? ‘ios’ : (ua.match(/(?:webos|android)/) || platform.match(/mac|win|linux/) || [‘other’])[0],
2439                        isMobile = /ios|android|webos/.test(platformName);*/
2440                        console.log(yel_body_width)
2441                        if (yel_body_width < 481) {
2442                            console.log("ot is mobile")
2443                            $zopim.livechat.window.setOffsetVertical((yel_body_height - yel_zopim_height) - yel_popup_offset);
2444                        }
2445
2446                    })
2447                }
2448
2449
2450
2451            }
2452        })
2453
2454        if (yetience_callback) {
2455            yetience_callback()
2456        }
2457    }
2458
2459
2460};
2461window.defineAutienceBack = function(yetience_callback) {
2462    /*
2463    Autience.lifecycle.render.push(function(widget) {
2464        // console.log('inside back button code')
2465        // console.log(widget.trigger)
2466        //console.log('checking for  trigger for back button')
2467
2468
2469        if (((Autience.utils.nestedValue(widget, ['trigger', 'trigger'])) == 'back') && !window.location.hash) {
2470            //console.log('inserting  trigger for back button')
2471            var history_length = window.history.length
2472                //console.log('history length before - ' + history_length)
2473
2474            setTimeout(function() {
2475                //console.log('setting hash using window.location.hash')
2476                window.location.hash = Autience.utils.randomString(); //
2477
2478                setTimeout(function() {
2479                    Autience.hash_set = true
2480                }, 1000)
2481
2482                setTimeout(function() {
2483                    //console.log('history length after setting hash using window.location.hash ' + window.history.length)
2484                    //if history length is still the same that means popup on back button wont work
2485                    if (history_length == window.history.length) {
2486                        //console.log('changing hash by changing location')
2487                        var new_location = window.location.protocol + '//' + window.location.host + window.location.pathname + '#' + Autience.utils.randomString()
2488                        window.location = new_location
2489
2490                        setTimeout(function() {
2491                            //console.log('history length after setting hash using window.location ' + window.history.length)
2492                            if (history_length == window.history.length) {
2493                                if (window.history.pushState) {
2494                                    new_location = window.location.protocol + '//' + window.location.host + window.location.pathname + '#' + Autience.utils.randomString()
2495                                        //console.log('inserting using window.history.pushState')
2496                                    window.history.pushState(null, null, new_location)
2497                                    setTimeout(function() {
2498                                        //console.log('history length after pushState- '+window.history.length)
2499                                    }, 1000)
2500                                }
2501
2502                            }
2503                        }, 1000)
2504                    }
2505                }, 1000)
2506            }, 1000)
2507
2508
2509        } else {
2510            //console.log('no need to insert trigger for back button')
2511            //console.log('hash at this point of time- ' + window.location.hash)
2512            if (!window.location.hash) {
2513                console.log('hash is not defined')
2514            }
2515        }
2516
2517    })
2518    */
2519
2520    Autience.lifecycle.render.push(function(widget) {
2521        if ((Autience.utils.nestedValue(widget, ['trigger', 'trigger'])) == 'back') {
2522            //Add an extra state in the browser with the same url as current one
2523            if (window.history && window.history.pushState) {
2524                history.pushState({
2525                    foo: "bar"
2526                }, "page 2", window.location.pathname);
2527            } else {
2528                console.log('window.history is not defined on this browser')
2529            }
2530
2531        }
2532    })
2533
2534    if (yetience_callback) {
2535        yetience_callback()
2536    }
2537}
2538
2539window.defineAutienceActionButton = function (yetience_callback) {
2540    //honor disable widget setting
2541
2542    Autience.lifecycle.displayValidation.push(function (widget) {
2543        //return true = show, false = hide
2544        if (isActionButtonTheme(widget.themeType)) {
2545            var widget_enabled = widget.configuration.what.enable
2546
2547            if (widget_enabled) {
2548                //console.log('enabled')
2549                return true
2550            } else {
2551                // console.log('disabled')
2552                return false
2553            }
2554        }
2555        return true
2556    })
2557
2558
2559
2560    //Keep the button on screen when "no" is clicked in yes no popup
2561    Autience.lifecycle.postRender.push(function (widget) {
2562        if (isActionButtonTheme(widget.themeType) && widget.theme == "action-button-yesno") {
2563
2564            // for button 1 - YES
2565            // if (widget.components.button1Link.values.operation == 'close') {
2566            if ((Autience.utils.nestedValue(widget, ['components', 'button1Link', 'values', 'operation'])) == 'close') {
2567                Autience.utils.classListen('yel-yes-button', 'click', function (el) {
2568                    document.getElementsByClassName("yel-ab-main-wrapper")[0].style.visibility = "visible"
2569                    document.getElementById("yel-main-box-wrapper").style.display = "none"
2570                    document.getElementById("yel-circle-wrapper").style.display = "block"
2571
2572                })
2573            }
2574
2575            // for button 2 - NO
2576            // if (widget.components.button2Link.values.operation == 'close') {
2577            if ((Autience.utils.nestedValue(widget, ['components', 'button2Link', 'values', 'operation'])) == 'close') {
2578                Autience.utils.classListen('yel-no-button', 'click', function (el) {
2579                    document.getElementsByClassName("yel-ab-main-wrapper")[0].style.visibility = "visible"
2580                    document.getElementById("yel-main-box-wrapper").style.display = "none"
2581                    document.getElementById("yel-circle-wrapper").style.display = "block"
2582
2583                })
2584            }
2585        }
2586    })
2587
2588    //close on closing small popup
2589    Autience.lifecycle.postRender.push(function (widget) {
2590        if (isActionButtonTheme(widget.themeType)) {
2591            Autience.utils.classListen('yel-arrow-box-close', 'click', function (el) {
2592                //console.log('yel-arrow-box-close clicked')
2593                document.getElementById("yel-arrow-wrapper").style.display = "none"
2594            })
2595        }
2596    })
2597
2598    //close on closing Large popup
2599    Autience.lifecycle.postRender.push(function (widget) {
2600        if (isActionButtonTheme(widget.themeType)) {
2601            Autience.utils.classListen('yel-mb-close', 'click', function (el) {
2602                //console.log('yel-main-box-close clicked')
2603                document.getElementById("yel-main-box-wrapper").style.display = "none"
2604            })
2605        }
2606    })
2607
2608    //big popup on clicking button
2609    Autience.lifecycle.postRender.push(function (widget) {
2610        if (isActionButtonTheme(widget.themeType)) {
2611            document.getElementsByClassName("yel-main-box-wrapper")[0].style.display = "none";
2612            Autience.utils.classListen('yel-cta-button', 'click', function (el) {
2613                //Open big popup
2614                //set css as display:block for yel-main-box-wrapper
2615                document.getElementsByClassName("yel-main-box-wrapper")[0].style.display = "block";
2616            })
2617        }
2618    })
2619
2620    //check if it is an action button theme, only then execute the functions
2621    function isActionButtonTheme(themeType) {
2622        if (themeType == "ActionButtons")
2623            return true
2624        else
2625            return false
2626    }
2627
2628
2629    if (yetience_callback) {
2630        yetience_callback()
2631    }
2632}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.