PageSourceSearch

https://truthbetold.news/wp-content/themes/citynews/assets/js/jquery.flexloader.js

js truthbetold.news collected 2026-10-02 12:45:34 UTC 11,253 bytes, 398 lines download raw bytes

1;(function($) {
2
3	$.flexloader = function(flexslider, options) {
4
5		// constructor
6		function Flexloader(flexslider, options) {
7
8			this.flexslider = flexslider;
9			this.current_slide = 0;
10			this.next_slide = 0;
11			this.prev_slide = 0;
12			this.last_slide = 0;
13			this.visible_slides = 0;
14			this.offset = 0;
15			this.slide_ids = [];
16			// flexslider.slides does not include any cloned elements
17			this.$slides = $(this.flexslider.slides);
18			this.options = $.extend({
19				picturefill: false,
20				background_images: false,
21				class_name: 'flexloader-background-image-loaded'
22			}, options);
23
24			// if the slider.move is defined, set offset to that, otherwise set to 1
25			(typeof this.flexslider.move !== 'undefined') ? this.offset = this.flexslider.move : this.offset = 1;
26
27			this.current_slide = this.flexslider.currentSlide;
28
29			this.last_slide = this.flexslider.last;
30
31			// if flexslider.visible is defined, calculate the visible items, otherwise set visible_slides to 0
32			// don't forget, flexslider.visible is zero indexed and is the quantity of visible slides
33			// so if there are 6 visible slides in the slideshow, flexslider.visible will be 5
34			(typeof this.flexslider.visible !== 'undefined') ? this.visible_slides = this.calculate_visible_items() : this.visible_slides = 0;
35
36			// these functions add slides to the slide_ids array
37			this.get_current_slides();
38			this.get_next_slides();
39			this.get_prev_slides();
40
41			this.init();
42
43		}
44		// end constructor
45
46		// plugin prototype methods
47		Flexloader.prototype = {
48
49			init: function() {
50
51				var _this = this;
52
53				// if this slideshow implements picturefill
54				if (this.options.picturefill === true) {
55
56					// load the slides
57					_this.load_picturefill_slides(this.slide_ids);
58
59					// load any cloned slides
60					_this.load_picturefill_cloned_slides();
61
62				// if this slideshow has background images
63				} else if (this.options.background_images === true) {
64
65					// load slides with background images
66					_this.load_background_image_slides(this.slide_ids);
67
68					// load any cloned slides
69					_this.load_background_image_clone_slides();
70
71				} else {
72
73					// load the slides
74					_this.load_slides(this.slide_ids);
75
76					// load any cloned slides
77					_this.load_cloned_slides();
78
79				}
80
81			},
82
83			// flexslider does not correctly calculate visible items for a carousel
84			// because does not take into account slider.itemMargin
85			// TODO - figure out why this flexslider code is not working
86			// slider.itemW = (slider.minW > slider.w) ? (slider.w - (slideMargin * (minItems - 1)))/minItems :
87			//                (slider.maxW < slider.w) ? (slider.w - (slideMargin * (maxItems - 1)))/maxItems :
88			//                (slider.vars.itemWidth > slider.w) ? slider.w : slider.vars.itemWidth;
89			//
90			// slider.visible = Math.floor(slider.w/(slider.itemW));
91			// https://github.com/woothemes/FlexSlider/blob/master/jquery.flexslider.js
92			calculate_visible_items: function() {
93
94				var slider_width,
95						item_width;
96
97				slider_width = (this.flexslider.viewport===undefined) ? this.flexslider.width() : this.flexslider.viewport.width();
98				item_width = this.flexslider.vars.itemWidth + this.flexslider.vars.itemMargin;
99
100				return Math.floor(slider_width / item_width);
101
102			},
103
104			// GET THE IDS OF SLIDES TO LOAD
105
106			// get the currently visible slides and add to slide_ids array
107			get_current_slides: function() {
108
109				var first_visible_slide = this.current_slide * this.offset,
110						last_visible_slide = first_visible_slide + this.visible_slides,
111						i;
112
113				for (i = first_visible_slide; i <= last_visible_slide; i++) {
114					this.slide_ids.push(i);
115				}
116
117			},
118			// end get the currently visible slides
119
120			// get the next slides
121			get_next_slides: function() {
122
123				var current_last_slide = (this.current_slide * this.offset) + this.visible_slides,
124						future_last_slide = current_last_slide + this.offset,
125						i;
126
127				// if this is the last slide
128				if (this.current_slide === this.last_slide) {
129
130					// add the first slide
131					this.slide_ids.push(0);
132
133				} else {
134
135					for (i = future_last_slide; i > current_last_slide; i--) {
136						this.slide_ids.push(i);
137					}
138
139				}
140
141			},
142			// end get the next slides
143
144			// get the prev slides
145			get_prev_slides: function() {
146
147				var adjusted_last_slide,
148						future_last_slide,
149						current_first_slide,
150						future_first_slide,
151						i;
152
153				// if this is the first slide
154				if (this.current_slide === 0) {
155
156					// calculate the last slides (or last slide if not a carousel)
157					adjusted_last_slide = (this.last_slide * this.offset) + this.visible_slides;
158					future_last_slide = adjusted_last_slide + this.offset;
159
160					// add the last slides
161					for (i = adjusted_last_slide; i < future_last_slide; i++) {
162						this.slide_ids.push(i);
163					}
164
165				// if this is any slide except the first slide
166				} else {
167
168					current_first_slide = this.current_slide * this.offset;
169					future_first_slide = current_first_slide - this.offset;
170
171					for (i = future_first_slide; i < current_first_slide; i++) {
172						this.slide_ids.push(i);
173					}
174
175				}
176
177			},
178			// end get the prev slides
179
180			// END GET THE IDS OF SLIDES TO LOAD
181
182			// NO PICTUREFILL LOAD SLIDES
183			load_slides: function(_slides_ids) {
184
185				var _this = this;
186
187				$(_slides_ids).each(function(index) {
188
189					var slide_id = _slides_ids[index],
190							current_src,
191							current_data_original,
192							$slide = $(_this.$slides[slide_id]);
193
194					current_src = $slide.find('img').attr('src');
195					current_data_original = $slide.find('img').attr('data-original');
196
197					// if there is a data-original attribute and it has not already been loaded into src
198					if ( current_data_original !== 'undefined' && current_src !== current_data_original ) {
199
200						// update the current slide source
201						$slide.find('img').attr('src', current_data_original);
202
203					}
204
205				});
206
207			},
208			// END NO PICTUREFILL LOAD SLIDES
209
210			// NO PICTUREFILL LOAD CLONED SLIDES
211			load_cloned_slides: function() {
212
213					if ( $(this.flexslider).find('.clone').length > 0 ) {
214
215					// get the cloned slides
216						$(this.flexslider).find('.clone').each(function() {
217
218						var $clone_slide_image = $(this).find('img'),
219								current_src,
220								current_data_original;
221
222						// get this slide's picturefill element and get the value of it's first span data-src
223						current_src = $clone_slide_image.attr('src');
224
225						current_data_original = $clone_slide_image.attr('data-original');
226
227						// if there is a data-original attribute and it has not already been loaded into src
228						if ( current_data_original !== 'undefined' && current_src !== current_data_original ) {
229
230							// load data-original into img src
231							$clone_slide_image.attr('src', current_data_original);
232
233						}
234
235					});
236
237				}
238
239			},
240			// END NO PICTUREFILL LOAD CLONED SLIDES
241
242			// PICTUREFILL LOAD SLIDES
243			load_picturefill_slides: function(_slides) {
244
245				var _this = this;
246
247				$(_slides).each(function(_slide) {
248
249					var slide_id = _slides[_slide],
250							picturefill_container,
251							current_data_src,
252							current_data_original,
253							$spans;
254
255					// get the jquery object for this slide and find an element with attribute data-picture
256					picturefill_container = $(_this.$slides[slide_id]).find('[data-picture]');
257
258					// get this slide's picturefill element and get the value of it's first span data-src
259					current_data_src = $(picturefill_container).find('span').attr('data-src');
260
261					current_data_original = $(picturefill_container).find('span').attr('data-original');
262
263					// if there is a data-original attribute and it has not already been loaded into src
264					if ( current_data_original !== 'undefined' && current_data_src !== current_data_original ) {
265
266						// get all the children span elements of the picturefill container
267						$spans = $(picturefill_container).find('span');
268
269						// for each span in the picturefill container span
270						$.each($spans, function(index) {
271
272							var $span = $($spans[index]),
273									source = $span.attr('data-original');
274
275							$span.attr('data-src', source);
276
277							// if this span has a child element img
278							if ($span.find('img').length > 0) {
279								$span.find('img').attr('src', source);
280							}
281
282						});
283
284					}
285
286				});
287
288			},
289			// END PICTUREFILL LOAD SLIDES
290
291			// PICTUREFILL LOAD CLONED SLIDES
292			load_picturefill_cloned_slides: function() {
293
294				if ( $(this.flexslider).find('.clone').length > 0 ) {
295
296					// get the cloned slides
297					$(this.flexslider).find('.clone').each(function() {
298
299						var $clone_slide = $(this),
300						    picturefill_container,
301						    current_data_src,
302						    current_data_original,
303						    $spans;
304
305						// get the jquery object for this slide and find an element with attribute data-picture
306						picturefill_container = $clone_slide.find('[data-picture]');
307
308						// get this slide's picturefill element and get the value of it's first span data-src
309						current_data_src = $(picturefill_container).find('span').attr('data-src');
310
311						current_data_original = $(picturefill_container).find('span').attr('data-original');
312
313						// if there is a data-original attribute and it has not already been loaded into src
314						if ( current_data_original !== 'undefined' && current_data_src !== current_data_original ) {
315
316							// get all the children span elements of the picturefill container
317							$spans = $(picturefill_container).find('span');
318
319							// for each span in the picturefill container span
320							$.each($spans, function(index) {
321
322								var $span = $($spans[index]),
323										source = $span.attr('data-original');
324
325								$span.attr('data-src', source);
326
327								// if this span has a child element img
328								if ($span.find('img').length > 0) {
329									$span.find('img').attr('src', source);
330								}
331
332							});
333
334						}
335
336					});
337
338				}
339
340			},
341			// END PICTUREFILL LOAD CLONED SLIDES
342
343			// LOAD SLIDES WITH BACKGROUND IMAGES
344			load_background_image_slides: function(_slides_ids) {
345
346				var _this = this;
347
348				// for each slide id in the slide_ids array
349				$(_slides_ids).each(function(index, _slide_id) {
350
351					// get the slide and add load the image by adding the background image loaded class
352					$(_this.$slides[_slide_id]).addClass(_this.options.class_name);
353
354				});
355
356			},
357			// END LOAD SLIDES WITH BACKGROUND IMAGES
358
359			// LOAD CLONE SLIDES WITH BACKGROUND IMAGES
360			load_background_image_clone_slides: function() {
361
362				var _this = this;
363
364				// if the slider has cloned slides
365				if ( $(_this.flexslider).find('.clone').length > 0 ) {
366
367					// get the cloned slides
368					$(_this.flexslider).find('.clone').each(function(index, slide) {
369
370						// for each cloned slide add class to load the background image
371						$(slide).addClass(_this.options.class_name);
372
373					});
374
375				}
376
377			}
378			// END LOAD CLONE SLIDES WITH BACKGROUND IMAGES
379
380		};
381		// end plugin prototype methods
382
383		// wrapper to prevent multiple instances of flexloader
384		if ( !$.data(this, 'plugin_flexloader') ) {
385
386			// add a data attribute
387			$.data(this, 'plugin_flexloader');
388
389			// create an instance of flexloader
390			return new Flexloader(flexslider, options);
391
392		}
393		// end wrapper to prevent multiple instances of flexloader
394
395  };
396
397}(jQuery));
398

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.