PageSourceSearch

https://www.cutpoint-inc.com/assets/plugins/master-slider/source/views/BasicView.js

js cutpoint-inc.com collected 2026-10-02 01:28:38 UTC 14,727 bytes, 544 lines download raw bytes

1;(function($){
2
3	"use strict";
4
5	window.MSBasicView = function(options){
6
7		this.options = {
8			loop 			: false,
9			dir  			: 'h',
10			autoHeight 		: false,
11			spacing			: 5,
12			mouseSwipe		: true,
13			swipe			: true,
14			speed			: 17,
15			minSlideSpeed	: 2,
16			viewNum			: 20,
17			critMargin		: 1
18		};
19
20		$.extend(this.options , options);
21
22		this.dir		= this.options.dir;
23		this.loop   	= this.options.loop;
24		this.spacing	= this.options.spacing;
25
26		this.__width  = 0;
27		this.__height = 0;
28
29		this.__cssProb 		= this.dir === 'h' ? 'left'    : 'top';
30		this.__offset 		= this.dir === 'h' ? 'offsetLeft' : 'offsetTop';
31		this.__dimension    = this.dir === 'h' ? '__width' : '__height';
32
33		this.__translate_end	= window._css3d ? ' translateZ(0px)' : '';
34
35		this.$slideCont	= $('<div></div>').addClass('ms-slide-container');
36		this.$element 	= $('<div></div>').addClass('ms-view').addClass('ms-basic-view').append(this.$slideCont);
37
38		this.currentSlide 	= null;
39		this.index 			= -1;
40		this.slidesCount	= 0;
41
42		this.slides			= [];
43		this.slideList		= []; // All of slides with added priority sort;
44		this.viewSlidesList = [];
45
46		this.css3 			= window._cssanim;
47		this.start_buffer = 0;
48		this.firstslide_snap = 0;
49
50		this.slideChanged 	= false;
51
52		this.controller 	 = new Controller(0 , 0 , {
53			snapping	     : true,
54			snapsize		 : 100,
55			paging			 : true,
56			snappingMinSpeed : this.options.minSlideSpeed,
57			friction		 : (100 - this.options.speed * 0.5) / 100,
58			endless			 : this.loop
59		});
60
61		this.controller.renderCallback(this.dir === 'h'? this._horizUpdate : this._vertiUpdate , this);
62		this.controller.snappingCallback(this.__snapUpdate , this);
63		this.controller.snapCompleteCallback(this.__snapCompelet , this);
64
65		averta.EventDispatcher.call(this);
66	};
67
68	var p = MSBasicView.prototype;
69
70	/*-------------- METHODS --------------*/
71
72	p.__snapCompelet = function(snap , type){
73		// if(this.loop && Math.abs(this.__contPos) > 20000){
74		// 	this.__locateSlides();
75		// 	this.gotoSlide(this.index , true);
76		// }
77		//
78
79		if ( !this.slideChanged ) {
80			return;
81		}
82
83		this.slideChanged = false;
84
85		this.__locateSlides();
86		this.start_buffer = 0;
87		this.dispatchEvent(new MSViewEvents(MSViewEvents.CHANGE_END));
88	};
89
90	p.__snapUpdate = function(controller , snap , change){
91
92		if(this.loop){
93			var target_index = this.index + change;
94			this.updateLoop(target_index);
95
96			if(target_index >= this.slidesCount)	target_index = target_index - this.slidesCount;
97			if(target_index <  0)					target_index = this.slidesCount + target_index;
98
99			this.index = target_index;
100		}else{
101			if(snap < 0 ||  snap >= this.slidesCount) return
102			this.index = snap;
103		}
104
105		this._checkCritMargins();
106
107		if($.browser.mozilla){
108			this.slideList[this.index].$element[0].style.marginTop 	= '0.1px';
109			if(this.currentSlide){
110				this.currentSlide.$element[0].style.marginTop 	= '';
111			}
112		}
113		var new_slide = this.slideList[this.index];
114		if(new_slide === this.currentSlide)return;
115		this.currentSlide = new_slide;
116
117		if ( this.autoUpdateZIndex ) {
118			this.__updateSlidesZindex();
119		}
120
121		this.slideChanged = true;
122		this.dispatchEvent(new MSViewEvents(MSViewEvents.CHANGE_START));
123	};
124
125
126	p._checkCritMargins = function(){
127		if(this.normalMode) return;
128
129		var hlf 	= Math.floor(this.options.viewNum / 2),
130			inView 	= this.viewSlidesList.indexOf(this.slideList[this.index]),
131			size 	= (this[this.__dimension] + this.spacing),
132			cm 		= this.options.critMargin;
133
134		if(this.loop){
135			if(inView <= cm || inView >= this.viewSlidesList.length - cm){
136				size *= (inView - hlf);
137				this.__locateSlides(false ,  size + this.start_buffer );
138				this.start_buffer += size;
139			}
140
141			return;
142		}
143
144		if( (inView < cm && this.index >= cm ) || (inView >= this.viewSlidesList.length - cm && this.index < this.slidesCount - cm)){
145			this.__locateSlides(false);
146		}
147
148	};
149
150
151	p._vertiUpdate = function(controller , value){
152
153		this.__contPos = value;
154		this.dispatchEvent(new MSViewEvents(MSViewEvents.SCROLL));
155
156		if(this.css3){
157			this.$slideCont[0].style[window._jcsspfx + 'Transform'] = 'translateY('+-value+'px)' + this.__translate_end;
158			return;
159		}
160
161		this.$slideCont[0].style.top = -value + 'px';
162
163	};
164
165	p._horizUpdate = function(controller , value){
166
167		this.__contPos = value;
168		this.dispatchEvent(new MSViewEvents(MSViewEvents.SCROLL));
169
170		if(this.css3) {
171			this.$slideCont[0].style[window._jcsspfx + 'Transform'] = 'translateX('+-value+'px)'+ this.__translate_end;
172			return;
173		}
174
175		this.$slideCont[0].style.left = -value + 'px';
176
177	};
178
179
180	p.__updateViewList = function(){
181
182		if(this.normalMode) {
183			this.viewSlidesList = this.slides;
184			return;
185		}
186
187		var temp = this.viewSlidesList.slice();
188
189		// update view list
190		this.viewSlidesList = [];
191		var i = 0 , hlf = Math.floor(this.options.viewNum / 2) , l;
192
193		if(this.loop){
194			for(; i !== this.options.viewNum ; i++)
195				this.viewSlidesList.push(this.slides[this.currentSlideLoc - hlf + i]);
196		}else{
197			// before
198			for(i = 0 ; i !== hlf && this.index - i !== -1 ; i++)
199				this.viewSlidesList.unshift(this.slideList[this.index - i]);
200			// after
201			for(i = 1; i !== hlf && this.index + i !== this.slidesCount; i++)
202				this.viewSlidesList.push(this.slideList[this.index + i]);
203		}
204
205		for (i = 0 , l = temp.length ; i !== l ; i++)
206			if( this.viewSlidesList.indexOf(temp[i]) === -1)
207				temp[i].sleep();
208
209		temp = null;
210
211		if( this.currentSlide ) {
212			this.__updateSlidesZindex();
213		}
214	};
215
216	p.__locateSlides = function(move , start){
217
218		this.__updateViewList();
219
220		start = !this.loop ? this.slides.indexOf(this.viewSlidesList[0]) * (this[this.__dimension] + this.spacing ) : start || 0;
221
222		// old method
223		/*for(i = 0; i < this.slidesCount ; ++i){
224			var pos =  i * (this[this.__dimension] + this.spacing);
225
226			this.slides[i].position = pos;
227			this.slides[i].$element[0].style[this.__cssProb] =  pos + 'px';
228		}*/
229
230		var l = this.viewSlidesList.length , slide;
231
232		for(var i = 0; i !== l ; i++){
233			var pos =  start + i * (this[this.__dimension] + this.spacing );
234			slide = this.viewSlidesList[i];
235			slide.wakeup();
236			slide.position = pos;
237			slide.$element[0].style[this.__cssProb] =  pos + 'px';
238		}
239
240		if(move !== false)this.controller.changeTo( this.slideList[this.index].position , false , null , null , false);
241
242	};
243
244	p.__createLoopList = function(){
245		var return_arr = [];
246		var i = 0,
247			count = this.slidesCount / 2;
248
249		var before_count  = (this.slidesCount % 2 === 0)? count - 1	: Math.floor(count);
250		var after_count	  = (this.slidesCount % 2 === 0)? count 	: Math.floor(count);
251
252		this.currentSlideLoc = before_count;
253
254		// before
255		for(i = 1 ; i <= before_count ; ++i)
256			return_arr.unshift(this.slideList[(this.index - i < 0)? this.slidesCount -  i + this.index: this.index - i]);
257
258		// current
259		return_arr.push(this.slideList[this.index]);
260
261		// after
262		for(i = 1; i <= after_count; ++i)
263			return_arr.push(this.slideList[(this.index + i >= this.slidesCount)? this.index + i - this.slidesCount : this.index + i]);
264
265		return return_arr;
266
267	};
268
269	/*
270	 * Calculate shortest distance from index to target.
271	 * It will used in loop gesture.
272	 *
273	 * Negative values means left direction.
274	 */
275
276	p.__getSteps = function(index , target){
277		var right = (target < index)?  this.slidesCount - index + target : target - index;
278		var left  = Math.abs(this.slidesCount - right);
279
280		return (right < left)? right : -left;
281	};
282
283	p.__pushEnd = function(){
284		var first_slide = this.slides.shift();
285		var last_slide = this.slides[this.slidesCount - 2];
286
287		this.slides.push(first_slide);
288
289		if(!this.normalMode) return;
290
291		var pos = last_slide.$element[0][this.__offset] + this.spacing + this[this.__dimension];
292		first_slide.$element[0].style[this.__cssProb] = pos + 'px';
293		first_slide.position = pos;
294	};
295
296	p.__pushStart = function(){
297		var last_slide =  this.slides.pop();
298		var first_slide = this.slides[0];
299
300		this.slides.unshift(last_slide);
301
302		if(!this.normalMode) return;
303
304		var pos = first_slide.$element[0][this.__offset] - this.spacing - this[this.__dimension];
305		last_slide.$element[0].style[this.__cssProb] = pos + 'px';
306		last_slide.position = pos;
307	};
308
309	// @since 1.7.0
310	// adds z-index to slides
311	p.__updateSlidesZindex = function(){
312
313
314		var slide,
315			l = this.viewSlidesList.length,
316			hlf = Math.floor( l/2 );
317
318		if( this.loop ){
319			var loc = this.viewSlidesList.indexOf(this.currentSlide);
320			for ( var i = 0; i!==l; i++ ){
321				slide = this.viewSlidesList[i];
322				this.viewSlidesList[i].$element.css('z-index', i<=loc ? i+1 : l-i);
323			}
324		} else {
325
326			var beforeNum = this.currentSlide.index - this.viewSlidesList[0].index,
327				afterNum = l - beforeNum,
328				diff = beforeNum - afterNum;
329
330			for ( var i = 0; i!==l; i++ ){
331				this.viewSlidesList[i].$element.css('z-index', i<=beforeNum ? i+1 : l-i);
332			}
333
334			this.currentSlide.$element.css('z-index', l);
335		}
336
337	};
338
339	p.addSlide = function(slide){
340		slide.view = this;
341		this.slides.push(slide);
342		this.slideList.push(slide);
343		this.slidesCount++;
344	};
345
346	p.appendSlide = function(slide){
347		this.$slideCont.append(slide.$element);
348	};
349
350	p.updateLoop = function(index){
351		if(this.loop){
352			var steps = this.__getSteps(this.index , index);
353
354			for(var i = 0 , l = Math.abs(steps) ; i < l ; ++ i){
355				if(steps < 0) 	this.__pushStart();
356				else			this.__pushEnd();
357			}
358		}
359	};
360
361	p.gotoSlide = function(index , fast){
362		this.updateLoop(index);
363		this.index = index;
364
365		var target_slide = this.slideList[index];
366
367		this._checkCritMargins();
368
369		this.controller.changeTo( target_slide.position , !fast , null , null , false);
370		if(target_slide === this.currentSlide) return;
371		this.slideChanged = true;
372		this.currentSlide = target_slide;
373
374		if ( this.autoUpdateZIndex ) {
375			this.__updateSlidesZindex();
376		}
377
378		this.dispatchEvent(new MSViewEvents(MSViewEvents.CHANGE_START));
379		if(fast)this.dispatchEvent(new MSViewEvents(MSViewEvents.CHANGE_END));
380	};
381
382	p.next = function(checkLoop){
383		if ( checkLoop && !this.loop && this.index + 1 >= this.slidesCount ) {
384			this.controller.bounce(10);
385			return;
386		}
387
388		this.gotoSlide((this.index + 1 >= this.slidesCount)? 0 : this.index + 1);
389	};
390
391	p.previous = function(checkLoop){
392		if ( checkLoop && !this.loop && this.index - 1 < 0 ) {
393			this.controller.bounce(-10);
394			return;
395		}
396
397		this.gotoSlide((this.index - 1 < 0)? this.slidesCount - 1 : this.index - 1);
398	};
399
400	/* --------------- Swipe control ------------------*/
401
402	p.setupSwipe = function(){
403
404		this.swipeControl = new averta.TouchSwipe(this.$element);
405		this.swipeControl.swipeType = this.dir === 'h'? 'horizontal' : 'vertical';
406		var that = this;
407
408		if(this.dir === 'h'){
409			this.swipeControl.onSwipe = function(status){
410				that.horizSwipeMove(status);
411			};
412		}else{
413			this.swipeControl.onSwipe = function(status){
414				that.vertSwipeMove(status);
415			};
416		}
417
418	};
419
420	p.vertSwipeMove = function(status){
421		var phase = status.phase;
422		if(phase === 'start'){
423			this.controller.stop();
424			this.dispatchEvent(new MSViewEvents(MSViewEvents.SWIPE_START, status));
425		}else if(phase === 'move' && (!this.loop || Math.abs(this.currentSlide.position - this.controller.value + status.moveY ) < this.cont_size / 2)){
426			this.controller.drag(status.moveY);
427			this.dispatchEvent(new MSViewEvents(MSViewEvents.SWIPE_MOVE, status));
428		}else if(phase === 'end' || phase === 'cancel'){
429
430            var speed = status.distanceY / status.duration * 50/3,
431			    speedh = Math.abs( status.distanceY / status.duration * 50/3 );
432
433			if ( Math.abs(speed) > 0.1 && Math.abs(speed) >= speedh ){
434				this.controller.push(-speed);
435				if(speed > this.controller.options.snappingMinSpeed)
436				this.dispatchEvent(new MSViewEvents(MSViewEvents.SWIPE_END, status));
437			}else {
438				this.controller.cancel();
439				this.dispatchEvent(new MSViewEvents(MSViewEvents.SWIPE_CANCEL, status));
440			}
441
442		}
443	};
444
445	p.horizSwipeMove = function(status){
446		var phase = status.phase;
447
448		if(phase === 'start'){
449			this.controller.stop();
450			this.dispatchEvent(new MSViewEvents(MSViewEvents.SWIPE_
450START, status));
451		}else if(phase === 'move' && (!this.loop || Math.abs(this.currentSlide.position - this.controller.value + status.moveX ) < this.cont_size / 2)){
452			this.controller.drag(status.moveX);
453			this.dispatchEvent(new MSViewEvents(MSViewEvents.SWIPE_MOVE, status));
454		}else if(phase === 'end' || phase === 'cancel'){
455
456			var speed = status.distanceX / status.duration * 50/3,
457                speedv = Math.abs( status.distanceY / status.duration * 50/3 );
458
459			if ( Math.abs(speed) > 0.1 && Math.abs(speed) >= speedv ) {
460				this.controller.push(-speed );
461				if(speed > this.controller.options.snappingMinSpeed)
462				this.dispatchEvent(new MSViewEvents(MSViewEvents.SWIPE_END, status));
463			}else{
464				this.controller.cancel();
465				this.dispatchEvent(new MSViewEvents(MSViewEvents.SWIPE_CANCEL, status));
466			}
467
468		}
469	};
470
471	/* ------------------------------------------------*/
472
473	p.setSize = function(width , height , hard){
474		if(this.lastWidth === width && height === this.lastHeight && !hard) return;
475
476		this.$element.width(width).height(height);
477
478		for(var i = 0; i < this.slidesCount ; ++i)
479				this.slides[i].setSize(width , height , hard);
480
481		this.__width 	= width;
482		this.__height 	= height;
483
484		if(this.__created){
485			this.__locateSlides();
486
487			this.cont_size = (this.slidesCount - 1) * (this[this.__dimension] + this.spacing);
488			if(!this.loop) 	this.controller._max_value = this.cont_size;
489
490			this.controller.options.snapsize = this[this.__dimension] + this.spacing;
491			this.controller.changeTo(this.currentSlide.position , false , null , null , false );
492			this.controller.cancel();
493
494			this.lastWidth = width;
495			this.lastHeight = height;
496		}
497	};
498
499	p.create = function(index){
500
501		this.__created = true;
502
503		this.index = Math.min((index || 0), this.slidesCount - 1);
504		this.lastSnap = this.index; // it will be used to check snap changed or not on snap complete
505
506		if(this.loop)
507			this.slides = this.__createLoopList();
508
509		this.normalMode = this.slidesCount <= this.options.viewNum;
510
511		for(var i = 0; i < this.slidesCount ; ++i)
512			this.slides[i].create();
513
514		this.__locateSlides();
515
516		this.controller.options.snapsize = this[this.__dimension] + this.spacing;
517		if(!this.loop)	this.controller._max_value = (this.slidesCount - 1) * (this[this.__dimension] + this.spacing);
518
519		this.gotoSlide(this.index , true);
520
521		if(this.options.swipe && (window._touch || this.options.mouseSwipe))
522			this.setupSwipe();
523
524	};
525
526	p.destroy = function(){
527		if(!this.__created) return;
528
529		for(var i = 0; i < this.slidesCount ; ++i)
530			this.slides[i].destroy();
531
532		this.slides = null;
533		this.slideList = null;
534		this.$element.remove();
535
536		this.controller.destroy();
537		this.controller = null;
538	};
539
540	averta.EventDispatcher.extend(p);
541
542	MSSlideController.registerView('basic' , MSBasicView);
543
544})(jQuery);

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.