diff --git a/.jshintrc b/.jshintrc index 34e8388..cdbe5de 100644 --- a/.jshintrc +++ b/.jshintrc @@ -7,7 +7,7 @@ "immed": true, "noarg": true, "onevar": true, - "quotmark": "double", + "quotmark": "single", "smarttabs": true, "trailing": true, "unused": true, diff --git a/Gruntfile.js b/Gruntfile.js index 45eb6dd..6b06adb 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -20,8 +20,8 @@ module.exports = function(grunt) { // Concat definitions concat: { dist: { - src: ["src/jquery.boilerplate.js"], - dest: "dist/jquery.boilerplate.js" + src: ["src/jquery.flexloader.js"], + dest: "dist/jquery.flexloader.js" }, options: { banner: "<%= meta.banner %>" @@ -30,7 +30,7 @@ module.exports = function(grunt) { // Lint definitions jshint: { - files: ["src/jquery.boilerplate.js"], + files: ["src/jquery.flexloader.js"], options: { jshintrc: ".jshintrc" } @@ -40,7 +40,7 @@ module.exports = function(grunt) { copy: { main: { files: [ - {expand: true, src: ['src/jquery.boilerplate.js'], dest: 'dist/jquery.boilerplate.js', filter: 'isFile'} + {expand: true, src: ['src/jquery.flexloader.js'], dest: 'dist/jquery.flexloader.js', filter: 'isFile'} ] } }, @@ -48,8 +48,8 @@ module.exports = function(grunt) { // Minify definitions uglify: { my_target: { - src: ["dist/jquery.boilerplate.js"], - dest: "dist/jquery.boilerplate.min.js" + src: ["dist/jquery.flexloader.js"], + dest: "dist/jquery.flexloader.min.js" }, options: { banner: "<%= meta.banner %>" diff --git a/dist/jquery.boilerplate.js b/dist/jquery.boilerplate.js deleted file mode 100644 index 473bdd2..0000000 --- a/dist/jquery.boilerplate.js +++ /dev/null @@ -1,66 +0,0 @@ -/* - * jQuery Boilerplate - v3.3.1 - * A jump-start for jQuery plugins development. - * http://jqueryboilerplate.com - * - * Made by Zeno Rocha - * Under MIT License - */ -// the semi-colon before function invocation is a safety net against concatenated -// scripts and/or other plugins which may not be closed properly. -;(function ( $, window, document, undefined ) { - - // undefined is used here as the undefined global variable in ECMAScript 3 is - // mutable (ie. it can be changed by someone else). undefined isn't really being - // passed in so we can ensure the value of it is truly undefined. In ES5, undefined - // can no longer be modified. - - // window and document are passed through as local variable rather than global - // as this (slightly) quickens the resolution process and can be more efficiently - // minified (especially when both are regularly referenced in your plugin). - - // Create the defaults once - var pluginName = "defaultPluginName", - defaults = { - propertyName: "value" - }; - - // The actual plugin constructor - function Plugin ( element, options ) { - this.element = element; - // jQuery has an extend method which merges the contents of two or - // more objects, storing the result in the first object. The first object - // is generally empty as we don't want to alter the default options for - // future instances of the plugin - this.options = $.extend( {}, defaults, options ); - this._defaults = defaults; - this._name = pluginName; - this.init(); - } - - Plugin.prototype = { - init: function () { - // Place initialization logic here - // You already have access to the DOM element and - // the options via the instance, e.g. this.element - // and this.options - // you can add more functions like the one below and - // call them like so: this.yourOtherFunction(this.element, this.options). - console.log("xD"); - }, - yourOtherFunction: function () { - // some logic - } - }; - - // A really lightweight plugin wrapper around the constructor, - // preventing against multiple instantiations - $.fn[ pluginName ] = function ( options ) { - return this.each(function() { - if ( !$.data( this, "plugin_" + pluginName ) ) { - $.data( this, "plugin_" + pluginName, new Plugin( this, options ) ); - } - }); - }; - -})( jQuery, window, document ); diff --git a/dist/jquery.boilerplate.min.js b/dist/jquery.boilerplate.min.js deleted file mode 100644 index f8b3b26..0000000 --- a/dist/jquery.boilerplate.min.js +++ /dev/null @@ -1,9 +0,0 @@ -/* - * jQuery Boilerplate - v3.3.1 - * A jump-start for jQuery plugins development. - * http://jqueryboilerplate.com - * - * Made by Zeno Rocha - * Under MIT License - */ -(function(t){function n(n,o){this.element=n,this.options=t.extend({},e,o),this._defaults=e,this._name=i,this.init()}var i="defaultPluginName",e={propertyName:"value"};n.prototype={init:function(){console.log("xD")},yourOtherFunction:function(){}},t.fn[i]=function(e){return this.each(function(){t.data(this,"plugin_"+i)||t.data(this,"plugin_"+i,new n(this,e))})}})(jQuery,window,document); \ No newline at end of file diff --git a/dist/jquery.flexloader.js b/dist/jquery.flexloader.js new file mode 100644 index 0000000..4cec248 --- /dev/null +++ b/dist/jquery.flexloader.js @@ -0,0 +1,406 @@ +/* + * jQuery Flexloader - v0.0.1 + * Lazyload Flexslider slides, optionally using Picturefill + * http://shaekuronen.github.io/jquery.flexloader + * + * Made by Shae Kuronen + * Under MIT License + */ +;(function($) { + + $.flexloader = function(flexslider, options) { + + // constructor + function Flexloader(flexslider, options) { + + this.flexslider = flexslider; + this.current_slide = 0; + this.next_slide = 0; + this.prev_slide = 0; + this.last_slide = 0; + this.visible_slides = 0; + this.offset = 0; + this.slide_ids = []; + // flexslider.slides does not include any cloned elements + this.$slides = $(this.flexslider.slides); + this.options = $.extend({ + picturefill: false, + background_images: false, + class_name: 'flexloader-background-image-loaded' + }, options); + + // if the slider.move is defined, set offset to that, otherwise set to 1 + (typeof this.flexslider.move !== 'undefined') ? this.offset = this.flexslider.move : this.offset = 1; + + this.current_slide = this.flexslider.currentSlide; + + this.last_slide = this.flexslider.last; + + // if flexslider.visible is defined, calculate the visible items, otherwise set visible_slides to 0 + // don't forget, flexslider.visible is zero indexed and is the quantity of visible slides + // so if there are 6 visible slides in the slideshow, flexslider.visible will be 5 + (typeof this.flexslider.visible !== 'undefined') ? this.visible_slides = this.calculate_visible_items() : this.visible_slides = 0; + + // these functions add slides to the slide_ids array + this.get_current_slides(); + this.get_next_slides(); + this.get_prev_slides(); + + this.init(); + + } + // end constructor + + // plugin prototype methods + Flexloader.prototype = { + + init: function() { + + var _this = this; + + // if this slideshow implements picturefill + if (this.options.picturefill === true) { + + // load the slides + _this.load_picturefill_slides(this.slide_ids); + + // load any cloned slides + _this.load_picturefill_cloned_slides(); + + // if this slideshow has background images + } else if (this.options.background_images === true) { + + // load slides with background images + _this.load_background_image_slides(this.slide_ids); + + // load any cloned slides + _this.load_background_image_clone_slides(); + + } else { + + // load the slides + _this.load_slides(this.slide_ids); + + // load any cloned slides + _this.load_cloned_slides(); + + } + + }, + + // flexslider does not correctly calculate visible items for a carousel + // because does not take into account slider.itemMargin + // TODO - figure out why this flexslider code is not working + // slider.itemW = (slider.minW > slider.w) ? (slider.w - (slideMargin * (minItems - 1)))/minItems : + // (slider.maxW < slider.w) ? (slider.w - (slideMargin * (maxItems - 1)))/maxItems : + // (slider.vars.itemWidth > slider.w) ? slider.w : slider.vars.itemWidth; + // + // slider.visible = Math.floor(slider.w/(slider.itemW)); + // https://github.com/woothemes/FlexSlider/blob/master/jquery.flexslider.js + calculate_visible_items: function() { + + var slider_width, + item_width; + + slider_width = (this.flexslider.viewport===undefined) ? this.flexslider.width() : this.flexslider.viewport.width(); + item_width = this.flexslider.vars.itemWidth + this.flexslider.vars.itemMargin; + + return Math.floor(slider_width / item_width); + + }, + + // GET THE IDS OF SLIDES TO LOAD + + // get the currently visible slides and add to slide_ids array + get_current_slides: function() { + + var first_visible_slide = this.current_slide * this.offset, + last_visible_slide = first_visible_slide + this.visible_slides, + i; + + for (i = first_visible_slide; i <= last_visible_slide; i++) { + this.slide_ids.push(i); + } + + }, + // end get the currently visible slides + + // get the next slides + get_next_slides: function() { + + var current_last_slide = (this.current_slide * this.offset) + this.visible_slides, + future_last_slide = current_last_slide + this.offset, + i; + + // if this is the last slide + if (this.current_slide === this.last_slide) { + + // add the first slide + this.slide_ids.push(0); + + } else { + + for (i = future_last_slide; i > current_last_slide; i--) { + this.slide_ids.push(i); + } + + } + + }, + // end get the next slides + + // get the prev slides + get_prev_slides: function() { + + var adjusted_last_slide, + future_last_slide, + current_first_slide, + future_first_slide, + i; + + // if this is the first slide + if (this.current_slide === 0) { + + // calculate the last slides (or last slide if not a carousel) + adjusted_last_slide = (this.last_slide * this.offset) + this.visible_slides; + future_last_slide = adjusted_last_slide + this.offset; + + // add the last slides + for (i = adjusted_last_slide; i < future_last_slide; i++) { + this.slide_ids.push(i); + } + + // if this is any slide except the first slide + } else { + + current_first_slide = this.current_slide * this.offset; + future_first_slide = current_first_slide - this.offset; + + for (i = future_first_slide; i < current_first_slide; i++) { + this.slide_ids.push(i); + } + + } + + }, + // end get the prev slides + + // END GET THE IDS OF SLIDES TO LOAD + + // NO PICTUREFILL LOAD SLIDES + load_slides: function(_slides_ids) { + + var _this = this; + + $(_slides_ids).each(function(index) { + + var slide_id = _slides_ids[index], + current_src, + current_data_original, + $slide = $(_this.$slides[slide_id]); + + current_src = $slide.find('img').attr('src'); + current_data_original = $slide.find('img').attr('data-original'); + + // if there is a data-original attribute and it has not already been loaded into src + if ( current_data_original !== 'undefined' && current_src !== current_data_original ) { + + // update the current slide source + $slide.find('img').attr('src', current_data_original); + + } + + }); + + }, + // END NO PICTUREFILL LOAD SLIDES + + // NO PICTUREFILL LOAD CLONED SLIDES + load_cloned_slides: function() { + + if ( $(this.flexslider).find('.clone').length > 0 ) { + + // get the cloned slides + $(this.flexslider).find('.clone').each(function() { + + var $clone_slide_image = $(this).find('img'), + current_src, + current_data_original; + + // get this slide's picturefill element and get the value of it's first span data-src + current_src = $clone_slide_image.attr('src'); + + current_data_original = $clone_slide_image.attr('data-original'); + + // if there is a data-original attribute and it has not already been loaded into src + if ( current_data_original !== 'undefined' && current_src !== current_data_original ) { + + // load data-original into img src + $clone_slide_image.attr('src', current_data_original); + + } + + }); + + } + + }, + // END NO PICTUREFILL LOAD CLONED SLIDES + + // PICTUREFILL LOAD SLIDES + load_picturefill_slides: function(_slides) { + + var _this = this; + + $(_slides).each(function(_slide) { + + var slide_id = _slides[_slide], + picturefill_container, + current_data_src, + current_data_original, + $spans; + + // get the jquery object for this slide and find an element with attribute data-picture + picturefill_container = $(_this.$slides[slide_id]).find('[data-picture]'); + + // get this slide's picturefill element and get the value of it's first span data-src + current_data_src = $(picturefill_container).find('span').attr('data-src'); + + current_data_original = $(picturefill_container).find('span').attr('data-original'); + + // if there is a data-original attribute and it has not already been loaded into src + if ( current_data_original !== 'undefined' && current_data_src !== current_data_original ) { + + // get all the children span elements of the picturefill container + $spans = $(picturefill_container).find('span'); + + // for each span in the picturefill container span + $.each($spans, function(index) { + + var $span = $($spans[index]), + source = $span.attr('data-original'); + + $span.attr('data-src', source); + + // if this span has a child element img + if ($span.find('img').length > 0) { + $span.find('img').attr('src', source); + } + + }); + + } + + }); + + }, + // END PICTUREFILL LOAD SLIDES + + // PICTUREFILL LOAD CLONED SLIDES + load_picturefill_cloned_slides: function() { + + if ( $(this.flexslider).find('.clone').length > 0 ) { + + // get the cloned slides + $(this.flexslider).find('.clone').each(function() { + + var $clone_slide = $(this), + picturefill_container, + current_data_src, + current_data_original, + $spans; + + // get the jquery object for this slide and find an element with attribute data-picture + picturefill_container = $clone_slide.find('[data-picture]'); + + // get this slide's picturefill element and get the value of it's first span data-src + current_data_src = $(picturefill_container).find('span').attr('data-src'); + + current_data_original = $(picturefill_container).find('span').attr('data-original'); + + // if there is a data-original attribute and it has not already been loaded into src + if ( current_data_original !== 'undefined' && current_data_src !== current_data_original ) { + + // get all the children span elements of the picturefill container + $spans = $(picturefill_container).find('span'); + + // for each span in the picturefill container span + $.each($spans, function(index) { + + var $span = $($spans[index]), + source = $span.attr('data-original'); + + $span.attr('data-src', source); + + // if this span has a child element img + if ($span.find('img').length > 0) { + $span.find('img').attr('src', source); + } + + }); + + } + + }); + + } + + }, + // END PICTUREFILL LOAD CLONED SLIDES + + // LOAD SLIDES WITH BACKGROUND IMAGES + load_background_image_slides: function(_slides_ids) { + + var _this = this; + + // for each slide id in the slide_ids array + $(_slides_ids).each(function(index, _slide_id) { + + // get the slide and add load the image by adding the background image loaded class + $(_this.$slides[_slide_id]).addClass(_this.options.class_name); + + }); + + }, + // END LOAD SLIDES WITH BACKGROUND IMAGES + + // LOAD CLONE SLIDES WITH BACKGROUND IMAGES + load_background_image_clone_slides: function() { + + var _this = this; + + // if the slider has cloned slides + if ( $(_this.flexslider).find('.clone').length > 0 ) { + + // get the cloned slides + $(_this.flexslider).find('.clone').each(function(index, slide) { + + // for each cloned slide add class to load the background image + $(slide).addClass(_this.options.class_name); + + }); + + } + + } + // END LOAD CLONE SLIDES WITH BACKGROUND IMAGES + + }; + // end plugin prototype methods + + // wrapper to prevent multiple instances of flexloader + if ( !$.data(this, 'plugin_flexloader') ) { + + // add a data attribute + $.data(this, 'plugin_flexloader'); + + // create an instance of flexloader + return new Flexloader(flexslider, options); + + } + // end wrapper to prevent multiple instances of flexloader + + }; + +}(jQuery)); + diff --git a/dist/jquery.flexloader.min.js b/dist/jquery.flexloader.min.js new file mode 100644 index 0000000..eb5ee87 --- /dev/null +++ b/dist/jquery.flexloader.min.js @@ -0,0 +1,9 @@ +/* + * jQuery Flexloader - v0.0.1 + * Lazyload Flexslider slides, optionally using Picturefill + * http://shaekuronen.github.io/jquery.flexloader + * + * Made by Shae Kuronen + * Under MIT License + */ +!function(a){a.flexloader=function(b,c){function d(b,c){this.flexslider=b,this.current_slide=0,this.next_slide=0,this.prev_slide=0,this.last_slide=0,this.visible_slides=0,this.offset=0,this.slide_ids=[],this.$slides=a(this.flexslider.slides),this.options=a.extend({picturefill:!1,background_images:!1,class_name:"flexloader-background-image-loaded"},c),this.offset="undefined"!=typeof this.flexslider.move?this.flexslider.move:1,this.current_slide=this.flexslider.currentSlide,this.last_slide=this.flexslider.last,this.visible_slides="undefined"!=typeof this.flexslider.visible?this.calculate_visible_items():0,this.get_current_slides(),this.get_next_slides(),this.get_prev_slides(),this.init()}return d.prototype={init:function(){var a=this;this.options.picturefill===!0?(a.load_picturefill_slides(this.slide_ids),a.load_picturefill_cloned_slides()):this.options.background_images===!0?(a.load_background_image_slides(this.slide_ids),a.load_background_image_clone_slides()):(a.load_slides(this.slide_ids),a.load_cloned_slides())},calculate_visible_items:function(){var a,b;return a=void 0===this.flexslider.viewport?this.flexslider.width():this.flexslider.viewport.width(),b=this.flexslider.vars.itemWidth+this.flexslider.vars.itemMargin,Math.floor(a/b)},get_current_slides:function(){var a,b=this.current_slide*this.offset,c=b+this.visible_slides;for(a=b;c>=a;a++)this.slide_ids.push(a)},get_next_slides:function(){var a,b=this.current_slide*this.offset+this.visible_slides,c=b+this.offset;if(this.current_slide===this.last_slide)this.slide_ids.push(0);else for(a=c;a>b;a--)this.slide_ids.push(a)},get_prev_slides:function(){var a,b,c,d,e;if(0===this.current_slide)for(a=this.last_slide*this.offset+this.visible_slides,b=a+this.offset,e=a;b>e;e++)this.slide_ids.push(e);else for(c=this.current_slide*this.offset,d=c-this.offset,e=d;c>e;e++)this.slide_ids.push(e)},load_slides:function(b){var c=this;a(b).each(function(d){var e,f,g=b[d],h=a(c.$slides[g]);e=h.find("img").attr("src"),f=h.find("img").attr("data-original"),"undefined"!==f&&e!==f&&h.find("img").attr("src",f)})},load_cloned_slides:function(){a(this.flexslider).find(".clone").length>0&&a(this.flexslider).find(".clone").each(function(){var b,c,d=a(this).find("img");b=d.attr("src"),c=d.attr("data-original"),"undefined"!==c&&b!==c&&d.attr("src",c)})},load_picturefill_slides:function(b){var c=this;a(b).each(function(d){var e,f,g,h,i=b[d];e=a(c.$slides[i]).find("[data-picture]"),f=a(e).find("span").attr("data-src"),g=a(e).find("span").attr("data-original"),"undefined"!==g&&f!==g&&(h=a(e).find("span"),a.each(h,function(b){var c=a(h[b]),d=c.attr("data-original");c.attr("data-src",d),c.find("img").length>0&&c.find("img").attr("src",d)}))})},load_picturefill_cloned_slides:function(){a(this.flexslider).find(".clone").length>0&&a(this.flexslider).find(".clone").each(function(){var b,c,d,e,f=a(this);b=f.find("[data-picture]"),c=a(b).find("span").attr("data-src"),d=a(b).find("span").attr("data-original"),"undefined"!==d&&c!==d&&(e=a(b).find("span"),a.each(e,function(b){var c=a(e[b]),d=c.attr("data-original");c.attr("data-src",d),c.find("img").length>0&&c.find("img").attr("src",d)}))})},load_background_image_slides:function(b){var c=this;a(b).each(function(b,d){a(c.$slides[d]).addClass(c.options.class_name)})},load_background_image_clone_slides:function(){var b=this;a(b.flexslider).find(".clone").length>0&&a(b.flexslider).find(".clone").each(function(c,d){a(d).addClass(b.options.class_name)})}},a.data(this,"plugin_flexloader")?void 0:(a.data(this,"plugin_flexloader"),new d(b,c))}}(jQuery); \ No newline at end of file diff --git a/src/jquery.flexloader.js b/src/jquery.flexloader.js index ec02529..ef7eca0 100644 --- a/src/jquery.flexloader.js +++ b/src/jquery.flexloader.js @@ -2,8 +2,6 @@ $.flexloader = function(flexslider, options) { - var Flexloader; - // constructor function Flexloader(flexslider, options) { @@ -55,334 +53,343 @@ // if this slideshow implements picturefill if (this.options.picturefill === true) { - // load the slides - _this.load_picturefill_slides(this.slide_ids); + // load the slides + _this.load_picturefill_slides(this.slide_ids); - // load any cloned slides - _this.load_picturefill_cloned_slides(); + // load any cloned slides + _this.load_picturefill_cloned_slides(); - // if this slideshow has background images - } else if (this.options.background_images === true) { + // if this slideshow has background images + } else if (this.options.background_images === true) { - // load slides with background images - _this.load_background_image_slides(this.slide_ids); + // load slides with background images + _this.load_background_image_slides(this.slide_ids); - // load any cloned slides - _this.load_background_image_clone_slides(); + // load any cloned slides + _this.load_background_image_clone_slides(); } else { - // load the slides - _this.load_slides(this.slide_ids); + // load the slides + _this.load_slides(this.slide_ids); - // load any cloned slides - _this.load_cloned_slides(); + // load any cloned slides + _this.load_cloned_slides(); } }, - // flexslider does not correctly calculate visible items for a carousel - // because does not take into account slider.itemMargin - // TODO - figure out why this flexslider code is not working - // slider.itemW = (slider.minW > slider.w) ? (slider.w - (slideMargin * (minItems - 1)))/minItems : - // (slider.maxW < slider.w) ? (slider.w - (slideMargin * (maxItems - 1)))/maxItems : - // (slider.vars.itemWidth > slider.w) ? slider.w : slider.vars.itemWidth; - // - // slider.visible = Math.floor(slider.w/(slider.itemW)); - // https://github.com/woothemes/FlexSlider/blob/master/jquery.flexslider.js - calculate_visible_items: function() { + // flexslider does not correctly calculate visible items for a carousel + // because does not take into account slider.itemMargin + // TODO - figure out why this flexslider code is not working + // slider.itemW = (slider.minW > slider.w) ? (slider.w - (slideMargin * (minItems - 1)))/minItems : + // (slider.maxW < slider.w) ? (slider.w - (slideMargin * (maxItems - 1)))/maxItems : + // (slider.vars.itemWidth > slider.w) ? slider.w : slider.vars.itemWidth; + // + // slider.visible = Math.floor(slider.w/(slider.itemW)); + // https://github.com/woothemes/FlexSlider/blob/master/jquery.flexslider.js + calculate_visible_items: function() { - var slider_width, - item_width; + var slider_width, + item_width; - slider_width = (this.flexslider.viewport===undefined) ? this.flexslider.width() : this.flexslider.viewport.width(); - item_width = this.flexslider.vars.itemWidth + this.flexslider.vars.itemMargin; + slider_width = (this.flexslider.viewport===undefined) ? this.flexslider.width() : this.flexslider.viewport.width(); + item_width = this.flexslider.vars.itemWidth + this.flexslider.vars.itemMargin; - return Math.floor(slider_width / item_width); + return Math.floor(slider_width / item_width); - }, + }, - // GET THE IDS OF SLIDES TO LOAD + // GET THE IDS OF SLIDES TO LOAD - // get the currently visible slides and add to slide_ids array - get_current_slides: function() { + // get the currently visible slides and add to slide_ids array + get_current_slides: function() { - var first_visible_slide = this.current_slide * this.offset, - last_visible_slide = first_visible_slide + this.visible_slides; + var first_visible_slide = this.current_slide * this.offset, + last_visible_slide = first_visible_slide + this.visible_slides, + i; - for (var i = first_visible_slide; i <= last_visible_slide; i++) { - this.slide_ids.push(i); - } + for (i = first_visible_slide; i <= last_visible_slide; i++) { + this.slide_ids.push(i); + } - }, - // end get the currently visible slides + }, + // end get the currently visible slides - // get the next slides - get_next_slides: function() { + // get the next slides + get_next_slides: function() { - var current_last_slide = (this.current_slide * this.offset) + this.visible_slides, - future_last_slide = current_last_slide + this.offset; + var current_last_slide = (this.current_slide * this.offset) + this.visible_slides, + future_last_slide = current_last_slide + this.offset, + i; - // if this is the last slide - if (this.current_slide === this.last_slide) { + // if this is the last slide + if (this.current_slide === this.last_slide) { - // add the first slide - this.slide_ids.push(0); + // add the first slide + this.slide_ids.push(0); - } else { + } else { - for (var i = future_last_slide; i > current_last_slide; i--) { - this.slide_ids.push(i); - } + for (i = future_last_slide; i > current_last_slide; i--) { + this.slide_ids.push(i); + } - } + } - }, - // end get the next slides + }, + // end get the next slides - // get the prev slides - get_prev_slides: function() { + // get the prev slides + get_prev_slides: function() { - // if this is the first slide - if (this.current_slide === 0) { + var adjusted_last_slide, + future_last_slide, + current_first_slide, + future_first_slide, + i; - // calculate the last slides (or last slide if not a carousel) - var adjusted_last_slide = (this.last_slide * this.offset) + this.visible_slides, - future_last_slide = adjusted_last_slide + this.offset; + // if this is the first slide + if (this.current_slide === 0) { - // add the last slides - for (var i = adjusted_last_slide; i < future_last_slide; i++) { - this.slide_ids.push(i); - } + // calculate the last slides (or last slide if not a carousel) + adjusted_last_slide = (this.last_slide * this.offset) + this.visible_slides; + future_last_slide = adjusted_last_slide + this.offset; - // if this is any slide except the first slide - } else { + // add the last slides + for (i = adjusted_last_slide; i < future_last_slide; i++) { + this.slide_ids.push(i); + } - var current_first_slide = this.current_slide * this.offset, - future_first_slide = current_first_slide - this.offset; + // if this is any slide except the first slide + } else { - for (var i = future_first_slide; i < current_first_slide; i++) { - this.slide_ids.push(i); - } + current_first_slide = this.current_slide * this.offset; + future_first_slide = current_first_slide - this.offset; - } + for (i = future_first_slide; i < current_first_slide; i++) { + this.slide_ids.push(i); + } - }, - // end get the prev slides + } - // END GET THE IDS OF SLIDES TO LOAD + }, + // end get the prev slides - // NO PICTUREFILL LOAD SLIDES - load_slides: function(_slides_ids) { + // END GET THE IDS OF SLIDES TO LOAD - var _this = this; + // NO PICTUREFILL LOAD SLIDES + load_slides: function(_slides_ids) { - $(_slides_ids).each(function(index) { + var _this = this; - var slide_id = _slides_ids[index], - current_src, - current_data_original, - $slide = $(_this.$slides[slide_id]); + $(_slides_ids).each(function(index) { - current_src = $slide.find('img').attr('src'); - current_data_original = $slide.find('img').attr('data-original'); + var slide_id = _slides_ids[index], + current_src, + current_data_original, + $slide = $(_this.$slides[slide_id]); - // if there is a data-original attribute and it has not already been loaded into src - if ( current_data_original !== 'undefined' && current_src !== current_data_original ) { + current_src = $slide.find('img').attr('src'); + current_data_original = $slide.find('img').attr('data-original'); - // update the current slide source - $slide.find('img').attr('src', current_data_original); + // if there is a data-original attribute and it has not already been loaded into src + if ( current_data_original !== 'undefined' && current_src !== current_data_original ) { - } + // update the current slide source + $slide.find('img').attr('src', current_data_original); - }); - }, - // END NO PICTUREFILL LOAD SLIDES + } - // NO PICTUREFILL LOAD CLONED SLIDES - load_cloned_slides: function() { + }); - if ( $(this.flexslider).find('.clone').length > 0 ) { + }, + // END NO PICTUREFILL LOAD SLIDES - // get the cloned slides - $(this.flexslider).find('.clone').each(function() { + // NO PICTUREFILL LOAD CLONED SLIDES + load_cloned_slides: function() { - var $clone_slide_image = $(this).find('img'), - current_src, - current_data_original; + if ( $(this.flexslider).find('.clone').length > 0 ) { - // get this slide's picturefill element and get the value of it's first span data-src - current_src = $clone_slide_image.attr('src'); + // get the cloned slides + $(this.flexslider).find('.clone').each(function() { - current_data_original = $clone_slide_image.attr('data-original'); + var $clone_slide_image = $(this).find('img'), + current_src, + current_data_original; - // if there is a data-original attribute and it has not already been loaded into src - if ( current_data_original !== 'undefined' && current_src !== current_data_original ) { + // get this slide's picturefill element and get the value of it's first span data-src + current_src = $clone_slide_image.attr('src'); - // load data-original into img src - $clone_slide_image.attr('src', current_data_original); + current_data_original = $clone_slide_image.attr('data-original'); - } + // if there is a data-original attribute and it has not already been loaded into src + if ( current_data_original !== 'undefined' && current_src !== current_data_original ) { - }); + // load data-original into img src + $clone_slide_image.attr('src', current_data_original); - } + } - }, - // END NO PICTUREFILL LOAD CLONED SLIDES + }); - // PICTUREFILL LOAD SLIDES - load_picturefill_slides: function(_slides) { + } - var _this = this; + }, + // END NO PICTUREFILL LOAD CLONED SLIDES + + // PICTUREFILL LOAD SLIDES + load_picturefill_slides: function(_slides) { + + var _this = this; - $(_slides).each(function(_slide) { + $(_slides).each(function(_slide) { - var slide_id = _slides[_slide], - picturefill_container, - current_data_src, - current_data_original, - $slide = $(_this.$slides[slide_id]), - $noscript; + var slide_id = _slides[_slide], + picturefill_container, + current_data_src, + current_data_original, + $spans; - // get the jquery object for this slide and find an element with attribute data-picture - picturefill_container = $(_this.$slides[slide_id]).find('[data-picture]'); + // get the jquery object for this slide and find an element with attribute data-picture + picturefill_container = $(_this.$slides[slide_id]).find('[data-picture]'); - // get this slide's picturefill element and get the value of it's first span data-src - current_data_src = $(picturefill_container).find('span').attr('data-src'); + // get this slide's picturefill element and get the value of it's first span data-src + current_data_src = $(picturefill_container).find('span').attr('data-src'); - current_data_original = $(picturefill_container).find('span').attr('data-original'); + current_data_original = $(picturefill_container).find('span').attr('data-original'); - // if there is a data-original attribute and it has not already been loaded into src - if ( current_data_original !== 'undefined' && current_data_src !== current_data_original ) { + // if there is a data-original attribute and it has not already been loaded into src + if ( current_data_original !== 'undefined' && current_data_src !== current_data_original ) { - // get all the children span elements of the picturefill container - var $spans = $(picturefill_container).find('span'); + // get all the children span elements of the picturefill container + $spans = $(picturefill_container).find('span'); - // for each span in the picturefill container span - $.each($spans, function(index, value) { + // for each span in the picturefill container span + $.each($spans, function(index) { - var $span = $($spans[index]), - source = $span.attr('data-original'); + var $span = $($spans[index]), + source = $span.attr('data-original'); - $span.attr('data-src', source); + $span.attr('data-src', source); - // if this span has a child element img - if ($span.find('img').length > 0) { - $span.find('img').attr('src', source); - } + // if this span has a child element img + if ($span.find('img').length > 0) { + $span.find('img').attr('src', source); + } - }); + }); - } + } - }); + }); - }, - // END PICTUREFILL LOAD SLIDES + }, + // END PICTUREFILL LOAD SLIDES - // PICTUREFILL LOAD CLONED SLIDES - load_picturefill_cloned_slides: function() { + // PICTUREFILL LOAD CLONED SLIDES + load_picturefill_cloned_slides: function() { - if ( $(this.flexslider).find('.clone').length > 0 ) { + if ( $(this.flexslider).find('.clone').length > 0 ) { - // get the cloned slides - $(this.flexslider).find('.clone').each(function() { + // get the cloned slides + $(this.flexslider).find('.clone').each(function() { - var $clone_slide = $(this), - picturefill_container, - current_data_src, - current_data_original; + var $clone_slide = $(this), + picturefill_container, + current_data_src, + current_data_original, + $spans; - // get the jquery object for this slide and find an element with attribute data-picture - picturefill_container = $clone_slide.find('[data-picture]'); + // get the jquery object for this slide and find an element with attribute data-picture + picturefill_container = $clone_slide.find('[data-picture]'); - // get this slide's picturefill element and get the value of it's first span data-src - current_data_src = $(picturefill_container).find('span').attr('data-src'); + // get this slide's picturefill element and get the value of it's first span data-src + current_data_src = $(picturefill_container).find('span').attr('data-src'); - current_data_original = $(picturefill_container).find('span').attr('data-original'); + current_data_original = $(picturefill_container).find('span').attr('data-original'); - // if there is a data-original attribute and it has not already been loaded into src - if ( current_data_original !== 'undefined' && current_data_src !== current_data_original ) { + // if there is a data-original attribute and it has not already been loaded into src + if ( current_data_original !== 'undefined' && current_data_src !== current_data_original ) { - // get all the children span elements of the picturefill container - var $spans = $(picturefill_container).find('span'); + // get all the children span elements of the picturefill container + $spans = $(picturefill_container).find('span'); - // for each span in the picturefill container span - $.each($spans, function(index, value) { + // for each span in the picturefill container span + $.each($spans, function(index) { - var $span = $($spans[index]), - source = $span.attr('data-original'); + var $span = $($spans[index]), + source = $span.attr('data-original'); - $span.attr('data-src', source); + $span.attr('data-src', source); - // if this span has a child element img - if ($span.find('img').length > 0) { - $span.find('img').attr('src', source); - } + // if this span has a child element img + if ($span.find('img').length > 0) { + $span.find('img').attr('src', source); + } - }); + }); - } + } - }); + }); - } + } - }, - // END PICTUREFILL LOAD CLONED SLIDES + }, + // END PICTUREFILL LOAD CLONED SLIDES - // LOAD SLIDES WITH BACKGROUND IMAGES - load_background_image_slides: function(_slides_ids) { + // LOAD SLIDES WITH BACKGROUND IMAGES + load_background_image_slides: function(_slides_ids) { - var _this = this; + var _this = this; - // for each slide id in the slide_ids array - $(_slides_ids).each(function(index, _slide_id) { + // for each slide id in the slide_ids array + $(_slides_ids).each(function(index, _slide_id) { - // get the slide and add load the image by adding the background image loaded class - $(_this.$slides[_slide_id]).addClass(_this.options.class_name); + // get the slide and add load the image by adding the background image loaded class + $(_this.$slides[_slide_id]).addClass(_this.options.class_name); - }); + }); - }, - // END LOAD SLIDES WITH BACKGROUND IMAGES + }, + // END LOAD SLIDES WITH BACKGROUND IMAGES - // LOAD CLONE SLIDES WITH BACKGROUND IMAGES - load_background_image_clone_slides: function() { + // LOAD CLONE SLIDES WITH BACKGROUND IMAGES + load_background_image_clone_slides: function() { - var _this = this; + var _this = this; - // if the slider has cloned slides - if ( $(_this.flexslider).find('.clone').length > 0 ) { + // if the slider has cloned slides + if ( $(_this.flexslider).find('.clone').length > 0 ) { - // get the cloned slides - $(_this.flexslider).find('.clone').each(function(index, slide) { + // get the cloned slides + $(_this.flexslider).find('.clone').each(function(index, slide) { - // for each cloned slide add class to load the background image - $(slide).addClass(_this.options.class_name); + // for each cloned slide add class to load the background image + $(slide).addClass(_this.options.class_name); - }); + }); - } + } - } - // END LOAD CLONE SLIDES WITH BACKGROUND IMAGES + } + // END LOAD CLONE SLIDES WITH BACKGROUND IMAGES }; // end plugin prototype methods // wrapper to prevent multiple instances of flexloader - if ( !$.data( this, "plugin_flexloader" ) ) { + if ( !$.data(this, 'plugin_flexloader') ) { - // add a data attribute - $.data( this, "plugin_flexloader"); + // add a data attribute + $.data(this, 'plugin_flexloader'); - // create an instance of flexloader - return new Flexloader(flexslider, options); + // create an instance of flexloader + return new Flexloader(flexslider, options); - } + } // end wrapper to prevent multiple instances of flexloader };