"use strict"; var core; (function (core) { var slider = (function () { function slider() { // durations this.durations = { auto: 6000, slide: 1400 }; // dom this.dom = { wrapper: null, container: null, project: null, current: null, next: null, arrow: null }; // misc stuff this.length = 0; this.current = 0; this.next = 0; this.isauto = true; this.working = false; this.dom.wrapper = $('.slider-view'); this.dom.project = this.dom.wrapper.find('.project'); this.dom.arrow = this.dom.wrapper.find('.arrow'); this.length = this.dom.project.length; this.init(); this.events(); this.auto = setinterval(this.updatenext.bind(this), this.durations.auto); } /** * set initial z-indexes & get current project */ slider.prototype.init = function () { console.log(this.dom.project) this.dom.project.addclass('disable'); // this.dom.project.css('z-index', 10); this.dom.current = $(this.dom.project[this.current]); this.dom.next = $(this.dom.project[this.current + 1]); this.dom.current.addclass('click'); this.dom.next.addclass('active'); // this.dom.current.css('z-index', 30); // this.dom.next.css('z-index', 20); }; slider.prototype.clear = function () { this.dom.arrow.off('click'); if (this.isauto) clearinterval(this.auto); }; /** * initialize events */ slider.prototype.events = function () { var self = this; this.dom.arrow.on('click', function () { if (self.working) return; self.processbtn($(this)); }); }; slider.prototype.processbtn = function (btn) { if (this.isauto) { this.isauto = false; clearinterval(this.auto); } if (btn.hasclass('next')) this.updatenext(); if (btn.hasclass('previous')) this.updateprevious(); }; /** * update next global index */ slider.prototype.updatenext = function () { this.next = (this.current + 1) % this.length; this.process(); }; /** * update next global index */ slider.prototype.updateprevious = function () { this.next--; if (this.next < 0) this.next = this.length - 1; this.process(); }; /** * process, calculate and switch beetween slides */ slider.prototype.process = function () { var self = this; this.working = true; this.dom.next = $(this.dom.project[this.next]); this.dom.current.removeclass('active'); this.dom.current.removeclass('disable'); this.dom.current.addclass('click'); // this.dom.current.css('z-index', 30); self.dom.next.removeclass('click'); self.dom.next.removeclass('disable'); self.dom.next.addclass('active'); // self.dom.next.css('z-index', 20); // hide current this.dom.current.addclass('hide'); settimeout(function () { self.dom.current.removeclass('hide'); self.dom.current.removeclass('active'); self.dom.current.removeclass('click'); self.dom.current.addclass('disable'); self.dom.next.removeclass('disable'); self.dom.next.removeclass('active'); self.dom.next.addclass('click'); // self.dom.current.css('z-index', 10); // self.dom.next.css('z-index', 30); self.dom.current = self.dom.next; self.current = self.next; self.working = false; }, this.durations.slide); }; return slider; }()); core.slider = slider; })(core || (core = {})); document.addeventlistener('domcontentloaded', function () { var imgload0 = imagesloaded( '.slider-view', { background: true }, function() { console.log('slider-view loaded'); }); imgload0.on( 'done', function( instance ) { new core.slider(); }); });