{"version":3,"file":"onLoad-DrDovK3M.js","sources":["../../../app/assets/javascripts/components/layout/sections/mobile_searcher_app_smart_banner/index.ts","../../../app/assets/javascripts/components/layout/sections/mobile_searcher_app_smart_banner/onLoad.ts"],"sourcesContent":["\nimport u from \"umbrellajs\"\nimport _once from \"lodash/once\"\n\n// # Assumed one element only\nconst getSectionJQueryElement = _once(() => u(\"#layout-section--mobile-searcher-app-smart-banner\"))\n\n\n// # See `app/assets/stylesheets/components/layout/sections/mobile_searcher_app_smart_banner/all.scss`\nconst SHOWN_STATE_CLASS_NAME = \"layout-section--mobile-searcher-app-smart-banner--shown\"\n\nconst hide = () => {\n  getSectionJQueryElement().removeClass(SHOWN_STATE_CLASS_NAME)\n}\n\nexport default {\n  hide,\n}\n","\nimport $ from \"jquery\"\nimport URI from \"urijs\"\n\nimport Cookies from \"plugins/cookies-js/index\"\nimport {\n  requestIdleCallback,\n} from \"plugins/request-animation-frame-polyfill\"\n\nimport WaitObjectByPathPromise from \"app/wait_object_by_path_promise\"\nimport DataRetriever from \"app/data_retriever\"\nimport MobileOsDetection from \"app/detection/mobile_os\"\nimport MobileSearcherAppSmartBanner from \"./index\"\nimport Goal_track from \"app/tracking/goals/track\"\n\n\nimport I18n from \"plugins/i18n-js\"\n\n\nconst {isIOS, isAndroid} = MobileOsDetection\n\n\nconst DONT_SHOW_MOBILE_SMART_BANNER = \"dont_show_searcher_app_smartbanner\"\n\nconst showBannerWithCooldownForMobile = () => {\n  // # ONLY show for searcher app\n  if ($(\"meta[property=\\\"al:android:package\\\"]\").attr(\"content\") !== \"spacious.home\") { return }\n\n  let deep_link_url = null as null|string\n  if (isIOS()){\n    deep_link_url = $(\"meta[property=\\\"al:ios:url\\\"]\").attr(\"content\")\n  }\n\n  if (isAndroid()){\n    deep_link_url = $(\"meta[property=\\\"al:android:url\\\"]\").attr(\"content\")\n  }\n\n  if (!deep_link_url) {\n    MobileSearcherAppSmartBanner.hide()\n  }\n\n\n  let download_link = null as null|string\n\n  if (isAndroid()){\n    const is_user_in_china = DataRetriever.get(\"current-location-country-code-is-china\")\n\n    if (is_user_in_china){\n      download_link = \"http://cdn.spacious.hk/spacious/mobile_searcher_app/releases/official/latest/android/Spacious.apk\"\n    }\n    else{\n      const url_object = URI(\"https://play.google.com/store/apps/details\")\n      url_object.addSearch(\"id\", \"spacious.home\")\n      url_object.addSearch(\"hl\", I18n.locale) // locale attr on the Play Store\n      url_object.addSearch(\"referrer\", `utm_source=${location.hostname}&utm_medium=smart-banner&utm_campaign=${location.pathname}`)\n\n      download_link = url_object.toString()\n    }\n  }\n\n  if (isIOS()){\n    download_link = \"https://itunes.apple.com/app/apple-store/id889041542?pt=95954229&ct=website-smartbanner&mt=8\"\n  }\n\n  $(\".cell--mobile-apps--searcher-app--smart-banner--default-style__btn--install-app\").on(\"click\", () => {\n    if (typeof download_link === \"string\") {\n      window.location.href = download_link\n    }\n\n    // Track Mobile App Download Leads\n    Goal_track.MobileAppDownloadLead.track(\"download link clicked on smartbanner\")\n  })\n\n  $(\".cell--mobile-apps--searcher-app--smart-banner--default-style__btn--open-app\").on(\"click\", () => {\n    const now = new Date().valueOf()\n\n    window.location.href = deep_link_url as string\n\n    setTimeout(() => {\n      if (new Date().valueOf() - now < 1025 && document.hasFocus()) {\n        window.location.href = download_link as string\n\n        // Track Mobile App Download Leads\n        Goal_track.MobileAppDownloadLead.track(\"download link clicked on smartbanner\")\n      }\n    }, 1000)\n\n  })\n\n  $(\".cell--mobile-apps--searcher-app--smart-banner--default-style__close-banner-button\").on(\"click\", () => {\n    MobileSearcherAppSmartBanner.hide()\n    Cookies.set(DONT_SHOW_MOBILE_SMART_BANNER, true, {expires: 86400}) // If banner closed, don\"t show for 1 day\n  })\n\n}\n\n\nconst onLoad = () => {\n  requestIdleCallback(() => {\n    WaitObjectByPathPromise(\"window._spacious_main_css_loaded\")\n    .then(() => {\n      requestIdleCallback(() => {\n        showBannerWithCooldownForMobile()\n      })\n    })\n    .done()\n  })\n}\n\nexport default {onLoad}\n\n\n\n\n"],"names":["getSectionJQueryElement","_once","SHOWN_STATE_CLASS_NAME","hide","MobileSearcherAppSmartBanner","isIOS","isAndroid","MobileOsDetection","DONT_SHOW_MOBILE_SMART_BANNER","showBannerWithCooldownForMobile","$","deep_link_url","download_link","DataRetriever","url_object","URI","I18n","Goal_track","now","Cookies","onLoad","requestIdleCallback","WaitObjectByPathPromise","onLoad$1"],"mappings":"6jCAKA,MAAMA,EAA0BC,EAAM,IAAM,EAAE,mDAAmD,CAAC,EAI5FC,EAAyB,0DAEzBC,EAAO,IAAM,CACOH,EAAA,EAAE,YAAYE,CAAsB,CAC9D,EAEeE,EAAA,CACb,KAAAD,CACF,ECEM,CAAC,MAAAE,EAAO,UAAAC,CAAA,EAAaC,EAGrBC,EAAgC,qCAEhCC,EAAkC,IAAM,CAE5C,GAAIC,EAAE,qCAAuC,EAAE,KAAK,SAAS,IAAM,gBAAmB,OAEtF,IAAIC,EAAgB,KAChBN,MACFM,EAAgBD,EAAE,6BAA+B,EAAE,KAAK,SAAS,GAG/DJ,MACFK,EAAgBD,EAAE,iCAAmC,EAAE,KAAK,SAAS,GAGlEC,GACHP,EAA6B,KAAK,EAIpC,IAAIQ,EAAgB,KAEpB,GAAIN,IAGF,GAFyBO,EAAc,IAAI,wCAAwC,EAGjED,EAAA,wGAEd,CACI,MAAAE,EAAaC,EAAI,4CAA4C,EACxDD,EAAA,UAAU,KAAM,eAAe,EAC/BA,EAAA,UAAU,KAAME,EAAK,MAAM,EAC3BF,EAAA,UAAU,WAAY,cAAc,gBAAS,SAAQ,0CAAyC,gBAAS,SAAU,EAE5HF,EAAgBE,EAAW,SAAS,CAAA,CAIpCT,MACcO,EAAA,gGAGlBF,EAAE,iFAAiF,EAAE,GAAG,QAAS,IAAM,CACjG,OAAOE,GAAkB,WAC3B,OAAO,SAAS,KAAOA,GAIdK,EAAA,sBAAsB,MAAM,sCAAsC,CAAA,CAC9E,EAEDP,EAAE,8EAA8E,EAAE,GAAG,QAAS,IA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