diff --git a/README.md b/README.md index 9e56887..7216263 100644 --- a/README.md +++ b/README.md @@ -90,7 +90,7 @@ Addons: script-based tagging of lazy loaded elements - [jquery.lazyloadxt.script.js + jquery.lazyloadxt.script.js jquery.lazyloadxt.script.min.js diff --git a/dist/jqlight.lazyloadxt.js b/dist/jqlight.lazyloadxt.js index 767e07d..5428d2b 100644 --- a/dist/jqlight.lazyloadxt.js +++ b/dist/jqlight.lazyloadxt.js @@ -1,9 +1,13 @@ -/*! Lazy Load XT v1.1.0 2016-01-12 +/*! Lazy Load XT v1.1.0 2016-01-28 * http://ressio.github.io/lazy-load-xt * (C) 2016 RESS.io * Licensed under MIT */ (function (window, document, Element, undefined) { + var prev_$ = window.$, + DATAKEYPROP = '__jqlight_data__', + matches = Element.matches || Element.matchesSelector || Element.mozMatchesSelector || Element.msMatchesSelector || Element.oMatchesSelector || Element.webkitMatchesSelector; + function Wrapper(collection) { if (collection) { for (var i = 0, length = collection.length; i < length; i++) { @@ -21,18 +25,15 @@ : (selector && (selector === window || selector.nodeType) ? [selector] : selector)); } - $.fn = { + Wrapper.prototype = $.fn = { constructor: Wrapper, length: 0 }; - Wrapper.prototype = $.fn; - $.extend = function (target) { - var options, name, copy, i = 0, length = arguments.length; - if (length <= 1) { - target = this; - } else { - i = 1; + $.fn.extend = $.extend = function () { + var options, name, copy, target = this, i = 0, length = arguments.length; + if (length > 1) { + target = arguments[i++]; } for (; i < length; i++) { options = arguments[i]; @@ -45,10 +46,6 @@ } return target; }; - $.fn.extend = $.extend; - - var prev_$ = window.$; - window.$ = $; $.extend({ noConflict: function () { @@ -69,36 +66,34 @@ return false; }, each: function (array, callback) { - var value, i = 0, length = array.length; - for (; i < length; i++) { - value = array[i]; - if (callback.call(value, i, value) === false) { + for (var i = 0, length = array.length ; i < length; i++) { + if (callback(i, array[i]) === false) { return false; } } return true; }, - grep: function (elems, callback, invert) { + grep: function (array, callback, invert) { var callbackInverse, matches = [], i = 0, - length = elems.length, + length = array.length, callbackExpect = !invert; for (; i < length; i++) { - callbackInverse = !callback(i, elems[i]); + callbackInverse = !callback(i, array[i]); if (callbackInverse !== callbackExpect) { - matches.push(elems[i]); + matches.push(array[i]); } } return matches; }, - map: function (elems, callback) { + map: function (array, callback) { var value, i = 0, - length = elems.length, + length = array.length, ret = []; for (; i < length; i++) { - value = callback(i, elems[i]); + value = callback(array[i], i); if (value != null) { ret.push(value); } @@ -107,12 +102,23 @@ } }); - var DATAKEYPROP = '__jqlight_data__'; $.fn.extend({ - each: function (callback, args) { - $.each(this, callback, args); + each: function (callback) { + $.each(this, function (index, elem) { + return callback.call(elem, index, elem); + }); return this; }, + map: function (callback) { + return $($.map(this, function (elem, index) { + return callback.call(elem, index, elem); + })); + }, + filter: function (callback) { + return $($.grep(this, function (index, elem) { + return callback.call(elem, index, elem); + })); + }, ready: function (fn) { if (/complete|loaded|interactive/.test(document.readyState) && document.body) { fn(); @@ -138,7 +144,7 @@ selector = undefined; } types = types.split(' '); - return this.each(function (i, elem) { + return this.each(function (index, elem) { var listener = selector ? delegateHandler.bind(elem, selector, fn) : fn; $.each(types, function (j, eventName) { if (eventName) { @@ -148,13 +154,14 @@ }); }, off: function (types, selector, fn) { + // Note: off() for delegated events is not supported if (selector === false || $.isFunction(selector)) { // ( types [, fn] ) fn = selector; - selector = undefined; + // selector = undefined; } types = types.split(' '); - return this.each(function (i, elem) { + return this.each(function (index, elem) { $.each(types, function (j, eventName) { if (eventName) { elem.removeEventListener(eventName, fn); @@ -179,29 +186,25 @@ var elem = this[0]; return elem && elem[DATAKEYPROP] ? elem[DATAKEYPROP][key] : undefined; } - this.each(function (i, elem) { + this.each(function (index, elem) { elem[DATAKEYPROP] = elem[DATAKEYPROP] || {}; elem[DATAKEYPROP][key] = value; }); return this; }, - map: function (callback) { - return $($.map(this, callback)); - }, - filter: function (callback) { - return $($.grep(this, callback)); - }, attr: function (name, value) { if (value === undefined) { return this.length ? this[0].getAttribute(name) : undefined; } - $.each(this, function (i, elem) { - elem.setAttribute(name, value + ''); + this.each(function () { + this.setAttribute(name, value + ''); }); return this; } }); + window.$ = $; + function eachClass(obj, value, callback) { var classes = ( value || '' ).match(/\S+/g) || [], elem, cur, clazz, j, origValue, finalValue, @@ -212,8 +215,7 @@ if (elem.nodeType === 1) { origValue = elem.className; cur = origValue ? ( ' ' + origValue + ' ' ).replace(/[\t\r\n\f]/g, ' ') : ' '; - j = 0; - while ((clazz = classes[j++])) { + for (j = 0; (clazz = classes[j++]); ) { cur = callback(cur, clazz, cur.indexOf(' ' + clazz + ' ') >= 0); } finalValue = cur.slice(1, -1); @@ -226,27 +228,12 @@ } function delegateHandler(selector, handler, event) { - var currentTarget = closest.call([event.target], selector, this)[0]; - if (currentTarget && currentTarget !== this) { - handler.call(currentTarget, event); - } - } - - var matches = Element.matches || Element.matchesSelector || Element.mozMatchesSelector || Element.msMatchesSelector || Element.oMatchesSelector || Element.webkitMatchesSelector; - - function closest(selector, context) { - var nodes = []; - $.each(this, function (i, node) { - while (node && node !== context) { - if (matches.call(node, selector)) { - nodes.push(node); - break; - } - node = node.parentElement; + var node = event.target; + while (node && node !== this) { + if (matches.call(node, selector)) { + return handler.call(node, event); } - }); - return $($.grep(nodes, function (index, item) { - return nodes.indexOf(item) === index; - })); + node = node.parentElement; + } } })(window, document, Element.prototype); diff --git a/dist/jqlight.lazyloadxt.min.js b/dist/jqlight.lazyloadxt.min.js index aca0c3d..e80d37f 100644 --- a/dist/jqlight.lazyloadxt.min.js +++ b/dist/jqlight.lazyloadxt.min.js @@ -1,2 +1,2 @@ /* Lazy Load XT 1.1.0 | MIT License */ -!function(a,b,c,d){function e(a){if(a){for(var b=0,c=a.length;c>b;b++)this[b]=a[b];this.length=c}}function f(c){return c instanceof e?c:new e("string"==typeof c?b.querySelectorAll(c):c&&(c===a||c.nodeType)?[c]:c)}function g(a,b,c){for(var d,e,f,g,h,i,j=(b||"").match(/\S+/g)||[],k=0,l=a.length;l>k;)if(d=a[k++],1===d.nodeType){for(h=d.className,e=h?(" "+h+" ").replace(/[\t\r\n\f]/g," "):" ",g=0;f=j[g++];)e=c(e,f,e.indexOf(" "+f+" ")>=0);i=e.slice(1,-1),h!==i&&(d.className=i)}return a}function h(a,b,c){var d=i.call([c.target],a,this)[0];d&&d!==this&&b.call(d,c)}function i(a,b){var c=[];return f.each(this,function(d,e){for(;e&&e!==b;){if(l.call(e,a)){c.push(e);break}e=e.parentElement}}),f(f.grep(c,function(a,b){return c.indexOf(b)===a}))}f.fn={constructor:e,length:0},e.prototype=f.fn,f.extend=function(a){var b,c,e,f=0,g=arguments.length;for(1>=g?a=this:f=1;g>f;f++){b=arguments[f];for(c in b)e=b[c],e!==d&&e!==a&&(a[c]=e)}return a},f.fn.extend=f.extend;var j=a.$;a.$=f,f.extend({noConflict:function(){return a.$=j,f},isFunction:function(a){return"function"==typeof a},contains:function(a,b){if(b)for(;b=b.parentNode;)if(b===a)return!0;return!1},each:function(a,b){for(var c,d=0,e=a.length;e>d;d++)if(c=a[d],b.call(c,d,c)===!1)return!1;return!0},grep:function(a,b,c){for(var d,e=[],f=0,g=a.length,h=!c;g>f;f++)d=!b(f,a[f]),d!==h&&e.push(a[f]);return e},map:function(a,b){for(var c,d=0,e=a.length,f=[];e>d;d++)c=b(d,a[d]),null!=c&&f.push(c);return f}});var k="__jqlight_data__";f.fn.extend({each:function(a,b){return f.each(this,a,b),this},ready:function(a){return/complete|loaded|interactive/.test(b.readyState)&&b.body?a():f(b).on("DOMContentLoaded",a),this},addClass:function(a){return g(this,a,function(a,b,c){return c?a:a+b+" "})},removeClass:function(a){return g(this,a,function(a,b,c){return c?a.replace(" "+b+" "," "):a})},on:function(a,b,c){return null==c&&(c=b,b=d),a=a.split(" "),this.each(function(d,e){var g=b?h.bind(e,b,c):c;f.each(a,function(a,b){b&&e.addEventListener(b,g)})})},off:function(a,b,c){return(b===!1||f.isFunction(b))&&(c=b,b=d),a=a.split(" "),this.each(function(b,d){f.each(a,function(a,b){b&&d.removeEventListener(b,c)})})},trigger:function(c,d){return this.each(function(){var e;a.CustomEvent?e=new CustomEvent(c,{detail:d}):(e=b.createEvent("CustomEvent"),e.initCustomEvent(c,!0,!0,d)),this.dispatchEvent(e)})},data:function(a,b){if("string"==typeof a&&b===d){var c=this[0];return c&&c[k]?c[k][a]:d}return this.each(function(c,d){d[k]=d[k]||{},d[k][a]=b}),this},map:function(a){return f(f.map(this,a))},filter:function(a){return f(f.grep(this,a))},attr:function(a,b){return b===d?this.length?this[0].getAttribute(a):d:(f.each(this,function(c,d){d.setAttribute(a,b+"")}),this)}});var l=c.matches||c.matchesSelector||c.mozMatchesSelector||c.msMatchesSelector||c.oMatchesSelector||c.webkitMatchesSelector}(window,document,Element.prototype); \ No newline at end of file +!function(a,b,c,d){function e(a){if(a){for(var b=0,c=a.length;c>b;b++)this[b]=a[b];this.length=c}}function f(c){return c instanceof e?c:new e("string"==typeof c?b.querySelectorAll(c):c&&(c===a||c.nodeType)?[c]:c)}function g(a,b,c){for(var d,e,f,g,h,i,j=(b||"").match(/\S+/g)||[],k=0,l=a.length;l>k;)if(d=a[k++],1===d.nodeType){for(h=d.className,e=h?(" "+h+" ").replace(/[\t\r\n\f]/g," "):" ",g=0;f=j[g++];)e=c(e,f,e.indexOf(" "+f+" ")>=0);i=e.slice(1,-1),h!==i&&(d.className=i)}return a}function h(a,b,c){for(var d=c.target;d&&d!==this;){if(k.call(d,a))return b.call(d,c);d=d.parentElement}}var i=a.$,j="__jqlight_data__",k=c.matches||c.matchesSelector||c.mozMatchesSelector||c.msMatchesSelector||c.oMatchesSelector||c.webkitMatchesSelector;e.prototype=f.fn={constructor:e,length:0},f.fn.extend=f.extend=function(){var a,b,c,e=this,f=0,g=arguments.length;for(g>1&&(e=arguments[f++]);g>f;f++){a=arguments[f];for(b in a)c=a[b],c!==d&&c!==e&&(e[b]=c)}return e},f.extend({noConflict:function(){return a.$=i,f},isFunction:function(a){return"function"==typeof a},contains:function(a,b){if(b)for(;b=b.parentNode;)if(b===a)return!0;return!1},each:function(a,b){for(var c=0,d=a.length;d>c;c++)if(b(c,a[c])===!1)return!1;return!0},grep:function(a,b,c){for(var d,e=[],f=0,g=a.length,h=!c;g>f;f++)d=!b(f,a[f]),d!==h&&e.push(a[f]);return e},map:function(a,b){for(var c,d=0,e=a.length,f=[];e>d;d++)c=b(a[d],d),null!=c&&f.push(c);return f}}),f.fn.extend({each:function(a){return f.each(this,function(b,c){return a.call(c,b,c)}),this},map:function(a){return f(f.map(this,function(b,c){return a.call(b,c,b)}))},filter:function(a){return f(f.grep(this,function(b,c){return a.call(c,b,c)}))},ready:function(a){return/complete|loaded|interactive/.test(b.readyState)&&b.body?a():f(b).on("DOMContentLoaded",a),this},addClass:function(a){return g(this,a,function(a,b,c){return c?a:a+b+" "})},removeClass:function(a){return g(this,a,function(a,b,c){return c?a.replace(" "+b+" "," "):a})},on:function(a,b,c){return null==c&&(c=b,b=d),a=a.split(" "),this.each(function(d,e){var g=b?h.bind(e,b,c):c;f.each(a,function(a,b){b&&e.addEventListener(b,g)})})},off:function(a,b,c){return(b===!1||f.isFunction(b))&&(c=b),a=a.split(" "),this.each(function(b,d){f.each(a,function(a,b){b&&d.removeEventListener(b,c)})})},trigger:function(c,d){return this.each(function(){var e;a.CustomEvent?e=new CustomEvent(c,{detail:d}):(e=b.createEvent("CustomEvent"),e.initCustomEvent(c,!0,!0,d)),this.dispatchEvent(e)})},data:function(a,b){if("string"==typeof a&&b===d){var c=this[0];return c&&c[j]?c[j][a]:d}return this.each(function(c,d){d[j]=d[j]||{},d[j][a]=b}),this},attr:function(a,b){return b===d?this.length?this[0].getAttribute(a):d:(this.each(function(){this.setAttribute(a,b+"")}),this)}}),a.$=f}(window,document,Element.prototype); \ No newline at end of file diff --git a/lazyloadxt.jquery.json b/lazyloadxt.jquery.json index 391776f..d8584af 100644 --- a/lazyloadxt.jquery.json +++ b/lazyloadxt.jquery.json @@ -6,8 +6,8 @@ "homepage": "http://ressio.github.io/lazy-load-xt", "author": { "name": "RESS.io", - "email": "hello@ress.io", - "url": "http://ress.io/" + "email": "denis@mobilejoomla.com", + "url": "http://ressio.github.io/" }, "keywords": ["effect", "image", "images", "jquery", "jquerymobile", "lazy", "lazyload", "load", "media", "mobile", "performance", "responsive", "speed", "video", "vimeo", "youtube"], "bugs": "https://github.com/ressio/lazy-load-xt/issues", diff --git a/package.json b/package.json index 423f29e..45c7876 100644 --- a/package.json +++ b/package.json @@ -6,8 +6,8 @@ "homepage": "http://ressio.github.io/lazy-load-xt", "author": { "name": "RESS.io", - "email": "hello@ress.io", - "url": "http://ress.io/" + "email": "denis@mobilejoomla.com", + "url": "http://ressio.github.io/" }, "repository": { "type": "git", diff --git a/src/jqlight.lazyloadxt.js b/src/jqlight.lazyloadxt.js index 310e8e1..76f996d 100644 --- a/src/jqlight.lazyloadxt.js +++ b/src/jqlight.lazyloadxt.js @@ -6,6 +6,10 @@ (function (window, document, Element, undefined) { 'use strict'; + var prev_$ = window.$, + DATAKEYPROP = '__jqlight_data__', + matches = Element.matches || Element.matchesSelector || Element.mozMatchesSelector || Element.msMatchesSelector || Element.oMatchesSelector || Element.webkitMatchesSelector; + function Wrapper(collection) { if (collection) { for (var i = 0, length = collection.length; i < length; i++) { @@ -28,12 +32,10 @@ length: 0 }; - $.fn.extend = $.extend = function (target) { - var options, name, copy, i = 0, length = arguments.length; - if (length <= 1) { - target = this; - } else { - i = 1; + $.fn.extend = $.extend = function () { + var options, name, copy, target = this, i = 0, length = arguments.length; + if (length > 1) { + target = arguments[i++]; } for (; i < length; i++) { options = arguments[i]; @@ -47,9 +49,6 @@ return target; }; - var prev_$ = window.$; - window.$ = $; - $.extend({ noConflict: function () { window.$ = prev_$; @@ -105,7 +104,6 @@ } }); - var DATAKEYPROP = '__jqlight_data__'; $.fn.extend({ each: function (callback) { $.each(this, function (index, elem) { @@ -177,7 +175,7 @@ return this.each(function () { var evt; if (window.CustomEvent) { - evt = new CustomEvent(type, {detail: data}); + evt = new CustomEvent(type, {bubbles: true, cancelable: true, detail: data}); } else { evt = document.createEvent('CustomEvent'); evt.initCustomEvent(type, true, true, data); @@ -207,6 +205,8 @@ } }); + window.$ = $; + function eachClass(obj, value, callback) { var classes = ( value || '' ).match(/\S+/g) || [], elem, cur, clazz, j, origValue, finalValue, @@ -229,13 +229,11 @@ return obj; } - var matches = Element.matches || Element.matchesSelector || Element.mozMatchesSelector || Element.msMatchesSelector || Element.oMatchesSelector || Element.webkitMatchesSelector; - function delegateHandler(selector, handler, event) { var node = event.target; while (node && node !== this) { if (matches.call(node, selector)) { - return handler.call(node, event); + return handler.apply(node, [].concat(event, event.detail)); } node = node.parentElement; } diff --git a/src/jquery.lazyloadxt.js b/src/jquery.lazyloadxt.js index 566d37c..b804b40 100644 --- a/src/jquery.lazyloadxt.js +++ b/src/jquery.lazyloadxt.js @@ -215,7 +215,10 @@ src = $isFunction(srcAttr) ? srcAttr($el) : el.getAttribute(srcAttr); if (src) { - el.src = src; + if ( el.tagName === 'IFRAME' ) + el.contentWindow.location.replace( src ); + else + el.src = src; } removeNode = true;