diff options
Diffstat (limited to 'StoneIsland/platforms/ios/www/js')
11 files changed, 164 insertions, 99 deletions
diff --git a/StoneIsland/platforms/ios/www/js/index.js b/StoneIsland/platforms/ios/www/js/index.js index 8574372d..3947b43e 100755 --- a/StoneIsland/platforms/ios/www/js/index.js +++ b/StoneIsland/platforms/ios/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,10 +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" } @@ -117,8 +118,11 @@ var app = (function(){ if (navigator.onLine) { app.account.connect(window.deepLinkRoute || '/intro') app.blog.fetch(function(){ - console.log("navigating to deep link route after fetch") + console.log("blog fetched, launching router") app.router.initial_route = window.deepLinkRoute || null + if (app.router.initial_route) { + analytics.sendPageView('push/' + app.router.initial_route) + } app.router.launch() }) } diff --git a/StoneIsland/platforms/ios/www/js/lib/_router.js b/StoneIsland/platforms/ios/www/js/lib/_router.js index 75f598e9..7d487689 100755 --- a/StoneIsland/platforms/ios/www/js/lib/_router.js +++ b/StoneIsland/platforms/ios/www/js/lib/_router.js @@ -101,6 +101,7 @@ var SiteRouter = Router.extend({ } // window.FirebasePlugin && window.FirebasePlugin.setScreenName(name) + analytics.sendPageView(name) console.log("view >>", app.view) app.header.set_back( !! app.view.back ) app.view.show() @@ -128,6 +129,7 @@ var SiteRouter = Router.extend({ if (app.view && app.view.hide) { app.view.hide() } + analytics.sendPageView('store/' + code) app.view = app.product app.header.set_back( true ) app.product.load(code) diff --git a/StoneIsland/platforms/ios/www/js/lib/blogs/BlogView.js b/StoneIsland/platforms/ios/www/js/lib/blogs/BlogView.js index 9190634c..d37846c2 100755 --- a/StoneIsland/platforms/ios/www/js/lib/blogs/BlogView.js +++ b/StoneIsland/platforms/ios/www/js/lib/blogs/BlogView.js @@ -61,9 +61,11 @@ var BlogView = View.extend({ } else { app.departments = app.store.Departments - app.department_id = app.store.Departments[0].uri + if (app.store.Departments.length) { + app.department_id = app.store.Departments[0].uri + app.collection.setCollectionName( app.store.Departments[0].text ) + } $("#collections h1").toggleClass("single-dept", app.store.Departments.length == 1) - app.collection.setCollectionName( app.store.Departments[0].text ) //// demo department for shoes with weird SizeTypeId // app.department_id = "NKDrtSC" if (sdk.env === 'test') { diff --git a/StoneIsland/platforms/ios/www/js/lib/blogs/HubView.js b/StoneIsland/platforms/ios/www/js/lib/blogs/HubView.js index 0d59bcc8..7a6f17d9 100755 --- a/StoneIsland/platforms/ios/www/js/lib/blogs/HubView.js +++ b/StoneIsland/platforms/ios/www/js/lib/blogs/HubView.js @@ -70,6 +70,7 @@ var HubView = ScrollableView.extend({ if (row.image && row.image.length > 1) { // image gallery var $gallery = $(".gallery-" + row.id) + var default_title = stonewash(row.title) + ". Image gallery, use the arrows to scroll." row.image.forEach(function(img){ var el = document.createElement("div") el.style.backgroundImage = "url(" + img.uri + ")" @@ -93,9 +94,17 @@ var HubView = ScrollableView.extend({ var url = gallery.selectedElement.style.backgroundImage.replace(/url\(\"?/,"").replace(/\"?\)/,"") app.fullscreenViewer.show(url, url, stonewash(row.title)) }) - $(".gallery-" + row.id).attr('aria-label', stonewash(row.title) + ". Image gallery, use the arrows to scroll.") + gallery.on('settle', function(e){ + // console.log(".gallery-target-" + row.id) + var currentImage = gallery.selectedElement + var title = $(currentImage).get(0).getAttribute('aria-label') || default_title + $(".gallery-" + row.id).attr('aria-label', title) + $(".gallery-target-" + row.id).attr('aria-label', title) + }) + var current_title = row.image[0].caption || default_title + $(".gallery-" + row.id).attr('aria-label', current_title) if (accessibility.voiceOver) { - $(".gallery-target-" + row.id).attr('aria-label', stonewash(row.title) + ". Image gallery, use the arrows to scroll.") + $(".gallery-target-" + row.id).attr('aria-label', current_title) $(".gallery-target-" + row.id).click(function(e){ e && e.preventDefault() var url = gallery.selectedElement.style.backgroundImage.replace(/url\(\"?/,"").replace(/\"?\)/,"") diff --git a/StoneIsland/platforms/ios/www/js/lib/etc/analytics.js b/StoneIsland/platforms/ios/www/js/lib/etc/analytics.js new file mode 100644 index 00000000..f5f871f5 --- /dev/null +++ b/StoneIsland/platforms/ios/www/js/lib/etc/analytics.js @@ -0,0 +1,21 @@ +var analytics = (function() { + var analytics = {} + + analytics.init = function() { + console.log("Analytics init") + if (window.FirebasePlugin) { + window.FirebasePlugin.setAnalyticsCollectionEnabled(true) + } + analytics.sendPageView('/') + } + + analytics.sendPageView = function(path) { + console.log("/a\\ send", path) + FirebasePlugin.logEvent("select_content", { + content_type: "page_view", + item_id: path, + }) + } + + return analytics +})() diff --git a/StoneIsland/platforms/ios/www/js/lib/etc/push.js b/StoneIsland/platforms/ios/www/js/lib/etc/push.js index 74aaf7b5..1f0ab9b6 100755 --- a/StoneIsland/platforms/ios/www/js/lib/etc/push.js +++ b/StoneIsland/platforms/ios/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,42 +138,26 @@ 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) { - app.router.go("hub") - } - else { + analytics.sendPageView("push/open/store") app.router.go("intro") } } diff --git a/StoneIsland/platforms/ios/www/js/lib/etc/sim.js b/StoneIsland/platforms/ios/www/js/lib/etc/sim.js index 65be02b0..19d2e3c3 100644 --- a/StoneIsland/platforms/ios/www/js/lib/etc/sim.js +++ b/StoneIsland/platforms/ios/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/platforms/ios/www/js/lib/products/CollectionView.js b/StoneIsland/platforms/ios/www/js/lib/products/CollectionView.js index 70bb22b4..507c51d7 100755 --- a/StoneIsland/platforms/ios/www/js/lib/products/CollectionView.js +++ b/StoneIsland/platforms/ios/www/js/lib/products/CollectionView.js @@ -84,6 +84,9 @@ var CollectionView = ScrollableView.extend({ return } this.$loader.show() + if (!app.department_id) { + console.log("no department ID, store is closed") + } console.log("fetching", app.department_id) sdk.product.collection({ department_id: app.department_id, diff --git a/StoneIsland/platforms/ios/www/js/lib/products/ProductView.js b/StoneIsland/platforms/ios/www/js/lib/products/ProductView.js index 570024b6..63f651b6 100755 --- a/StoneIsland/platforms/ios/www/js/lib/products/ProductView.js +++ b/StoneIsland/platforms/ios/www/js/lib/products/ProductView.js @@ -313,6 +313,7 @@ var ProductView = ScrollableView.extend({ this.sizes = sizes this.colors = colors + // console.log('populated colors', sizes, colors, default_color) return default_color }, @@ -329,6 +330,9 @@ var ProductView = ScrollableView.extend({ var option = document.createElement('option') option.value = size.value option.innerHTML = size.label + if (this.size && size.id === this.size.id) { + option.selected = true + } this.$sizeSelect.append(option) }.bind(this)) }, @@ -337,13 +341,18 @@ var ProductView = ScrollableView.extend({ if (this.sold_out) { return } if (this.notAvailable) { return } if (this.details['ModelColors'].length == 0) { return } + console.log('populate colors', this.color) this.$colorSelect.empty() Object.keys(this.colors).forEach(function(key){ var color = this.colors[key] + console.log(color) var option = document.createElement('option') option.value = key option.innerHTML = color.label + if (this.color && color.id === this.color.id) { + option.selected = true + } this.$colorSelect.append(option) }.bind(this)) }, @@ -352,7 +361,7 @@ var ProductView = ScrollableView.extend({ console.log(this.colors) var value = this.$sizeSelect.val() var size = this.sizes[value] - console.log(size) + console.log('size', size) this.set_size_label(size.label) this.size = size.value }, @@ -360,7 +369,7 @@ var ProductView = ScrollableView.extend({ select_color: function(){ var value = this.$colorSelect.val() var color = this.colors[value] - console.log(color) + console.log('color', color) this.code = color.code this.set_color_label(color.label) this.gallery.populate( color.code, this.details['ImageTypes'] ) diff --git a/StoneIsland/platforms/ios/www/js/lib/view/Serializable.js b/StoneIsland/platforms/ios/www/js/lib/view/Serializable.js index 0d638412..acf77f2c 100755 --- a/StoneIsland/platforms/ios/www/js/lib/view/Serializable.js +++ b/StoneIsland/platforms/ios/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/platforms/ios/www/js/sdk/_sdk.js b/StoneIsland/platforms/ios/www/js/sdk/_sdk.js index aba05ca3..cc68dd67 100755 --- a/StoneIsland/platforms/ios/www/js/sdk/_sdk.js +++ b/StoneIsland/platforms/ios/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' } |
