﻿!function (a) { "use strict"; var b = a.userAgent = function (a) { function b(a) { var b = {}, d = /(dolfin)[ \/]([\w.]+)/.exec(a) || /(chrome)[ \/]([\w.]+)/.exec(a) || /(opera)(?:.*version)?[ \/]([\w.]+)/.exec(a) || /(webkit)(?:.*version)?[ \/]([\w.]+)/.exec(a) || /(msie) ([\w.]+)/.exec(a) || a.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+))?/.exec(a) || ["", "unknown"]; return "webkit" === d[1] ? d = /(iphone|ipad|ipod)[\S\s]*os ([\w._\-]+) like/.exec(a) || /(android)[ \/]([\w._\-]+);/.exec(a) || [d[0], "safari", d[2]] : "mozilla" === d[1] ? d[1] = /trident/.test(a) ? "msie" : "firefox" : /polaris|natebrowser|([010|011|016|017|018|019]{3}\d{3,4}\d{4}$)/.test(a) && (d[1] = "polaris"), b[d[1]] = !0, b.name = d[1], b.version = c(d[2]), b } function c(a) { var b = {}, c = a ? a.split(/\.|-|_/) : ["0", "0", "0"]; return b.info = c.join("."), b.major = c[0] || "0", b.minor = c[1] || "0", b.patch = c[2] || "0", b } function d(a) { return e(a) ? "pc" : f(a) ? "tablet" : g(a) ? "mobile" : "" } function e(a) { return a.match(/linux|windows (nt|98)|macintosh/) && !a.match(/android|mobile|polaris|lgtelecom|uzard|natebrowser|ktf;|skt;/) ? !0 : !1 } function f(a) { return a.match(/ipad/) || a.match(/android/) && !a.match(/mobi|mini|fennec/) ? !0 : !1 } function g(a) { return a.match(/ip(hone|od)|android.+mobile|windows (ce|phone)|blackberry|bb10|symbian|webos|firefox.+fennec|opera m(ob|in)i|polaris|iemobile|lgtelecom|nokia|sonyericsson|dolfin|uzard|natebrowser|ktf;|skt;/) ? !0 : !1 } function h(a) { var b = {}, d = /(iphone|ipad|ipod)[\S\s]*os ([\w._\-]+) like/.exec(a) || /(android)[ \/]([\w._\-]+);/.exec(a) || (/android/.test(a) ? ["", "android", "0.0.0"] : !1) || (/polaris|natebrowser|([010|011|016|017|018|019]{3}\d{3,4}\d{4}$)/.test(a) ? ["", "polaris", "0.0.0"] : !1) || /(windows)(?: nt | phone(?: os){0,1} | )([\w._\-]+)/.exec(a) || (/(windows)/.test(a) ? ["", "windows", "0.0.0"] : !1) || /(mac) os x ([\w._\-]+)/.exec(a) || (/(linux)/.test(a) ? ["", "linux", "0.0.0"] : !1) || (/webos/.test(a) ? ["", "webos", "0.0.0"] : !1) || /(bada)[ \/]([\w._\-]+)/.exec(a) || (/bada/.test(a) ? ["", "bada", "0.0.0"] : !1) || (/(rim|blackberry|bb10)/.test(a) ? ["", "blackberry", "0.0.0"] : !1) || ["", "unknown", "0.0.0"]; return "iphone" === d[1] || "ipad" === d[1] || "ipod" === d[1] ? d[1] = "ios" : "windows" === d[1] && "98" === d[2] && (d[2] = "0.98.0"), b[d[1]] = !0, b.name = d[1], b.version = c(d[2]), b } function i(a) { var b = {}, d = /(crios)[ \/]([\w.]+)/.exec(a) || /(daumapps)[ \/]([\w.]+)/.exec(a) || ["", ""]; return d[1] ? (b.isApp = !0, b.name = d[1], b.version = c(d[2])) : b.isApp = !1, b } return a = (a || window.navigator.userAgent).toString().toLowerCase(), { ua: a, browser: b(a), platform: d(a), os: h(a), app: i(a) } }; "object" == typeof window && window.navigator.userAgent && (window.ua_result = b(window.navigator.userAgent) || null) }(function () { return "object" == typeof exports ? (exports.apptools = exports, exports.util = exports, exports) : "object" == typeof window ? (window.apptools = "undefined" == typeof window.apptools ? {} : window.apptools, window.util = "undefined" == typeof window.util ? window.apptools : window.util, window.apptools) : void 0 }());

(function (exports) {
    "use strict";

    exports.goApp = (function () {

        var ua = apptools.userAgent(),
            os = ua.os;

        var intentNotSupportedBrowserList = [
            'firefox',
            'opr'
        ];

        var moveToStore = function (storeURL) {
            window.location.href = storeURL;
        };

        function goApp(context) {

            var willInvokeApp = (typeof context.willInvokeApp === 'function') ? context.willInvokeApp : function () { },
                onAppMissing = (typeof context.onAppMissing === 'function') ? context.onAppMissing : moveToStore,
                onUnsupportedEnvironment = (typeof context.onUnsupportedEnvironment === 'function') ? context.onUnsupportedEnvironment : function () { };

            willInvokeApp();

            //setTimeout(function () {
            if (os.android && context.storeURL) {

                if (isIntentNotSupportedBrowser() || !!context.useUrlScheme) {
                    goApp_android_scheme(context.urlScheme, context.storeURL, onAppMissing);

                } else {
                    goApp_android_intent(context.intentURI);
                }
            } else if (os.ios && context.storeURL) {
                goApp_iOS(context.urlScheme, context.storeURL, onAppMissing);
            } else {
                onUnsupportedEnvironment();
            }
            //}, 100);
        }

        function isIntentNotSupportedBrowser() {
            var blackListRegexp = new RegExp(intentNotSupportedBrowserList.join('|'), "i");
            var isNotSB = blackListRegexp.test(ua.ua);
            if (isNotSB && ua.ua.indexOf('Build/OPR1.') > -1 && ua.ua.indexOf('Chrome') > -1) { // LG 안드로이드 8.0
                isNotSB = false;
            }

            return isNotSB;
        }

        function goApp_iOS(launchURI, storeURL, fallbackFunction) {
            var clickedAt = new Date().getTime();
            setTimeout(function () {
                var now = new Date().getTime();
                if (now - clickedAt < 1500) {
                    fallbackFunction(storeURL);
                }
            }, 1000);

            window.location.href = launchURI;
        }

        function goApp_android_intent(launchURI) {
            top.location.href = launchURI;
        }

        function goApp_android_scheme(launchURI, storeURL, fallbackFunction) {
            var clickedAt = new Date().getTime();
            setTimeout(function () {
                var now = new Date().getTime();
                if (isPageVisible() && now - clickedAt < 1500) {
                    fallbackFunction(storeURL);
                }
            }, 1000);

            var iframe = createHiddenIframe('appLauncher');
            iframe.src = launchURI;
        }

        function isPageVisible() {
            if (typeof document.webkitHidden !== 'undefined') {
                return !document.webkitHidden;
            }
            return true;
        }

        function createHiddenIframe(id) {
            var iframe = document.createElement('iframe');
            iframe.id = id;
            iframe.style.border = 'none';
            iframe.style.width = '0';
            iframe.style.height = '0';
            iframe.style.display = 'none';
            iframe.style.overflow = 'hidden';
            document.body.appendChild(iframe);
            return iframe;
        }

        /**
         * app.을 실행하거나 / store 페이지에 연결하여 준다.
         * @function 
         * @param context {object} urlScheme, intentURI, storeURL, appName, onAppMissing, onUnsupportedEnvironment, willInvokeApp 
         * @example apptools.goApp({ urlScheme : 'daumapps://open', intentURI : '', storeURL: 'itms-app://...', appName: '다음앱' });
         */
        return goApp;

    })();

    exports.goAppViewer = (function () {

        var ua = apptools.userAgent(),
            os = ua.os;

        var intentNotSupportedBrowserList = [
            'firefox',
            'opr'
        ];

        var moveToStore = function (storeURL) {
            window.location.href = storeURL;
        };

        function goAppViewer(context) {
            var willInvokeApp = (typeof context.willInvokeApp === 'function') ? context.willInvokeApp : function () { },
                onAppMissing = (typeof context.onAppMissing === 'function') ? context.onAppMissing : moveToStore,
                onUnsupportedEnvironment = (typeof context.onUnsupportedEnvironment === 'function') ? context.onUnsupportedEnvironment : function () { };

            willInvokeApp();

            if (os.android && context.storeURL) {
                if (context.urlScheme != null && context.urlScheme != undefined) {
                    goApp_android_scheme(context.urlScheme, context.storeURL, onAppMissing);

                } else {
                    goApp_android_intent(context.intentURI);
                }
            } else if (os.ios && context.storeURL) {


                //goApp_iOS(context.urlScheme, context.storeURL, onAppMissing);


                // ios universal link
                if (os.version.major > 8) {
                    window.location.href = context.urlScheme;
                }
                else {
                    goApp_iOS(context.urlScheme, context.storeURL, onAppMissing);
                }
            } else {
                onUnsupportedEnvironment();
            }
        }

        function isIntentNotSupportedBrowser() {
            var blackListRegexp = new RegExp(intentNotSupportedBrowserList.join('|'), "i");
            var isNotSB = blackListRegexp.test(ua.ua);
            if (isNotSB && ua.ua.indexOf('Build/OPR1.') > -1 && ua.ua.indexOf('Chrome') > -1) { // LG 안드로이드 8.0
                isNotSB = false;
            }

            return isNotSB;
        }

        function goApp_iOS(launchURI, storeURL, fallbackFunction) {

            var clickedAt = +new Date;
            setTimeout(function () {
                if (+new Date - clickedAt < 2000) {
                    if (window.confirm("알라딘 뷰어 앱 최신 버전이 설치되어 있지 않습니다.   \n설치페이지로 이동하시겠습니까?")) { location.href = storeURL; }
                }
            }, 1500);

            location.href = launchURI;

            //var clickedAt = new Date().getTime();
            //setTimeout(function () {
            //    var now = new Date().getTime();
            //    if (now - clickedAt < 1500) {
            //        fallbackFunction(storeURL);
            //    }
            //}, 1000);

            //window.location.href = launchURI;
        }

        function goApp_android_intent(launchURI) {
            top.location.href = launchURI;
        }

        function goApp_android_scheme(launchURI, storeURL, fallbackFunction) {
            var clickedAt = new Date().getTime();
            setTimeout(function () {
                var now = new Date().getTime();
                if (isPageVisible() && now - clickedAt < 1500) {
                    fallbackFunction(storeURL);
                }
            }, 1000);

            var iframe = createHiddenIframe('appLauncher');
            iframe.src = launchURI;
        }

        function isPageVisible() {
            if (typeof document.webkitHidden !== 'undefined') {
                return !document.webkitHidden;
            }
            return true;
        }

        function createHiddenIframe(id) {
            var iframe = document.createElement('iframe');
            iframe.id = id;
            iframe.style.border = 'none';
            iframe.style.width = '0';
            iframe.style.height = '0';
            iframe.style.display = 'none';
            iframe.style.overflow = 'hidden';
            document.body.appendChild(iframe);
            return iframe;
        }

        /**
         * app.을 실행하거나 / store 페이지에 연결하여 준다.
         * @function 
         * @param context {object} urlScheme, intentURI, storeURL, appName, onAppMissing, onUnsupportedEnvironment, willInvokeApp 
         * @example apptools.goApp({ urlScheme : 'daumapps://open', intentURI : '', storeURL: 'itms-app://...', appName: '다음앱' });
         */
        return goAppViewer;

    })();


})(window.apptools = (typeof window.apptools === 'undefined') ? {} : window.apptools);




(function (exports) {
    "use strict";
    exports.apptools = (typeof exports.apptools === "undefined") ? {} : exports.apptools;
}(window));


function exe_shoppingApp() {
    var ua = apptools.userAgent(), os = ua.os;
    var intentScheme = '#Intent;scheme=aladinshopping;package=kr.co.aladin.third_shop;end';
    var scheme = os.android ? "aladinshopping://" : "aladinShop://";

    apptools.goApp({ urlScheme: scheme, intentURI: 'intent://' + intentScheme, storeURL: 'itms://itunes.apple.com/kr/app/id365898918?mt=8' });
}

function exe_ebookviewerApp() {
    var ua = apptools.userAgent(), os = ua.os;
    var intentScheme = '#Intent;scheme=aladinreader;package=kr.co.aladin.ebook;end';
    var scheme = os.android ? "aladinreader://" : "aladinreader://";

    apptools.goApp({ urlScheme: scheme, intentURI: 'intent://' + intentScheme, storeURL: 'itms://itunes.apple.com/kr/app/id1023251042?mt=8' });
}


function exe_ebookviewerApp_V1(view, custKey, itemId) {
    var ua = apptools.userAgent(), os = ua.os;
    var scheme = undefined;
    var intentScheme = undefined;
    var url = "move?view=" + view + "&custkey=" + custKey + "&ct=" + Date.now();

    var storeURL = os.android ? "https://play.google.com/store/apps/details?id=kr.co.aladin.ebook" : "itms://itunes.apple.com/kr/app/id1023251042?mt=8";

    if (itemId != null && itemId != 0) {
        url = url + "&itemid=" + itemId;
    }

    if (os.android) {

        if (os.version.major < 4) {
            scheme = "aladinreader://" + url;
        }
        else {
            intentScheme = "Intent://" + url + "#Intent;scheme=aladinreader;package=kr.co.aladin.ebook;end";
        }
    }
    else {

        // ios universal link
        if (os.version.major > 8) {
            scheme = "https://ess1.aladin.co.kr/.well-known/app.html?view=viewer&custkey=" + custKey + "&itemId=" + itemId;
        }
        else {
            scheme = "aladinreader://" + url;
        }

        //scheme = "aladinreader://" + url;
    }

    apptools.goAppViewer({ urlScheme: scheme, intentURI: intentScheme, storeURL: storeURL });
}


function exe_barcodeApp_ByViewType(viewType) {
    var scheme = "";
    var ua = apptools.userAgent(), os = ua.os;
    var returnUrl = "";
    // returnUrl += encodeURIComponent("http://m.aladin.co.kr/m/c2b/c2b_search.aspx?IsBarcode=1&SearchWord=");

    var intentScheme = '#Intent;scheme=aladinshopping;package=kr.co.aladin.third_shop;end';
    if (os.android) {
        scheme = "aladinshopping://move?view=" + viewType + "&url=" + returnUrl;
        intentScheme = '#Intent;scheme=' + scheme + ';package=kr.co.aladin.third_shop;end';
    }
    else {
        scheme = "aladinShop://move?view=" + viewType + "&url=" + returnUrl;
    }
    apptools.goApp({ urlScheme: scheme, intentURI: 'intent://' + intentScheme, storeURL: 'itms://itunes.apple.com/kr/app/id365898918?mt=8' });
}

function exe_barcodeUrl_ByViewType(viewType, returnUrl) {
    location.href = "/m/mservice/common_hooking.aspx?pType=" + viewType + "&url=" + encodeURIComponent(returnUrl);
}

function exe_barcodeApp() {
    exe_barcodeApp_ByViewType("barcode");
}

function exe_barcodeUrl() {
    exe_barcodeUrl_ByViewType("barcode_c2b", "http://m.aladin.co.kr/m/c2b/c2b_search.aspx?SearchWord=");
}

function exe_c2c_barcodeApp() {
    exe_barcodeApp_ByViewType("barcode_c2c");
}

function exe_c2c_barcodeUrl() {
    exe_barcodeUrl_ByViewType("barcode_c2c", "http://m.aladin.co.kr/m/c2c/search.aspx?KeyWord=");
}

function exe_run_barcodeApp() {
    exe_barcodeApp_ByViewType("barcode_run");
}

function exe_run_barcodeUrl() {
    exe_barcodeUrl_ByViewType("barcode_run", "http://m.aladin.co.kr/m/events/searchBarCode.aspx?KeyWord=");
}

function exe_search_barcodeUrl() {
    exe_barcodeUrl_ByViewType("barcode", "http://m.aladin.co.kr/m/msearch.aspx?SearchWord=");
}

function exe_jinyorder_barcodeApp() {
    exe_barcodeApp_ByViewType("barcode_jinyorder");
}

function exe_jinyorder_barcodeUrl() {
    exe_barcodeUrl_ByViewType("barcode_jinyorder", "https://www.aladin.co.kr/m/mjinyorder.aspx");
}