Advertisement
Guest User

Untitled

a guest
Sep 16th, 2011
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.40 KB | None | 0 0
  1. // JavaScript Document
  2. /*! Copyright (c) 2009 Brandon Aaron (http://brandonaaron.net)
  3. * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
  4. * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
  5. * Thanks to: http://adomas.org/javascript-mouse-wheel/ for some pointers.
  6. * Thanks to: Mathias Bank(http://www.mathias-bank.de) for a scope bug fix.
  7. *
  8. * Version: 3.0.2
  9. *
  10. * Requires: 1.2.2+
  11. */
  12.  
  13. (function($) {
  14.  
  15. var types = ['DOMMouseScroll', 'mousewheel'];
  16.  
  17. $.event.special.mousewheel = {
  18. setup: function() {
  19. if ( this.addEventListener )
  20. for ( var i=types.length; i; )
  21. this.addEventListener( types[--i], handler, false );
  22. else
  23. this.onmousewheel = handler;
  24. },
  25.  
  26. teardown: function() {
  27. if ( this.removeEventListener )
  28. for ( var i=types.length; i; )
  29. this.removeEventListener( types[--i], handler, false );
  30. else
  31. this.onmousewheel = null;
  32. }
  33. };
  34.  
  35. $.fn.extend({
  36. mousewheel: function(fn) {
  37. return fn ? this.bind("mousewheel", fn) : this.trigger("mousewheel");
  38. },
  39.  
  40. unmousewheel: function(fn) {
  41. return this.unbind("mousewheel", fn);
  42. }
  43. });
  44.  
  45.  
  46. function handler(event) {
  47. var args = [].slice.call( arguments, 1 ), delta = 0, returnValue = true;
  48.  
  49. event = $.event.fix(event || window.event);
  50. event.type = "mousewheel";
  51.  
  52. if ( event.wheelDelta ) delta = event.wheelDelta/120;
  53. if ( event.detail ) delta = -event.detail/3;
  54.  
  55. // Add events and delta to the front of the arguments
  56. args.unshift(event, delta);
  57.  
  58. return $.event.handle.apply(this, args);
  59. }
  60.  
  61. })(jQuery);
  62.  
  63. /**
  64. * @version $Id: $Revision
  65. * @package jquery
  66. * @subpackage lofslidernews
  67. * @copyright Copyright (C) JAN 2010 LandOfCoder.com <@emai:landofcoder@gmail.com>. All rights reserved.
  68. * @website http://landofcoder.com
  69. * @license This plugin is dual-licensed under the GNU General Public License and the MIT License
  70. */
  71. // JavaScript Document
  72. (function($) {
  73. $.fn.lofJSidernews = function( settings ) {
  74. return this.each(function() {
  75. // get instance of the lofSiderNew.
  76. new $.lofSidernews( this, settings );
  77. });
  78. }
  79. $.lofSidernews = function( obj, settings ){
  80. this.settings = {
  81. direction : '',
  82. mainItemSelector : 'li',
  83. navInnerSelector : 'ul',
  84. navSelector : 'li' ,
  85. navigatorEvent : 'click',
  86. wapperSelector: '.lof-main-wapper',
  87. interval : 4000,
  88. auto : true, // whether to automatic play the slideshow
  89. maxItemDisplay : 3,
  90. startItem : 0,
  91. navPosition : 'vertical',
  92. navigatorHeight : 100,
  93. navigatorWidth : 310,
  94. duration : 600,
  95. navItemsSelector : '.lof-navigator li',
  96. navOuterSelector : '.lof-navigator-outer' ,
  97. isPreloaded : true,
  98. easing : 'easeInOutQuad'
  99. }
  100. $.extend( this.settings, settings ||{} );
  101. this.nextNo = null;
  102. this.previousNo = null;
  103. this.maxWidth = this.settings.mainWidth || 600;
  104. this.wrapper = $( obj ).find( this.settings.wapperSelector );
  105. this.slides = this.wrapper.find( this.settings.mainItemSelector );
  106. if( !this.wrapper.length || !this.slides.length ) return ;
  107. // set width of wapper
  108. if( this.settings.maxItemDisplay > this.slides.length ){
  109. this.settings.maxItemDisplay = this.slides.length;
  110. }
  111. this.currentNo = isNaN(this.settings.startItem)||this.settings.startItem > this.slides.length?0:this.settings.startItem;
  112. this.navigatorOuter = $( obj ).find( this.settings.navOuterSelector );
  113. this.navigatorItems = $( obj ).find( this.settings.navItemsSelector ) ;
  114. this.navigatorInner = this.navigatorOuter.find( this.settings.navInnerSelector );
  115.  
  116. if( this.settings.navPosition == 'horizontal' ){
  117. this.navigatorInner.width( this.slides.length * this.settings.navigatorWidth );
  118. this.navigatorOuter.width( this.settings.maxItemDisplay * this.settings.navigatorWidth );
  119. this.navigatorOuter.height( this.settings.navigatorHeight );
  120.  
  121. } else {
  122. this.navigatorInner.height( this.slides.length * this.settings.navigatorHeight );
  123.  
  124. this.navigatorOuter.height( this.settings.maxItemDisplay * this.settings.navigatorHeight );
  125. this.navigatorOuter.width( this.settings.navigatorWidth );
  126. }
  127. this.navigratorStep = this.__getPositionMode( this.settings.navPosition );
  128. this.directionMode = this.__getDirectionMode();
  129.  
  130.  
  131. if( this.settings.direction == 'opacity') {
  132. var text = '.lof-main-item-desc';
  133. this.wrapper.addClass( 'lof-opacity' );
  134. $(this.slides).css({'opacity':0, 'display':'none'}).eq(this.currentNo).css({'opacity':1, 'display':'block'});
  135. $(this.wrapper).find(text).slideUp().eq(this.currentNo).slideDown();
  136. } else {
  137. var text = '.lof-main-item-desc';
  138. this.wrapper.css({'left':'-'+this.currentNo*this.maxSize+'px', 'width':( this.maxWidth ) * this.slides.length } );
  139. $(this.wrapper).find(text).show();
  140. }
  141.  
  142.  
  143. if( this.settings.isPreloaded ) {
  144. this.preLoadImage( this.onComplete );
  145. } else {
  146. this.onComplete();
  147. }
  148.  
  149. }
  150. $.lofSidernews.fn = $.lofSidernews.prototype;
  151. $.lofSidernews.fn.extend = $.lofSidernews.extend = $.extend;
  152.  
  153. $.lofSidernews.fn.extend({
  154.  
  155. startUp:function( obj, wrapper ) {
  156.  
  157. this.navigatorItems.each( function(index, item ){
  158. $(item).click( function(){
  159. obj.jumping( index, true );
  160. obj.setNavActive( index, item );
  161. } );
  162. $(item).css( {'height': obj.settings.navigatorHeight, 'width': obj.settings.navigatorWidth} );
  163. })
  164. this.navigatorItems.find('img').hover(function(){ $(this).stop().animate({'opacity':0.7},500,'easeInOutQuad') },
  165. function(){ $(this).animate({'opacity':1},500,'easeInOutSine') } );
  166. this.registerWheelHandler( this.navigatorOuter, this );
  167. this.setNavActive(this.currentNo );
  168.  
  169. if( this.settings.buttons && typeof (this.settings.buttons) == "object" ){
  170. this.registerButtonsControl( 'click', this.settings.buttons, this );
  171.  
  172. }
  173. if( this.settings.auto )
  174. this.play( this.settings.interval,'next', true );
  175.  
  176. return this;
  177. },
  178. onComplete:function(){
  179.  
  180. setTimeout( function(){ $('.preload').fadeOut( 900 ); }, 400 ); this.startUp( this );
  181. },
  182. preLoadImage:function( callback ){
  183. var self = this;
  184. var images = this.wrapper.find('img');
  185. var count = 0;
  186. images.one('load', function() {
  187. count++;
  188. if(count == images.length) {
  189. self.onComplete();
  190. }
  191. }).each(function(){
  192. if(this.complete || (jQuery.browser.msie && parseInt(jQuery.browser.version) >= 6))
  193. $(this).trigger('load');
  194. });
  195. },
  196. navivationAnimate:function( currentIndex ) {
  197. if (currentIndex <= this.settings.startItem
  198. || currentIndex - this.settings.startItem >= this.settings.maxItemDisplay-1) {
  199. this.settings.startItem = currentIndex - this.settings.maxItemDisplay+2;
  200. if (this.settings.startItem < 0) this.settings.startItem = 0;
  201. if (this.settings.startItem >this.slides.length-this.settings.maxItemDisplay) {
  202. this.settings.startItem = this.slides.length-this.settings.maxItemDisplay;
  203. }
  204. }
  205. this.navigatorInner.stop().animate( eval('({'+this.navigratorStep[0]+':-'+this.settings.startItem*this.navigratorStep[1]+'})'),
  206. {duration:500, easing:'easeInOutQuad'} );
  207. },
  208. setNavActive:function( index, item ){
  209. if( (this.navigatorItems) ){
  210. this.navigatorItems.removeClass( 'active' );
  211. $(this.navigatorItems.get(index)).addClass( 'active' );
  212. this.navivationAnimate( this.currentNo );
  213. }
  214. },
  215. __getPositionMode:function( position ){
  216. if( position == 'horizontal' ){
  217. return ['left', this.settings.navigatorWidth];
  218. }
  219. return ['top', this.settings.navigatorHeight];
  220. },
  221. __getDirectionMode:function(){
  222. switch( this.settings.direction ){
  223. case 'opacity': this.maxSize=0; return ['opacity','opacity'];
  224. default: this.maxSize=this.maxWidth; return ['left','width'];
  225. }
  226. },
  227. registerWheelHandler:function( element, obj ){
  228. element.bind('mousewheel', function(event, delta ) {
  229. var dir = delta > 0 ? 'Up' : 'Down',
  230. vel = Math.abs(delta);
  231. if( delta > 0 ){
  232. obj.previous( true );
  233. } else {
  234. obj.next( true );
  235. }
  236. return false;
  237. });
  238. },
  239. registerButtonsControl:function( eventHandler, objects, self ){
  240. for( var action in objects ){
  241. switch (action.toString() ){
  242. case 'next':
  243. objects[action].click( function() { self.next( true) } );
  244. break;
  245. case 'previous':
  246. objects[action].click( function() { self.previous( true) } );
  247. break;
  248. }
  249. }
  250. return this;
  251. },
  252. onProcessing:function( manual, start, end ){
  253. this.previousNo = this.currentNo + (this.currentNo>0 ? -1 : this.slides.length-1);
  254. this.nextNo = this.currentNo + (this.currentNo < this.slides.length-1 ? 1 : 1- this.slides.length);
  255. return this;
  256. },
  257. finishFx:function( manual ){
  258. if( manual ) this.stop();
  259. if( manual && this.settings.auto ){
  260. this.play( this.settings.interval,'next', true );
  261. }
  262. this.setNavActive( this.currentNo );
  263. },
  264. getObjectDirection:function( start, end ){
  265. return eval("({'"+this.directionMode[0]+"':-"+(this.currentNo*start)+"})");
  266. },
  267. fxStart:function( index, obj, currentObj ){
  268. if( this.settings.direction == 'opacity' ) {
  269. var text = '.lof-main-item-desc';
  270. $(text).slideUp(200);
  271. $(this.slides).stop().animate({opacity:0}, {
  272. duration: this.settings.duration,
  273. easing:this.settings.easing,
  274. complete:function(){
  275. $(this).css({'display':'none'});
  276. }
  277. });
  278. $(this.slides).eq(index).stop().animate( {opacity:1}, {
  279. duration: this.settings.duration,
  280. easing:this.settings.easing,
  281. step:function(){
  282. $(this).css({'display':'block'})
  283. },
  284. complete:function(){
  285. $(this).find(text).slideDown(200);
  286. }
  287. });
  288. }else {
  289. var text = '.lof-main-item-desc';
  290. $(this.wrapper).find(text).slideUp(200);
  291. this.wrapper.stop().animate( obj, {
  292. duration: this.settings.duration,
  293. easing:this.settings.easing,
  294. complete:function() {
  295. $(this).find(text).slideDown(200); } });
  296. }
  297. return this;
  298. },
  299. jumping:function( no, manual ){
  300. this.stop();
  301. if( this.currentNo == no ) return;
  302. var obj = eval("({'"+this.directionMode[0]+"':-"+(this.maxSize*no)+"})");
  303. this.onProcessing( null, manual, 0, this.maxSize )
  304. .fxStart( no, obj, this )
  305. .finishFx( manual );
  306. this.currentNo = no;
  307. },
  308. next:function( manual , item){
  309.  
  310. this.currentNo += (this.currentNo < this.slides.length-1) ? 1 : (1 - this.slides.length);
  311. this.onProcessing( item, manual, 0, this.maxSize )
  312. .fxStart( this.currentNo, this.getObjectDirection(this.maxSize ), this )
  313. .finishFx( manual );
  314. },
  315. previous:function( manual, item ){
  316. this.currentNo += this.currentNo > 0 ? -1 : this.slides.length - 1;
  317. this.onProcessing( item, manual )
  318. .fxStart( this.currentNo, this.getObjectDirection(this.maxSize ), this )
  319. .finishFx( manual );
  320. },
  321. play:function( delay, direction, wait ){
  322. this.stop();
  323. if(!wait){ this[direction](false); }
  324. var self = this;
  325. this.isRun = setTimeout(function() { self[direction](true); }, delay);
  326. },
  327. stop:function(){
  328. if (this.isRun == null) return;
  329. clearTimeout(this.isRun);
  330. this.isRun = null;
  331. }
  332. })
  333. })(jQuery)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement