From 612561818f907f0f9988247c82ec158ba4494986 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Tue, 24 Nov 2015 20:57:41 -0500 Subject: build --- StoneIsland/platforms/ios/www/js/index.js | 29 +- StoneIsland/platforms/ios/www/js/lib/_router.js | 106 +- .../ios/www/js/lib/account/AccountView.js | 70 + .../platforms/ios/www/js/lib/account/OrdersView.js | 29 + .../ios/www/js/lib/account/PaymentView.js | 25 + .../ios/www/js/lib/account/ProfileView.js | 100 + .../ios/www/js/lib/account/SettingsView.js | 23 + .../ios/www/js/lib/account/ShippingView.js | 24 + .../ios/www/js/lib/account/orders/OrderList.js | 17 + .../ios/www/js/lib/account/orders/SingleOrder.js | 18 + .../platforms/ios/www/js/lib/auth/LoginView.js | 53 + .../platforms/ios/www/js/lib/auth/LogoutView.js | 15 + .../platforms/ios/www/js/lib/auth/SignupView.js | 103 + .../platforms/ios/www/js/lib/blogs/ArchiveView.js | 12 +- .../platforms/ios/www/js/lib/blogs/BlogView.js | 20 +- .../platforms/ios/www/js/lib/blogs/HubView.js | 67 +- .../platforms/ios/www/js/lib/blogs/PageView.js | 24 + .../platforms/ios/www/js/lib/blogs/StoryView.js | 45 +- .../platforms/ios/www/js/lib/cart/CartBilling.js | 11 - .../platforms/ios/www/js/lib/cart/CartConfirm.js | 29 + .../platforms/ios/www/js/lib/cart/CartPayment.js | 40 + .../platforms/ios/www/js/lib/cart/CartShipping.js | 28 +- .../platforms/ios/www/js/lib/cart/CartSummary.js | 179 +- .../platforms/ios/www/js/lib/cart/CartThanks.js | 23 + .../platforms/ios/www/js/lib/cart/CartView.js | 38 +- .../platforms/ios/www/js/lib/nav/AddressView.js | 39 + .../platforms/ios/www/js/lib/nav/CreditCardView.js | 27 + .../platforms/ios/www/js/lib/nav/CurtainView.js | 18 +- .../platforms/ios/www/js/lib/nav/FooterView.js | 36 +- .../platforms/ios/www/js/lib/nav/HeaderView.js | 31 +- .../platforms/ios/www/js/lib/nav/IntroView.js | 1 + .../platforms/ios/www/js/lib/nav/LoginView.js | 57 - .../platforms/ios/www/js/lib/nav/NavView.js | 103 +- .../platforms/ios/www/js/lib/nav/SearchView.js | 16 + .../ios/www/js/lib/products/ClosedStoreView.js | 47 + .../ios/www/js/lib/products/CollectionView.js | 91 +- .../ios/www/js/lib/products/GalleryView.js | 46 +- .../ios/www/js/lib/products/ProductView.js | 264 +- .../platforms/ios/www/js/lib/products/Selector.js | 16 +- .../www/js/lib/products/filters/CategoryFilter.js | 40 + StoneIsland/platforms/ios/www/js/sdk/_sdk.js | 10 +- StoneIsland/platforms/ios/www/js/sdk/account.js | 66 +- StoneIsland/platforms/ios/www/js/sdk/address.js | 6 +- StoneIsland/platforms/ios/www/js/sdk/auth.js | 104 +- StoneIsland/platforms/ios/www/js/sdk/cart.js | 80 +- StoneIsland/platforms/ios/www/js/sdk/payment.js | 30 +- StoneIsland/platforms/ios/www/js/sdk/product.js | 18 +- StoneIsland/platforms/ios/www/js/sdk/shipping.js | 54 +- .../platforms/ios/www/js/vendor/flickity.pkgd.js | 5090 ++++++++++++++++++++ StoneIsland/platforms/ios/www/js/vendor/moment.js | 3195 ++++++++++++ .../platforms/ios/www/js/vendor/prefixfree.js | 497 ++ StoneIsland/platforms/ios/www/js/vendor/promise.js | 34 + StoneIsland/platforms/ios/www/js/vendor/util.js | 12 + .../platforms/ios/www/js/vendor/view/formview.js | 146 - .../platforms/ios/www/js/vendor/view/router.js | 8 +- .../platforms/ios/www/js/vendor/view/scrollable.js | 20 + .../ios/www/js/vendor/view/serializable.js | 129 + .../platforms/ios/www/js/vendor/view/view.js | 11 +- 58 files changed, 10980 insertions(+), 490 deletions(-) create mode 100644 StoneIsland/platforms/ios/www/js/lib/account/AccountView.js create mode 100644 StoneIsland/platforms/ios/www/js/lib/account/OrdersView.js create mode 100644 StoneIsland/platforms/ios/www/js/lib/account/PaymentView.js create mode 100644 StoneIsland/platforms/ios/www/js/lib/account/ProfileView.js create mode 100644 StoneIsland/platforms/ios/www/js/lib/account/SettingsView.js create mode 100644 StoneIsland/platforms/ios/www/js/lib/account/ShippingView.js create mode 100644 StoneIsland/platforms/ios/www/js/lib/account/orders/OrderList.js create mode 100644 StoneIsland/platforms/ios/www/js/lib/account/orders/SingleOrder.js create mode 100644 StoneIsland/platforms/ios/www/js/lib/auth/LoginView.js create mode 100644 StoneIsland/platforms/ios/www/js/lib/auth/LogoutView.js create mode 100644 StoneIsland/platforms/ios/www/js/lib/auth/SignupView.js create mode 100644 StoneIsland/platforms/ios/www/js/lib/blogs/PageView.js delete mode 100644 StoneIsland/platforms/ios/www/js/lib/cart/CartBilling.js create mode 100644 StoneIsland/platforms/ios/www/js/lib/cart/CartConfirm.js create mode 100644 StoneIsland/platforms/ios/www/js/lib/cart/CartPayment.js create mode 100644 StoneIsland/platforms/ios/www/js/lib/cart/CartThanks.js create mode 100644 StoneIsland/platforms/ios/www/js/lib/nav/AddressView.js create mode 100644 StoneIsland/platforms/ios/www/js/lib/nav/CreditCardView.js delete mode 100644 StoneIsland/platforms/ios/www/js/lib/nav/LoginView.js create mode 100644 StoneIsland/platforms/ios/www/js/lib/nav/SearchView.js create mode 100644 StoneIsland/platforms/ios/www/js/lib/products/ClosedStoreView.js create mode 100644 StoneIsland/platforms/ios/www/js/lib/products/filters/CategoryFilter.js create mode 100644 StoneIsland/platforms/ios/www/js/vendor/flickity.pkgd.js create mode 100644 StoneIsland/platforms/ios/www/js/vendor/moment.js create mode 100644 StoneIsland/platforms/ios/www/js/vendor/prefixfree.js create mode 100644 StoneIsland/platforms/ios/www/js/vendor/promise.js delete mode 100644 StoneIsland/platforms/ios/www/js/vendor/view/formview.js create mode 100644 StoneIsland/platforms/ios/www/js/vendor/view/scrollable.js create mode 100644 StoneIsland/platforms/ios/www/js/vendor/view/serializable.js (limited to 'StoneIsland/platforms/ios/www/js') diff --git a/StoneIsland/platforms/ios/www/js/index.js b/StoneIsland/platforms/ios/www/js/index.js index e0b08351..ed8d9e5a 100644 --- a/StoneIsland/platforms/ios/www/js/index.js +++ b/StoneIsland/platforms/ios/www/js/index.js @@ -6,6 +6,11 @@ var app = (function(){ app.build() sdk.init({ env: "test" }) + + app.iscroll_options = { + mouseWheel: true, + scrollbars: true, + } if (window.cordova) { document.addEventListener('deviceready', app.ready, false) @@ -25,20 +30,34 @@ var app = (function(){ app.archive = new ArchiveView () app.hub = new HubView () app.story = new StoryView () - app.cart = new CartView () + app.intro = new IntroView () app.header = new HeaderView () app.footer = new FooterView () app.curtain = new CurtainView () app.nav = new NavView () + app.account = new AccountView () app.login = new LoginView () - app.intro = new IntroView () + app.logout = new LogoutView () + app.signup = new SignupView () + app.profile = new ProfileView () + app.payment = new PaymentView () + app.shipping = new ShippingView () + app.settings = new SettingsView () + app.orders = new OrdersView () - app.product = new ProductView () - app.collection = new CollectionView () + app.terms = new PageView ({ page: "terms" }) + app.privacy = new PageView ({ page: "privacy" }) + app.returns = new PageView ({ page: "returns" }) + app.care = new PageView ({ page: "care" }) + app.collection = new CollectionView () + app.product = new ProductView () + app.closed = new ClosedStoreView () + app.search = new SearchView () + app.selector = new Selector () } @@ -49,7 +68,7 @@ var app = (function(){ app.view = null app.router = new SiteRouter () - app.router.route() + app.account.connect( app.router.route.bind(app.router) ) } return app diff --git a/StoneIsland/platforms/ios/www/js/lib/_router.js b/StoneIsland/platforms/ios/www/js/lib/_router.js index 08b8b819..b70d9be8 100644 --- a/StoneIsland/platforms/ios/www/js/lib/_router.js +++ b/StoneIsland/platforms/ios/www/js/lib/_router.js @@ -4,20 +4,48 @@ var SiteRouter = Router.extend({ routeByHash: true, routes: { - '/': 'intro', - '/intro': 'intro', - '/store': 'store', - '/hub': 'hub', - '/story': 'story', - '/archive': 'archive', + '/': 'intro', + '/intro': 'intro', + '/hub': 'hub', + '/story': 'story', + '/archive': 'archive', - '/faq': 'faq', - '/search': 'search', + '/store': 'collection', + '/store/closed': 'closed', + '/store/:code': 'product', - '/cart': 'cart', + '/account/login': 'login', + '/account/logout': 'logout', + '/account/signup': 'signup', + '/account/profile': 'profile', + '/account/payment': 'payment', + '/account/shipping': 'shipping', + '/account/orders': 'orders', + '/account/settings': 'settings', + + '/page/terms': 'terms', + '/page/privacy': 'privacy', + '/page/returns': 'returns', + '/page/care': 'care', + + '/search': 'search', + + '/cart': 'cart.summary', + '/cart/summary': 'cart.summary', + '/cart/payment': 'cart.payment', + '/cart/shipping': 'cart.shipping', + '/cart/confirm': 'cart.confirm', + '/cart/thanks': 'cart.thanks', }, initialize: function(){ + var fn + for (var route in this.routes) { + fn = this.routes[route] + if (! this[fn]) { + this[fn] = this.default_view(fn) + } + } }, go: function(url){ @@ -27,35 +55,39 @@ var SiteRouter = Router.extend({ window.location.href = "#/" + url this.parseRoute(url) }, + + default_view: function(name){ + var fn = function(){ + console.log(name) + if (app.view != app.login && app.view != app.signin) { + app.last_view = app.view + } + if (app.view && app.view.hide) { + app.view.hide() + } + if (name.match(/\./)) { + var n = name.split(".") + console.log(name, n) + app.view = app[n[0]][n[1]] + } + else { + app.view = app[name] + } + app.header.set_back( !! app.view.back ) + app.view.show() + }.bind(this) + return fn + }, - intro: function(){ - app.view = app.intro - app.intro.show() - }, - - store: function(){ - app.view = app.store - app.collection.show() - }, - - hub: function(){ - app.view = app.hub - app.hub.show() - }, - - story: function(){ - app.view = app.story - app.story.show() - }, - - archive: function(){ - app.view = app.archive - app.archive.show() - }, - - cart: function(){ - app.view = app.cart - app.cart.show() + product: function(code){ + if (app.view && app.view.hide) { + app.view.hide() + } + app.view = app.product + app.header.set_back( true ) + app.product.load(code) + app.product.show() }, }) + diff --git a/StoneIsland/platforms/ios/www/js/lib/account/AccountView.js b/StoneIsland/platforms/ios/www/js/lib/account/AccountView.js new file mode 100644 index 00000000..cbd9a9c6 --- /dev/null +++ b/StoneIsland/platforms/ios/www/js/lib/account/AccountView.js @@ -0,0 +1,70 @@ +var AccountView = View.extend({ + + initialize: function(){ + }, + + connect: function(cb){ + auth.init(this.ready.bind(this, cb)) + }, + + ready: function(cb){ + if (auth.logged_in()) { + this.logged_in(cb) + } + else { + this.logged_out(cb) + } + }, + + populateAddresses: function(data){ + console.log("populate addresses:", data) + if (! data.AddressBook) { + console.log("no addresses") + return + } + // console.log(data.AddressBook) + data.AddressBook.addressBookItem.forEach(function(item){ + if (item.isDefault) { + // populate app.shipping.address + } + else if (item.isBillingDefault) { + // populate app.billing.address + } + }) + }, + + logged_in: function(cb){ + sdk.address.list({ + success: this.populateAddresses.bind(this) + }) + $("#nav .login").hide() + $("#nav .account, #nav .logout").show() + if (app.last_view && app.last_view != app.login && app.last_view != app.signin && app.last_view != app.logout) { + app.view && app.view.hide && app.view.hide() + app.view = app.last_view + app.view.show() + } + else { + cb && cb() + } + if ( ! auth.has_cart() ) { + auth.create_cart(auth.add_deferred_product_to_cart) + } + else { + if (auth.deferred_product) { + auth.add_deferred_product_to_cart() + } + else { + app.cart.load() + } + } + }, + + logged_out: function(cb){ + $("#nav .login").show() + $("#nav .account, #nav .logout").hide() + $("#nav").removeClass("account") + cb && cb() + }, + +}) diff --git a/StoneIsland/platforms/ios/www/js/lib/account/OrdersView.js b/StoneIsland/platforms/ios/www/js/lib/account/OrdersView.js new file mode 100644 index 00000000..7283b65c --- /dev/null +++ b/StoneIsland/platforms/ios/www/js/lib/account/OrdersView.js @@ -0,0 +1,29 @@ +var OrdersView = View.extend({ + + el: "#orders", + + events: { + "click .back": "back", + "click .details": "load_single", + }, + + initialize: function(){ + this.single = new SingleOrder ({ parent: this }) + this.list = new OrderList ({ parent: this }) + }, + + show: function(){ + if (! auth.logged_in()) { return app.router.go("intro") } + app.footer.hide() + document.body.className = "orders" + this.el.className = "list" + }, + + load_single: function(){ + }, + + back: function(){ + this.list.show() + }, + +}) diff --git a/StoneIsland/platforms/ios/www/js/lib/account/PaymentView.js b/StoneIsland/platforms/ios/www/js/lib/account/PaymentView.js new file mode 100644 index 00000000..d61ab5ab --- /dev/null +++ b/StoneIsland/platforms/ios/www/js/lib/account/PaymentView.js @@ -0,0 +1,25 @@ +var PaymentView = FormView.extend({ + + el: "#payment", + + events: { + }, + + initialize: function(){ + this.$form = this.$("form") + this.$msg = this.$(".msg") + this.address = new AddressView ({ parent: this }) + this.cc = new CreditCardView ({ parent: this }) + this.scroller = new IScroll('#payment', app.iscroll_options) + }, + + show: function(){ + if (! auth.logged_in()) { return app.router.go("intro") } + app.footer.show("SAVE", "CANCEL") + document.body.className = "payment" + }, + + save: function(){ + }, + +}) diff --git a/StoneIsland/platforms/ios/www/js/lib/account/ProfileView.js b/StoneIsland/platforms/ios/www/js/lib/account/ProfileView.js new file mode 100644 index 00000000..9150f874 --- /dev/null +++ b/StoneIsland/platforms/ios/www/js/lib/account/ProfileView.js @@ -0,0 +1,100 @@ +var ProfileView = FormView.extend({ + + el: "#profile", + + events: { + }, + + initialize: function(){ + this.$form = this.$("form") + this.$msg = this.$(".msg") + this.scroller = new IScroll('#profile', app.iscroll_options) + }, + + show: function(){ + if (! auth.logged_in()) { return app.router.go("intro") } + app.footer.show("SAVE", "CANCEL") + document.body.className = "profile" + + this.preload(auth.user) + }, + + validate_presence: { + "Name": "Please enter your first name.", + "Surname": "Please enter your last name.", + "Email": "Please enter a valid email address.", + }, + + validate_fields: function(data, errors){ + if (! data.Email.match("@")) { errors.push([ "Email", "Email address is not valid." ]) } + if (! data.CurrentPassword && (data.NewPassword || data.Email !== auth.user.Email)) { errors.push([ "CurrentPassword", "Please enter your current password." ]) } + if (data.CurrentPassword && ! data.NewPassword) { errors.push([ "NewPassword", "Please enter your new password." ]) } + if (data.NewPassword && data.NewPassword.length < 7) { errors.push([ "CurrentPassword", "New password must be 7 characters or more." ]) } + if (data.Gender === "NONE") { errors.push([ "Gender", "Please supply your gender." ]) } + + data.BirthDay += "T00:00:00Z" + data.YooxLetter = data.YooxLetter || "false" + }, + + save: function(e){ + e && e.preventDefault() + + var valid = this.validate() + if (valid.errors.length) { + this.show_errors(valid.errors) + return + } + else { + this.hide_errors() + } + + var data = valid.data + if (data.CurrentPassword && (data.NewPassword || data.Email !== auth.user.Email)) { + data.NewPassword = data.NewPassword || data.CurrentPassword + data.NewEmail = data.NewEmail || auth.user.Email + + sdk.account.update_mail_and_password({ + data: { + Password: data.CurrentPassword, + NewPassword: data.NewPassword || data.CurrentPassword, + Email: auth.user, + NewEmail: data.NewEmail || auth.user.Email, + }, + success: function(){ console.log("updated password") }, + error: function(){ console.log("error updating password") }, + }) + } + + var submissible_data = _.pick(valid.data, "Name Surname BirthDay Gender YooxLetter".split(" ")) + + submissible_data.idUser = auth.user_id + submissible_data.AccessToken = auth.access_token + submissible_data.Premium = "false" + submissible_data.LanguageId = "" + submissible_data.SiteCode = "STONEISLAND_US" + submissible_data.FuriganaName = "" + submissible_data.FuriganaSurname = "" + submissible_data.UserPromocode = "" + submissible_data.DataProfiling = "true" + + app.curtain.show("loading") + sdk.account.update({ + data: submissible_data, + success: function(data){ + app.curtain.hide("loading") + this.success(data) + }.bind(this), + error: function(data){ + app.curtain.hide("loading") + this.error(data) + }.bind(this), + }) + }, + + success: function(data){ + }, + + error: function(data){ + }, + +}) \ No newline at end of file diff --git a/StoneIsland/platforms/ios/www/js/lib/account/SettingsView.js b/StoneIsland/platforms/ios/www/js/lib/account/SettingsView.js new file mode 100644 index 00000000..81b8b5cc --- /dev/null +++ b/StoneIsland/platforms/ios/www/js/lib/account/SettingsView.js @@ -0,0 +1,23 @@ +var SettingsView = FormView.extend({ + + el: "#settings", + + events: { + }, + + initialize: function(){ + this.$form = this.$("form") + this.$msg = this.$(".msg") + this.scroller = new IScroll('#settings', app.iscroll_options) + }, + + show: function(){ + if (! auth.logged_in()) { return app.router.go("intro") } + app.footer.show("SAVE", "CANCEL") + document.body.className = "settings" + }, + + save: function(){ + }, + +}) \ No newline at end of file diff --git a/StoneIsland/platforms/ios/www/js/lib/account/ShippingView.js b/StoneIsland/platforms/ios/www/js/lib/account/ShippingView.js new file mode 100644 index 00000000..f5bf1661 --- /dev/null +++ b/StoneIsland/platforms/ios/www/js/lib/account/ShippingView.js @@ -0,0 +1,24 @@ +var ShippingView = FormView.extend({ + + el: "#shipping", + + events: { + }, + + initialize: function(){ + this.$form = this.$("form") + this.$msg = this.$(".msg") + this.address = new AddressView ({ parent: this }) + this.scroller = new IScroll('#shipping', app.iscroll_options) + }, + + show: function(){ + if (! auth.logged_in()) { return app.router.go("intro") } + app.footer.show("SAVE", "CANCEL") + document.body.className = "shipping" + }, + + save: function(){ + }, + +}) \ No newline at end of file diff --git a/StoneIsland/platforms/ios/www/js/lib/account/orders/OrderList.js b/StoneIsland/platforms/ios/www/js/lib/account/orders/OrderList.js new file mode 100644 index 00000000..876f609e --- /dev/null +++ b/StoneIsland/platforms/ios/www/js/lib/account/orders/OrderList.js @@ -0,0 +1,17 @@ +var OrderList = ScrollableView.extend({ + + el: "#order_list", + + template: $("#order_list .template"), + + initialize: function(opt){ + this.parent = opt.parent + this.scroller = new IScroll('#order_list', app.iscroll_options) + }, + + show: function(){ + document.body.className = "orders" + app.orders.el.className = "list" + }, + +}) diff --git a/StoneIsland/platforms/ios/www/js/lib/account/orders/SingleOrder.js b/StoneIsland/platforms/ios/www/js/lib/account/orders/SingleOrder.js new file mode 100644 index 00000000..21416401 --- /dev/null +++ b/StoneIsland/platforms/ios/www/js/lib/account/orders/SingleOrder.js @@ -0,0 +1,18 @@ +var SingleOrder = ScrollableView.extend({ + + el: "#single_order", + + template: $("#single_order .template"), + + initialize: function(opt){ + this.parent = opt.parent + this.scroller = new IScroll('#single_order', app.iscroll_options) + }, + + show: function(id){ + document.body.className = "orders" + app.orders.el.className = "single" + this.deferScrollToTop() + }, + +}) diff --git a/StoneIsland/platforms/ios/www/js/lib/auth/LoginView.js b/StoneIsland/platforms/ios/www/js/lib/auth/LoginView.js new file mode 100644 index 00000000..1f7438cc --- /dev/null +++ b/StoneIsland/platforms/ios/www/js/lib/auth/LoginView.js @@ -0,0 +1,53 @@ +var LoginView = FormView.extend({ + + el: "#login", + + action: sdk.account.login, + + events: { + "click .newuser": "new_user", + "submit form": "save", + }, + + initialize: function(){ + this.$form = this.$("form") + this.$msg = this.$(".msg") + this.scroller = new IScroll('#login', app.iscroll_options) + }, + + show: function(){ + if (auth.logged_in()) { + app.router.go("intro") + return + } + var msg = "* Your personal and payment
information will always remain private" + app.footer.show("SUBMIT", "CANCEL") + this.$form.get(0).reset() + this.$msg.html(msg) + document.body.className = "login" + }, + + new_user: function(){ + app.router.go("account/signup") + }, + + validate_presence: { + "Email": "Please enter a valid email address.", + "Password": "Please enter your password.", + }, + + success: function(data){ + // console.log(data) + app.account.logged_in(function(){ app.router.go("store") }) + }, + + error: function(data){ + this.$msg.html("There was an error logging you in. Bad password?") + this.$msg.addClass('alert-notice') + }, + + cancel: function(){ + auth.deferred_product = null + }, + +}) diff --git a/StoneIsland/platforms/ios/www/js/lib/auth/LogoutView.js b/StoneIsland/platforms/ios/www/js/lib/auth/LogoutView.js new file mode 100644 index 00000000..735c0242 --- /dev/null +++ b/StoneIsland/platforms/ios/www/js/lib/auth/LogoutView.js @@ -0,0 +1,15 @@ +var LogoutView = View.extend({ + + el: "#logout", + + events: { + }, + + show: function(){ + document.body.className = "logout" + app.footer.hide() + app.account.logged_out() + auth.clear_user() + }, + +}) \ No newline at end of file diff --git a/StoneIsland/platforms/ios/www/js/lib/auth/SignupView.js b/StoneIsland/platforms/ios/www/js/lib/auth/SignupView.js new file mode 100644 index 00000000..7f894c3c --- /dev/null +++ b/StoneIsland/platforms/ios/www/js/lib/auth/SignupView.js @@ -0,0 +1,103 @@ +var SignupView = FormView.extend({ + + el: "#signup", + + action: sdk.account.signup, + last_data: null, + + test_data: { + "Email": "testit.account" + Math.floor(Math.random() * 10000000) + "@yoox.com", + "Password": "TestPassword", + "Password2": "TestPassword", + "Gender": "U", + "Name": "TestName", + "Surname": "TestSurname", + "BirthDay": "1978-11-12", + "DataProfiling": true, + "DataProfiling2": true, + }, + + events: { + "click .privacy-msg": "privacy_link", + "submit form": "save", + }, + + initialize: function(){ + this.$form = this.$("form") + this.$msg = this.$(".msg") + this.scroller = new IScroll('#signup', app.iscroll_options) + }, + + show: function(){ + if (auth.logged_in()) { + app.router.go("intro") + return + } + var msg = "* Your personal and payment
information will always remain private" + app.footer.show("SUBMIT", "CANCEL") + this.$form.get(0).reset() + this.$msg.html(msg) + document.body.className = "signup" + + this.preload() + }, + + validate_presence: { + "Name": "Please enter your first name.", + "Surname": "Please enter your last name.", + "Email": "Please enter a valid email address.", + "ConfirmEmail": "Please enter a valid email address.", + "Password": "Please enter your password.", + "Password2": "Please enter your password again.", + "DataProfiling": "You must agree to data profiling.", + }, + + validate_fields: function(data, errors){ + if (data.Password.length < 7) { errors.push([ "Password", "Password must be 7 characters or more." ]) } + if (data.Password !== data.Password2) { errors.push([ "Password2", "Passwords don't match." ]) } + if (! data.Email.match("@")) { errors.push([ "Email", "Email address is not valid." ]) } + if (data.Email.toLowerCase() !== data.ConfirmEmail.toLowerCase()) { errors.push([ "ConfirmEmail", "Email addresses don't match." ]) } + if (data.Gender === "NONE") { errors.push([ "Gender", "Please supply your gender." ]) } + if (data.DataProfiling !== "true") { errors.push([ "DataProfiling", "You must consent to use this service." ]) } + if (data.DataProfiling2 !== "true") { errors.push([ "DataProfiling2", "You must consent to use this service." ]) } + if (! data.YooxLetter) { data.YooxLetter = false } + + delete data.DataProfiling2 + delete data.ConfirmEmail + + data.BirthDay += "T00:00:00Z" + + this.last_data = data + console.log(data) + }, + + privacy_link: function(){ + // rewrite app.privacy instance temporarily + app.privacy.back = function(){ + app.router.go("account/signup") + } + app.privacy.hide = function(){ + app.privacy.back = app.privacy.hide = null + } + app.router.go("page/privacy") + }, + + success: function(data){ + console.log('success', data) + auth.user = auth.user || {} + auth.user.Name = this.last_data.Name + auth.user.Surname = this.last_data.Surname + auth.user.Email = this.last_data.Email + auth.user.BirthDay = this.last_data.BirthDay + app.account.logged_in(function(){ app.router.go("store") }) + }, + + error: function(data){ + console.log('error', data) + }, + + cancel: function(){ + auth.deferred_product = null + }, + +}) \ No newline at end of file diff --git a/StoneIsland/platforms/ios/www/js/lib/blogs/ArchiveView.js b/StoneIsland/platforms/ios/www/js/lib/blogs/ArchiveView.js index 34e8b109..051ef0c9 100644 --- a/StoneIsland/platforms/ios/www/js/lib/blogs/ArchiveView.js +++ b/StoneIsland/platforms/ios/www/js/lib/blogs/ArchiveView.js @@ -1,4 +1,4 @@ -var ArchiveView = View.extend({ +var ArchiveView = ScrollableView.extend({ el: "#archive", template: $("#archive .template").html(), @@ -9,10 +9,12 @@ var ArchiveView = View.extend({ initialize: function(){ this.$content = this.$(".content") this.$loader = this.$(".loader") - this.scroller = new IScroll('#archive .scroll') + this.scroller = new IScroll('#archive', app.iscroll_options) }, show: function(){ + this.deferScrollToTop() + app.footer.hide() document.body.className = "archive" }, @@ -20,14 +22,14 @@ var ArchiveView = View.extend({ this.data = data this.$loader.hide() this.$content.empty() + + // id title images[ uri label code caption ] this.data.forEach(function(row){ - var t = this.template.replace(/{{image}}/, row.image.url) + var t = this.template.replace(/{{image}}/, row.images[0].uri) .replace(/{{code}}/, row.code) .replace(/{{title}}/, row.title) - .replace(/{{body}}/, row.body) this.$content.append(t) }.bind(this)) }, - }) \ No newline at end of file diff --git a/StoneIsland/platforms/ios/www/js/lib/blogs/BlogView.js b/StoneIsland/platforms/ios/www/js/lib/blogs/BlogView.js index 70fc910a..19666f8b 100644 --- a/StoneIsland/platforms/ios/www/js/lib/blogs/BlogView.js +++ b/StoneIsland/platforms/ios/www/js/lib/blogs/BlogView.js @@ -17,17 +17,31 @@ var BlogView = View.extend({ }, success: function(data){ + + if (this.loaded) return + this.loaded = true this.data = data - this.loader.preloadImage(data.archive[0].image.url, function(img){ + + this.loader.preloadImage(data.archive[0].images[0].uri, function(img){ app.archive.populate(data.archive) }) - this.loader.preloadImage(data.hub[0].image.url, function(img){ + this.loader.preloadImage(data.hub[0].image[0].uri, function(img){ app.hub.populate(data.hub) }) - this.loader.preloadImage(data.story[0].image.url, function(img){ + this.loader.preloadImage(data.story[0].image.uri, function(img){ app.story.populate(data.story) }) + data.page.forEach(function(page){ + app[page.tag].populate(page) + + }) + app.collection.setCollectionName( data.store[0].collection ) + + app.closed.populate(data.store[0].ClosedStoreImages) + if (data.store[0].StoreIsOpen !== "true") { + app.closed.storeIsClosed = true + } }, }) \ No newline at end of file diff --git a/StoneIsland/platforms/ios/www/js/lib/blogs/HubView.js b/StoneIsland/platforms/ios/www/js/lib/blogs/HubView.js index ea9b3048..3b2900ad 100644 --- a/StoneIsland/platforms/ios/www/js/lib/blogs/HubView.js +++ b/StoneIsland/platforms/ios/www/js/lib/blogs/HubView.js @@ -1,18 +1,21 @@ -var HubView = View.extend({ +var HubView = ScrollableView.extend({ el: "#hub", template: $("#hub .template").html(), events: { + "click .store": "store_link", }, initialize: function(){ this.$content = this.$(".content") this.$loader = this.$(".loader") - this.scroller = new IScroll('#hub .scroll') + this.scroller = new IScroll('#hub', app.iscroll_optionsx) }, show: function(){ + this.deferScrollToTop() + app.footer.hide() document.body.className = "hub" }, @@ -20,17 +23,65 @@ var HubView = View.extend({ this.data = data this.$loader.hide() this.$content.empty() + // id date subtitle body link store image[uri caption] this.data.forEach(function(row){ - var t = this.template.replace(/{{image}}/, row.image.url) - .replace(/{{date}}/, row.date) - .replace(/{{code}}/, row.code) + // console.log(row) + var t = this.template.replace(/{{id}}/, row.id) + .replace(/{{date}}/, moment(row.date).format("MM.DD.YYYY")) .replace(/{{title}}/, row.title) .replace(/{{subtitle}}/, row.subtitle) .replace(/{{link}}/, row.link) - .replace(/{{body}}/, row.body) - this.$content.append(t) + .replace(/{{body}}/, row.body.replace(/\n/g, "
")) + var $t = $(t) + if (row.store != "true") { + $t.find(".store").remove() + } + this.$content.append($t) + + if (row.image.length > 1) { + // image gallery + var $gallery = $(".gallery-" + row.id) + row.image.forEach(function(img){ + var el = document.createElement("div") + el.style.backgroundImage = "url(" + img.uri + ")" + el.className = "item" + $gallery.append(el) + }) + new Flickity( ".gallery-" + row.id, { + selector: '.item', + cellAlign: 'center', + autoPlay: false, + freeScroll: false, + wrapAround: true, + imagesLoaded: true, + prevNextButtons: false, + pageDots: false, + contain: true, + draggable: true, + }) + } + else { + // single image + var el = document.createElement("div") + el.style.backgroundImage = "url(" + row.image[0].uri + ")" + el.className = "item" + $(".gallery-" + row.id).append(el) + + // video, append play button + if (row.link.match(/youtube|youtu.be|vimeo/)) { + var play = document.createElement("div") + play.className = "play" + $(".gallery-" + row.id).append(play) + } + } + }.bind(this)) + + this.deferScrollToTop() + }, + + store_link: function(){ + app.router.go("store") }, - }) \ No newline at end of file diff --git a/StoneIsland/platforms/ios/www/js/lib/blogs/PageView.js b/StoneIsland/platforms/ios/www/js/lib/blogs/PageView.js new file mode 100644 index 00000000..4bf05430 --- /dev/null +++ b/StoneIsland/platforms/ios/www/js/lib/blogs/PageView.js @@ -0,0 +1,24 @@ +var PageView = ScrollableView.extend({ + + events: { + }, + + initialize: function(opt){ + this.page = opt.page + this.setElement("#" + opt.page) + this.$content = this.$(".content") + this.$loader = this.$(".loader") + this.scroller = new IScroll('#' + this.page, app.iscroll_options) + }, + + show: function(){ + this.deferScrollToTop() + app.footer.hide() + document.body.className = this.page + }, + + populate: function(data){ + this.$content.html(data.body.replace(/\n/g, "
")) + }, + +}) \ No newline at end of file diff --git a/StoneIsland/platforms/ios/www/js/lib/blogs/StoryView.js b/StoneIsland/platforms/ios/www/js/lib/blogs/StoryView.js index 7f9b30a1..84684ff7 100644 --- a/StoneIsland/platforms/ios/www/js/lib/blogs/StoryView.js +++ b/StoneIsland/platforms/ios/www/js/lib/blogs/StoryView.js @@ -1,32 +1,65 @@ -var StoryView = View.extend({ +var StoryView = ScrollableView.extend({ + + loaded: false, el: "#story", template: $("#story .template").html(), events: { + "click .links li": "pick", }, initialize: function(){ + this.sections = {} + this.$img = this.$("img") this.$content = this.$(".content") + this.$links = this.$(".links") this.$loader = this.$(".loader") - this.scroller = new IScroll('#story .scroll') + this.scroller = new IScroll('#story', app.iscroll_options) }, show: function(){ + this.deferScrollToTop() + app.footer.hide() document.body.className = "story" }, populate: function(data){ + if (this.loaded) { console.warn("populate called twice"); return } + this.loaded = true this.data = data this.$loader.hide() this.$content.empty() + // id title image[uri caption] body this.data.forEach(function(row){ - var t = this.template.replace(/{{image}}/, row.image.url) - .replace(/{{date}}/, row.date) - .replace(/{{title}}/, row.title) - .replace(/{{body}}/, row.body) + var t = this.template.replace(/{{id}}/, row.id) + .replace(/{{body}}/, row.body.replace(/\n/g, "
")) + var li = document.createElement("li") + li.dataset.id = row.id + li.innerHTML = row.title + this.sections[row.id] = row + this.$links.append(li) this.$content.append(t) }.bind(this)) + + this.set_active( this.data[0].id ) + }, + + pick: function(e){ + var id = e.currentTarget.dataset.id + this.set_active(id) + }, + + set_active: function(id){ + this.$links.find(".active").removeClass("active") + this.$links.find("[data-id=" + id + "]").addClass("active") + + this.$content.find(".active").removeClass("active") + this.$content.find("[data-id=" + id + "]").addClass("active") + + var section = this.sections[id] + this.$img.attr("src", section.image.uri) + this.deferScrollToTop() }, }) \ No newline at end of file diff --git a/StoneIsland/platforms/ios/www/js/lib/cart/CartBilling.js b/StoneIsland/platforms/ios/www/js/lib/cart/CartBilling.js deleted file mode 100644 index f3c9cbe2..00000000 --- a/StoneIsland/platforms/ios/www/js/lib/cart/CartBilling.js +++ /dev/null @@ -1,11 +0,0 @@ -var CartBilling = View.extend({ - - el: "#billing", - - events: { - }, - - initialize: function(){ - }, - -}) \ No newline at end of file diff --git a/StoneIsland/platforms/ios/www/js/lib/cart/CartConfirm.js b/StoneIsland/platforms/ios/www/js/lib/cart/CartConfirm.js new file mode 100644 index 00000000..687f3a93 --- /dev/null +++ b/StoneIsland/platforms/ios/www/js/lib/cart/CartConfirm.js @@ -0,0 +1,29 @@ +var CartConfirm = FormView.extend({ + + el: "#cart_confirm", + + events: { + }, + + initialize: function(opt){ + this.parent = opt.parent + this.scroller = new IScroll('#cart_confirm', app.iscroll_options) + }, + + show: function(){ + document.body.className = "cart" + app.cart.el.className = "confirm" + app.footer.show("PLACE ORDER", "CANCEL") + this.deferScrollToTop() + }, + + populate: function(){ + }, + + save: function(){ + }, + + cancel: function(){ + }, + +}) \ No newline at end of file diff --git a/StoneIsland/platforms/ios/www/js/lib/cart/CartPayment.js b/StoneIsland/platforms/ios/www/js/lib/cart/CartPayment.js new file mode 100644 index 00000000..19d21ffd --- /dev/null +++ b/StoneIsland/platforms/ios/www/js/lib/cart/CartPayment.js @@ -0,0 +1,40 @@ +var CartPayment = FormView.extend({ + + el: "#cart_payment", + + events: { + }, + + initialize: function(opt){ + this.parent = opt.parent + this.$form = this.$("form") + this.$msg = this.$(".msg") + this.address = new AddressView ({ parent: this }) + this.cc = new CreditCardView ({ parent: this }) + this.scroller = new IScroll('#cart_payment', app.iscroll_options) + }, + + // sdk.cart.set_credit_card + // sdk.payment.list_credit_cards + // sdk.payment.add_credit_card + // sdk.payment.delete_credit_card + // sdk.payment.get_payment_types + // sdk.cart.use_stored_credit_card + + show: function(){ + document.body.className = "cart" + app.cart.el.className = "payment" + app.footer.show("CONFIRM >", "CANCEL") + + this.deferScrollToTop() + + sdk.cart.set_payment_type({ data: payment_id }) + }, + + save: function(){ + }, + + cancel: function(){ + }, + +}) \ No newline at end of file diff --git a/StoneIsland/platforms/ios/www/js/lib/cart/CartShipping.js b/StoneIsland/platforms/ios/www/js/lib/cart/CartShipping.js index beaf6bd2..7d7c8540 100644 --- a/StoneIsland/platforms/ios/www/js/lib/cart/CartShipping.js +++ b/StoneIsland/platforms/ios/www/js/lib/cart/CartShipping.js @@ -1,11 +1,33 @@ -var CartShipping = View.extend({ +var CartShipping = FormView.extend({ - el: "#shipping", + el: "#cart_shipping", events: { }, + + initialize: function(opt){ + this.parent = opt.parent + this.$form = this.$("form") + this.$msg = this.$(".msg") + this.address = new AddressView ({ parent: this }) + this.scroller = new IScroll('#cart_shipping', app.iscroll_options) + }, + + show: function(){ + document.body.className = "cart" + app.cart.el.className = "shipping" + app.footer.show("PAYMENT >", "CANCEL") + this.deferScrollToTop() + }, + + // sdk.cart.set_shipping_address + // sdk.shipping.get_delivery_types + // sdk.shipping.set_delivery_type + + save: function(){ + }, - initialize: function(){ + cancel: function(){ }, }) \ No newline at end of file diff --git a/StoneIsland/platforms/ios/www/js/lib/cart/CartSummary.js b/StoneIsland/platforms/ios/www/js/lib/cart/CartSummary.js index 37400dd0..209e3102 100644 --- a/StoneIsland/platforms/ios/www/js/lib/cart/CartSummary.js +++ b/StoneIsland/platforms/ios/www/js/lib/cart/CartSummary.js @@ -1,11 +1,184 @@ -var CartSummary = View.extend({ +var CartSummary = ScrollableView.extend({ - el: "#summary", + el: "#cart_summary", + + template: $("#cart_summary .template").html(), events: { + "click .remove": "remove_item", + }, + + data: null, + + initialize: function(opt){ + this.parent = opt.parent + this.$loader = this.$(".loader") + this.$cart_body = this.$(".cart_body") + this.$cart_empty = this.$(".cart_empty") + this.scroller = new IScroll('#cart_summary', app.iscroll_options) + + this.$rows = this.$(".rows") + this.$subtotal = this.$(".subtotal") + this.$shipping = this.$(".shipping") + this.$tax = this.$(".tax") + this.$total = this.$(".total") + }, + + show: function(){ + document.body.className = "cart" + app.cart.el.className = "summary" + if (auth.has_cart()) { + this.load() + } + else { + this.empty() + } + }, + + load: function(){ + this.el.className = "loading" + app.footer.show("SHIPPING >", "CANCEL") + sdk.cart.get_status({ + success: this.populate.bind(this), + error: this.empty.bind(this), + }) + }, + + populate: function(data){ + this.data = data + + console.log("CART", data) + + if (! data.Cart.Items || data.Cart.Items.length == 0) { + return this.empty() + } + + this.updateCounts() + + this.$rows.empty() + + data.Cart.Items.forEach(function(item){ + var code_ten = item['Code10'] + var code = code_ten.substr(0, 8) + var size_id = item['Size'] + + var $el = $("
").addClass("cart_item_row") + $el.data({ + code: code_ten, + size: size_id, + }) + this.$rows.append($el) + app.product.find(code, function(data, details){ + // console.log(data, details) + + var descriptions = app.product.get_descriptions( details ) + // console.log(descriptions) + + var name_partz = descriptions['ModelNames'].split(' ') + var num = name_partz.shift() + var title = name_partz.join(' ') + var type = title_case( descriptions['MicroCategory'] ) + + var color_name, size_name + // console.log(code) + details.Item.ModelColors.some(function(color){ + if (color['Code10'] == code_ten) { + color_name = color['ColorDescription'] + // console.log(color) + return true + } + return false + }) + details.Item.ModelSizes.some(function(size){ + if (size['SizeId'] == size_id) { + // console.log(size) + size_name = size['Default']['Text'] + size_name = SIZE_LOOKUP[ size_name ] || size_name + return true + } + return false + }) + + var t = this.template + .replace(/{{image}}/, sdk.image(item['Code10'], '11_f')) + .replace(/{{sku}}/, num) + .replace(/{{title}}/, title) + .replace(/{{type}}/, type) + .replace(/{{size}}/, size_name) + .replace(/{{color}}/, color_name) + .replace(/{{quantity}}/, 1) + .replace(/{{price}}/, as_cash(details.Item.Price.DiscountedPrice)) + $el.data("price", details.Item.Price.DiscountedPrice) + $el.html(t) + this.deferScrollToTop() + }.bind(this)) + }.bind(this)) + + this.updateTotals() + + this.el.className = "full" + this.deferScrollToTop() + }, + + updateCounts: function(){ + app.header.set_cart_count(this.data.Cart.Items.length) + this.parent.$itemcount.html(pluralize(this.data.Cart.Items.length, "ITEM", "S")) + }, + + updateTotals: function(){ + var subtotal = this.data.Cart.Totals.TotalWithoutPromotions + var shipping_cost = this.data.Cart.DeliveryMethod.Selected.Amount.Total + var tax = 0 + var total = this.data.Cart.Totals.TotalToPay + + this.$subtotal.html( as_cash(subtotal) ) + this.$shipping.html( as_cash(shipping_cost) ) + this.$tax.html( as_cash(tax) ) + this.$total.html( as_cash(total) ) + }, + + empty: function(){ + app.footer.hide() + app.header.set_cart_count(0) + this.parent.$itemcount.html("0 ITEMS") + this.el.className = "empty" + }, + + save: function(){ + app.router.go('cart/shipping') + }, + + cancel: function(){ + app.router.go('intro') }, - initialize: function(){ + remove_item: function(e){ + var $el = $( e.currentTarget ).closest(".cart_item_row") + var data = $el.data() + data.Cart.Totals.TotalWithoutPromotions -= data.price + data.Cart.Totals.TotalToPay -= data.price + + this.data.Cart.Items = this.data.Cart.Items.filter(function(item){ + return ( item['Code10'] !== data.code || item['Size'] !== data.size) + }) + + this.updateTotals() + this.updateCounts() + $el.remove() + + if (this.data.Cart.Items.length == 0) { + this.empty() + } + + sdk.cart.delete_item({ + data: { + Code10: data.code, + Size: data.size, + }, + success: function(){ + console.log("damn") + }, + }) }, }) \ No newline at end of file diff --git a/StoneIsland/platforms/ios/www/js/lib/cart/CartThanks.js b/StoneIsland/platforms/ios/www/js/lib/cart/CartThanks.js new file mode 100644 index 00000000..993fd9ac --- /dev/null +++ b/StoneIsland/platforms/ios/www/js/lib/cart/CartThanks.js @@ -0,0 +1,23 @@ +var CartThanks = View.extend({ + + el: "#cart_thanks", + + events: { + }, + + initialize: function(opt){ + this.parent = opt.parent + }, + + show: function(){ + document.body.className = "cart" + app.cart.el.className = "thanks" + app.footer.show("< BACK TO COLLECTION") + app.footer.hide() + }, + + ok: function(){ + app.router.go("store") + }, + +}) \ No newline at end of file diff --git a/StoneIsland/platforms/ios/www/js/lib/cart/CartView.js b/StoneIsland/platforms/ios/www/js/lib/cart/CartView.js index 5d741492..8bea43dc 100644 --- a/StoneIsland/platforms/ios/www/js/lib/cart/CartView.js +++ b/StoneIsland/platforms/ios/www/js/lib/cart/CartView.js @@ -3,16 +3,48 @@ var CartView = View.extend({ el: "#cart", events: { + "click .summary_step": "show_summary", + "click .shipping_step": "show_shipping", + "click .payment_step": "show_payment", }, initialize: function(){ - this.summary = new CartSummary () - this.billing = new CartBilling () - this.shipping = new CartShipping () + this.summary = new CartSummary ({ parent: this }) + this.payment = new CartPayment ({ parent: this }) + this.shipping = new CartShipping ({ parent: this }) + this.confirm = new CartConfirm ({ parent: this }) + this.thanks = new CartThanks ({ parent: this }) + + this.$itemcount = this.$(".itemcount") + }, + + load: function(){ + sdk.cart.get_status({ + success: function(data){ + this.summary.data = data + this.summary.updateCounts() + }.bind(this), + error: function(data){ + console.log(data) + }, + }) }, show: function(){ document.body.className = "cart" + this.show_summary() + }, + + show_summary: function(){ + this.summary.show() + }, + + show_shipping: function(){ + this.shipping.show() + }, + + show_payment: function(){ + this.payment.show() }, }) \ No newline at end of file diff --git a/StoneIsland/platforms/ios/www/js/lib/nav/AddressView.js b/StoneIsland/platforms/ios/www/js/lib/nav/AddressView.js new file mode 100644 index 00000000..15a5784d --- /dev/null +++ b/StoneIsland/platforms/ios/www/js/lib/nav/AddressView.js @@ -0,0 +1,39 @@ + +var AddressView = SerializableView.extend({ + + template: $("#address_template").html(), + + events: { + }, + + initialize: function(opt){ + this.parent = opt.parent + this.$el = this.parent.$(".address") + this.el = this.$el[0] + this.$el.html(this.template) + }, + + populate: function(data){ + this.parent.$(".address input").val("") + Object.keys(data).forEach(function(key){ + this.parent$(".address [name=" + key + "]").val(data[key]) + }.bind(this)) + }, + + deserialize: function(){ + }, + + validate_presence: { + "Name": "Please enter your first name.", + "Surname": "Please enter your last name.", + "Address1": "Please enter your street address.", + "City": "Please enter your city.", + "State": "Please choose your state.", + "Phone": "Please enter your phone number.", + }, + + validate_fields: function(data, errors){ + if (data.Phone.replace(/[^0-9]/g, "").length < 10) { errors.push([ "Phone", "Phone numbers must be at least 10 digits." ]) } + }, + +}) diff --git a/StoneIsland/platforms/ios/www/js/lib/nav/CreditCardView.js b/StoneIsland/platforms/ios/www/js/lib/nav/CreditCardView.js new file mode 100644 index 00000000..33ecab79 --- /dev/null +++ b/StoneIsland/platforms/ios/www/js/lib/nav/CreditCardView.js @@ -0,0 +1,27 @@ + +var CreditCardView = View.extend({ + + template: $("#creditcard_template").html(), + + events: { + }, + + initialize: function(opt){ + this.parent = opt.parent + this.parent.$(".cc").html(this.template) + }, + + populate: function(data){ + this.parent.$(".cc input").val("") + Object.keys(data).forEach(function(key){ + this.parent$(".cc [name=" + key + "]").val(data[key]) + }.bind(this)) + }, + + validate_presence: { + }, + + validate_fields: function(data, errors){ + }, + +}) diff --git a/StoneIsland/platforms/ios/www/js/lib/nav/CurtainView.js b/StoneIsland/platforms/ios/www/js/lib/nav/CurtainView.js index ba10e232..d444fd60 100644 --- a/StoneIsland/platforms/ios/www/js/lib/nav/CurtainView.js +++ b/StoneIsland/platforms/ios/www/js/lib/nav/CurtainView.js @@ -9,20 +9,30 @@ var CurtainView = View.extend({ initialize: function(){ }, - show: function(){ + klass: null, + show: function(klass){ this.$el.addClass("visible") + if (klass) { + this.klass = klass + this.$el.addClass(klass) + } }, - hide: function(){ + hide: function(k){ this.$el.removeClass("visible") + if (this.klass) { + setTimeout( function(){ + this.$el.removeClass(this.klass) + }.bind(this), 200 ) + } }, click: function(){ if (document.body.classList.contains("nav")) { app.nav.hide() } - else if (document.body.classList.contains("login")) { - app.login.hide() + if (app.selector.visible) { + app.selector.hide() } }, diff --git a/StoneIsland/platforms/ios/www/js/lib/nav/FooterView.js b/StoneIsland/platforms/ios/www/js/lib/nav/FooterView.js index 76126102..74b249e6 100644 --- a/StoneIsland/platforms/ios/www/js/lib/nav/FooterView.js +++ b/StoneIsland/platforms/ios/www/js/lib/nav/FooterView.js @@ -3,28 +3,38 @@ var FooterView = View.extend({ el: "#footer", events: { - "click .filter": "filter", - "click .buynow": "buynow", - "click .addtocart": "addtocart", + "click .ok": "ok", "click .cancel": "cancel", - "click .checkout": "checkout", - "click .checkout_proceed": "checkout_proceed", }, initialize: function(){ + this.$ok = this.$(".ok") + this.$cancel = this.$(".cancel") }, - filter: function(){ + show: function(ok, cancel){ + if (cancel) { + this.$ok.removeClass("wide") + this.$cancel.show().html(cancel) + } + else { + this.$ok.addClass("wide") + this.$cancel.hide() + } + this.$ok.html(ok) + this.$el.show() }, - buynow: function(){ + + hide: function(){ + this.$el.hide() }, - addtocart: function(){ + + ok: function(){ + (app.view.save || app.view.ok).bind(app.view)() }, + cancel: function(){ + app.view.cancel ? app.view.cancel() : app.intro.show() }, - checkout: function(){ - }, - checkout_proceed: function(){ - }, - + }) \ No newline at end of file diff --git a/StoneIsland/platforms/ios/www/js/lib/nav/HeaderView.js b/StoneIsland/platforms/ios/www/js/lib/nav/HeaderView.js index bbf18274..7563be2d 100644 --- a/StoneIsland/platforms/ios/www/js/lib/nav/HeaderView.js +++ b/StoneIsland/platforms/ios/www/js/lib/nav/HeaderView.js @@ -9,10 +9,27 @@ var HeaderView = View.extend({ }, initialize: function(){ + this.$burger = this.$(".burger") + this.$cart = this.$(".cart") + this.$cart_count = this.$(".cart_count") + }, + + set_back: function(state){ + if (state) { + this.$burger[0].className = "burger ion-ios-arrow-left" + } + else { + this.$burger[0].className = "burger ion-android-menu" + } }, nav: function(){ - app.nav.show() + if (app.view.back) { + app.view.back() + } + else { + app.nav.show() + } }, logo: function(){ @@ -22,5 +39,17 @@ var HeaderView = View.extend({ cart: function(){ app.router.go("cart") }, + + count: 0, + set_cart_count: function(n){ + this.count = n + this.$cart_count.html(n) + }, + increment_cart_count: function(){ + this.$cart_count.html( ++this.count ) + }, + decrement_cart_count: function(){ + this.$cart_count.html( --this.count ) + }, }) \ No newline at end of file diff --git a/StoneIsland/platforms/ios/www/js/lib/nav/IntroView.js b/StoneIsland/platforms/ios/www/js/lib/nav/IntroView.js index 93602eb5..87e68959 100644 --- a/StoneIsland/platforms/ios/www/js/lib/nav/IntroView.js +++ b/StoneIsland/platforms/ios/www/js/lib/nav/IntroView.js @@ -17,6 +17,7 @@ var IntroView = View.extend({ show: function(){ document.body.className = "intro" window.addEventListener("deviceorientation", this.orient) + app.footer.hide() this.orient({ alpha: 0 }) // get location.. }, diff --git a/StoneIsland/platforms/ios/www/js/lib/nav/LoginView.js b/StoneIsland/platforms/ios/www/js/lib/nav/LoginView.js deleted file mode 100644 index 60f6263e..00000000 --- a/StoneIsland/platforms/ios/www/js/lib/nav/LoginView.js +++ /dev/null @@ -1,57 +0,0 @@ -var LoginView = View.extend({ - - el: "#login", - - events: { - "click .close": "hide", - "click .login_ask": "login", - "click .signup_ask": "signup", - "submit form": "submit", - }, - - mode: null, - - initialize: function(){ - this.$form = this.$("form") - this.$email = this.$("[name=email]") - this.$password = this.$("[name=password]") - }, - - show: function(){ - this.$form.hide() - this.$email.val("") - this.$password.val("") - app.curtain.show() - document.body.classList.add("login") - }, - - hide: function(){ - app.curtain.hide() - document.body.classList.remove("login") - }, - - login: function(){ - this.mode = "login" - this.$form.show() - }, - - signup: function(){ - this.mode = "signup" - this.$form.show() - }, - - submit: function(e){ - e.preventDefault() - if (this.mode == "login") { - // login api - } - else { - // signup api - } - }, - - success: function(){ - // change login in ui to logout or whatever - }, - -}) \ No newline at end of file diff --git a/StoneIsland/platforms/ios/www/js/lib/nav/NavView.js b/StoneIsland/platforms/ios/www/js/lib/nav/NavView.js index 3949c3c5..1445a0d5 100644 --- a/StoneIsland/platforms/ios/www/js/lib/nav/NavView.js +++ b/StoneIsland/platforms/ios/www/js/lib/nav/NavView.js @@ -3,33 +3,61 @@ var NavView = View.extend({ el: "#nav", events: { + "click .logo": "intro", + "click .store": "store", "click .hub": "hub", "click .story": "story", "click .archive": "archive", "click .login": "login", + "click .logout": "logout", + "click .account": "account", "click .faq": "faq", "click .search": "search", + "click .main": "back", + "click .account_back": "back", + "click .profile": "profile", + "click .payment": "payment", + "click .shipping": "shipping", + "click .settings": "settings", + "click .orders": "orders", + "click .return_link": "return_link", + + "click .faq_back": "back", + "click .privacy": "privacy", + "click .returns": "returns", + "click .terms": "terms", + "click .care": "care", + "click .fb": "fb", "click .insta": "insta", "click .tw": "tw", }, - initialize: function(){ - }, + initialize: function(){ + }, - show: function(){ + show: function(klass){ $("body").addClass("nav") - app.curtain.show() + app.curtain.show("dark") + if (klass) { + setTimeout(function(){ + this.addClass(klass) + }.bind(this), 500) + } }, hide: function(){ $("body").removeClass("nav") - app.curtain.hide() + app.curtain.hide("dark") }, + intro: function(){ + this.hide() + app.router.go("intro") + }, store: function(){ this.hide() app.router.go("store") @@ -49,18 +77,74 @@ var NavView = View.extend({ login: function(){ this.hide() - app.router.go("login") + auth.last_view = app.view + app.router.go("account/login") + }, + logout: function(){ + this.hide() + auth.last_view = app.view + app.router.go("account/logout") + }, + account: function(){ + this.el.className = "account" }, - search: function(){ + back: function(){ + this.el.className = "" + }, + + profile: function(){ this.hide() - app.router.go("search") + app.router.go("account/profile") + }, + payment: function(){ + this.hide() + app.router.go("account/payment") }, + shipping: function(){ + this.hide() + app.router.go("account/shipping") + }, + orders: function(){ + this.hide() + app.router.go("account/orders") + }, + settings: function(){ + this.hide() + app.router.go("account/settings") + }, + return_link: function(){ + window.open("http://www.stoneisland.com/", '_system') + }, + + faq: function(){ + this.el.className = "faq" + }, + privacy: function(){ this.hide() - app.router.go("faq") + app.router.go("page/privacy") + }, + returns: function(){ + this.hide() + app.router.go("page/returns") + }, + terms: function(){ + this.hide() + app.router.go("page/terms") + }, + care: function(){ + this.hide() + app.router.go("page/care") + }, + + + search: function(){ + this.hide() + app.router.go("search") }, + fb: function(){ window.open("https://www.facebook.com/StoneIsland", '_system') }, @@ -70,6 +154,5 @@ var NavView = View.extend({ tw: function(){ window.open("https://twitter.com/stoneisland", '_system') }, - }) diff --git a/StoneIsland/platforms/ios/www/js/lib/nav/SearchView.js b/StoneIsland/platforms/ios/www/js/lib/nav/SearchView.js new file mode 100644 index 00000000..f21634a5 --- /dev/null +++ b/StoneIsland/platforms/ios/www/js/lib/nav/SearchView.js @@ -0,0 +1,16 @@ +var SearchView = View.extend({ + + el: "#search", + + events: { + }, + + show: function(){ + app.footer.show("SEARCH", "CANCEL") + document.body.className = "search" + }, + + save: function(){ + }, + +}) \ No newline at end of file diff --git a/StoneIsland/platforms/ios/www/js/lib/products/ClosedStoreView.js b/StoneIsland/platforms/ios/www/js/lib/products/ClosedStoreView.js new file mode 100644 index 00000000..77dc15b1 --- /dev/null +++ b/StoneIsland/platforms/ios/www/js/lib/products/ClosedStoreView.js @@ -0,0 +1,47 @@ +var ClosedStoreView = View.extend({ + + el: "#closed", + + storeIsClosed: false, + + events: { + "click .website_link": "website_link", + }, + + delay: 8000, + + timeout: -1, + images: null, + + initialize: function(){ + this.loader = new Loader () + }, + + show: function(){ + document.body.className = "closed" + this.animate() + app.footer.hide() + }, + + hide: function(){ + clearTimeout(this.timeout) + }, + + animate: function(){ + this.timeout = setTimeout(this.animate.bind(this), this.delay) + if (! this.images) return + var url = choice(this.images) + this.loader.preloadImage(url, function(img){ + this.el.style.backgroundImage = 'url(' + img.src + ')' + }.bind(this)) + }, + + populate: function(data){ + this.images = data.map(function(img){ return img.uri }) + }, + + website_link: function(){ + window.open("http://www.stoneisland.com/", '_system') + }, + +}) \ 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 987804fc..8ea03bd4 100644 --- a/StoneIsland/platforms/ios/www/js/lib/products/CollectionView.js +++ b/StoneIsland/platforms/ios/www/js/lib/products/CollectionView.js @@ -1,4 +1,5 @@ -var CollectionView = View.extend({ + +var CollectionView = ScrollableView.extend({ el: "#collection", template: $("#collection .template").html(), @@ -7,16 +8,27 @@ var CollectionView = View.extend({ items: {}, events: { - "click .item": "pick", + "touchstart .item": "touchstart", + "touchmove .item": "touchmove", + "touchend .item": "touchend", + "mousedown .item": "touchstart", + "mousemove .item": "touchmove", + "mouseup .item": "touchend", }, initialize: function(){ + this.$title = this.$("h1") this.$content = this.$(".content") this.$loader = this.$(".loader") - this.scroller = new IScroll('#collection .scroll') + this.scroller = new IScroll('#collection', app.iscroll_options) + this.filterView = new CategoryFilter ({ parent: this }) }, - + show: function(){ + if (app.closed.storeIsClosed) { + return app.closed.show() + } + app.footer.show("FILTER") document.body.className = "collection" if (this.loaded) { return this.populate(this.data) @@ -24,32 +36,77 @@ var CollectionView = View.extend({ this.fetch() }, + ok: function(){ + this.filterView.filter() + }, + fetch: function(){ + if (this.loaded) return this.$loader.show() sdk.product.collection({ - gallery_id: 31617, + gallery_id: 32780, success: this.populate.bind(this) }) }, populate: function(data){ - this.$loader.hide() - this.$content.empty() - // DefaultCode10 - console.log(data) - data.SearchResponseFull.Results.Items.forEach(function(item){ - this.items[ item['Code8'] ] = item - var t = this.template.replace(/{{image}}/, sdk.image(item['DefaultCode10'])) - .replace(/{{code8}}/, item['Code8']) - this.$content.append(t) - - }.bind(this)) + if (this.loaded && ! data) { + data = this.data + } + else { + this.data = data + } + if (! this.loaded) { + this.loaded = true + this.$loader.hide() + this.$content.empty() + // DefaultCode10 + data.SearchResponseFull.Results.Items.forEach(this.append.bind(this)) + this.deferScrollToTop() + } + this.afterFetchCallback && this.afterFetchCallback() + }, + + append: function(item){ + this.items[ item['Code8'] ] = item + var t = this.template.replace(/{{image}}/, sdk.image(item['DefaultCode10'], '11_f')) + .replace(/{{code8}}/, item['Code8']) + this.$content.append(t) }, pick: function(e){ var code = $(e.currentTarget).data("code") var data = this.items[code] - app.product.load(data) + app.product.load(code, data) + }, + + collectionName: "STONE ISLAND", + setCollectionName: function(name){ + this.collectionName = name + this.$title.html(this.collectionName) + }, + + firstTouch: { x: 0, y: 0, id: "" }, + lastTouch: { x: 0, y: 0, id: "" }, + touchstart: function(e){ + var p = e.originalEvent.touches ? e.originalEvent.touches[0] : e.originalEvent + this.firstTouch.x = this.lastTouch.x = p.pageX + this.firstTouch.y = this.lastTouch.y = p.pageY + this.firstTouch.id = e.currentTarget.dataset.id + }, + touchmove: function(e){ + var p = e.originalEvent.touches ? e.originalEvent.touches[0] : e.originalEvent + this.lastTouch.x = p.pageX + this.lastTouch.y = p.pageY + this.lastTouch.id = e.currentTarget.dataset.id + }, + touchend: function(e){ + var first = app.collection.firstTouch + var last = app.collection.lastTouch + var distance = Math.sqrt( Math.pow(first.x - last.x, 2) + Math.pow(first.y - last.y, 2) ) + if (distance < 20) { + this.pick(e) + } }, }) diff --git a/StoneIsland/platforms/ios/www/js/lib/products/GalleryView.js b/StoneIsland/platforms/ios/www/js/lib/products/GalleryView.js index 2eabe2a6..ea4637eb 100644 --- a/StoneIsland/platforms/ios/www/js/lib/products/GalleryView.js +++ b/StoneIsland/platforms/ios/www/js/lib/products/GalleryView.js @@ -1,22 +1,54 @@ var GalleryView = View.extend({ el: "#gallery", + template: $("#gallery .template").html(), events: { "click .left": "prev", "click .right": "next", - "touchstart .gallery": "touchstart", - "touchmove .gallery": "touchmove", - "touchend .gallery": "touchend", +// "touchstart .gallery": "touchstart", +// "touchmove .gallery": "touchmove", +// "touchend .gallery": "touchend", }, initialize: function(){ - this.$prev = this.$(".prev") - this.$next = this.$(".next") - this.$slider = this.$(".slider") + this.$(".template").remove() }, - populate: function(){ + reset: function(){ + this.gallery && this.gallery.destroy() + this.$el.empty() + }, + + populate: function(code, image_ids){ + var valid_styles = {} + image_ids.forEach(function(id){ + if (id.indexOf("_") == -1) return + var partz = id.split("_") + var size = parseInt(partz[0]), style = partz[1] + if (size > 13) return; + if (! valid_styles[style] || valid_styles[style] < size) { + valid_styles[style] = size + } + }) + Object.keys(valid_styles).forEach(function(style){ + var id = valid_styles[style] + "_" + style + var t = this.template.replace(/{{image}}/, sdk.image(code, id)) + this.$el.append(t) + }.bind(this)) + + this.gallery = new Flickity( "#gallery", { + selector: '.item', + cellAlign: 'center', + autoPlay: false, + freeScroll: false, + wrapAround: true, + imagesLoaded: true, + prevNextButtons: false, + pageDots: false, + contain: true, + draggable: true, + }) }, prev: function(){ diff --git a/StoneIsland/platforms/ios/www/js/lib/products/ProductView.js b/StoneIsland/platforms/ios/www/js/lib/products/ProductView.js index 76527c8b..c99ff0ab 100644 --- a/StoneIsland/platforms/ios/www/js/lib/products/ProductView.js +++ b/StoneIsland/platforms/ios/www/js/lib/products/ProductView.js @@ -1,14 +1,5 @@ -var SIZE_LOOKUP = { - "XS": "X-SMALL", - "S": "SMALL", - "M": "MEDIUM", - "L": "LARGE", - "XL": "X-LARGE", - "XXL": "XX-LARGE", - "XXXL": "XXX-LARGE", -}; -var ProductView = View.extend({ +var ProductView = ScrollableView.extend({ el: "#product", @@ -20,6 +11,7 @@ var ProductView = View.extend({ initialize: function(){ this.gallery = new GalleryView () + this.scroller = new IScroll('#product', app.iscroll_options) this.$num = this.$(".num") this.$title = this.$(".title") @@ -31,54 +23,170 @@ var ProductView = View.extend({ }, show: function(){ + app.footer.show("ADD TO CART", "BUY NOW") document.body.className = "product" }, hide: function(){ }, item: null, + details: null, size: null, color: null, code: null, + + sizes: null, + colors: null, + + cache: {}, - load: function(data){ + find: function(code, cb){ + data = app.collection.items[code] + if (code in this.cache) { + return cb(data, this.cache[code]) + } + sdk.product.item({ + code: code + }).done(function(details){ + this.cache[code] = details + cb(data, details) + }.bind(this)) + }, + + load: function(code, data){ + this.gallery.reset() + this.show() + if (app.view && app.view.hide) { + app.view.hide() + } + app.view = this + app.header.set_back(true) + + if (! app.collection.loaded) { + this.el.className = "loading" + app.collection.afterFetchCallback = this.load.bind(this, code, data) + app.collection.fetch() + return + } + else { + app.collection.afterFetchCallback = null + } + window.location.href = "#/store/" + code + + console.log(data) + if (data) { + app.collection.items[code] = data + } + + this.el.className = "loading" + this.find(code, this.populate.bind(this)) + }, + + populate: function(data, details){ + this.el.className = "" + + console.log(data, details) + + var descriptions = this.get_descriptions(details) + + this.gallery.populate( data['Code8'], details['Item']['ImageTypes'] ) + var name_partz = data['ModelNames'].split(' ') var num = name_partz.shift() var title = name_partz.join(' ') - var type = data['MicroCategory'].toUpperCase() + var type = title_case( data['MicroCategory'] ) var price = "$" + data['DiscountedPrice'] + ".00" - var size = data['Sizes'][0] - var size_label = SIZE_LOOKUP[size] - var color = data['Colors'][0] - var color_label = color['Text'] - var body = "" - + var body = descriptions['EditorialDescription'].replace(/
/g, "

") + + var default_color_id = this.populate_selectors(data, details) + + var color = this.colors[default_color_id] + var color_label = color.label + var sizes = this.find_sizes_for_color(default_color_id) + var size = sizes[0] + var size_label = this.sizes[size].label + + // console.log(color, color_label, size, size_label) + this.item = data + this.details = details['Item'] + this.code = data['DefaultCode10'] + this.color = color this.size = size - this.code = data['DefaultCode10'] this.$num.html(num) this.$title.html(title) this.$type.html(type) this.$price.html(price) - this.$size.html(size_label) - this.$color.html(color) this.$body.html(body) - // TODO: fetch product from item API, get other Code10s so you can populate the gallery + this.$size.html(size_label) + if (color_label) { + this.$color.show().html(color_label) + } + else { + this.$color.hide() + } + + this.deferScrollToTop() }, - select_size: function(){ - if (this.item['Sizes'].length == 0) { return } - var mapped_sizes = this.item['Sizes'].map(function(size){ - return { - id: size['Id'], - label: SIZE_LOOKUP[ size['Text'] ], - value: size, + get_descriptions: function (details){ + var descriptions = {} + details['Item']['Descriptions'].forEach(function(pair){ + descriptions[pair.Key] = pair.Value + }) + return descriptions + }, + find_sizes_for_color: function(color_id){ + return Object.keys( this.colors[color_id].sizes ).sort(function(a,b){ + var ao = SIZE_ORDER[ a.label ], bo = SIZE_ORDER[ b.label ] + return aoShort sleeve T-Shirt in cotton jersey. Garment dyed.
Stone Island Compass logo print on the front, made up of a series of numbers." +ItemDescription: "Logo detail
Jersey
Round collar
Solid color
" +KeywordDescription: "Logo detail Jersey Round collar Solid color Jersey Woven not made of fur " +Kind of fabric: "Woven" +MFC: "631520081CC-6315-81V0060" +MacroCategory: "POLO SHIRTS & T-SHIRTS" +MadeIn: "Made In Turkmenistan" +MadeInIsoCode: "TN" +MainMaterial: "Cotton" +Material Description: "Jersey" +MicroCategory: "Short sleeve t-shirt" +MicroCategoryPlural: "Short sleeve t-shirts" +ModelFabric: "631520081CC-6315-81" +ModelNames: "20081 DATA DRIP PIN" +Neckline: "Claudine or round collar" + */ \ No newline at end of file diff --git a/StoneIsland/platforms/ios/www/js/lib/products/Selector.js b/StoneIsland/platforms/ios/www/js/lib/products/Selector.js index 1580624b..76c498ec 100644 --- a/StoneIsland/platforms/ios/www/js/lib/products/Selector.js +++ b/StoneIsland/platforms/ios/www/js/lib/products/Selector.js @@ -5,7 +5,7 @@ var Selector = View.extend({ events: { "click .close": "hide", - "click span": "pick", + "click .options div": "pick", }, initialize: function(){ @@ -15,26 +15,32 @@ var Selector = View.extend({ lookup: null, callback: null, select: function(options, callback){ - var lookup = this.lookup = {} + this.lookup = {} + this.callback = callback || function(item){ console.log(item) } this.$options.empty() options.forEach(function(opt){ - lookup[opt.id] = opt + this.lookup[String(opt.id)] = opt var t = this.template.replace(/{{id}}/, opt.id) .replace(/{{label}}/, opt.label) this.$options.append(t) - }) + }.bind(this)) this.$el.show() + app.curtain.show("white") + this.visible = true }, hide: function(){ this.lookup = this.callback = null this.$el.hide() + app.curtain.hide() + this.visible = false }, pick: function(e){ var $option = $(e.currentTarget) - var id = $option.data("id") + var id = String($option.data("id")) var selection = this.lookup[id] + this.callback( selection ) this.hide() }, diff --git a/StoneIsland/platforms/ios/www/js/lib/products/filters/CategoryFilter.js b/StoneIsland/platforms/ios/www/js/lib/products/filters/CategoryFilter.js new file mode 100644 index 00000000..4e6baf62 --- /dev/null +++ b/StoneIsland/platforms/ios/www/js/lib/products/filters/CategoryFilter.js @@ -0,0 +1,40 @@ +var CategoryFilter = View.extend({ + + initialize: function(opt){ + this.parent = opt.parent + }, + + filter: function(){ + var cats = this.parent.data.SearchResponseFull.Refinements.Filters.Categories.map(function(cat){ + return { + id: cat.Id, + label: cat.Value + } + }) + if (this.last_choice) { + cats.push({ + id: "__remove_filter", + label: "REMOVE FILTER", + }) + } + app.selector.select(cats, this.pick.bind(this)) + }, + + last_choice: null, + + pick: function(choice){ + this.parent.$content.empty() + if (choice.id == "__remove_filter") { + this.last_choice = null + this.parent.data.SearchResponseFull.Results.Items.forEach(this.parent.append.bind(this.parent)) + } + else { + this.last_choice = choice + this.parent.data.SearchResponseFull.Results.Items.filter(function(item){ + return item.MacroCategory == choice.label + }).forEach(this.parent.append.bind(this.parent)) + } + this.parent.deferScrollToTop() + }, + +}) diff --git a/StoneIsland/platforms/ios/www/js/sdk/_sdk.js b/StoneIsland/platforms/ios/www/js/sdk/_sdk.js index 31fd96ca..27773310 100644 --- a/StoneIsland/platforms/ios/www/js/sdk/_sdk.js +++ b/StoneIsland/platforms/ios/www/js/sdk/_sdk.js @@ -1,11 +1,13 @@ var sdk = (function(){ var sdk = {} - + + sdk.env = "development" + var endpoint = "https://secure.api.yoox.biz/" // var endpoint = "http://api.yoox.biz/" sdk.init = function(opt){ - switch (opt.env) { + switch (sdk.env = opt.env || "development") { case 'test': endpoint = "http://lvh.me:9090/" break @@ -23,8 +25,8 @@ var sdk = (function(){ return endpoint + api + "/STONEISLAND_US/" + path } - sdk.image = function(code){ - return "http://cdn.yoox.biz/" + code.substr(0,2) + "/" + code + "_11_f.jpg" + sdk.image = function(code, size){ + return "http://cdn.yoox.biz/" + code.substr(0,2) + "/" + code.substr(0,8) + "_" + size + ".jpg" } $.ajaxSetup({ diff --git a/StoneIsland/platforms/ios/www/js/sdk/account.js b/StoneIsland/platforms/ios/www/js/sdk/account.js index 3dfe2cfe..fe5f03cd 100644 --- a/StoneIsland/platforms/ios/www/js/sdk/account.js +++ b/StoneIsland/platforms/ios/www/js/sdk/account.js @@ -5,14 +5,14 @@ sdk.account = (function(){ // https://gist.github.com/fanfare/d18498e7fa25acbd4486 var account = {} account.signup = function(opt){ - $.ajax({ + return $.ajax({ method: "POST", url: sdk.path("Account.API/1.5", "users.json"), headers: { "x-yoox-appname": auth.appname, "x-yoox-api-key": auth.apikey, }, - data: opt.data, + data: JSON.stringify( opt.data ), success: function(data){ user_id = data['UserAccount']['UserId'] access_token = data['UserAccount']['AccessToken'] @@ -26,21 +26,20 @@ sdk.account = (function(){ } account.login = function(opt){ - $.ajax({ + return $.ajax({ method: "POST", url: sdk.path("Account.API/1.5", "authfull.json"), headers: { "x-yoox-appname": auth.appname, "x-yoox-account-token": auth.access_token, }, - data: opt.data, + data: JSON.stringify( opt.data ), success: function(data){ - // console.log(data) - // auth.user_id = data['UserFull']['UserId'] - // auth.access_token = data['UserFull']['AccessToken'] + auth.user = data['UserFull'] + user_id = data['UserFull']['idUser'] + access_token = data['UserFull']['AccessToken'] - // why bother? - // auth.set_user(user_id, access_token, name) + auth.set_user(user_id, access_token) opt.success(data) }, @@ -48,6 +47,55 @@ sdk.account = (function(){ }) } + account.checkin = function(opt){ + return $.ajax({ + method: "GET", + url: sdk.path("Account.API/1.5", "users/" + auth.user_id + ".json"), + headers: { + "x-yoox-appname": auth.appname, + "x-yoox-account-token": auth.access_token, + }, + data: "{}", + success: function(data){ + auth.user = data.User + opt.success(data) + }, + error: opt.error, + }) + } + + account.update = function(opt){ + return $.ajax({ + method: "PUT", + url: sdk.path("Account.API/1.5", "users/" + auth.user_id + ".json"), + headers: { + "x-yoox-appname": auth.appname, + "x-yoox-account-token": auth.access_token, + }, + data: JSON.stringify( opt.data ), + success: function(data){ + opt.success(data) + }, + error: opt.error, + }) + } + + account.update_mail_and_password = function(opt){ + return $.ajax({ + method: "PUT", + url: sdk.path("Account.API/1.5", "auth/" + auth.user_id + ".json"), + headers: { + "x-yoox-appname": auth.appname, + "x-yoox-account-token": auth.access_token, + }, + data: JSON.stringify( opt.data ), + success: function(data){ + opt.success(data) + }, + error: opt.error, + }) + } + return account })() diff --git a/StoneIsland/platforms/ios/www/js/sdk/address.js b/StoneIsland/platforms/ios/www/js/sdk/address.js index 144589d0..f4e36376 100644 --- a/StoneIsland/platforms/ios/www/js/sdk/address.js +++ b/StoneIsland/platforms/ios/www/js/sdk/address.js @@ -2,14 +2,14 @@ sdk.address = (function(){ var address = {} address.add = function(opt){ - $.ajax({ + return $.ajax({ method: "POST", url: sdk.path("Account.API/1.5", "users/" + auth.user_id + "/addressBook/item.json"), headers: { "x-yoox-appname": auth.appname, "x-yoox-account-token": auth.access_token, }, - data: opt.data, + data: JSON.stringify( opt.data ), success: function(data){ // console.log(data) opt.success(data) @@ -19,7 +19,7 @@ sdk.address = (function(){ } address.list = function(opt){ - $.ajax({ + return $.ajax({ method: "GET", url: sdk.path("Account.API/1.5", "users/" + auth.user_id + "/addressBook.json"), headers: { diff --git a/StoneIsland/platforms/ios/www/js/sdk/auth.js b/StoneIsland/platforms/ios/www/js/sdk/auth.js index cea0054c..8a72dd46 100644 --- a/StoneIsland/platforms/ios/www/js/sdk/auth.js +++ b/StoneIsland/platforms/ios/www/js/sdk/auth.js @@ -7,7 +7,7 @@ }, */ -var auth = (function(){ +var auth = sdk.auth = (function(){ var auth = {} auth.appname = is_iphone ? "native-iphone-stoneisland/1.0.0" : "native-android-stoneisland/1.0.0" @@ -16,18 +16,110 @@ var auth = (function(){ auth.access_token = "" auth.user_id = -1 + + auth.next_view = null + auth.deferred_product = null // ios: integrate keychain api // android: cordova.file.externalRootDirectory api - auth.set_user = function(user_id, access_token){ - // persist user data - auth.user_id = user_id + auth.init = function(fn){ + console.log("AUTH INIT") + auth.get_user(function(){ + if (auth.logged_in()) { + sdk.account.checkin({ + success: function(data){ + fn && fn( auth.logged_in() ) + } + }) + auth.get_cart() + } + else { + fn && fn( auth.logged_in() ) + } + }) + } + + auth.set_user = function(user_id, access_token, cb){ auth.access_token = access_token + auth.user_id = user_id + + localStorage.setItem("yoox.access_token", access_token) + localStorage.setItem("yoox.user_id", user_id) + cb && cb() } auth.get_user = function(cb){ - // fetch user data + auth.access_token = localStorage.getItem("yoox.access_token") || "" + auth.user_id = localStorage.getItem("yoox.user_id") || -1 + cb && cb() + } + auth.clear_user = function(cb){ + auth.access_token = "" + auth.user_id = -1 + localStorage.removeItem("yoox.access_token") + localStorage.removeItem("yoox.user_id") + cb && cb() + } + + auth.set_cart = function(cart_id, cart_token, cb){ + localStorage.setItem("yoox.cart_token", cart_token) + localStorage.setItem("yoox.cart_id", cart_id) + cb && cb() + } + auth.get_cart = function(cb){ + sdk.cart.token = localStorage.getItem("yoox.cart_token") || "" + sdk.cart.id = localStorage.getItem("yoox.cart_id") || -1 + cb && cb() + } + auth.clear_cart = function(cb){ + sdk.cart.token = "" + sdk.cart.id = -1 + localStorage.removeItem("yoox.cart_token") + localStorage.removeItem("yoox.cart_id") + cb && cb() + } + auth.create_cart = function(cb){ + if (auth.has_cart()) { return cb() } + sdk.cart.initialize({ + success: function(data){ + sdk.cart.set_user({ + success: function(){ + auth.set_cart(sdk.cart.id, sdk.cart.token, function(){ + cb && cb() + }) + } + }) + } + }) + } + auth.add_deferred_product_to_cart = function(cb){ + // auth.deferred_product + if (! auth.deferred_product) { + cb && cb() + return + } + sdk.cart.add_item({ + data: auth.deferred_product, + success: function(){ + console.log("ADDED") + cb && cb() + } + }) + auth.deferred_product = null + app.header.increment_cart_count() + } + + auth.log_out = function(){ + auth.clear_user() + auth.clear_cart() + auth.view_logged_out() + } + auth.logged_in = function(){ + return (auth.user_id !== -1) && (auth.user_id !== "undefined") + } + auth.has_cart = function(){ + return (sdk.cart.id !== -1) && (sdk.cart.id !== "undefined") } return auth -})() +})() \ No newline at end of file diff --git a/StoneIsland/platforms/ios/www/js/sdk/cart.js b/StoneIsland/platforms/ios/www/js/sdk/cart.js index 9f9d81f1..bbd03299 100644 --- a/StoneIsland/platforms/ios/www/js/sdk/cart.js +++ b/StoneIsland/platforms/ios/www/js/sdk/cart.js @@ -6,18 +6,19 @@ sdk.cart = (function(){ // https://gist.github.com/fanfare/9a50c524aea417d0bf3e cart.initialize = function(opt){ - $.ajax({ + return $.ajax({ method: "POST", url: sdk.path("Cart.API/1.6", "carts.json"), headers: { "x-yoox-appname": auth.appname, "x-yoox-device": auth.device, }, + data: "{}", // data: opt.data, success: function(data){ - console.log(data) cart.id = data["CartSession"]["CartId"] cart.token = data["CartSession"]["CartToken"] + auth.set_cart( cart.id, cart.token ) opt.success(data) }, error: opt.error, @@ -25,19 +26,18 @@ sdk.cart = (function(){ } cart.set_user = function(opt){ - $.ajax({ + return $.ajax({ method: "PUT", - url: sdk.path("Cart.API/1.6", "user.json"), + url: sdk.path("Cart.API/1.6", "carts/" + cart.id + "/user.json"), headers: { "x-yoox-appname": auth.appname, "x-yoox-cart-token": cart.token, }, - data: { + data: JSON.stringify({ "UserId": auth.user_id, "UserToken": auth.access_token, - }, + }), success: function(data){ - console.log(data) opt.success(data) }, error: opt.error, @@ -46,16 +46,16 @@ sdk.cart = (function(){ // Code10, Size, Section cart.add_item = function(opt){ - $.ajax({ + return $.ajax({ method: "POST", url: sdk.path("Cart.API/1.6", "carts/" + cart.id + "/items.json"), headers: { "x-yoox-appname": auth.appname, "x-yoox-cart-token": cart.token, }, - data: opt.data, + data: JSON.stringify( opt.data ), success: function(data){ - console.log(data) + // console.log(data) opt.success(data) }, error: opt.error, @@ -63,17 +63,18 @@ sdk.cart = (function(){ } cart.delete_item = function(opt){ - $.ajax({ + return $.ajax({ method: "DELETE", url: sdk.path("Cart.API/1.6", "carts/" + cart.id + - "/items/" + opt.code10 + - "/" + opt.size + ".json"), + "/items/" + opt.data.Code10 + + "/" + opt.data.Size + ".json"), headers: { "x-yoox-appname": auth.appname, "x-yoox-cart-token": cart.token, }, + data: "{}", success: function(data){ - console.log(data) + // console.log(data) opt.success(data) }, error: opt.error, @@ -81,21 +82,24 @@ sdk.cart = (function(){ } cart.get_status = function(opt){ - $.ajax({ + if (! cart.id) { + return opt.error({ error: "no cart" }) + } + return $.ajax({ method: "GET", - url: sdk.path("Cart.API/1.6", "carts/" + cart.id), + url: sdk.path("Cart.API/1.6", "carts/" + cart.id + ".json"), headers: { "x-yoox-appname": auth.appname, "x-yoox-cart-token": cart.token, "x-yoox-device": auth.device, }, - data: { - "UserId": auth.user_id, - "UserToken": auth.access_token, - }, success: function(data){ - console.log(data) - opt.success(data) + if (data['Error']) { + opt.error && opt.error(data) + } + else { + opt.success(data) + } }, error: opt.error, }) @@ -103,16 +107,16 @@ sdk.cart = (function(){ // NOTE: data might be wrapped in a Receiver object cart.set_shipping_address = function(opt){ - $.ajax({ + return $.ajax({ method: "PUT", - url: sdk.path("Cart.API/1.6", "receiver.json"), + url: sdk.path("Cart.API/1.6", "carts/" + cart.id + "/receiver.json"), headers: { "x-yoox-appname": auth.appname, "x-yoox-cart-token": cart.token, }, - data: opt.data, + data: JSON.stringify(opt.data), success: function(data){ - console.log(data) + // console.log(data) opt.success(data) }, error: opt.error, @@ -121,16 +125,16 @@ sdk.cart = (function(){ // NB: Payment type may simply be 1 (credit card) cart.set_payment_type = function(opt){ - $.ajax({ + return $.ajax({ method: "PUT", url: sdk.path("Cart.API/1.6", "carts/" + cart.id + "/paymentType.json"), headers: { "x-yoox-appname": auth.appname, "x-yoox-cart-token": cart.token, }, - data: opt.data, + data: JSON.stringify( opt.data ), success: function(data){ - console.log(data) + // console.log(data) opt.success(data) }, error: opt.error, @@ -139,16 +143,16 @@ sdk.cart = (function(){ // use with full CC data if not storing it in wallet cart.set_credit_card = function(opt){ - $.ajax({ + return $.ajax({ method: "PUT", url: sdk.path("Cart.API/1.6", "carts/" + cart.id + "/creditCard.json"), headers: { "x-yoox-appname": auth.appname, "x-yoox-cart-token": cart.token, }, - data: opt.data, + data: JSON.stringify( opt.data ), success: function(data){ - console.log(data) + // console.log(data) opt.success(data) }, error: opt.error, @@ -159,22 +163,22 @@ sdk.cart = (function(){ // NB: if "verification number" is 1, use CVV/CID/CVC security code // if "verification number" is 2, use "Issue Number" cart.use_stored_credit_card = function(opt){ - $.ajax({ + return $.ajax({ method: "PUT", url: sdk.path("Cart.API/1.6", "carts/" + cart.id + "/userCreditCard.json"), headers: { "x-yoox-appname": auth.appname, "x-yoox-cart-token": cart.token, }, - data: { // NB may be wrapped in UserCreditCard object + data: JSON.stringify({ // NB may be wrapped in UserCreditCard object "Guid": opt.guid, "UserId": auth.user_id, "AccessToken": auth.access_token, "Cvv": opt.cvv, "Issue": opt.issue, - }, + }), success: function(data){ - console.log(data) + // console.log(data) opt.success(data) }, error: opt.error, @@ -182,7 +186,7 @@ sdk.cart = (function(){ } cart.finalize = function(opt){ - $.ajax({ + return $.ajax({ method: "PUT", url: sdk.path("Cart.API/1.6", "carts/" + cart.id + "/secureFinalizer.json"), headers: { @@ -190,7 +194,7 @@ sdk.cart = (function(){ "x-yoox-cart-token": cart.token, "x-yoox-device": auth.device, }, - data: opt.data, + data: JSON.stringify( opt.data ), success: function(data){ console.log(data) // order number is: diff --git a/StoneIsland/platforms/ios/www/js/sdk/payment.js b/StoneIsland/platforms/ios/www/js/sdk/payment.js index 048cde4b..d0951017 100644 --- a/StoneIsland/platforms/ios/www/js/sdk/payment.js +++ b/StoneIsland/platforms/ios/www/js/sdk/payment.js @@ -1,26 +1,28 @@ sdk.payment = (function(){ var payment = {} - payment.list_credit_cards = function(opt){ - $.ajax({ - method: "GET", + payment.add_credit_card = function(opt){ + return $.ajax({ + method: "POST", url: sdk.path("Account.API/1.5", "users/" + auth.user_id + "/cards.json"), headers: { "x-yoox-appname": auth.appname, "x-yoox-account-token": auth.access_token, }, - data: opt.data, + data: JSON.stringify( opt.data ), success: function(data){ - console.log(data) + // console.log(data) opt.success(data) }, error: opt.error, }) } - - payment.add_credit_card = function(opt){ - $.ajax({ - method: "POST", + + // LISTING A CREDIT CARD ONCE A CARD HAS BEEN ADDED PRODUCES ERROR + + payment.list_credit_cards = function(opt){ + return $.ajax({ + method: "GET", url: sdk.path("Account.API/1.5", "users/" + auth.user_id + "/cards.json"), headers: { "x-yoox-appname": auth.appname, @@ -28,6 +30,7 @@ sdk.payment = (function(){ }, data: opt.data, success: function(data){ + console.log("listing credit cards") console.log(data) opt.success(data) }, @@ -36,15 +39,16 @@ sdk.payment = (function(){ } payment.delete_credit_card = function(opt){ - $.ajax({ + return $.ajax({ method: "DELETE", url: sdk.path("Account.API/1.5", "users/" + auth.user_id + "/cards/" + opt.guid + ".json"), headers: { "x-yoox-appname": auth.appname, "x-yoox-account-token": auth.access_token, }, + data: "{}", success: function(data){ - console.log(data) + // console.log(data) opt.success(data) }, error: opt.error, @@ -52,7 +56,7 @@ sdk.payment = (function(){ } payment.get_payment_types = function(opt){ - $.ajax({ + return $.ajax({ method: "GET", url: sdk.path("Cart.API/1.6", "availablePaymentTypes.json"), headers: { @@ -61,7 +65,7 @@ sdk.payment = (function(){ }, data: opt.data, success: function(data){ - console.log(data) + // console.log(data) opt.success(data) }, error: opt.error, diff --git a/StoneIsland/platforms/ios/www/js/sdk/product.js b/StoneIsland/platforms/ios/www/js/sdk/product.js index a2ba30a1..55f1940a 100644 --- a/StoneIsland/platforms/ios/www/js/sdk/product.js +++ b/StoneIsland/platforms/ios/www/js/sdk/product.js @@ -1,11 +1,13 @@ sdk.product = (function(){ var product = {} + + var default_gallery = 31617 product.collection = function(opt){ - $.ajax({ + return $.ajax({ method: "GET", url: sdk.path("Search.API/1.2", "search.json"), - data: { format: "full", gallery: opt.gallery_id }, + data: { format: "full", gallery: opt.gallery_id || default_gallery, productsPerPage: 100 }, success: opt.success, error: opt.error, }) @@ -13,7 +15,7 @@ sdk.product = (function(){ // https://gist.github.com/fanfare/2d25d1b36944188948ff product.item = function(opt){ - $.ajax({ + return $.ajax({ method: "GET", url: sdk.path("Item.API/1.0", "item/" + opt.code + ".json"), success: opt.success, @@ -21,5 +23,15 @@ sdk.product = (function(){ }) } + product.search = function(opt){ + return $.ajax({ + method: "GET", + url: sdk.path("Search.API/1.2", "search.json"), + data: { format: "full", gallery: opt.gallery_id || default_gallery, textSearch: opt.query, productsPerPage: 100 }, + success: opt.success, + error: opt.error, + }) + } + return product })() \ No newline at end of file diff --git a/StoneIsland/platforms/ios/www/js/sdk/shipping.js b/StoneIsland/platforms/ios/www/js/sdk/shipping.js index 400d3199..a4615531 100644 --- a/StoneIsland/platforms/ios/www/js/sdk/shipping.js +++ b/StoneIsland/platforms/ios/www/js/sdk/shipping.js @@ -1,39 +1,40 @@ -sdk.shipping = (function(){ +sdk.shipping = (function() { var shipping = {} + // https://gist.github.com/fanfare/edb524128461b573d833 // BOX TYPE shipping.get_box_types = function(opt){ - $.ajax({ + return $.ajax({ method: "GET", - url: sdk.path("Cart.API/1.6", "carts/" + cart.id + "/availableBoxTypes.json"), + url: sdk.path("Cart.API/1.6", "carts/" + sdk.cart.id + "/availableBoxTypes.json"), headers: { "x-yoox-appname": auth.appname, - "x-yoox-cart-token": cart.token, + "x-yoox-cart-token": sdk.cart.token, }, success: function(data){ - console.log(data) - opt.success(data['BoxTypes']['Types']) + // console.log(data) + opt.success(data) }, error: opt.error, }) } shipping.set_box_type = function(opt){ - $.ajax({ + return $.ajax({ method: "PUT", - url: sdk.path("Cart.API/1.6", "carts/" + cart.id + "/boxType.json"), + url: sdk.path("Cart.API/1.6", "carts/" + sdk.cart.id + "/boxType.json"), headers: { "x-yoox-appname": auth.appname, - "x-yoox-cart-token": cart.token, + "x-yoox-cart-token": sdk.cart.token, }, - data: { + data: JSON.stringify({ "Type": opt.type, - }, + }), success: function(data){ - console.log(data) + // console.log(data) opt.success(data) }, error: opt.error, @@ -42,36 +43,41 @@ sdk.shipping = (function(){ // DELIVERY TYPES + + // The response is different than described in the API reference.. + // https://gist.github.com/fanfare/15dfbca6a16ae6bed503 shipping.get_delivery_types = function(opt){ - $.ajax({ + return $.ajax({ method: "GET", - url: sdk.path("Cart.API/1.6", "carts/" + cart.id + "/availableDeliveryTypes.json"), + url: sdk.path("Cart.API/1.6", "carts/" + sdk.cart.id + "/availableDeliveryTypes.json"), headers: { "x-yoox-appname": auth.appname, - "x-yoox-cart-token": cart.token, + "x-yoox-cart-token": sdk.cart.token, }, success: function(data){ - console.log(data) - opt.success(data['DeliveryTypes']['Types']) + opt.success(data) }, error: opt.error, }) } shipping.set_delivery_type = function(opt){ - $.ajax({ + return $.ajax({ method: "PUT", - url: sdk.path("Cart.API/1.6", "carts/" + cart.id + "/availableBoxTypes.json"), + url: sdk.path("Cart.API/1.6", "carts/" + sdk.cart.id + "/deliveryType.json"), headers: { "x-yoox-appname": auth.appname, - "x-yoox-cart-token": cart.token, + "x-yoox-cart-token": sdk.cart.token, }, - data: { + // temporarily commented out + /* + data: JSON.stringify({ "Id": opt.id, - }, + }), + */ success: function(data){ - console.log(data) + //console.log(data) opt.success(data) }, error: opt.error, @@ -79,4 +85,4 @@ sdk.shipping = (function(){ } return shipping -})() \ No newline at end of file +})() diff --git a/StoneIsland/platforms/ios/www/js/vendor/flickity.pkgd.js b/StoneIsland/platforms/ios/www/js/vendor/flickity.pkgd.js new file mode 100644 index 00000000..0471fa5b --- /dev/null +++ b/StoneIsland/platforms/ios/www/js/vendor/flickity.pkgd.js @@ -0,0 +1,5090 @@ +/*! + * Flickity PACKAGED v1.0.1 + * Touch, responsive, flickable galleries + * + * Licensed GPLv3 for open source use + * or Flickity Commercial License for commercial use + * + * http://flickity.metafizzy.co + * Copyright 2015 Metafizzy + */ + +/** + * Bridget makes jQuery widgets + * v1.1.0 + * MIT license + */ + +( function( window ) { + + + +// -------------------------- utils -------------------------- // + +var slice = Array.prototype.slice; + +function noop() {} + +// -------------------------- definition -------------------------- // + +function defineBridget( $ ) { + +// bail if no jQuery +if ( !$ ) { + return; +} + +// -------------------------- addOptionMethod -------------------------- // + +/** + * adds option method -> $().plugin('option', {...}) + * @param {Function} PluginClass - constructor class + */ +function addOptionMethod( PluginClass ) { + // don't overwrite original option method + if ( PluginClass.prototype.option ) { + return; + } + + // option setter + PluginClass.prototype.option = function( opts ) { + // bail out if not an object + if ( !$.isPlainObject( opts ) ){ + return; + } + this.options = $.extend( true, this.options, opts ); + }; +} + +// -------------------------- plugin bridge -------------------------- // + +// helper function for logging errors +// $.error breaks jQuery chaining +var logError = typeof console === 'undefined' ? noop : + function( message ) { + console.error( message ); + }; + +/** + * jQuery plugin bridge, access methods like $elem.plugin('method') + * @param {String} namespace - plugin name + * @param {Function} PluginClass - constructor class + */ +function bridge( namespace, PluginClass ) { + // add to jQuery fn namespace + $.fn[ namespace ] = function( options ) { + if ( typeof options === 'string' ) { + // call plugin method when first argument is a string + // get arguments for method + var args = slice.call( arguments, 1 ); + + for ( var i=0, len = this.length; i < len; i++ ) { + var elem = this[i]; + var instance = $.data( elem, namespace ); + if ( !instance ) { + logError( "cannot call methods on " + namespace + " prior to initialization; " + + "attempted to call '" + options + "'" ); + continue; + } + if ( !$.isFunction( instance[options] ) || options.charAt(0) === '_' ) { + logError( "no such method '" + options + "' for " + namespace + " instance" ); + continue; + } + + // trigger method with arguments + var returnValue = instance[ options ].apply( instance, args ); + + // break look and return first value if provided + if ( returnValue !== undefined ) { + return returnValue; + } + } + // return this if no return value + return this; + } else { + return this.each( function() { + var instance = $.data( this, namespace ); + if ( instance ) { + // apply options & init + instance.option( options ); + instance._init(); + } else { + // initialize new instance + instance = new PluginClass( this, options ); + $.data( this, namespace, instance ); + } + }); + } + }; + +} + +// -------------------------- bridget -------------------------- // + +/** + * converts a Prototypical class into a proper jQuery plugin + * the class must have a ._init method + * @param {String} namespace - plugin name, used in $().pluginName + * @param {Function} PluginClass - constructor class + */ +$.bridget = function( namespace, PluginClass ) { + addOptionMethod( PluginClass ); + bridge( namespace, PluginClass ); +}; + +return $.bridget; + +} + +// transport +if ( typeof define === 'function' && define.amd ) { + // AMD + define( 'jquery-bridget/jquery.bridget',[ 'jquery' ], defineBridget ); +} else if ( typeof exports === 'object' ) { + defineBridget( require('jquery') ); +} else { + // get jquery from browser global + defineBridget( window.jQuery ); +} + +})( window ); + +/*! + * classie v1.0.1 + * class helper functions + * from bonzo https://github.com/ded/bonzo + * MIT license + * + * classie.has( elem, 'my-class' ) -> true/false + * classie.add( elem, 'my-new-class' ) + * classie.remove( elem, 'my-unwanted-class' ) + * classie.toggle( elem, 'my-class' ) + */ + +/*jshint browser: true, strict: true, undef: true, unused: true */ +/*global define: false, module: false */ + +( function( window ) { + + + +// class helper functions from bonzo https://github.com/ded/bonzo + +function classReg( className ) { + return new RegExp("(^|\\s+)" + className + "(\\s+|$)"); +} + +// classList support for class management +// altho to be fair, the api sucks because it won't accept multiple classes at once +var hasClass, addClass, removeClass; + +if ( 'classList' in document.documentElement ) { + hasClass = function( elem, c ) { + return elem.classList.contains( c ); + }; + addClass = function( elem, c ) { + elem.classList.add( c ); + }; + removeClass = function( elem, c ) { + elem.classList.remove( c ); + }; +} +else { + hasClass = function( elem, c ) { + return classReg( c ).test( elem.className ); + }; + addClass = function( elem, c ) { + if ( !hasClass( elem, c ) ) { + elem.className = elem.className + ' ' + c; + } + }; + removeClass = function( elem, c ) { + elem.className = elem.className.replace( classReg( c ), ' ' ); + }; +} + +function toggleClass( elem, c ) { + var fn = hasClass( elem, c ) ? removeClass : addClass; + fn( elem, c ); +} + +var classie = { + // full names + hasClass: hasClass, + addClass: addClass, + removeClass: removeClass, + toggleClass: toggleClass, + // short names + has: hasClass, + add: addClass, + remove: removeClass, + toggle: toggleClass +}; + +// transport +if ( typeof define === 'function' && define.amd ) { + // AMD + define( 'classie/classie',classie ); +} else if ( typeof exports === 'object' ) { + // CommonJS + module.exports = classie; +} else { + // browser global + window.classie = classie; +} + +})( window ); + +/*! + * EventEmitter v4.2.11 - git.io/ee + * Unlicense - http://unlicense.org/ + * Oliver Caldwell - http://oli.me.uk/ + * @preserve + */ + +;(function () { + + + /** + * Class for managing events. + * Can be extended to provide event functionality in other classes. + * + * @class EventEmitter Manages event registering and emitting. + */ + function EventEmitter() {} + + // Shortcuts to improve speed and size + var proto = EventEmitter.prototype; + var exports = this; + var originalGlobalValue = exports.EventEmitter; + + /** + * Finds the index of the listener for the event in its storage array. + * + * @param {Function[]} listeners Array of listeners to search through. + * @param {Function} listener Method to look for. + * @return {Number} Index of the specified listener, -1 if not found + * @api private + */ + function indexOfListener(listeners, listener) { + var i = listeners.length; + while (i--) { + if (listeners[i].listener === listener) { + return i; + } + } + + return -1; + } + + /** + * Alias a method while keeping the context correct, to allow for overwriting of target method. + * + * @param {String} name The name of the target method. + * @return {Function} The aliased method + * @api private + */ + function alias(name) { + return function aliasClosure() { + return this[name].apply(this, arguments); + }; + } + + /** + * Returns the listener array for the specified event. + * Will initialise the event object and listener arrays if required. + * Will return an object if you use a regex search. The object contains keys for each matched event. So /ba[rz]/ might return an object containing bar and baz. But only if you have either defined them with defineEvent or added some listeners to them. + * Each property in the object response is an array of listener functions. + * + * @param {String|RegExp} evt Name of the event to return the listeners from. + * @return {Function[]|Object} All listener functions for the event. + */ + proto.getListeners = function getListeners(evt) { + var events = this._getEvents(); + var response; + var key; + + // Return a concatenated array of all matching events if + // the selector is a regular expression. + if (evt instanceof RegExp) { + response = {}; + for (key in events) { + if (events.hasOwnProperty(key) && evt.test(key)) { + response[key] = events[key]; + } + } + } + else { + response = events[evt] || (events[evt] = []); + } + + return response; + }; + + /** + * Takes a list of listener objects and flattens it into a list of listener functions. + * + * @param {Object[]} listeners Raw listener objects. + * @return {Function[]} Just the listener functions. + */ + proto.flattenListeners = function flattenListeners(listeners) { + var flatListeners = []; + var i; + + for (i = 0; i < listeners.length; i += 1) { + flatListeners.push(listeners[i].listener); + } + + return flatListeners; + }; + + /** + * Fetches the requested listeners via getListeners but will always return the results inside an object. This is mainly for internal use but others may find it useful. + * + * @param {String|RegExp} evt Name of the event to return the listeners from. + * @return {Object} All listener functions for an event in an object. + */ + proto.getListenersAsObject = function getListenersAsObject(evt) { + var listeners = this.getListeners(evt); + var response; + + if (listeners instanceof Array) { + response = {}; + response[evt] = listeners; + } + + return response || listeners; + }; + + /** + * Adds a listener function to the specified event. + * The listener will not be added if it is a duplicate. + * If the listener returns true then it will be removed after it is called. + * If you pass a regular expression as the event name then the listener will be added to all events that match it. + * + * @param {String|RegExp} evt Name of the event to attach the listener to. + * @param {Function} listener Method to be called when the event is emitted. If the function returns true then it will be removed after calling. + * @return {Object} Current instance of EventEmitter for chaining. + */ + proto.addListener = function addListener(evt, listener) { + var listeners = this.getListenersAsObject(evt); + var listenerIsWrapped = typeof listener === 'object'; + var key; + + for (key in listeners) { + if (listeners.hasOwnProperty(key) && indexOfListener(listeners[key], listener) === -1) { + listeners[key].push(listenerIsWrapped ? listener : { + listener: listener, + once: false + }); + } + } + + return this; + }; + + /** + * Alias of addListener + */ + proto.on = alias('addListener'); + + /** + * Semi-alias of addListener. It will add a listener that will be + * automatically removed after its first execution. + * + * @param {String|RegExp} evt Name of the event to attach the listener to. + * @param {Function} listener Method to be called when the event is emitted. If the function returns true then it will be removed after calling. + * @return {Object} Current instance of EventEmitter for chaining. + */ + proto.addOnceListener = function addOnceListener(evt, listener) { + return this.addListener(evt, { + listener: listener, + once: true + }); + }; + + /** + * Alias of addOnceListener. + */ + proto.once = alias('addOnceListener'); + + /** + * Defines an event name. This is required if you want to use a regex to add a listener to multiple events at once. If you don't do this then how do you expect it to know what event to add to? Should it just add to every possible match for a regex? No. That is scary and bad. + * You need to tell it what event names should be matched by a regex. + * + * @param {String} evt Name of the event to create. + * @return {Object} Current instance of EventEmitter for chaining. + */ + proto.defineEvent = function defineEvent(evt) { + this.getListeners(evt); + return this; + }; + + /** + * Uses defineEvent to define multiple events. + * + * @param {String[]} evts An array of event names to define. + * @return {Object} Current instance of EventEmitter for chaining. + */ + proto.defineEvents = function defineEvents(evts) { + for (var i = 0; i < evts.length; i += 1) { + this.defineEvent(evts[i]); + } + return this; + }; + + /** + * Removes a listener function from the specified event. + * When passed a regular expression as the event name, it will remove the listener from all events that match it. + * + * @param {String|RegExp} evt Name of the event to remove the listener from. + * @param {Function} listener Method to remove from the event. + * @return {Object} Current instance of EventEmitter for chaining. + */ + proto.removeListener = function removeListener(evt, listener) { + var listeners = this.getListenersAsObject(evt); + var index; + var key; + + for (key in listeners) { + if (listeners.hasOwnProperty(key)) { + index = indexOfListener(listeners[key], listener); + + if (index !== -1) { + listeners[key].splice(index, 1); + } + } + } + + return this; + }; + + /** + * Alias of removeListener + */ + proto.off = alias('removeListener'); + + /** + * Adds listeners in bulk using the manipulateListeners method. + * If you pass an object as the second argument you can add to multiple events at once. The object should contain key value pairs of events and listeners or listener arrays. You can also pass it an event name and an array of listeners to be added. + * You can also pass it a regular expression to add the array of listeners to all events that match it. + * Yeah, this function does quite a bit. That's probably a bad thing. + * + * @param {String|Object|RegExp} evt An event name if you will pass an array of listeners next. An object if you wish to add to multiple events at once. + * @param {Function[]} [listeners] An optional array of listener functions to add. + * @return {Object} Current instance of EventEmitter for chaining. + */ + proto.addListeners = function addListeners(evt, listeners) { + // Pass through to manipulateListeners + return this.manipulateListeners(false, evt, listeners); + }; + + /** + * Removes listeners in bulk using the manipulateListeners method. + * If you pass an object as the second argument you can remove from multiple events at once. The object should contain key value pairs of events and listeners or listener arrays. + * You can also pass it an event name and an array of listeners to be removed. + * You can also pass it a regular expression to remove the listeners from all events that match it. + * + * @param {String|Object|RegExp} evt An event name if you will pass an array of listeners next. An object if you wish to remove from multiple events at once. + * @param {Function[]} [listeners] An optional array of listener functions to remove. + * @return {Object} Current instance of EventEmitter for chaining. + */ + proto.removeListeners = function removeListeners(evt, listeners) { + // Pass through to manipulateListeners + return this.manipulateListeners(true, evt, listeners); + }; + + /** + * Edits listeners in bulk. The addListeners and removeListeners methods both use this to do their job. You should really use those instead, this is a little lower level. + * The first argument will determine if the listeners are removed (true) or added (false). + * If you pass an object as the second argument you can add/remove from multiple events at once. The object should contain key value pairs of events and listeners or listener arrays. + * You can also pass it an event name and an array of listeners to be added/removed. + * You can also pass it a regular expression to manipulate the listeners of all events that match it. + * + * @param {Boolean} remove True if you want to remove listeners, false if you want to add. + * @param {String|Object|RegExp} evt An event name if you will pass an array of listeners next. An object if you wish to add/remove from multiple events at once. + * @param {Function[]} [listeners] An optional array of listener functions to add/remove. + * @return {Object} Current instance of EventEmitter for chaining. + */ + proto.manipulateListeners = function manipulateListeners(remove, evt, listeners) { + var i; + var value; + var single = remove ? this.removeListener : this.addListener; + var multiple = remove ? this.removeListeners : this.addListeners; + + // If evt is an object then pass each of its properties to this method + if (typeof evt === 'object' && !(evt instanceof RegExp)) { + for (i in evt) { + if (evt.hasOwnProperty(i) && (value = evt[i])) { + // Pass the single listener straight through to the singular method + if (typeof value === 'function') { + single.call(this, i, value); + } + else { + // Otherwise pass back to the multiple function + multiple.call(this, i, value); + } + } + } + } + else { + // So evt must be a string + // And listeners must be an array of listeners + // Loop over it and pass each one to the multiple method + i = listeners.length; + while (i--) { + single.call(this, evt, listeners[i]); + } + } + + return this; + }; + + /** + * Removes all listeners from a specified event. + * If you do not specify an event then all listeners will be removed. + * That means every event will be emptied. + * You can also pass a regex to remove all events that match it. + * + * @param {String|RegExp} [evt] Optional name of the event to remove all listeners for. Will remove from every event if not passed. + * @return {Object} Current instance of EventEmitter for chaining. + */ + proto.removeEvent = function removeEvent(evt) { + var type = typeof evt; + var events = this._getEvents(); + var key; + + // Remove different things depending on the state of evt + if (type === 'string') { + // Remove all listeners for the specified event + delete events[evt]; + } + else if (evt instanceof RegExp) { + // Remove all events matching the regex. + for (key in events) { + if (events.hasOwnProperty(key) && evt.test(key)) { + delete events[key]; + } + } + } + else { + // Remove all listeners in all events + delete this._events; + } + + return this; + }; + + /** + * Alias of removeEvent. + * + * Added to mirror the node API. + */ + proto.removeAllListeners = alias('removeEvent'); + + /** + * Emits an event of your choice. + * When emitted, every listener attached to that event will be executed. + * If you pass the optional argument array then those arguments will be passed to every listener upon execution. + * Because it uses `apply`, your array of arguments will be passed as if you wrote them out separately. + * So they will not arrive within the array on the other side, they will be separate. + * You can also pass a regular expression to emit to all events that match it. + * + * @param {String|RegExp} evt Name of the event to emit and execute listeners for. + * @param {Array} [args] Optional array of arguments to be passed to each listener. + * @return {Object} Current instance of EventEmitter for chaining. + */ + proto.emitEvent = function emitEvent(evt, args) { + var listeners = this.getListenersAsObject(evt); + var listener; + var i; + var key; + var response; + + for (key in listeners) { + if (listeners.hasOwnProperty(key)) { + i = listeners[key].length; + + while (i--) { + // If the listener returns true then it shall be removed from the event + // The function is executed either with a basic call or an apply if there is an args array + listener = listeners[key][i]; + + if (listener.once === true) { + this.removeListener(evt, listener.listener); + } + + response = listener.listener.apply(this, args || []); + + if (response === this._getOnceReturnValue()) { + this.removeListener(evt, listener.listener); + } + } + } + } + + return this; + }; + + /** + * Alias of emitEvent + */ + proto.trigger = alias('emitEvent'); + + /** + * Subtly different from emitEvent in that it will pass its arguments on to the listeners, as opposed to taking a single array of arguments to pass on. + * As with emitEvent, you can pass a regex in place of the event name to emit to all events that match it. + * + * @param {String|RegExp} evt Name of the event to emit and execute listeners for. + * @param {...*} Optional additional arguments to be passed to each listener. + * @return {Object} Current instance of EventEmitter for chaining. + */ + proto.emit = function emit(evt) { + var args = Array.prototype.slice.call(arguments, 1); + return this.emitEvent(evt, args); + }; + + /** + * Sets the current value to check against when executing listeners. If a + * listeners return value matches the one set here then it will be removed + * after execution. This value defaults to true. + * + * @param {*} value The new value to check for when executing listeners. + * @return {Object} Current instance of EventEmitter for chaining. + */ + proto.setOnceReturnValue = function setOnceReturnValue(value) { + this._onceReturnValue = value; + return this; + }; + + /** + * Fetches the current value to check against when executing listeners. If + * the listeners return value matches this one then it should be removed + * automatically. It will return true by default. + * + * @return {*|Boolean} The current value to check for or the default, true. + * @api private + */ + proto._getOnceReturnValue = function _getOnceReturnValue() { + if (this.hasOwnProperty('_onceReturnValue')) { + return this._onceReturnValue; + } + else { + return true; + } + }; + + /** + * Fetches the events object and creates one if required. + * + * @return {Object} The events storage object. + * @api private + */ + proto._getEvents = function _getEvents() { + return this._events || (this._events = {}); + }; + + /** + * Reverts the global {@link EventEmitter} to its previous value and returns a reference to this version. + * + * @return {Function} Non conflicting EventEmitter class. + */ + EventEmitter.noConflict = function noConflict() { + exports.EventEmitter = originalGlobalValue; + return EventEmitter; + }; + + // Expose the class either via AMD, CommonJS or the global object + if (typeof define === 'function' && define.amd) { + define('eventEmitter/EventEmitter',[],function () { + return EventEmitter; + }); + } + else if (typeof module === 'object' && module.exports){ + module.exports = EventEmitter; + } + else { + exports.EventEmitter = EventEmitter; + } +}.call(this)); + +/*! + * eventie v1.0.6 + * event binding helper + * eventie.bind( elem, 'click', myFn ) + * eventie.unbind( elem, 'click', myFn ) + * MIT license + */ + +/*jshint browser: true, undef: true, unused: true */ +/*global define: false, module: false */ + +( function( window ) { + + + +var docElem = document.documentElement; + +var bind = function() {}; + +function getIEEvent( obj ) { + var event = window.event; + // add event.target + event.target = event.target || event.srcElement || obj; + return event; +} + +if ( docElem.addEventListener ) { + bind = function( obj, type, fn ) { + obj.addEventListener( type, fn, false ); + }; +} else if ( docElem.attachEvent ) { + bind = function( obj, type, fn ) { + obj[ type + fn ] = fn.handleEvent ? + function() { + var event = getIEEvent( obj ); + fn.handleEvent.call( fn, event ); + } : + function() { + var event = getIEEvent( obj ); + fn.call( obj, event ); + }; + obj.attachEvent( "on" + type, obj[ type + fn ] ); + }; +} + +var unbind = function() {}; + +if ( docElem.removeEventListener ) { + unbind = function( obj, type, fn ) { + obj.removeEventListener( type, fn, false ); + }; +} else if ( docElem.detachEvent ) { + unbind = function( obj, type, fn ) { + obj.detachEvent( "on" + type, obj[ type + fn ] ); + try { + delete obj[ type + fn ]; + } catch ( err ) { + // can't delete window object properties + obj[ type + fn ] = undefined; + } + }; +} + +var eventie = { + bind: bind, + unbind: unbind +}; + +// ----- module definition ----- // + +if ( typeof define === 'function' && define.amd ) { + // AMD + define( 'eventie/eventie',eventie ); +} else if ( typeof exports === 'object' ) { + // CommonJS + module.exports = eventie; +} else { + // browser global + window.eventie = eventie; +} + +})( window ); + +/*! + * getStyleProperty v1.0.4 + * original by kangax + * http://perfectionkills.com/feature-testing-css-properties/ + * MIT license + */ + +/*jshint browser: true, strict: true, undef: true */ +/*global define: false, exports: false, module: false */ + +( function( window ) { + + + +var prefixes = 'Webkit Moz ms Ms O'.split(' '); +var docElemStyle = document.documentElement.style; + +function getStyleProperty( propName ) { + if ( !propName ) { + return; + } + + // test standard property first + if ( typeof docElemStyle[ propName ] === 'string' ) { + return propName; + } + + // capitalize + propName = propName.charAt(0).toUpperCase() + propName.slice(1); + + // test vendor specific properties + var prefixed; + for ( var i=0, len = prefixes.length; i < len; i++ ) { + prefixed = prefixes[i] + propName; + if ( typeof docElemStyle[ prefixed ] === 'string' ) { + return prefixed; + } + } +} + +// transport +if ( typeof define === 'function' && define.amd ) { + // AMD + define( 'get-style-property/get-style-property',[],function() { + return getStyleProperty; + }); +} else if ( typeof exports === 'object' ) { + // CommonJS for Component + module.exports = getStyleProperty; +} else { + // browser global + window.getStyleProperty = getStyleProperty; +} + +})( window ); + +/*! + * getSize v1.2.2 + * measure size of elements + * MIT license + */ + +/*jshint browser: true, strict: true, undef: true, unused: true */ +/*global define: false, exports: false, require: false, module: false, console: false */ + +( function( window, undefined ) { + + + +// -------------------------- helpers -------------------------- // + +// get a number from a string, not a percentage +function getStyleSize( value ) { + var num = parseFloat( value ); + // not a percent like '100%', and a number + var isValid = value.indexOf('%') === -1 && !isNaN( num ); + return isValid && num; +} + +function noop() {} + +var logError = typeof console === 'undefined' ? noop : + function( message ) { + console.error( message ); + }; + +// -------------------------- measurements -------------------------- // + +var measurements = [ + 'paddingLeft', + 'paddingRight', + 'paddingTop', + 'paddingBottom', + 'marginLeft', + 'marginRight', + 'marginTop', + 'marginBottom', + 'borderLeftWidth', + 'borderRightWidth', + 'borderTopWidth', + 'borderBottomWidth' +]; + +function getZeroSize() { + var size = { + width: 0, + height: 0, + innerWidth: 0, + innerHeight: 0, + outerWidth: 0, + outerHeight: 0 + }; + for ( var i=0, len = measurements.length; i < len; i++ ) { + var measurement = measurements[i]; + size[ measurement ] = 0; + } + return size; +} + + + +function defineGetSize( getStyleProperty ) { + +// -------------------------- setup -------------------------- // + +var isSetup = false; + +var getStyle, boxSizingProp, isBoxSizeOuter; + +/** + * setup vars and functions + * do it on initial getSize(), rather than on script load + * For Firefox bug https://bugzilla.mozilla.org/show_bug.cgi?id=548397 + */ +function setup() { + // setup once + if ( isSetup ) { + return; + } + isSetup = true; + + var getComputedStyle = window.getComputedStyle; + getStyle = ( function() { + var getStyleFn = getComputedStyle ? + function( elem ) { + return getComputedStyle( elem, null ); + } : + function( elem ) { + return elem.currentStyle; + }; + + return function getStyle( elem ) { + var style = getStyleFn( elem ); + if ( !style ) { + logError( 'Style returned ' + style + + '. Are you running this code in a hidden iframe on Firefox? ' + + 'See http://bit.ly/getsizebug1' ); + } + return style; + }; + })(); + + // -------------------------- box sizing -------------------------- // + + boxSizingProp = getStyleProperty('boxSizing'); + + /** + * WebKit measures the outer-width on style.width on border-box elems + * IE & Firefox measures the inner-width + */ + if ( boxSizingProp ) { + var div = document.createElement('div'); + div.style.width = '200px'; + div.style.padding = '1px 2px 3px 4px'; + div.style.borderStyle = 'solid'; + div.style.borderWidth = '1px 2px 3px 4px'; + div.style[ boxSizingProp ] = 'border-box'; + + var body = document.body || document.documentElement; + body.appendChild( div ); + var style = getStyle( div ); + + isBoxSizeOuter = getStyleSize( style.width ) === 200; + body.removeChild( div ); + } + +} + +// -------------------------- getSize -------------------------- // + +function getSize( elem ) { + setup(); + + // use querySeletor if elem is string + if ( typeof elem === 'string' ) { + elem = document.querySelector( elem ); + } + + // do not proceed on non-objects + if ( !elem || typeof elem !== 'object' || !elem.nodeType ) { + return; + } + + var style = getStyle( elem ); + + // if hidden, everything is 0 + if ( style.display === 'none' ) { + return getZeroSize(); + } + + var size = {}; + size.width = elem.offsetWidth; + size.height = elem.offsetHeight; + + var isBorderBox = size.isBorderBox = !!( boxSizingProp && + style[ boxSizingProp ] && style[ boxSizingProp ] === 'border-box' ); + + // get all measurements + for ( var i=0, len = measurements.length; i < len; i++ ) { + var measurement = measurements[i]; + var value = style[ measurement ]; + value = mungeNonPixel( elem, value ); + var num = parseFloat( value ); + // any 'auto', 'medium' value will be 0 + size[ measurement ] = !isNaN( num ) ? num : 0; + } + + var paddingWidth = size.paddingLeft + size.paddingRight; + var paddingHeight = size.paddingTop + size.paddingBottom; + var marginWidth = size.marginLeft + size.marginRight; + var marginHeight = size.marginTop + size.marginBottom; + var borderWidth = size.borderLeftWidth + size.borderRightWidth; + var borderHeight = size.borderTopWidth + size.borderBottomWidth; + + var isBorderBoxSizeOuter = isBorderBox && isBoxSizeOuter; + + // overwrite width and height if we can get it from style + var styleWidth = getStyleSize( style.width ); + if ( styleWidth !== false ) { + size.width = styleWidth + + // add padding and border unless it's already including it + ( isBorderBoxSizeOuter ? 0 : paddingWidth + borderWidth ); + } + + var styleHeight = getStyleSize( style.height ); + if ( styleHeight !== false ) { + size.height = styleHeight + + // add padding and border unless it's already including it + ( isBorderBoxSizeOuter ? 0 : paddingHeight + borderHeight ); + } + + size.innerWidth = size.width - ( paddingWidth + borderWidth ); + size.innerHeight = size.height - ( paddingHeight + borderHeight ); + + size.outerWidth = size.width + marginWidth; + size.outerHeight = size.height + marginHeight; + + return size; +} + +// IE8 returns percent values, not pixels +// taken from jQuery's curCSS +function mungeNonPixel( elem, value ) { + // IE8 and has percent value + if ( window.getComputedStyle || value.indexOf('%') === -1 ) { + return value; + } + var style = elem.style; + // Remember the original values + var left = style.left; + var rs = elem.runtimeStyle; + var rsLeft = rs && rs.left; + + // Put in the new values to get a computed value out + if ( rsLeft ) { + rs.left = elem.currentStyle.left; + } + style.left = value; + value = style.pixelLeft; + + // Revert the changed values + style.left = left; + if ( rsLeft ) { + rs.left = rsLeft; + } + + return value; +} + +return getSize; + +} + +// transport +if ( typeof define === 'function' && define.amd ) { + // AMD for RequireJS + define( 'get-size/get-size',[ 'get-style-property/get-style-property' ], defineGetSize ); +} else if ( typeof exports === 'object' ) { + // CommonJS for Component + module.exports = defineGetSize( require('desandro-get-style-property') ); +} else { + // browser global + window.getSize = defineGetSize( window.getStyleProperty ); +} + +})( window ); + +/*! + * docReady v1.0.4 + * Cross browser DOMContentLoaded event emitter + * MIT license + */ + +/*jshint browser: true, strict: true, undef: true, unused: true*/ +/*global define: false, require: false, module: false */ + +( function( window ) { + + + +var document = window.document; +// collection of functions to be triggered on ready +var queue = []; + +function docReady( fn ) { + // throw out non-functions + if ( typeof fn !== 'function' ) { + return; + } + + if ( docReady.isReady ) { + // ready now, hit it + fn(); + } else { + // queue function when ready + queue.push( fn ); + } +} + +docReady.isReady = false; + +// triggered on various doc ready events +function onReady( event ) { + // bail if already triggered or IE8 document is not ready just yet + var isIE8NotReady = event.type === 'readystatechange' && document.readyState !== 'complete'; + if ( docReady.isReady || isIE8NotReady ) { + return; + } + + trigger(); +} + +function trigger() { + docReady.isReady = true; + // process queue + for ( var i=0, len = queue.length; i < len; i++ ) { + var fn = queue[i]; + fn(); + } +} + +function defineDocReady( eventie ) { + // trigger ready if page is ready + if ( document.readyState === 'complete' ) { + trigger(); + } else { + // listen for events + eventie.bind( document, 'DOMContentLoaded', onReady ); + eventie.bind( document, 'readystatechange', onReady ); + eventie.bind( window, 'load', onReady ); + } + + return docReady; +} + +// transport +if ( typeof define === 'function' && define.amd ) { + // AMD + define( 'doc-ready/doc-ready',[ 'eventie/eventie' ], defineDocReady ); +} else if ( typeof exports === 'object' ) { + module.exports = defineDocReady( require('eventie') ); +} else { + // browser global + window.docReady = defineDocReady( window.eventie ); +} + +})( window ); + +/** + * matchesSelector v1.0.3 + * matchesSelector( element, '.selector' ) + * MIT license + */ + +/*jshint browser: true, strict: true, undef: true, unused: true */ +/*global define: false, module: false */ + +( function( ElemProto ) { + + + + var matchesMethod = ( function() { + // check for the standard method name first + if ( ElemProto.matches ) { + return 'matches'; + } + // check un-prefixed + if ( ElemProto.matchesSelector ) { + return 'matchesSelector'; + } + // check vendor prefixes + var prefixes = [ 'webkit', 'moz', 'ms', 'o' ]; + + for ( var i=0, len = prefixes.length; i < len; i++ ) { + var prefix = prefixes[i]; + var method = prefix + 'MatchesSelector'; + if ( ElemProto[ method ] ) { + return method; + } + } + })(); + + // ----- match ----- // + + function match( elem, selector ) { + return elem[ matchesMethod ]( selector ); + } + + // ----- appendToFragment ----- // + + function checkParent( elem ) { + // not needed if already has parent + if ( elem.parentNode ) { + return; + } + var fragment = document.createDocumentFragment(); + fragment.appendChild( elem ); + } + + // ----- query ----- // + + // fall back to using QSA + // thx @jonathantneal https://gist.github.com/3062955 + function query( elem, selector ) { + // append to fragment if no parent + checkParent( elem ); + + // match elem with all selected elems of parent + var elems = elem.parentNode.querySelectorAll( selector ); + for ( var i=0, len = elems.length; i < len; i++ ) { + // return true if match + if ( elems[i] === elem ) { + return true; + } + } + // otherwise return false + return false; + } + + // ----- matchChild ----- // + + function matchChild( elem, selector ) { + checkParent( elem ); + return match( elem, selector ); + } + + // ----- matchesSelector ----- // + + var matchesSelector; + + if ( matchesMethod ) { + // IE9 supports matchesSelector, but doesn't work on orphaned elems + // check for that + var div = document.createElement('div'); + var supportsOrphans = match( div, 'div' ); + matchesSelector = supportsOrphans ? match : matchChild; + } else { + matchesSelector = query; + } + + // transport + if ( typeof define === 'function' && define.amd ) { + // AMD + define( 'matches-selector/matches-selector',[],function() { + return matchesSelector; + }); + } else if ( typeof exports === 'object' ) { + module.exports = matchesSelector; + } + else { + // browser global + window.matchesSelector = matchesSelector; + } + +})( Element.prototype ); + +/** + * Fizzy UI utils v1.0.1 + * MIT license + */ + +/*jshint browser: true, undef: true, unused: true, strict: true */ + +( function( window, factory ) { + /*global define: false, module: false, require: false */ + + // universal module definition + + if ( typeof define == 'function' && define.amd ) { + // AMD + define( 'fizzy-ui-utils/utils',[ + 'doc-ready/doc-ready', + 'matches-selector/matches-selector' + ], function( docReady, matchesSelector ) { + return factory( window, docReady, matchesSelector ); + }); + } else if ( typeof exports == 'object' ) { + // CommonJS + module.exports = factory( + window, + require('doc-ready'), + require('desandro-matches-selector') + ); + } else { + // browser global + window.fizzyUIUtils = factory( + window, + window.docReady, + window.matchesSelector + ); + } + +}( window, function factory( window, docReady, matchesSelector ) { + + + +var utils = {}; + +// ----- extend ----- // + +// extends objects +utils.extend = function( a, b ) { + for ( var prop in b ) { + a[ prop ] = b[ prop ]; + } + return a; +}; + +// ----- modulo ----- // + +utils.modulo = function( num, div ) { + return ( ( num % div ) + div ) % div; +}; + +// ----- isArray ----- // + +var objToString = Object.prototype.toString; +utils.isArray = function( obj ) { + return objToString.call( obj ) == '[object Array]'; +}; + +// ----- makeArray ----- // + +// turn element or nodeList into an array +utils.makeArray = function( obj ) { + var ary = []; + if ( utils.isArray( obj ) ) { + // use object if already an array + ary = obj; + } else if ( obj && typeof obj.length == 'number' ) { + // convert nodeList to array + for ( var i=0, len = obj.length; i < len; i++ ) { + ary.push( obj[i] ); + } + } else { + // array of single index + ary.push( obj ); + } + return ary; +}; + +// ----- indexOf ----- // + +// index of helper cause IE8 +utils.indexOf = Array.prototype.indexOf ? function( ary, obj ) { + return ary.indexOf( obj ); + } : function( ary, obj ) { + for ( var i=0, len = ary.length; i < len; i++ ) { + if ( ary[i] === obj ) { + return i; + } + } + return -1; + }; + +// ----- removeFrom ----- // + +utils.removeFrom = function( ary, obj ) { + var index = utils.indexOf( ary, obj ); + if ( index != -1 ) { + ary.splice( index, 1 ); + } +}; + +// ----- isElement ----- // + +// http://stackoverflow.com/a/384380/182183 +utils.isElement = ( typeof HTMLElement == 'function' || typeof HTMLElement == 'object' ) ? + function isElementDOM2( obj ) { + return obj instanceof HTMLElement; + } : + function isElementQuirky( obj ) { + return obj && typeof obj == 'object' && + obj.nodeType == 1 && typeof obj.nodeName == 'string'; + }; + +// ----- setText ----- // + +utils.setText = ( function() { + var setTextProperty; + function setText( elem, text ) { + // only check setTextProperty once + setTextProperty = setTextProperty || ( document.documentElement.textContent !== undefined ? 'textContent' : 'innerText' ); + elem[ setTextProperty ] = text; + } + return setText; +})(); + +// ----- getParent ----- // + +utils.getParent = function( elem, selector ) { + while ( elem != document.body ) { + elem = elem.parentNode; + if ( matchesSelector( elem, selector ) ) { + return elem; + } + } +}; + +// ----- getQueryElement ----- // + +// use element as selector string +utils.getQueryElement = function( elem ) { + if ( typeof elem == 'string' ) { + return document.querySelector( elem ); + } + return elem; +}; + +// ----- handleEvent ----- // + +// enable .ontype to trigger from .addEventListener( elem, 'type' ) +utils.handleEvent = function( event ) { + var method = 'on' + event.type; + if ( this[ method ] ) { + this[ method ]( event ); + } +}; + +// ----- filterFindElements ----- // + +utils.filterFindElements = function( elems, selector ) { + // make array of elems + elems = utils.makeArray( elems ); + var ffElems = []; + + for ( var i=0, len = elems.length; i < len; i++ ) { + var elem = elems[i]; + // check that elem is an actual element + if ( !utils.isElement( elem ) ) { + continue; + } + // filter & find items if we have a selector + if ( selector ) { + // filter siblings + if ( matchesSelector( elem, selector ) ) { + ffElems.push( elem ); + } + // find children + var childElems = elem.querySelectorAll( selector ); + // concat childElems to filterFound array + for ( var j=0, jLen = childElems.length; j < jLen; j++ ) { + ffElems.push( childElems[j] ); + } + } else { + ffElems.push( elem ); + } + } + + return ffElems; +}; + +// ----- debounceMethod ----- // + +utils.debounceMethod = function( _class, methodName, threshold ) { + // original method + var method = _class.prototype[ methodName ]; + var timeoutName = methodName + 'Timeout'; + + _class.prototype[ methodName ] = function() { + var timeout = this[ timeoutName ]; + if ( timeout ) { + clearTimeout( timeout ); + } + var args = arguments; + + var _this = this; + this[ timeoutName ] = setTimeout( function() { + method.apply( _this, args ); + delete _this[ timeoutName ]; + }, threshold || 100 ); + }; +}; + +// ----- htmlInit ----- // + +// http://jamesroberts.name/blog/2010/02/22/string-functions-for-javascript-trim-to-camel-case-to-dashed-and-to-underscore/ +utils.toDashed = function( str ) { + return str.replace( /(.)([A-Z])/g, function( match, $1, $2 ) { + return $1 + '-' + $2; + }).toLowerCase(); +}; + +var console = window.console; +/** + * allow user to initialize classes via .js-namespace class + * htmlInit( Widget, 'widgetName' ) + * options are parsed from data-namespace-option attribute + */ +utils.htmlInit = function( WidgetClass, namespace ) { + docReady( function() { + var dashedNamespace = utils.toDashed( namespace ); + var elems = document.querySelectorAll( '.js-' + dashedNamespace ); + var dataAttr = 'data-' + dashedNamespace + '-options'; + + for ( var i=0, len = elems.length; i < len; i++ ) { + var elem = elems[i]; + var attr = elem.getAttribute( dataAttr ); + var options; + try { + options = attr && JSON.parse( attr ); + } catch ( error ) { + // log error, do not initialize + if ( console ) { + console.error( 'Error parsing ' + dataAttr + ' on ' + + elem.nodeName.toLowerCase() + ( elem.id ? '#' + elem.id : '' ) + ': ' + + error ); + } + continue; + } + // initialize + var instance = new WidgetClass( elem, options ); + // make available via $().data('layoutname') + var jQuery = window.jQuery; + if ( jQuery ) { + jQuery.data( elem, namespace, instance ); + } + } + }); +}; + +// ----- ----- // + +return utils; + +})); + +( function( window, factory ) { + + // universal module definition + + if ( typeof define == 'function' && define.amd ) { + // AMD + define( 'flickity/js/cell',[ + 'get-size/get-size' + ], function( getSize ) { + return factory( window, getSize ); + }); + } else if ( typeof exports == 'object' ) { + // CommonJS + module.exports = factory( + window, + require('get-size') + ); + } else { + // browser global + window.Flickity = window.Flickity || {}; + window.Flickity.Cell = factory( + window, + window.getSize + ); + } + +}( window, function factory( window, getSize ) { + + + +function Cell( elem, parent ) { + this.element = elem; + this.parent = parent; + + this.create(); +} + +var isIE8 = 'attachEvent' in window; + +Cell.prototype.create = function() { + this.element.style.position = 'absolute'; + // IE8 prevent child from changing focus http://stackoverflow.com/a/17525223/182183 + if ( isIE8 ) { + this.element.setAttribute( 'unselectable', 'on' ); + } + this.x = 0; + this.shift = 0; +}; + +Cell.prototype.destroy = function() { + // reset style + this.element.style.position = ''; + var side = this.parent.originSide; + this.element.style[ side ] = ''; +}; + +Cell.prototype.getSize = function() { + this.size = getSize( this.element ); +}; + +Cell.prototype.setPosition = function( x ) { + this.x = x; + this.setDefaultTarget(); + this.renderPosition( x ); +}; + +Cell.prototype.setDefaultTarget = function() { + var marginProperty = this.parent.originSide == 'left' ? 'marginLeft' : 'marginRight'; + this.target = this.x + this.size[ marginProperty ] + + this.size.width * this.parent.cellAlign; +}; + +Cell.prototype.renderPosition = function( x ) { + // render position of cell with in slider + var side = this.parent.originSide; + this.element.style[ side ] = this.parent.getPositionValue( x ); +}; + +/** + * @param {Integer} factor - 0, 1, or -1 +**/ +Cell.prototype.wrapShift = function( shift ) { + this.shift = shift; + this.renderPosition( this.x + this.parent.slideableWidth * shift ); +}; + +Cell.prototype.remove = function() { + this.element.parentNode.removeChild( this.element ); +}; + +return Cell; + +})); + +( function( window, factory ) { + + // universal module definition + + if ( typeof define == 'function' && define.amd ) { + // AMD + define( 'flickity/js/animate',[ + 'get-style-property/get-style-property', + 'fizzy-ui-utils/utils' + ], function( getStyleProperty, utils ) { + return factory( window, getStyleProperty, utils ); + }); + } else if ( typeof exports == 'object' ) { + // CommonJS + module.exports = factory( + window, + require('desandro-get-style-property'), + require('fizzy-ui-utils') + ); + } else { + // browser global + window.Flickity = window.Flickity || {}; + window.Flickity.animatePrototype = factory( + window, + window.getStyleProperty, + window.fizzyUIUtils + ); + } + +}( window, function factory( window, getStyleProperty, utils ) { + + + +// -------------------------- requestAnimationFrame -------------------------- // + +// https://gist.github.com/1866474 + +var lastTime = 0; +var prefixes = 'webkit moz ms o'.split(' '); +// get unprefixed rAF and cAF, if present +var requestAnimationFrame = window.requestAnimationFrame; +var cancelAnimationFrame = window.cancelAnimationFrame; +// loop through vendor prefixes and get prefixed rAF and cAF +var prefix; +for( var i = 0; i < prefixes.length; i++ ) { + if ( requestAnimationFrame && cancelAnimationFrame ) { + break; + } + prefix = prefixes[i]; + requestAnimationFrame = requestAnimationFrame || window[ prefix + 'RequestAnimationFrame' ]; + cancelAnimationFrame = cancelAnimationFrame || window[ prefix + 'CancelAnimationFrame' ] || + window[ prefix + 'CancelRequestAnimationFrame' ]; +} + +// fallback to setTimeout and clearTimeout if either request/cancel is not supported +if ( !requestAnimationFrame || !cancelAnimationFrame ) { + requestAnimationFrame = function( callback ) { + var currTime = new Date().getTime(); + var timeToCall = Math.max( 0, 16 - ( currTime - lastTime ) ); + var id = window.setTimeout( function() { + callback( currTime + timeToCall ); + }, timeToCall ); + lastTime = currTime + timeToCall; + return id; + }; + + cancelAnimationFrame = function( id ) { + window.clearTimeout( id ); + }; +} + +// -------------------------- animate -------------------------- // + +var proto = {}; + +proto.startAnimation = function() { + if ( this.isAnimating ) { + return; + } + + this.isAnimating = true; + this.restingFrames = 0; + this.animate(); +}; + +proto.animate = function() { + this.applySelectedAttraction(); + + var previousX = this.x; + + this.integratePhysics(); + this.positionSlider(); + this.settle( previousX ); + // animate next frame + if ( this.isAnimating ) { + var _this = this; + requestAnimationFrame( function animateFrame() { + _this.animate(); + }); + } + + /** / + // log animation frame rate + var now = new Date(); + if ( this.then ) { + console.log( ~~( 1000 / (now-this.then)) + 'fps' ) + } + this.then = now; + /**/ +}; + + +var transformProperty = getStyleProperty('transform'); +var is3d = !!getStyleProperty('perspective'); + +proto.positionSlider = function() { + var x = this.x; + // wrap position around + if ( this.options.wrapAround && this.cells.length > 1 ) { + x = utils.modulo( x, this.slideableWidth ); + x = x - this.slideableWidth; + this.shiftWrapCells( x ); + } + + x = x + this.cursorPosition; + + // reverse if right-to-left and using transform + x = this.options.rightToLeft && transformProperty ? -x : x; + + var value = this.getPositionValue( x ); + + if ( transformProperty ) { + // use 3D tranforms for hardware acceleration on iOS + // but use 2D when settled, for better font-rendering + this.slider.style[ transformProperty ] = is3d && this.isAnimating ? + 'translate3d(' + value + ',0,0)' : 'translateX(' + value + ')'; + } else { + this.slider.style[ this.originSide ] = value; + } +}; + +proto.positionSliderAtSelected = function() { + if ( !this.cells.length ) { + return; + } + var selectedCell = this.cells[ this.selectedIndex ]; + this.x = -selectedCell.target; + this.positionSlider(); +}; + +proto.getPositionValue = function( position ) { + if ( this.options.percentPosition ) { + // percent position, round to 2 digits, like 12.34% + return ( Math.round( ( position / this.size.innerWidth ) * 10000 ) * 0.01 )+ '%'; + } else { + // pixel positioning + return Math.round( position ) + 'px'; + } +}; + +proto.settle = function( previousX ) { + // keep track of frames where x hasn't moved + if ( !this.isPointerDown && Math.round( this.x * 100 ) == Math.round( previousX * 100 ) ) { + this.restingFrames++; + } + // stop animating if resting for 3 or more frames + if ( this.restingFrames > 2 ) { + this.isAnimating = false; + delete this.isFreeScrolling; + // render position with translateX when settled + if ( is3d ) { + this.positionSlider(); + } + this.dispatchEvent('settle'); + } +}; + +proto.shiftWrapCells = function( x ) { + // shift before cells + var beforeGap = this.cursorPosition + x; + this._shiftCells( this.beforeShiftCells, beforeGap, -1 ); + // shift after cells + var afterGap = this.size.innerWidth - ( x + this.slideableWidth + this.cursorPosition ); + this._shiftCells( this.afterShiftCells, afterGap, 1 ); +}; + +proto._shiftCells = function( cells, gap, shift ) { + for ( var i=0, len = cells.length; i < len; i++ ) { + var cell = cells[i]; + var cellShift = gap > 0 ? shift : 0; + cell.wrapShift( cellShift ); + gap -= cell.size.outerWidth; + } +}; + +proto._unshiftCells = function( cells ) { + if ( !cells || !cells.length ) { + return; + } + for ( var i=0, len = cells.length; i < len; i++ ) { + cells[i].wrapShift( 0 ); + } +}; + +// -------------------------- physics -------------------------- // + +proto.integratePhysics = function() { + this.velocity += this.accel; + this.x += this.velocity; + this.velocity *= this.getFrictionFactor(); + // reset acceleration + this.accel = 0; +}; + +proto.applyForce = function( force ) { + this.accel += force; +}; + +proto.getFrictionFactor = function() { + return 1 - this.options[ this.isFreeScrolling ? 'freeScrollFriction' : 'friction' ]; +}; + + +proto.getRestingPosition = function() { + // my thanks to Steven Wittens, who simplified this math greatly + return this.x + this.velocity / ( 1 - this.getFrictionFactor() ); +}; + + +proto.applySelectedAttraction = function() { + // do not attract if pointer down or no cells + var len = this.cells.length; + if ( this.isPointerDown || this.isFreeScrolling || !len ) { + return; + } + var cell = this.cells[ this.selectedIndex ]; + var wrap = this.options.wrapAround && len > 1 ? + this.slideableWidth * Math.floor( this.selectedIndex / len ) : 0; + var distance = ( cell.target + wrap ) * -1 - this.x; + var force = distance * this.options.selectedAttraction; + this.applyForce( force ); +}; + +return proto; + +})); + +/*! + * Flickity v1.0.1 + * Touch, responsive, flickable galleries + * + * Licensed GPLv3 for open source use + * or Flickity Commercial License for commercial use + * + * http://flickity.metafizzy.co + * Copyright 2015 Metafizzy + */ + +( function( window, factory ) { + + // universal module definition + + if ( typeof define == 'function' && define.amd ) { + // AMD + define( 'flickity/js/flickity',[ + 'classie/classie', + 'eventEmitter/EventEmitter', + 'eventie/eventie', + 'get-size/get-size', + 'fizzy-ui-utils/utils', + './cell', + './animate' + ], function( classie, EventEmitter, eventie, getSize, utils, Cell, animatePrototype ) { + return factory( window, classie, EventEmitter, eventie, getSize, utils, Cell, animatePrototype ); + }); + } else if ( typeof exports == 'object' ) { + // CommonJS + module.exports = factory( + window, + require('desandro-classie'), + require('wolfy87-eventemitter'), + require('eventie'), + require('get-size'), + require('fizzy-ui-utils'), + require('./cell'), + require('./animate') + ); + } else { + // browser global + var _Flickity = window.Flickity; + + window.Flickity = factory( + window, + window.classie, + window.EventEmitter, + window.eventie, + window.getSize, + window.fizzyUIUtils, + _Flickity.Cell, + _Flickity.animatePrototype + ); + } + +}( window, function factory( window, classie, EventEmitter, eventie, getSize, + utils, Cell, animatePrototype ) { + + + +// vars +var jQuery = window.jQuery; +var getComputedStyle = window.getComputedStyle; +var console = window.console; + +function moveElements( elems, toElem ) { + elems = utils.makeArray( elems ); + while ( elems.length ) { + toElem.appendChild( elems.shift() ); + } +} + +// -------------------------- Flickity -------------------------- // + +// globally unique identifiers +var GUID = 0; +// internal store of all Flickity intances +var instances = {}; + +function Flickity( element, options ) { + var queryElement = utils.getQueryElement( element ); + if ( !queryElement ) { + if ( console ) { + console.error( 'Bad element for Flickity: ' + ( queryElement || element ) ); + } + return; + } + this.element = queryElement; + // add jQuery + if ( jQuery ) { + this.$element = jQuery( this.element ); + } + // options + this.options = utils.extend( {}, this.constructor.defaults ); + this.option( options ); + + // kick things off + this._create(); +} + +Flickity.defaults = { + accessibility: true, + cellAlign: 'center', + // cellSelector: undefined, + // contain: false, + freeScrollFriction: 0.075, // friction when free-scrolling + friction: 0.28, // friction when selecting + // initialIndex: 0, + percentPosition: true, + resize: true, + selectedAttraction: 0.025, + setGallerySize: true + // watchCSS: false, + // wrapAround: false +}; + +// hash of methods triggered on _create() +Flickity.createMethods = []; + +// inherit EventEmitter +utils.extend( Flickity.prototype, EventEmitter.prototype ); + +Flickity.prototype._create = function() { + // add id for Flickity.data + var id = this.guid = ++GUID; + this.element.flickityGUID = id; // expando + instances[ id ] = this; // associate via id + // initial properties + this.selectedIndex = this.options.initialIndex || 0; + // how many frames slider has been in same position + this.restingFrames = 0; + // initial physics properties + this.x = 0; + this.velocity = 0; + this.accel = 0; + this.originSide = this.options.rightToLeft ? 'right' : 'left'; + // create viewport & slider + this.viewport = document.createElement('div'); + this.viewport.className = 'flickity-viewport'; + Flickity.setUnselectable( this.viewport ); + this._createSlider(); + + if ( this.options.resize || this.options.watchCSS ) { + eventie.bind( window, 'resize', this ); + this.isResizeBound = true; + } + + for ( var i=0, len = Flickity.createMethods.length; i < len; i++ ) { + var method = Flickity.createMethods[i]; + this[ method ](); + } + + if ( this.options.watchCSS ) { + this.watchCSS(); + } else { + this.activate(); + } + +}; + +/** + * set options + * @param {Object} opts + */ +Flickity.prototype.option = function( opts ) { + utils.extend( this.options, opts ); +}; + +Flickity.prototype.activate = function() { + if ( this.isActive ) { + return; + } + this.isActive = true; + classie.add( this.element, 'flickity-enabled' ); + if ( this.options.rightToLeft ) { + classie.add( this.element, 'flickity-rtl' ); + } + + // move initial cell elements so they can be loaded as cells + var cellElems = this._filterFindCellElements( this.element.children ); + moveElements( cellElems, this.slider ); + this.viewport.appendChild( this.slider ); + this.element.appendChild( this.viewport ); + + this.getSize(); + // get cells from children + this.reloadCells(); + + if ( this.options.accessibility ) { + // allow element to focusable + this.element.tabIndex = 0; + // listen for key presses + eventie.bind( this.element, 'keydown', this ); + } + + this.emit('activate'); + + this.positionSliderAtSelected(); + this.select( this.selectedIndex ); +}; + +// slider positions the cells +Flickity.prototype._createSlider = function() { + // slider element does all the positioning + var slider = document.createElement('div'); + slider.className = 'flickity-slider'; + slider.style[ this.originSide ] = 0; + this.slider = slider; +}; + +Flickity.prototype._filterFindCellElements = function( elems ) { + return utils.filterFindElements( elems, this.options.cellSelector ); +}; + +// goes through all children +Flickity.prototype.reloadCells = function() { + // collection of item elements + this.cells = this._makeCells( this.slider.children ); + this.positionCells(); + this._getWrapShiftCells(); + this.setGallerySize(); +}; + +/** + * turn elements into Flickity.Cells + * @param {Array or NodeList or HTMLElement} elems + * @returns {Array} items - collection of new Flickity Cells + */ +Flickity.prototype._makeCells = function( elems ) { + var cellElems = this._filterFindCellElements( elems ); + + // create new Flickity for collection + var cells = []; + for ( var i=0, len = cellElems.length; i < len; i++ ) { + var elem = cellElems[i]; + var cell = new Cell( elem, this ); + cells.push( cell ); + } + + return cells; +}; + +Flickity.prototype.getLastCell = function() { + return this.cells[ this.cells.length - 1 ]; +}; + +// positions all cells +Flickity.prototype.positionCells = function() { + // size all cells + this._sizeCells( this.cells ); + // position all cells + this._positionCells( 0 ); +}; + +/** + * position certain cells + * @param {Integer} index - which cell to start with + */ +Flickity.prototype._positionCells = function( index ) { + // also measure maxCellHeight + // start 0 if positioning all cells + this.maxCellHeight = index ? this.maxCellHeight || 0 : 0; + var cellX = 0; + // get cellX + if ( index > 0 ) { + var startCell = this.cells[ index - 1 ]; + cellX = startCell.x + startCell.size.outerWidth; + } + var cell; + for ( var len = this.cells.length, i=index; i < len; i++ ) { + cell = this.cells[i]; + cell.setPosition( cellX ); + cellX += cell.size.outerWidth; + this.maxCellHeight = Math.max( cell.size.outerHeight, this.maxCellHeight ); + } + // keep track of cellX for wrap-around + this.slideableWidth = cellX; + // contain cell target + this._containCells(); +}; + +/** + * cell.getSize() on multiple cells + * @param {Array} cells + */ +Flickity.prototype._sizeCells = function( cells ) { + for ( var i=0, len = cells.length; i < len; i++ ) { + var cell = cells[i]; + cell.getSize(); + } +}; + +// alias _init for jQuery plugin .flickity() +Flickity.prototype._init = +Flickity.prototype.reposition = function() { + this.positionCells(); + this.positionSliderAtSelected(); +}; + +Flickity.prototype.getSize = function() { + this.size = getSize( this.element ); + this.setCellAlign(); + this.cursorPosition = this.size.innerWidth * this.cellAlign; +}; + +var cellAlignShorthands = { + // cell align, then based on origin side + center: { + left: 0.5, + right: 0.5 + }, + left: { + left: 0, + right: 1 + }, + right: { + right: 0, + left: 1 + } +}; + +Flickity.prototype.setCellAlign = function() { + var shorthand = cellAlignShorthands[ this.options.cellAlign ]; + this.cellAlign = shorthand ? shorthand[ this.originSide ] : this.options.cellAlign; +}; + +Flickity.prototype.setGallerySize = function() { + if ( this.options.setGallerySize ) { + this.viewport.style.height = this.maxCellHeight + 'px'; + } +}; + +Flickity.prototype._getWrapShiftCells = function() { + // only for wrap-around + if ( !this.options.wrapAround ) { + return; + } + // unshift previous cells + this._unshiftCells( this.beforeShiftCells ); + this._unshiftCells( this.afterShiftCells ); + // get before cells + // initial gap + var gapX = this.cursorPosition; + var cellIndex = this.cells.length - 1; + this.beforeShiftCells = this._getGapCells( gapX, cellIndex, -1 ); + // get after cells + // ending gap between last cell and end of gallery viewport + gapX = this.size.innerWidth - this.cursorPosition; + // start cloning at first cell, working forwards + this.afterShiftCells = this._getGapCells( gapX, 0, 1 ); +}; + +Flickity.prototype._getGapCells = function( gapX, cellIndex, increment ) { + // keep adding cells until the cover the initial gap + var cells = []; + while ( gapX > 0 ) { + var cell = this.cells[ cellIndex ]; + if ( !cell ) { + break; + } + cells.push( cell ); + cellIndex += increment; + gapX -= cell.size.outerWidth; + } + return cells; +}; + +// ----- contain ----- // + +// contain cell targets so no excess sliding +Flickity.prototype._containCells = function() { + if ( !this.options.contain || this.options.wrapAround || !this.cells.length ) { + return; + } + var startMargin = this.options.rightToLeft ? 'marginRight' : 'marginLeft'; + var endMargin = this.options.rightToLeft ? 'marginLeft' : 'marginRight'; + var firstCellStartMargin = this.cells[0].size[ startMargin ]; + var lastCell = this.getLastCell(); + var contentWidth = this.slideableWidth - lastCell.size[ endMargin ]; + var endLimit = contentWidth - this.size.innerWidth * ( 1 - this.cellAlign ); + // content is less than gallery size + var isContentSmaller = contentWidth < this.size.innerWidth; + // contain each cell target + for ( var i=0, len = this.cells.length; i < len; i++ ) { + var cell = this.cells[i]; + // reset default target + cell.setDefaultTarget(); + if ( isContentSmaller ) { + // all cells fit inside gallery + cell.target = contentWidth * this.cellAlign; + } else { + // contain to bounds + cell.target = Math.max( cell.target, this.cursorPosition + firstCellStartMargin ); + cell.target = Math.min( cell.target, endLimit ); + } + } +}; + +// ----- ----- // + +/** + * emits events via eventEmitter and jQuery events + * @param {String} type - name of event + * @param {Event} event - original event + * @param {Array} args - extra arguments + */ +Flickity.prototype.dispatchEvent = function( type, event, args ) { + var emitArgs = [ event ].concat( args ); + this.emitEvent( type, emitArgs ); + + if ( jQuery && this.$element ) { + if ( event ) { + // create jQuery event + var $event = jQuery.Event( event ); + $event.type = type; + this.$element.trigger( $event, args ); + } else { + // just trigger with type if no event available + this.$element.trigger( type, args ); + } + } +}; + +// -------------------------- select -------------------------- // + +/** + * @param {Integer} index - index of the cell + * @param {Boolean} isWrap - will wrap-around to last/first if at the end + */ +Flickity.prototype.select = function( index, isWrap ) { + if ( !this.isActive ) { + return; + } + // wrap position so slider is within normal area + var len = this.cells.length; + if ( this.options.wrapAround && len > 1 ) { + if ( index < 0 ) { + this.x -= this.slideableWidth; + } else if ( index >= len ) { + this.x += this.slideableWidth; + } + } + + if ( this.options.wrapAround || isWrap ) { + index = utils.modulo( index, len ); + } + + if ( this.cells[ index ] ) { + this.selectedIndex = index; + this.setSelectedCell(); + this.startAnimation(); + this.dispatchEvent('cellSelect'); + } +}; + +Flickity.prototype.previous = function( isWrap ) { + this.select( this.selectedIndex - 1, isWrap ); +}; + +Flickity.prototype.next = function( isWrap ) { + this.select( this.selectedIndex + 1, isWrap ); +}; + +Flickity.prototype.setSelectedCell = function() { + this._removeSelectedCellClass(); + this.selectedCell = this.cells[ this.selectedIndex ]; + this.selectedElement = this.selectedCell.element; + classie.add( this.selectedElement, 'is-selected' ); +}; + +Flickity.prototype._removeSelectedCellClass = function() { + if ( this.selectedCell ) { + classie.remove( this.selectedCell.element, 'is-selected' ); + } +}; + +// -------------------------- get cells -------------------------- // + +/** + * get Flickity.Cell, given an Element + * @param {Element} elem + * @returns {Flickity.Cell} item + */ +Flickity.prototype.getCell = function( elem ) { + // loop through cells to get the one that matches + for ( var i=0, len = this.cells.length; i < len; i++ ) { + var cell = this.cells[i]; + if ( cell.element == elem ) { + return cell; + } + } +}; + +/** + * get collection of Flickity.Cells, given Elements + * @param {Element, Array, NodeList} elems + * @returns {Array} cells - Flickity.Cells + */ +Flickity.prototype.getCells = function( elems ) { + elems = utils.makeArray( elems ); + var cells = []; + for ( var i=0, len = elems.length; i < len; i++ ) { + var elem = elems[i]; + var cell = this.getCell( elem ); + if ( cell ) { + cells.push( cell ); + } + } + return cells; +}; + +/** + * get cell elements + * @returns {Array} cellElems + */ +Flickity.prototype.getCellElements = function() { + var cellElems = []; + for ( var i=0, len = this.cells.length; i < len; i++ ) { + cellElems.push( this.cells[i].element ); + } + return cellElems; +}; + +/** + * get parent cell from an element + * @param {Element} elem + * @returns {Flickit.Cell} cell + */ +Flickity.prototype.getParentCell = function( elem ) { + // first check if elem is cell + var cell = this.getCell( elem ); + if ( cell ) { + return cell; + } + // try to get parent cell elem + elem = utils.getParent( elem, '.flickity-slider > *' ); + return this.getCell( elem ); +}; + +// -------------------------- events -------------------------- // + +Flickity.prototype.uiChange = function() { + this.emit('uiChange'); +}; + +Flickity.prototype.childUIPointerDown = function( event ) { + this.emitEvent( 'childUIPointerDown', [ event ] ); +}; + +// ----- resize ----- // + +Flickity.prototype.onresize = function() { + this.watchCSS(); + this.resize(); +}; + +utils.debounceMethod( Flickity, 'onresize', 150 ); + +Flickity.prototype.resize = function() { + if ( !this.isActive ) { + return; + } + this.getSize(); + // wrap values + if ( this.options.wrapAround ) { + this.x = utils.modulo( this.x, this.slideableWidth ); + } + this.positionCells(); + this._getWrapShiftCells(); + this.setGallerySize(); + this.positionSliderAtSelected(); +}; + +var supportsConditionalCSS = Flickity.supportsConditionalCSS = ( function() { + var supports; + return function checkSupport() { + if ( supports !== undefined ) { + return supports; + } + if ( !getComputedStyle ) { + supports = false; + return; + } + // style body's :after and check that + var style = document.createElement('style'); + var cssText = document.createTextNode('body:after { content: "foo"; display: none; }'); + style.appendChild( cssText ); + document.head.appendChild( style ); + var afterContent = getComputedStyle( document.body, ':after' ).content; + // check if able to get :after content + supports = afterContent.indexOf('foo') != -1; + document.head.removeChild( style ); + return supports; + }; +})(); + +// watches the :after property, activates/deactivates +Flickity.prototype.watchCSS = function() { + var watchOption = this.options.watchCSS; + if ( !watchOption ) { + return; + } + var supports = supportsConditionalCSS(); + if ( !supports ) { + // activate if watch option is fallbackOn + var method = watchOption == 'fallbackOn' ? 'activate' : 'deactivate'; + this[ method ](); + return; + } + + var afterContent = getComputedStyle( this.element, ':after' ).content; + // activate if :after { content: 'flickity' } + if ( afterContent.indexOf('flickity') != -1 ) { + this.activate(); + } else { + this.deactivate(); + } +}; + +// ----- keydown ----- // + +// go previous/next if left/right keys pressed +Flickity.prototype.onkeydown = function( event ) { + // only work if element is in focus + if ( !this.options.accessibility || + ( document.activeElement && document.activeElement != this.element ) ) { + return; + } + + if ( event.keyCode == 37 ) { + // go left + var leftMethod = this.options.rightToLeft ? 'next' : 'previous'; + this.uiChange(); + this[ leftMethod ](); + } else if ( event.keyCode == 39 ) { + // go right + var rightMethod = this.options.rightToLeft ? 'previous' : 'next'; + this.uiChange(); + this[ rightMethod ](); + } +}; + +// -------------------------- destroy -------------------------- // + +// deactivate all Flickity functionality, but keep stuff available +Flickity.prototype.deactivate = function() { + if ( !this.isActive ) { + return; + } + classie.remove( this.element, 'flickity-enabled' ); + classie.remove( this.element, 'flickity-rtl' ); + // destroy cells + for ( var i=0, len = this.cells.length; i < len; i++ ) { + var cell = this.cells[i]; + cell.destroy(); + } + this._removeSelectedCellClass(); + this.element.removeChild( this.viewport ); + // move child elements back into element + moveElements( this.slider.children, this.element ); + if ( this.options.accessibility ) { + this.element.removeAttribute('tabIndex'); + eventie.unbind( this.element, 'keydown', this ); + } + // set flags + this.isActive = false; + this.emit('deactivate'); +}; + +Flickity.prototype.destroy = function() { + this.deactivate(); + if ( this.isResizeBound ) { + eventie.unbind( window, 'resize', this ); + } + this.emit('destroy'); + if ( jQuery && this.$element ) { + jQuery.removeData( this.element, 'flickity' ); + } + delete this.element.flickityGUID; + delete instances[ this.guid ]; +}; + +// -------------------------- prototype -------------------------- // + +utils.extend( Flickity.prototype, animatePrototype ); + +// -------------------------- extras -------------------------- // + +// quick check for IE8 +var isIE8 = 'attachEvent' in window; + +Flickity.setUnselectable = function( elem ) { + if ( !isIE8 ) { + return; + } + // IE8 prevent child from changing focus http://stackoverflow.com/a/17525223/182183 + elem.setAttribute( 'unselectable', 'on' ); +}; + +/** + * get Flickity instance from element + * @param {Element} elem + * @returns {Flickity} + */ +Flickity.data = function( elem ) { + elem = utils.getQueryElement( elem ); + var id = elem && elem.flickityGUID; + return id && instances[ id ]; +}; + +utils.htmlInit( Flickity, 'flickity' ); + +if ( jQuery && jQuery.bridget ) { + jQuery.bridget( 'flickity', Flickity ); +} + +Flickity.Cell = Cell; + +return Flickity; + +})); + +/*! + * Unipointer v1.1.0 + * base class for doing one thing with pointer event + * MIT license + */ + +/*jshint browser: true, undef: true, unused: true, strict: true */ +/*global define: false, module: false, require: false */ + +( function( window, factory ) { + + // universal module definition + + if ( typeof define == 'function' && define.amd ) { + // AMD + define( 'unipointer/unipointer',[ + 'eventEmitter/EventEmitter', + 'eventie/eventie' + ], function( EventEmitter, eventie ) { + return factory( window, EventEmitter, eventie ); + }); + } else if ( typeof exports == 'object' ) { + // CommonJS + module.exports = factory( + window, + require('wolfy87-eventemitter'), + require('eventie') + ); + } else { + // browser global + window.Unipointer = factory( + window, + window.EventEmitter, + window.eventie + ); + } + +}( window, function factory( window, EventEmitter, eventie ) { + + + +function noop() {} + +function Unipointer() {} + +// inherit EventEmitter +Unipointer.prototype = new EventEmitter(); + +Unipointer.prototype.bindStartEvent = function( elem ) { + this._bindStartEvent( elem, true ); +}; + +Unipointer.prototype.unbindStartEvent = function( elem ) { + this._bindStartEvent( elem, false ); +}; + +/** + * works as unbinder, as you can ._bindStart( false ) to unbind + * @param {Boolean} isBind - will unbind if falsey + */ +Unipointer.prototype._bindStartEvent = function( elem, isBind ) { + // munge isBind, default to true + isBind = isBind === undefined ? true : !!isBind; + var bindMethod = isBind ? 'bind' : 'unbind'; + + if ( window.navigator.pointerEnabled ) { + // W3C Pointer Events, IE11. See https://coderwall.com/p/mfreca + eventie[ bindMethod ]( elem, 'pointerdown', this ); + } else if ( window.navigator.msPointerEnabled ) { + // IE10 Pointer Events + eventie[ bindMethod ]( elem, 'MSPointerDown', this ); + } else { + // listen for both, for devices like Chrome Pixel + eventie[ bindMethod ]( elem, 'mousedown', this ); + eventie[ bindMethod ]( elem, 'touchstart', this ); + } +}; + +// trigger handler methods for events +Unipointer.prototype.handleEvent = function( event ) { + var method = 'on' + event.type; + if ( this[ method ] ) { + this[ method ]( event ); + } +}; + +// returns the touch that we're keeping track of +Unipointer.prototype.getTouch = function( touches ) { + for ( var i=0, len = touches.length; i < len; i++ ) { + var touch = touches[i]; + if ( touch.identifier == this.pointerIdentifier ) { + return touch; + } + } +}; + +// ----- start event ----- // + +Unipointer.prototype.onmousedown = function( event ) { + // dismiss clicks from right or middle buttons + var button = event.button; + if ( button && ( button !== 0 && button !== 1 ) ) { + return; + } + this._pointerDown( event, event ); +}; + +Unipointer.prototype.ontouchstart = function( event ) { + this._pointerDown( event, event.changedTouches[0] ); +}; + +Unipointer.prototype.onMSPointerDown = +Unipointer.prototype.onpointerdown = function( event ) { + this._pointerDown( event, event ); +}; + +/** + * pointer start + * @param {Event} event + * @param {Event or Touch} pointer + */ +Unipointer.prototype._pointerDown = function( event, pointer ) { + // dismiss other pointers + if ( this.isPointerDown ) { + return; + } + + this.isPointerDown = true; + // save pointer identifier to match up touch events + this.pointerIdentifier = pointer.pointerId !== undefined ? + // pointerId for pointer events, touch.indentifier for touch events + pointer.pointerId : pointer.identifier; + + this.pointerDown( event, pointer ); +}; + +Unipointer.prototype.pointerDown = function( event, pointer ) { + this._bindPostStartEvents( event ); + this.emitEvent( 'pointerDown', [ event, pointer ] ); +}; + +// hash of events to be bound after start event +var postStartEvents = { + mousedown: [ 'mousemove', 'mouseup' ], + touchstart: [ 'touchmove', 'touchend', 'touchcancel' ], + pointerdown: [ 'pointermove', 'pointerup', 'pointercancel' ], + MSPointerDown: [ 'MSPointerMove', 'MSPointerUp', 'MSPointerCancel' ] +}; + +Unipointer.prototype._bindPostStartEvents = function( event ) { + if ( !event ) { + return; + } + // get proper events to match start event + var events = postStartEvents[ event.type ]; + // IE8 needs to be bound to document + var node = event.preventDefault ? window : document; + // bind events to node + for ( var i=0, len = events.length; i < len; i++ ) { + var evnt = events[i]; + eventie.bind( node, evnt, this ); + } + // save these arguments + this._boundPointerEvents = { + events: events, + node: node + }; +}; + +Unipointer.prototype._unbindPostStartEvents = function() { + var args = this._boundPointerEvents; + // IE8 can trigger dragEnd twice, check for _boundEvents + if ( !args || !args.events ) { + return; + } + + for ( var i=0, len = args.events.length; i < len; i++ ) { + var event = args.events[i]; + eventie.unbind( args.node, event, this ); + } + delete this._boundPointerEvents; +}; + +// ----- move event ----- // + +Unipointer.prototype.onmousemove = function( event ) { + this._pointerMove( event, event ); +}; + +Unipointer.prototype.onMSPointerMove = +Unipointer.prototype.onpointermove = function( event ) { + if ( event.pointerId == this.pointerIdentifier ) { + this._pointerMove( event, event ); + } +}; + +Unipointer.prototype.ontouchmove = function( event ) { + var touch = this.getTouch( event.changedTouches ); + if ( touch ) { + this._pointerMove( event, touch ); + } +}; + +/** + * pointer move + * @param {Event} event + * @param {Event or Touch} pointer + * @private + */ +Unipointer.prototype._pointerMove = function( event, pointer ) { + this.pointerMove( event, pointer ); +}; + +// public +Unipointer.prototype.pointerMove = function( event, pointer ) { + this.emitEvent( 'pointerMove', [ event, pointer ] ); +}; + +// ----- end event ----- // + + +Unipointer.prototype.onmouseup = function( event ) { + this._pointerUp( event, event ); +}; + +Unipointer.prototype.onMSPointerUp = +Unipointer.prototype.onpointerup = function( event ) { + if ( event.pointerId == this.pointerIdentifier ) { + this._pointerUp( event, event ); + } +}; + +Unipointer.prototype.ontouchend = function( event ) { + var touch = this.getTouch( event.changedTouches ); + if ( touch ) { + this._pointerUp( event, touch ); + } +}; + +/** + * pointer up + * @param {Event} event + * @param {Event or Touch} pointer + * @private + */ +Unipointer.prototype._pointerUp = function( event, pointer ) { + this._pointerDone(); + this.pointerUp( event, pointer ); +}; + +// public +Unipointer.prototype.pointerUp = function( event, pointer ) { + this.emitEvent( 'pointerUp', [ event, pointer ] ); +}; + +// ----- pointer done ----- // + +// triggered on pointer up & pointer cancel +Unipointer.prototype._pointerDone = function() { + // reset properties + this.isPointerDown = false; + delete this.pointerIdentifier; + // remove events + this._unbindPostStartEvents(); + this.pointerDone(); +}; + +Unipointer.prototype.pointerDone = noop; + +// ----- pointer cancel ----- // + +Unipointer.prototype.onMSPointerCancel = +Unipointer.prototype.onpointercancel = function( event ) { + if ( event.pointerId == this.pointerIdentifier ) { + this._pointerCancel( event, event ); + } +}; + +Unipointer.prototype.ontouchcancel = function( event ) { + var touch = this.getTouch( event.changedTouches ); + if ( touch ) { + this._pointerCancel( event, touch ); + } +}; + +/** + * pointer cancel + * @param {Event} event + * @param {Event or Touch} pointer + * @private + */ +Unipointer.prototype._pointerCancel = function( event, pointer ) { + this._pointerDone(); + this.pointerCancel( event, pointer ); +}; + +// public +Unipointer.prototype.pointerCancel = function( event, pointer ) { + this.emitEvent( 'pointerCancel', [ event, pointer ] ); +}; + +// ----- ----- // + +// utility function for getting x/y cooridinates from event, because IE8 +Unipointer.getPointerPoint = function( pointer ) { + return { + x: pointer.pageX !== undefined ? pointer.pageX : pointer.clientX, + y: pointer.pageY !== undefined ? pointer.pageY : pointer.clientY + }; +}; + +// ----- ----- // + +return Unipointer; + +})); + +/*! + * Unidragger v1.1.3 + * Draggable base class + * MIT license + */ + +/*jshint browser: true, unused: true, undef: true, strict: true */ + +( function( window, factory ) { + /*global define: false, module: false, require: false */ + + // universal module definition + + if ( typeof define == 'function' && define.amd ) { + // AMD + define( 'unidragger/unidragger',[ + 'eventie/eventie', + 'unipointer/unipointer' + ], function( eventie, Unipointer ) { + return factory( window, eventie, Unipointer ); + }); + } else if ( typeof exports == 'object' ) { + // CommonJS + module.exports = factory( + window, + require('eventie'), + require('unipointer') + ); + } else { + // browser global + window.Unidragger = factory( + window, + window.eventie, + window.Unipointer + ); + } + +}( window, function factory( window, eventie, Unipointer ) { + + + +// ----- ----- // + +function noop() {} + +// handle IE8 prevent default +function preventDefaultEvent( event ) { + if ( event.preventDefault ) { + event.preventDefault(); + } else { + event.returnValue = false; + } +} + +// -------------------------- Unidragger -------------------------- // + +function Unidragger() {} + +// inherit Unipointer & EventEmitter +Unidragger.prototype = new Unipointer(); + +// ----- bind start ----- // + +Unidragger.prototype.bindHandles = function() { + this._bindHandles( true ); +}; + +Unidragger.prototype.unbindHandles = function() { + this._bindHandles( false ); +}; + +var navigator = window.navigator; +/** + * works as unbinder, as you can .bindHandles( false ) to unbind + * @param {Boolean} isBind - will unbind if falsey + */ +Unidragger.prototype._bindHandles = function( isBind ) { + // munge isBind, default to true + isBind = isBind === undefined ? true : !!isBind; + // extra bind logic + var binderExtra; + if ( navigator.pointerEnabled ) { + binderExtra = function( handle ) { + // disable scrolling on the element + handle.style.touchAction = isBind ? 'none' : ''; + }; + } else if ( navigator.msPointerEnabled ) { + binderExtra = function( handle ) { + // disable scrolling on the element + handle.style.msTouchAction = isBind ? 'none' : ''; + }; + } else { + binderExtra = function() { + // TODO re-enable img.ondragstart when unbinding + if ( isBind ) { + disableImgOndragstart( handle ); + } + }; + } + // bind each handle + var bindMethod = isBind ? 'bind' : 'unbind'; + for ( var i=0, len = this.handles.length; i < len; i++ ) { + var handle = this.handles[i]; + this._bindStartEvent( handle, isBind ); + binderExtra( handle ); + eventie[ bindMethod ]( handle, 'click', this ); + } +}; + +// remove default dragging interaction on all images in IE8 +// IE8 does its own drag thing on images, which messes stuff up + +function noDragStart() { + return false; +} + +// TODO replace this with a IE8 test +var isIE8 = 'attachEvent' in document.documentElement; + +// IE8 only +var disableImgOndragstart = !isIE8 ? noop : function( handle ) { + + if ( handle.nodeName == 'IMG' ) { + handle.ondragstart = noDragStart; + } + + var images = handle.querySelectorAll('img'); + for ( var i=0, len = images.length; i < len; i++ ) { + var img = images[i]; + img.ondragstart = noDragStart; + } +}; + +// ----- start event ----- // + +/** + * pointer start + * @param {Event} event + * @param {Event or Touch} pointer + */ +Unidragger.prototype.pointerDown = function( event, pointer ) { + this._dragPointerDown( event, pointer ); + // kludge to blur focused inputs in dragger + var focused = document.activeElement; + if ( focused && focused.blur ) { + focused.blur(); + } + // bind move and end events + this._bindPostStartEvents( event ); + this.emitEvent( 'pointerDown', [ event, pointer ] ); +}; + +// base pointer down logic +Unidragger.prototype._dragPointerDown = function( event, pointer ) { + // track to see when dragging starts + this.pointerDownPoint = Unipointer.getPointerPoint( pointer ); + + // prevent default, unless touchstart or s and