1/* 2 _____ _____ _____ _______ 3 /\ \ /\ \ /\ \ /::\ \ 4 /::\ \ /::\ \ /::\ \ /::::\ \ 5 /::::\ \ \:::\ \ /::::\ \ /::::::\ \ 6 /::::::\ \ \:::\ \ /::::::\ \ /::::::::\ \ 7 /:::/\:::\ \ \:::\ \ /:::/\:::\ \ /:::/~~\:::\ \ 8 /:::/__\:::\ \ \:::\ \ /:::/__\:::\ \ /:::/ \:::\ \ 9 /::::\ \:::\ \ /::::\ \ \:::\ \:::\ \:::/ / \:::\ \ 10 /::::::\ \:::\ \__ /::::::\ \_\:::\ \:::\ \:/____/ \:::\____\ 11 /:::/\:::\ \:::\____\ \ /:::/\:::\ \ \:::\ \:::\ \ | |:::| | 12 /:::/ \:::\ \:::| | \/:::/ \:::\____\ \:::\ \:::\____\___| |:::|____| 13 \::/ |::::\ /:::|____| /:::/ \::/ / \:::\ \::/ / _\___/:::/ / 14 \/____|:::::\/:::/ /\/:::/ / \/____/\ \:::\ \/____/:\ |::| /:::/ / 15 |:::::::::/ /:::::/ / \:::\ \:::\ \ \:::\|::|/:::/ / 16 |::|\::::/ /\::::/____/ \:::\ \:::\____\ \::::::::::/ / 17 |::| \::/____/ \:::\ \ \:::\ /:::/ / \::::::::/ / 18 |::| ~| \:::\ \ \:::\/:::/ / \::::::/ / 19 |::| | \:::\ \ \::::::/ / \::::/____/ 20 \::| | \:::\____\ \::::/ / |::| | 21 \:| | \::/ / \::/ / |::|____| 22 \|___| \/____/ \/____/ ~~ 23 24 ____.________ _____ .___ .___ 25 | |\_____ \ __ __ ___________ ___.__. / _ \ __| _/__ _______ ____ ____ ____ __| _/ 26 | | / / \ \| | \_/ __ \_ __ < | | / /_\ \ / __ |\ \/ /\__ \ / \_/ ___\/ __ \ / __ | 27/\__| |/ \_/. \ | /\ ___/| | \/\___ | / | \/ /_/ | \ / / __ \| | \ \__\ ___// /_/ | 28\________|\_____\ \_/____/ \___ >__| / ____| \____|__ /\____ | \_/ (____ /___| /\___ >___ >____ | 29 \__> \/ \/ \/ \/ \/ \/ \/ \/ \/ 30 _______ ___________.__ __ 31 \ \ ______ _ ________ \__ ___/|__| ____ | | __ ___________ 32 ______ / | \_/ __ \ \/ \/ / ___/ | | | |/ ___\| |/ // __ \_ __ \ ______ 33 /_____/ / | \ ___/\ /\___ \ | | | \ \___| <\ ___/| | \/ /_____/ 34 \____|__ /\___ >\/\_//____ > |____| |__|\___ >__|_ \\___ >__| 35 \/ \/ \/ \/ \/ \/ 36*/ 37 38; 39(function($, window, document, undefined) { 40 'use strict'; 41 // undefined is used here as the undefined global variable in ECMAScript 3 is 42 // mutable (ie. it can be hasMoved by someone else). undefined isn't really being 43 // passed in so we can ensure the value of it is truly undefined. In ES5, undefined 44 // can no longer be modified. 45 46 // window and document are passed through as local variable rather than global 47 // as this (slightly) quickens the resolution process and can be more efficiently 48 // minified (especially when both are regularly referenced in your plugin). 49 50 // Create the defaults once 51 var pluginName = 'newsTicker', 52 defaults = { 53 row_height: 20, 54 max_rows: 3, 55 speed: 400, 56 duration: 2500, 57 direction: 'up', 58 autostart: 1, 59 pauseOnHover: 1, 60 nextButton: null, 61 prevButton: null, 62 startButton: null, 63 stopButton: null, 64 hasMoved: function() {}, 65 movingUp: function() {}, 66 movingDown: function() {}, 67 start: function() {}, 68 stop: function() {}, 69 pause: function() {}, 70 unpause: function() {} 71 }; 72 73 // The actual plugin constructor 74 function Plugin(element, options) { 75 this.element = element; 76 this.$el = $(element); 77 this.options = $.extend({}, defaults, options); 78 this._defaults = defaults; 79 this._name = pluginName; 80 this.moveInterval; 81 this.state = 0; 82 this.paused = 0; 83 this.moving = 0; 84 if (this.$el.is('ul')) { 85 this.init(); 86 } 87 } 88 89 Plugin.prototype = { 90 init: function() { 91 this.$el.height(this.options.row_height * this.options.max_rows) 92 .css({overflow : 'hidden'}); 93 94 this.checkSpeed(); 95 96 if(this.options.nextButton && typeof(this.options.nextButton[0]) !== 'undefined') 97 this.options.nextButton.click(function(e) { 98 this.moveNext(); 99 this.resetInterval(); 100 }.bind(this)); 101 if(this.options.prevButton && typeof(this.options.prevButton[0]) !== 'undefined') 102 this.options.prevButton.click(function(e) { 103 this.movePrev(); 104 this.resetInterval(); 105 }.bind(this)); 106 if(this.options.stopButton && typeof(this.options.stopButton[0]) !== 'undefined') 107 this.options.stopButton.click(function(e) { 108 this.stop() 109 }.bind(this)); 110 if(this.options.startButton && typeof(this.options.startButton[0]) !== 'undefined') 111 this.options.startButton.click(function(e) { 112 this.start() 113 }.bind(this)); 114 115 if(this.options.pauseOnHover) { 116 this.$el.hover(function() { 117 if (this.state) 118 this.pause(); 119 }.bind(this), function() { 120 if (this.state) 121 this.unpause(); 122 }.bind(this)); 123 } 124 125 if(this.options.autostart) 126 this.start(); 127 }, 128 129 start: function() { 130 if (!this.state) { 131 this.state = 1; 132 this.resetInterval(); 133 this.options.start(); 134 } 135 }, 136 137 stop: function() { 138 if (this.state) { 139 clearInterval(this.moveInterval); 140 this.state = 0; 141 this.options.stop(); 142 } 143 }, 144 145 resetInterval: function() { 146 if (this.state) { 147 clearInterval(this.moveInterval); 148 this.moveInterval = setInterval(function() {this.move()}.bind(this), this.options.duration); 149 } 150 }, 151 152 move: function() { 153 if (!this.paused) this.moveNext(); 154 }, 155 156 moveNext: function() { 157 if (this.options.direction === 'down') 158 this.moveDown(); 159 else if (this.options.direction === 'up') 160 this.moveUp(); 161 }, 162 163 movePrev: function() { 164 if (this.options.direction === 'down') 165 this.moveUp(); 166 else if (this.options.direction === 'up') 167 this.moveDown(); 168 }, 169 170 pause: function() { 171 if (!this.paused) this.paused = 1; 172 this.options.pause(); 173 }, 174 175 unpause: function() { 176 if (this.paused) this.paused = 0; 177 this.options.unpause(); 178 }, 179 180 moveDown: function() { 181 if (!this.moving) { 182 this.moving = 1; 183 this.options.movingDown(); 184 this.$el.children('li:last').detach().prependTo(this.$el).css('marginTop', '-' + this.options.row_height + 'px') 185 .animate({marginTop: '0px'}, this.options.speed, function(){ 186 this.moving = 0; 187 this.options.hasMoved(); 188 }.bind(this)); 189 } 190 }, 191 192 moveUp: function() { 193 if (!this.moving) { 194 this.moving = 1; 195 this.options.movingUp(); 196 var element = this.$el.children('li:first'); 197 element.animate({marginTop: '-' + this.options.row_height + 'px'}, this.options.speed, 198 function(){ 199 element.detach().css('marginTop', '0').appendTo(this.$el); 200 this.moving = 0; 201 this.options.hasMoved(); 202 }.bind(this)); 203 } 204 }, 205 206 updateOption: function(option, value) { 207 if (typeof(this.options[option]) !== 'undefined'){ 208 this.options[option] = value; 209 if (option == 'duration' || option == 'speed'){ 210 this.checkSpeed(); 211 this.resetInterval(); 212 } 213 } 214 }, 215 216 getState: function() { 217 if (paused) return 2 218 else return this.state;//0 = stopped, 1 = started 219 }, 220 221 checkSpeed: function() { 222 if (this.options.duration < (this.options.speed + 25)) 223 this.options.speed = this.options.duration - 25; 224 }, 225 226 destroy: function() { 227 this._destroy(); //or this.delete; depends on jQuery version 228 } 229 }; 230 231 // A really lightweight plugin wrapper around the constructor, 232 // preventing against multiple instantiations 233 $.fn[pluginName] = function(option) { 234 var args = arguments; 235 236 return this.each(function() { 237 var $this = $(this), 238 data = $.data(this, 'plugin_' + pluginName), 239 options = typeof option === 'object' && option; 240 if (!data) { 241 $this.data('plugin_' + pluginName, (data = new Plugin(this, options))); 242 } 243 // if first argument is a string, call silimarly named function 244 // this gives flexibility to call functions of the plugin e.g. 245 // - $('.dial').plugin('destroy'); 246 // - $('.dial').plugin('render', $('.new-child')); 247 if (typeof option === 'string') { 248 data[option].apply(data, Array.prototype.slice.call(args, 1)); 249 } 250 }); 251 }; 252})(jQuery, window, document);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.