UNPKG

vpn.email

Version:
188 lines (157 loc) 6.2 kB
$.widget( "metro.presenter" , { version: "3.0.0", options: { height: '200', width: '100%', effect: 'random', duration: 1000, timeout: 2000, sceneTimeout: 2000, easing: 'swing' }, _acts: undefined, _currentAct: 0, _actDone: true, _interval: undefined, _effects: ['top', 'bottom', 'left', 'right'], _actor_positions: [], _create: function () { var that = this, element = this.element, o = this.options; $.each(element.data(), function(key, value){ if (key in o) { try { o[key] = $.parseJSON(value); } catch (e) { o[key] = value; } } }); this._createPresenter(); this._showScene(); element.data('presenter', this); }, _createPresenter: function (){ var that = this, element = this.element, o = this.options; var acts = element.find('.act'); acts.hide(); this._acts = acts; element.css({ height: o.height, width: o.width }); }, _showScene: function(){ var that = this, element = this.element, o = this.options; this._interval = setInterval(function(){ if (that._actDone) { that._currentAct++; if (that._currentAct == that._acts.length) { that._currentAct = 0; } //that._closeAct(); that._showAct(); } }, 500); }, _closeAct: function(){ var that = this, element = this.element, o = this.options; var index = this._currentAct; setTimeout(function(){ if (that._acts[index] !== undefined) $(that._acts[index]).fadeOut(1000, function(){ that._actDone = true; }); }, o.sceneTimeout); }, _showAct: function(){ var that = this, element = this.element, o = this.options; var act = $(this._acts[this._currentAct]); var actors = act.find('.actor'); var i; this._actDone = false; act.fadeIn(1000); actors.css({ opacity: 0, position: 'absolute', display: 'none' }); i = 0; $.each(actors, function(){ var actor = $(this), pos = {top: actor.data('position').split(",")[0], left: actor.data('position').split(",")[1]};//that._actor_positions[$(that._acts[that._currentAct]).attr('id')][actor.attr('id')]; var actor_effect, actor_duration, actor_timeout, actor_easing; actor_effect = actor.data('effect') !== undefined ? actor.data('effect') : o.effect; if (actor_effect === 'random') { actor_effect = that._effects[Math.floor(Math.random() * that._effects.length)]; } actor_duration = actor.data('duration') !== undefined ? actor.data('duration') : o.duration; actor_timeout = actor.data('timeout') !== undefined ? actor.data('timeout') : o.timeout; actor_easing = actor.data('easing') !== undefined ? actor.data('easing') : o.easing; if (actor_effect === 'top') { setTimeout(function(){ actor.css({ top: - (element.height()), left: pos.left, display: 'block' }).animate({ top: pos.top, left: pos.left, opacity: 1 }, actor_duration, actor_easing, function(){if (actor[0] == actors[actors.length-1]) that._closeAct();}); }, i * actor_timeout); } else if (actor_effect === 'bottom') { setTimeout(function(){ actor.css({ top: element.height(), left: pos.left, display: 'block' }).animate({ top: pos.top, left: pos.left, opacity: 1 }, actor_duration, actor_easing, function(){if (actor[0] == actors[actors.length-1]) that._closeAct();}); }, i * actor_timeout); } else if (actor_effect === 'left') { setTimeout(function(){ actor.css({ left: - element.width(), top: pos.top, display: 'block' }).animate({ top: pos.top, left: pos.left, opacity: 1 }, actor_duration, actor_easing, function(){if (actor[0] == actors[actors.length-1]) that._closeAct();}); }, i * actor_timeout); } else if (actor_effect === 'right') { setTimeout(function(){ actor.css({ left: element.width(), top: pos.top, display: 'block' }).animate({ top: pos.top, left: pos.left, opacity: 1 }, actor_duration, actor_easing, function(){if (actor[0] == actors[actors.length-1]) that._closeAct();}); }, i * actor_timeout); } else { //fade setTimeout(function(){ actor.css({ top: pos.top, left: pos.left, display: 'block' }).animate({ top: pos.top, left: pos.left, opacity: 1 }, actor_duration, 'swing', function(){if (actor[0] == actors[actors.length-1]) that._closeAct();}); }, i * actor_timeout); } i++; }); }, _destroy: function () { }, _setOption: function ( key, value ) { this._super('_setOption', key, value); } });