PageSourceSearch

https://www.the-puppy-dog-place.com/sd/support-files/mobile.js

js the-puppy-dog-place.com collected 2026-10-02 14:07:04 UTC 18,660 bytes, 482 lines download raw bytes

1var MOBILE = MOBILE || {};
2
3MOBILE.viewMode = "full"; // or "mobile"
4MOBILE.deviceType = "other"; // or "mobile"
5MOBILE.currentSection = "content"; // or "navigation"
6MOBILE.orientation = ""; // "landscape" or "portrait"
7MOBILE.toolbarFactor = 0;
8MOBILE.mobileViewHeight = 0;
9MOBILE.footerHeight = 0;
10MOBILE.userAgent = "";
11MOBILE.toolbarEl = null;
12MOBILE.toolbarInnerWrapperEl = null;
13MOBILE.mobileBtnEl = null;
14MOBILE.navBtnEl = null;
15MOBILE.toTopBtnEl = null;
16MOBILE.enabled = false;
17MOBILE.contentColumnWidth = 0;
18
19MOBILE.checkIfMobile = function() {
20    if (!MOBILE.enabled) {
21        MOBILE.enabled = /mobileTrial=1/.test(document.cookie);
22    }
23    MOBILE.userAgent = navigator.userAgent;
24    if (MOBILE.enabled && MOBILE.userAgent.match(/iPhone|iPod|BlackBerry|Android/i)) { // we are on target mobile device
25        MOBILE.deviceType = "mobile";
26        document.documentElement.className += " m";
27        if (localStorage.getItem("fullView")) { // full site view
28            document.documentElement.className += " fullView";
29            MOBILE.viewMode = "full";
30        } else { // mobile view
31            document.documentElement.className += " mobile";
32            MOBILE.viewMode = "mobile";
33        }
34        if (MOBILE.userAgent.match(/Android 2/i)) { // Android 2.x fix
35            document.documentElement.className += " android2";
36        }
37    }
38};
39
40MOBILE.changeViewMode = function(mode) {
41    if (mode === "full") { // change to full site view
42        localStorage.setItem("fullView", true);
43        window.location.reload();
44    } else if (mode === "mobile") { // change to mobile view
45        localStorage.removeItem("fullView");
46        window.location.reload();
47    }
48};
49
50MOBILE.setHeaderHeight = function() {
51    var header = document.getElementById("Header");
52    var headerLiner = header.querySelector(".Liner");
53    var headerLinerBgUrl = window.getComputedStyle(headerLiner, null).getPropertyValue("background-image");
54    var phantomHeaderImage = document.createElement("img");
55    var newHeight = 0;
56    phantomHeaderImage.src = headerLinerBgUrl.replace(/^url\(["']?/, '').replace(/["']?\)$/, ' ');
57    phantomHeaderImage.className = "phantomHeaderImage";
58    phantomHeaderImage.width = header.offsetWidth;
59    header.appendChild(phantomHeaderImage);
60
61    var readNewHeight = function() {
62        newHeight = phantomHeaderImage.offsetHeight - 3;
63        if (newHeight > 0) {
64            headerLiner.style.minHeight = newHeight + "px";
65            if (MOBILE.viewMode === "mobile") {
66                MOBILE.setFooterPosition();
67            }
68        }
69    };
70
71    if (phantomHeaderImage.complete) {
72        readNewHeight();
73    } else {
74        phantomHeaderImage.onload = function() {
75            readNewHeight();
76        }
77    }
78
79    var onResize = function() {
80        phantomHeaderImage.width = header.offsetWidth;
81        readNewHeight();
82    };
83
84    window.addEventListener("resize", onResize, true);
85};
86
87MOBILE.fullBtnText = MOBILE.fullBtnText || 'Full Site';
88MOBILE.mobileBtnText = MOBILE.mobileBtnText || 'View Mobile Site';
89MOBILE.navBtnText = MOBILE.navBtnText || 'Navigation';
90MOBILE.toTopBtnText = MOBILE.toTopBtnText || 'Back to Top';
91
92MOBILE.addToolbars = function() {
93    var body = document.getElementsByTagName("body")[0];
94    var pageWrapper = document.getElementById("PageWrapper");
95    var navColumnEl = document.getElementById("NavColumn");
96    var toolbarEl = document.createElement("div");
97    var toolbarInnerWrapperEl = document.createElement("div");
98    toolbarEl.setAttribute("id", "toolbar");
99    toolbarInnerWrapperEl.setAttribute("id", "toolbarInnerWrapper");
100    toolbarInnerWrapperEl.innerHTML = '<button id="fullBtn">'+MOBILE.fullBtnText+'</button>' +
101        '<button id="mobileBtn">'+MOBILE.mobileBtnText+'</button>' +
102        '<button id="navBtn">'+MOBILE.navBtnText+'</button>' +
103        '<button id="toTopBtn">'+MOBILE.toTopBtnText+'</button>';
104    toolbarEl.appendChild(toolbarInnerWrapperEl);
105    body.insertBefore(toolbarEl, pageWrapper);
106    MOBILE.toolbarEl = toolbarEl;
107    MOBILE.toolbarInnerWrapperEl = toolbarInnerWrapperEl;
108
109    if (MOBILE.viewMode === "full") { // avoid flickering on start
110        toolbarEl.style.display = "none";
111    }
112
113    var fullBtnEl = document.getElementById("fullBtn");
114    var mobileBtnEl = document.getElementById("mobileBtn");
115    var navBtnEl = document.getElementById("navBtn");
116    var toTopBtnEl = document.getElementById("toTopBtn");
117    MOBILE.mobileBtnEl = mobileBtnEl;
118    MOBILE.navBtnEl = navBtnEl;
119    MOBILE.toTopBtnEl = toTopBtnEl;
120
121    fullBtnEl.onclick = function() { // change to full view
122        MOBILE.changeViewMode("full");
123    };
124
125    mobileBtnEl.onclick = function() { // change to mobile view
126        MOBILE.changeViewMode("mobile");
127    };
128
129    navBtnEl.onclick = function() { // scroll to nav
130        MOBILE.scrollTo(navColumnEl.offsetTop - 35); // 35 = toolbar height
131        MOBILE.switchButton("top");
132    };
133
134    toTopBtnEl.onclick = function() { // scroll to top
135        MOBILE.scrollTo(0);
136        MOBILE.switchButton("nav");
137    };
138};
139
140MOBILE.resizeToolbar = function() {
141    var horizontalSpace = screen.width;
142    var dpr = 1;
143    if (window.devicePixelRatio !== undefined) {
144        dpr = window.devicePixelRatio;
145    }
146
147    // buggy screen width fix (iPhone and Android Chrome)
148    if (MOBILE.userAgent.match(/iPhone/i) || (MOBILE.userAgent.match(/Android/i) && MOBILE.userAgent.match(/Chrome/i))) {
149        if ((window.orientation === 90) || (window.orientation === -90)) { // if in landscape mode
150            horizontalSpace = screen.height;
151        }
152    }
153    if (MOBILE.userAgent.match(/iPhone/i)) { // iPhone fix
154        if (dpr === 2) {
155            // retina fix for buggy screen size
156            horizontalSpace = horizontalSpace * 2;
157        }
158    }
159
160    var toolbarFactor = window.innerWidth / (horizontalSpace / dpr);
161    if (toolbarFactor !== MOBILE.toolbarFactor) {
162        MOBILE.toolbarFactor = toolbarFactor;
163
164        var newPadding = 2 * toolbarFactor;
165        newPadding = newPadding.toFixed(2) + "px";
166        var newFontSize = 12 * toolbarFactor;
167        newFontSize = newFontSize.toFixed(2) + "px";
168
169        //MOBILE.mobileBtnEl.innerHTML = "iw = " + window.innerWidth + " hs = " + horizontalSpace + " dpr = " + dpr + " f = " + toolbarFactor.toFixed(2);
170
171        MOBILE.mobileBtnEl.style.fontSize = newFontSize;
172        MOBILE.toolbarEl.style.padding = newPadding;
173        MOBILE.toolbarEl.style.display = "block";
174    }
175};
176
177MOBILE.refreshToolbar = function() {
178    MOBILE.toolbarEl.style.display = "none";
179    setTimeout(function() {
180        MOBILE.toolbarEl.style.display = "block";
181        MOBILE.toolbarInnerWrapperEl.style.width = window.innerWidth + "px"; // display:table fix
182    }, 500);
183};
184
185MOBILE.detectCurrentSection = function() {
186    var navColumnEl = document.getElementById("NavColumn");
187    var navColumnTopPosition = navColumnEl.offsetTop;
188    if ((navColumnTopPosition - window.pageYOffset - window.innerHeight) < 0) {
189        if (MOBILE.currentSection === "content") {
190            MOBILE.switchButton("top");
191            MOBILE.currentSection = "navigation";
192        }
193    } else {
194        if (MOBILE.currentSection === "navigation") {
195            MOBILE.switchButton("nav");
196            MOBILE.currentSection = "content";
197        }
198    }
199};
200
201MOBILE.switchButton = function(targetBtn) {
202    if (targetBtn === "top") {
203        MOBILE.navBtnEl.style.display = "none";
204        MOBILE.toTopBtnEl.style.display = "inline-block";
205    } else { // navigation
206        MOBILE.toTopBtnEl.style.display = "none";
207        MOBILE.navBtnEl.style.display = "inline-block";
208    }
209};
210
211MOBILE.scrollTo = function(y) {
212    var body = document.getElementsByTagName("body")[0];
213    var div = document.createElement("div");
214    div.className = "iosbtnfix";
215    body.appendChild(div);
216    window.scrollTo(0, y);
217    setTimeout(function() {
218        body.removeChild(document.querySelectorAll(".iosbtnfix")[0]);
219    }, 500);
220};
221
222MOBILE.orientationMarker = function() {
223    if ((window.orientation === 90) || (window.orientation === -90)) { // if in landscape mode
224        document.documentElement.className = document.documentElement.className.replace(/(^|\s+)portrait(\s+|$)/, ' ');
225        document.documentElement.className += " landscape";
226        MOBILE.orientation = "landscape";
227    } else { // portrait
228        document.documentElement.className = document.documentElement.className.replace(/(^|\s+)landscape(\s+|$)/, ' ');
229        document.documentElement.className += " portrait";
230        MOBILE.orientation = "portrait";
231    }
232};
233
234MOBILE.setFooterPosition = function() {
235    var footerEl = document.getElementById("Footer");
236    var NavColumnEl = document.getElementById("NavColumn");
237    var ExtraColumnEl = document.getElementById("ExtraColumn");
238    var mobileViewHeight = NavColumnEl.offsetTop - parseInt(window.getComputedStyle(NavColumnEl, null).getPropertyValue("margin-top"), 10);
239
240    if (!NavColumnEl && !ExtraColumnEl) {
241        return;
242    }
243
244    var footerHeight = footerEl.offsetHeight;
245
246    if (mobileViewHeight !== MOBILE.mobileViewHeight) {
247        footerEl.style.top = mobileViewHeight + "px";
248        MOBILE.mobileViewHeight = mobileViewHeight;
249    }
250
251    if (footerHeight !== MOBILE.footerHeight) {
252        NavColumnEl.style.marginTop = footerHeight + "px";
253        if (ExtraColumnEl) {
254            ExtraColumnEl.style.marginTop = footerHeight + "px";
255        }
256        MOBILE.footerHeight = footerHeight;
257    }
258};
259
260MOBILE.fixImageProportions = function() {
261    MOBILE.contentColumnWidth = parseInt(MOBILE.contentColumnWidth);
262    if (MOBILE.contentColumnWidth > 300) {
263        var images = document.querySelectorAll("#ContentColumn .Liner > .ItemCenter > img, #ContentColumn .Liner > .ItemLeft > img, #ContentColumn .Liner > .ItemRight > img, #ContentColumn .Liner > .ImageBlock > img, #ContentColumn .Liner > .ItemCenter > a > img, #ContentColumn .Liner > .ItemLeft > a > img, #ContentColumn .Liner > .ItemRight > a > img, #ContentColumn .Liner > .ImageBlock > a > img, #ContentColumn .Liner > .ImageBlock > .noalignment > a > img, #ContentColumn .Liner > .ImageBlock > .noalignment > img");
264        var width = 0;
265        var borderLeft = 0;
266        var borderRight = 0;
267        var marginLeft = 0;
268        var marginRight = 0;
269        var newWidth;
270        var parent = null;
271        var noalignmentNode = null;
272
273        function setPercentageWidth(img) {
274            borderLeft = parseInt(window.getComputedStyle(img, null).getPropertyValue("border-left-width"), 10);
275            borderRight = parseInt(window.getComputedStyle(img, null).getPropertyValue("border-right-width"), 10);
276            marginLeft = parseInt(window.getComputedStyle(img, null).getPropertyValue("margin-left"), 10);
277            marginRight = parseInt(window.getComputedStyle(img, null).getPropertyValue("margin-right"), 10);
278            if (img.getAttribute("width") !== null) {
279                width = parseInt(img.getAttribute("width"));
280            } else {
281                width = img.naturalWidth;
282            }
283            if (width === 0) {
284                return;
285            }
286            if (width < MOBILE.contentColumnWidth) {
287                newWidth = ((width + borderLeft + borderRight) / MOBILE.contentColumnWidth) * 100;
288                newWidth = newWidth.toFixed(2) + "%";
289                parent = img.parentNode;
290                if (parent.tagName === "A") {
291                    parent = parent.parentNode;
292                }
293                if (parent.className === "noalignment") {
294                    noalignmentNode = parent;
295                    parent = parent.parentNode;
296                }
297                if (parent.className.match(/ItemLeft|ItemRight|ImageBlockLeft|ImageBlockRight/i)) {
298                    parent.style.width = newWidth;
299                    if (marginLeft > 0) {
300                        img.style.marginLeft = 0;
301                        parent.style.paddingLeft = marginLeft + "px";
302                    }
303                    if (marginRight > 0) {
304                        img.style.marginRight = 0;
305                        parent.style.paddingRight = marginRight + "px";
306                    }
307                    img.setAttribute("width", "100%");
308                } else {
309                    img.setAttribute("width", newWidth);
310                    if (noalignmentNode) {
311                        noalignmentNode.style.width = "100%";
312                    }
313                }
314            }
315        }
316
317        for (var i = 0, ilen = images.length; i < ilen; i++) {
318            var widthAttribute = images[i].getAttribute("width");
319            if ((widthAttribute !== null) && (widthAttribute[widthAttribute.length - 1] === "%")) {
320                // skip images that already uses percentage width values
321                continue;
322            }
323            (function(img) {
324                if(img.complete) {
325                    setPercentageWidth(img);
326                } else {
327                    img.onload = function() {
328                        setPercentageWidth(img);
329                    }
330                }
331            }(images[i]));
332        }
333    }
334};
335
336MOBILE.fixAdAlignment = function() {
337    var ads;
338    var i, ilen;
339
340    ads = document.querySelectorAll("#ContentColumn .wasAdSenseBoxLeft");
341    for (i = 0, ilen = ads.length; i < ilen; i++) {
342        ads[i].className = ads[i].className.replace(/(^|\s+)wasAdSenseBoxLeft(\s+|$)/, ' ');
343        ads[i].className += " AdSenseBoxLeft";
344    }
345    ads = document.querySelectorAll("#ContentColumn .wasAdSenseBoxRight");
346    for (i = 0, ilen = ads.length; i < ilen; i++) {
347        ads[i].className = ads[i].className.replace(/(^|\s+)wasAdSenseBoxRight(\s+|$)/, ' ');
348        ads[i].className += " AdSenseBoxRight";
349    }
350
351    ads = document.querySelectorAll("#ContentColumn .AdSenseBoxLeft, #ContentColumn .AdSenseBoxRight");
352    for (i = 0, ilen = ads.length; i < ilen; i++) {
353        if ((ads[i].clientWidth / MOBILE.viewportWidth()) > 0.6) {
354            if (/(^|\s)AdSenseBoxLeft(\s|$)/.test(ads[i].className)) {
355                ads[i].className = ads[i].className.replace(/(^|\s+)AdSenseBoxLeft(\s+|$)/, ' ');
356                ads[i].className += " wasAdSenseBoxLeft";
357            } else if (/(^|\s)AdSenseBoxRight(\s|$)/.test(ads[i].className)) {
358                ads[i].className = ads[i].className.replace(/(^|\s+)AdSenseBoxRight(\s+|$)/, ' ');
359                ads[i].className += " wasAdSenseBoxRight";
360            }
361            ads[i].style.textAlign = "center";
362            ads[i].style.clear = "both";
363        }
364    }
365};
366
367MOBILE.startLoop = function(f, options) {
368    var counter = 0;
369    var max = options.max || 120;
370    var delay = options.delay || 500;
371    var loop = function() {
372        counter++;
373        if (counter > max) {
374            if (typeof options.callback !== 'undefined') {
375                options.callback();
376            }
377            return;
378        }
379        f();
380        setTimeout(function() {
381            loop();
382        }, delay);
383    };
384    loop();
385};
386
387MOBILE.doOnOrientationChange = function() {
388    MOBILE.orientationMarker();
389    MOBILE.startLoop(MOBILE.setFooterPosition, {max: 5, delay: 100});
390    MOBILE.refreshToolbar();
391    MOBILE.startLoop(MOBILE.fixImageProportions, {max: 2, delay: 1500});
392    MOBILE.startLoop(MOBILE.fixAdAlignment, {max: 2, delay: 1500});
393};
394
395MOBILE.removeDesktopOnly = function() {
396    var desktopOnlyItems = document.querySelectorAll(".desktopOnly");
397    for (var i = 0, ilen = desktopOnlyItems.length; i < ilen; i++) {
398        var desktopOnlyItem = desktopOnlyItems[i];
399        desktopOnlyItem.parentNode.removeChild(desktopOnlyItem);
400    }
401};
402
403MOBILE.init = function() {
404    MOBILE.checkIfMobile();
405    if (MOBILE.viewMode === "mobile") {
406        document.write('<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1">');
407    } else { // full
408        if (!MOBILE.userAgent.match(/BlackBerry/i)) {
409            document.write('<meta name="viewport" content="maximum-scale=1">');
410        }
411    }
412};
413
414MOBILE.doEndOfHead = function() {
415    if (typeof mobileSandBox !== 'undefined') {
416        MOBILE.enabled = true;
417        MOBILE.init();
418    }
419};
420
421MOBILE.doAfterHeader = function() {
422    if (MOBILE.viewMode === "mobile") {
423        MOBILE.setHeaderHeight();
424    }
425};
426
427MOBILE.doEndOfBody = function() {
428    if (MOBILE.deviceType === "mobile") {
429        MOBILE.addToolbars();
430        if (MOBILE.userAgent.match(/BlackBerry|Android 2/i)) {
431            // for the devices that don't support position:fixed
432            MOBILE.toolbarEl.style.position = "absolute";
433            window.addEventListener ("scroll", function() { MOBILE.toolbarEl.style.top = window.scrollY + 'px'; }, false);
434        }
435        if (MOBILE.viewMode === "full") {
436            setInterval(MOBILE.resizeToolbar, 100);
437            window.addEventListener ("resize", MOBILE.resizeToolbar, false);
438        } else { // mobile view
439            MOBILE.orientationMarker();
440            window.addEventListener ("orientationchange", MOBILE.doOnOrientationChange, false);
441            if (!MOBILE.userAgent.match(/iPhone/i)) {
442                window.addEventListener ("resize", MOBILE.refreshToolbar, false);
443            }
444            MOBILE.setFooterPosition();
445            MOBILE.startLoop(MOBILE.setFooterPosition, {max: 960, delay: 500});
446            window.addEventListener ("scroll", MOBILE.detectCurrentSection, false);
447            MOBILE.removeDesktopOnly();
448            MOBILE.fixImageProportions();
449            MOBILE.fixAdAlignment();
450        }
451        // hide side columns on msb.html page
452        if (typeof mobileSandBox !== 'undefined') {
453            var navColumnEl = document.getElementById("NavColumn");
454            var extraColumnEl = document.getElementById("ExtraColumn");
455            if (navColumnEl) {
456                navColumnEl.style.display = "none";
457            }
458            if (extraColumnEl) {
459                extraColumnEl.style.display = "none";
460            }
461        }
462    }
463};
464
465MOBILE.viewportWidth = function() {
466    var viewportWidth;
467    // browsers
468    if (typeof window.innerWidth != "undefined") {
469        viewportWidth = window.innerWidth;
470    }
471    // IE standard compliant mode
472    else if (typeof document.documentElement != "undefined"
473        && typeof document.documentElement.offsetWidth != "undefined"
474        && document.documentElement.offsetWidth != 0) {
475        viewportWidth = document.documentElement.offsetWidth;
476    }
477    // IE quirks mode
478    else {
479        viewportWidth = document.getElementsByTagName('body')[0].offsetWidth;
480    }
481    return viewportWidth;
482};

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.