diff options
Diffstat (limited to 'StoneIsland/www/js')
| -rwxr-xr-x | StoneIsland/www/js/index.js | 8 | ||||
| -rw-r--r-- | StoneIsland/www/js/lib/etc/analytics.js | 44 | ||||
| -rwxr-xr-x | StoneIsland/www/js/lib/etc/push.js | 144 | ||||
| -rw-r--r-- | StoneIsland/www/js/lib/etc/sim.js | 43 | ||||
| -rwxr-xr-x | StoneIsland/www/js/lib/view/Serializable.js | 2 | ||||
| -rwxr-xr-x | StoneIsland/www/js/sdk/_sdk.js | 2 |
6 files changed, 107 insertions, 136 deletions
diff --git a/StoneIsland/www/js/index.js b/StoneIsland/www/js/index.js index c8852f64..3947b43e 100755 --- a/StoneIsland/www/js/index.js +++ b/StoneIsland/www/js/index.js @@ -23,7 +23,7 @@ var app = (function(){ app.bind = function(){ document.addEventListener('touchmove', function(e){ e.preventDefault() }) if (!app.accessible) { - FastClick.attach(document.body) + // FastClick.attach(document.body) } } @@ -87,11 +87,11 @@ var app = (function(){ document.addEventListener('resume', app.resumed, false) document.addEventListener('online', app.online, false) document.addEventListener('offline', app.offline, false) - cordova.plugins.Keyboard.disableScroll(true) - cordova.plugins.Keyboard.hideKeyboardAccessoryBar(false) + window.Keyboard.disableScroll(true) + // window.Keyboard.HideKeyboardFormAccessoryBar(false) analytics.init() geo.fetch() - sim.fetch(app.api_ready) + simcard.fetch(app.api_ready) var image = new Image image.src = "./img/compass-logo.png" } diff --git a/StoneIsland/www/js/lib/etc/analytics.js b/StoneIsland/www/js/lib/etc/analytics.js index 2df8a04c..f5f871f5 100644 --- a/StoneIsland/www/js/lib/etc/analytics.js +++ b/StoneIsland/www/js/lib/etc/analytics.js @@ -1,63 +1,21 @@ var analytics = (function() { var analytics = {} - analytics.fields = { - trackingId: 'G-24XNLKH9Z6', - clientId: localStorage.getItem('ga:clientId'), - storage: 'none', - } - analytics.init = function() { console.log("Analytics init") if (window.FirebasePlugin) { window.FirebasePlugin.setAnalyticsCollectionEnabled(true) } - analytics.build() analytics.sendPageView('/') } - - analytics.build = function() { - // ;( function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ - // (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), - // m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) - // })(window,document,'script','https://www.google-analytics.com/analytics.js','ga' ); - - // analytics.ga = window.ga - // analytics.ga('create', analytics.fields) - // // prevent tasks that would abort tracking - // analytics.ga('set', { - // // don't abort if the protocol is not http(s) - // checkProtocolTask: null, - // // don't expect cookies to be enabled - // checkStorageTask: null, - // }) - // // a callback function to get the clientId and store it ourselves - // analytics.ga(function(tracker){ - // localStorage.setItem('ga:clientId', tracker.get('clientId')); - // }) - - // window.dataLayer = window.dataLayer || []; - // analytics.dataLayer = window.dataLayer - // analytics.gtag = () => { analytics.dataLayer.push(arguments) } - // analytics.gtag('js', new Date()) - // analytics.gtag('config', 'G-24XNLKH9Z6') - } analytics.sendPageView = function(path) { console.log("/a\\ send", path) - if (!analytics.gtag) return FirebasePlugin.logEvent("select_content", { content_type: "page_view", item_id: path, }) - // FirebasePlugin.setScreenName(path) - // analytics.gtag('send', { - // // these are the three required properties, check GA's doc for the optional ones - // hitType: 'screenview', - // screenName: path, - // appName: 'StoneIsland' - // }) } - + return analytics })() diff --git a/StoneIsland/www/js/lib/etc/push.js b/StoneIsland/www/js/lib/etc/push.js index a744d5c9..1f0ab9b6 100755 --- a/StoneIsland/www/js/lib/etc/push.js +++ b/StoneIsland/www/js/lib/etc/push.js @@ -1,34 +1,68 @@ var push = (function(){ var push = { settings: {}, disabled: false } - var pushPlugin + // var pushPlugin push.init = function(){ if (! ('device' in window) || (device.platform || "").toLowerCase() !== "ios") { console.log("push disabled") push.disabled = true return } - - pushPlugin = PushNotification.init({ - ios: { - alert: true, - badge: true, - sound: false, - clearBadge: true, - }, - }) console.log("push init") - - PushNotification.hasPermission(push.did_initialize) - pushPlugin.on('registration', push.got_registration) - pushPlugin.on('notification', push.got_push_notification) + + // Register handlers + FirebasePlugin.onMessageReceived(function(message) { + try { + console.log("onMessageReceived") + console.dir(message) + if (message.messageType === "notification") { + push.got_push_notification(message) + } + } catch(e) { + console.error("Exception in onMessageReceived callback: " + e.message) + } + }, function(error) { + console.error("Failed receiving FirebasePlugin message", error); + }) + + checkNotificationPermission(false) // Check permission then get token + FirebasePlugin.setBadgeNumber(0) } - push.did_initialize = function(data) { - // console.log(data) - if (! data.isEnabled) { - console.log("push did not initialize") - return - } + + var checkNotificationPermission = function(requested) { + FirebasePlugin.hasPermission(function(hasPermission) { + if (hasPermission) { + // Granted + console.log("Remote notifications permission granted") + push.disabled = false + getAPNSToken() + } else if (!requested) { + // Request permission + console.log("Requesting remote notifications permission") + FirebasePlugin.grantPermission(checkNotificationPermission.bind(this, true)) + } else { + // Denied + push.disabled = true + console.error("Notifications won't be shown as permission is denied") + } + }) + } + + var getAPNSToken = function() { + FirebasePlugin.getAPNSToken(function(token) { + console.log("Got APNS token: " + token) + if (!token) { + console.log("Token is null, probably in simulator") + return + } + push.did_initialize() + push.got_registration(token) + }, function(error) { + console.error("Failed to get APNS token", error) + }) + } + + push.did_initialize = function() { console.log("push did initialize") var hub_status = localStorage.getItem("yoox.push_hub") var store_status = localStorage.getItem("yoox.push_store") @@ -36,30 +70,19 @@ var push = (function(){ push.settings.requested = localStorage.getItem("yoox.push_requested") == "true" push.settings.hub = hub_status == "true" push.settings.store = store_status == "true" - - if (push.settings.requested) { - return - } - // not sure why we're also signing up for notifications here?? - if (! hub_status || hub_status == "true") { - push.subscribe("hub") - } - if (! store_status || store_status == "true") { - push.subscribe("store") - } } - push.got_registration = function(data){ - var registrationId = data.registrationId + + push.got_registration = function(registrationId){ var oldRegistrationId = localStorage.getItem("yoox.registrationId") - // console.log(registrationId, oldRegistrationId) - if (registrationId !== oldRegistrationId || ! push.settings.requested) { + localStorage.setItem("yoox.push_requested", "true") localStorage.setItem("yoox.registrationId", registrationId) - push.subscribe("hub", function(){ - push.subscribe("store") - }) + push.settings.requested = true + push.subscribe("hub") + push.subscribe("store") } } + push.subscribe = function(channel, cb){ if (push.disabled) return push.settings[channel] = true @@ -69,8 +92,10 @@ var push = (function(){ channel: channel, platform: device.platform, } - pushPlugin.subscribe(channel, function(){ - console.log("subscribed to", channel) + FirebasePlugin.subscribe(channel, function(){ + console.log("Subscribed to topic") + }, function(error){ + console.error("Error subscribing to topic: " + error) }) $.ajax({ method: "POST", @@ -93,6 +118,11 @@ var push = (function(){ channel: channel, platform: device.platform, } + FirebasePlugin.unsubscribe(channel, function(){ + console.log("Unsubscribed from topic"); + }, function(error){ + console.error("Error unsubscribing from topic: " + error); + }) $.ajax({ method: "POST", url: push.url('remove'), @@ -108,43 +138,25 @@ var push = (function(){ push.url = function(key){ return sdk.cms() + '/_services/push/' + key } - push.got_push_notification = function(push_obj) { + push.got_push_notification = function(message) { // console.log('We received this push notification: ' + JSON.stringify(push_obj)); - app.blog.refresh() - push_obj.additionalData = push_obj.additionalData || {} - var is_hub = true + FirebasePlugin.setBadgeNumber(0) + try { - is_hub = JSON.stringify(push_obj || {}).match(/hub/i) - } - catch (e) { - } + is_hub = !! JSON.stringify(push_obj || {}).match(/hub/i) + } catch (e) { } if (is_hub) { app.intro.$alert.show().html("[ HUB UPDATED ]") - } - else if (! push_obj.additionalData.url) { + analytics.sendPageView("push/open/hub") + app.router.go("intro") + } else { auth.clear_cart() app.intro.$alert.show().html("[ STORE UPDATED ]") - } - - if (push_obj.additionalData.foreground === false) { - // TODO: route the user to the uri in push_obj - pushPlugin.finish(function(){}, function(){}) - - if (push_obj.additionalData.url) { - app.deepLinkRoute = push_obj.additionalData.url - app.router.go(push_obj.additionalData.url) - } - } - else if (is_hub) { - analytics.sendPageView("push/open/hub") - app.router.go("hub") - } - else { analytics.sendPageView("push/open/store") app.router.go("intro") } diff --git a/StoneIsland/www/js/lib/etc/sim.js b/StoneIsland/www/js/lib/etc/sim.js index 65be02b0..19d2e3c3 100644 --- a/StoneIsland/www/js/lib/etc/sim.js +++ b/StoneIsland/www/js/lib/etc/sim.js @@ -1,49 +1,50 @@ -var sim = (function(){ - var sim = {} +var simcard = (function(){ + var simcard = {} - sim.loaded = false - sim.data = { + simcard.loaded = false + simcard.data = { carrierName: 'unknown', countryCode: 'us', mcc: '0', mnc: '0', } - sim.fetch = function(cb){ + simcard.fetch = function(cb){ console.log('fetching sim data') - sim.afterFetch = cb - window.plugins.sim.getSimInfo(sim.success, sim.error) + simcard.afterFetch = cb + window.plugins.sim.getSimInfo(simcard.success, simcard.error) + // cordova.exec(simcard.success, simcard.error, 'Sim', 'getSimInfo', []) } - sim.afterFetch = function(){} + simcard.afterFetch = function(){} - sim.success = function(data){ + simcard.success = function(data){ console.log(data) - if (sim.data.countryCode) { - sim.data = data - sim.data.countryCode = sim.data.countryCode.toLowerCase() + if (simcard.data.countryCode) { + simcard.data = data + simcard.data.countryCode = simcard.data.countryCode.toLowerCase() // app is only available in US or Canada, so call the US API regardless - if (sim.data.countryCode !== 'ca') { - sim.data.countryCode = 'us' + if (simcard.data.countryCode !== 'ca') { + simcard.data.countryCode = 'us' } } - sim.loaded = true - sim.afterFetch() + simcard.loaded = true + simcard.afterFetch() } - sim.error = function(){ + simcard.error = function(){ console.log("no SIM card detected") $.ajax({ url: "http://ip-api.com/json/", jsonp: "callback", dataType: "jsonp", - success: sim.success, + success: simcard.success, error: function(){ - sim.loaded = true - sim.afterFetch() + simcard.loaded = true + simcard.afterFetch() } }) } - return sim + return simcard })()
\ No newline at end of file diff --git a/StoneIsland/www/js/lib/view/Serializable.js b/StoneIsland/www/js/lib/view/Serializable.js index 0d638412..acf77f2c 100755 --- a/StoneIsland/www/js/lib/view/Serializable.js +++ b/StoneIsland/www/js/lib/view/Serializable.js @@ -155,7 +155,7 @@ var SerializableView = View.extend({ } else { this.hide_errors() - window.cordova && cordova.plugins.Keyboard.close() + window.cordova && window.Keyboard.close() } var finalized_data = this.finalize(valid.data) diff --git a/StoneIsland/www/js/sdk/_sdk.js b/StoneIsland/www/js/sdk/_sdk.js index aba05ca3..cc68dd67 100755 --- a/StoneIsland/www/js/sdk/_sdk.js +++ b/StoneIsland/www/js/sdk/_sdk.js @@ -30,7 +30,7 @@ var sdk = (function(){ } sdk.cc = function(){ - return sim.data.countryCode.toUpperCase() + return simcard.data.countryCode.toUpperCase() // return 'CA' } |
