PageSourceSearch

https://www.fool.ca/wp-content/mu-plugins/fool-wp-assets/js/Fool/Base.js?ver=Jan%207%2C%202021

js fool.ca collected 2026-09-24 19:28:39 UTC 6,427 bytes, 178 lines download raw bytes

1jQuery.foolNameSpace = function() {
2    var a=arguments, o=null, i, j, d;
3    for (i=0; i<a.length; i=i+1) {
4        d=a[i].split(".");
5        o=window;
6        for (j=0; j<d.length; j=j+1) {
7            o[d[j]]=o[d[j]] || {};
8            o=o[d[j]];
9        }
10    }
11    return o;
12};
13
14jQuery.foolNameSpace('Fool');
15
16Fool.Base = function($) {
17	
18    // private
19    var self, domain = SiteInfo.domain;
20	
21	//public
22    return {
23
24        initialize: function() {
25            self = this;
26            this.eatConsole();
27            this.setPrintables();
28            this.appendMarketingVarsToCtaButton();
29        },
30
31        setPrintables: function(){
32            $(".print-printables").click(function() {
33                // Print the DIV.
34                $(".printable").print();
35                // Cancel click event.
36                return( false );
37            });
38        },
39
40        eatConsole: function() {
41            /* Let IE and other browsers eat calls to console.log accidentally committed to svn */
42            if (typeof console == 'undefined') {
43                window.console = {
44                    log: function(msg) { return; },info: function(msg) { return; },
45                    debug: function(msg) { return; },warn: function(msg) { return; },
46                    error: function(msg) { return; },dir: function() { return; },
47                    time: function() { return; },timeEnd: function() { return; },
48                    profile: function() { return; },profileEnd: function() { return; },
49                    trace: function() { return; },group: function() { return; },groupEnd: function() { return; }
50                };
51            }
52        },
53
54        getTimeString: function(oDate) {
55            if (!oDate) {
56                oDate = new Date();
57            }
58            
59            var sMonths, sDate, sHours, sMinutes, sSeconds, sMilliseconds;
60            var sTime = oDate.getFullYear().toString();
61
62            sMonths = (oDate.getMonth() + 1).toString(); // zero-based
63            sTime += sMonths.length == 1 ? "0" + sMonths : sMonths;
64
65            sDate = oDate.getDate().toString();
66            sTime += sDate.length == 1 ? "0" + sDate : sDate;
67
68            sHours = oDate.getHours().toString();
69            sTime += sHours.length == 1 ? "0" + sHours : sHours;
70
71            sMinutes = oDate.getMinutes().toString();
72            sTime += sMinutes.length == 1 ? "0" + sMinutes : sMinutes;
73
74            sSeconds = oDate.getSeconds().toString();
75            sTime += sSeconds.length == 1 ? "0" + sSeconds : sSeconds;
76
77            sMilliseconds = oDate.getMilliseconds().toString();
78            if (sMilliseconds.length == 1) {
79                sTime += "00" + sMilliseconds;
80            }
81            else if (sMilliseconds.length == 2) {
82                sTime += "0" + sMilliseconds;
83            }
84            else {
85                sTime += sMilliseconds;
86            }
87
88            return sTime;
89        },
90
91        // Cookie Util functions
92        setCookie: function(cookieName) {
93            var set = ('Cookies' in window) ? Cookies : jQuery.cookie;
94            if (Fool.Base.getCookie(cookieName)) {
95                if (Fool.Base.getCookie(cookieName) !== '-1') {
96                    var newValue = parseInt(Fool.Base.getCookie(cookieName)) + 1;
97                    set(cookieName, newValue, { expires: 7, path: '/', domain: domain, secure: true });
98                }
99            } else {
100                set(cookieName, 1, { expires: 7, path: '/', domain: domain, secure: true });
101            }
102        },
103
104        parseVars: function(queryVars) {
105            var vars = [], hash;
106            var hashes = queryVars.split('&');
107            for(var i = 0; i < hashes.length; i++)
108            {
109                hash = hashes[i].split('=');
110                vars.push(hash[0]);
111                vars[hash[0]] = hash[1];
112            }
113            return vars;
114        },
115		
116        getCookie: function(cookieName) {
117            if ('Cookies' in window) {
118                return Cookies.get(cookieName);
119            }
120            return document.cookie.indexOf(cookieName) != -1 ? jQuery.cookie(cookieName) : false;
121        },
122
123        resetCookie: function(cookieName) {
124            var set = ('Cookies' in window) ? Cookies : jQuery.cookie;
125            console.log('Fool.Base.resetCookie', cookieName);
126            set(cookieName, 1, { expires: 7, path: '/', domain: domain, secure: true });
127        },
128
129        killCookie: function(cookieName) {
130            var set = ('Cookies' in window) ? Cookies : jQuery.cookie;
131            // ecapped, don't recreate
132            set(cookieName, -1, { expires: 3650, path: '/', domain: domain, secure: true });
133        },
134
135        getParameterByName: function(name) {
136            name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
137            var regexS = "[\\?&]" + name + "=([^&#]*)";
138            var regex = new RegExp(regexS);
139            var results = regex.exec(window.location.href);
140            if(results == null)
141                return "";
142            else
143                return decodeURIComponent(results[1].replace(/\+/g, " "));
144        },
145
146        htmlEntities: function(str) {
147            if (!str) return;
148            return String(str).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
149        },
150
151        appendMarketingVarsToCtaButton: function () {
152            var currentWindowParams = new URLSearchParams(window.location.search);
153            var cta = $('.cta-reveal a');
154            if (cta.length < 1) {
155                return;
156            }
157            cta.each(function () {
158                var ctaUrl = new URL($(this).attr('href'));
159                var ctaParams = ctaUrl.search ? new URLSearchParams(ctaUrl.search) : new URLSearchParams();
160
161                // check to see if CTA url already has some params defined in a query string and merge them, leaving originals intact
162                currentWindowParams.forEach(function (value, key) {
163                    if (!ctaParams.has(key)) { // key not found in CTA query string, so add it
164                        ctaParams.append(key, value);
165                    }
166                });
167
168                ctaUrl.search = ctaParams.toString();
169                $(this).attr('href', ctaUrl.toString());
170            });
171        }
172    };
173
174}(jQuery.noConflict());
175
176jQuery(document).ready(function() {
177	Fool.Base.initialize();
178});

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.