vendor/assets/javascripts/webshims/shims/dom-extend.js in webshims-rails-1.13.0 vs vendor/assets/javascripts/webshims/shims/dom-extend.js in webshims-rails-1.14.1

- old
+ new

@@ -177,12 +177,12 @@ $(evtDel).off(evt, fn); } }); return this; }; - - var dataID = '_webshimsLib'+ (Math.round(Math.random() * 1000)); + var idCount = 0; + var dataID = '_webshims'+ (Math.round(Math.random() * 1000)); var elementData = function(elem, key, val){ elem = elem.jquery ? elem[0] : elem; if(!elem){return val || {};} var data = $.data(elem, dataID); if(val !== undefined){ @@ -209,10 +209,39 @@ } }); return this.pushStack(elems); }; }); + + function clone(elem, dataAndEvents, uniqueIds){ + var cloned = $.clone( elem, dataAndEvents, false ); + $(cloned.querySelectorAll('.'+webshims.shadowClass)).detach(); + if(uniqueIds){ + idCount++; + $(cloned.querySelectorAll('[id]')).prop('id', function(i, id){ + return id +idCount; + }); + } else { + $(cloned.querySelectorAll('audio[id^="ID-"], video[id^="ID-"], label[id^="ID-"]')).removeAttr('id'); + } + return cloned; + } + + $.fn.clonePolyfill = function(dataAndEvents, uniqueIds){ + dataAndEvents = dataAndEvents || false; + return this + .map(function() { + var cloned = clone( this, dataAndEvents, uniqueIds ); + setTimeout(function(){ + if($.contains(document.body, cloned)){ + $(cloned).updatePolyfill(); + } + }); + return cloned; + }) + ; + }; //add support for $('video').trigger('play') in case extendNative is set to false if(!webshims.cfg.extendNative && !webshims.cfg.noTriggerOverride){ (function(oldTrigger){ $.event.trigger = function(event, data, elem, onlyHandlers){ @@ -520,9 +549,10 @@ elem.eq(0).prop('id', id); } return id; }; })(), + shadowClass: 'wsshadow-'+(Date.now()), implement: function(elem, type){ var data = elementData(elem, 'implemented') || elementData(elem, 'implemented', {}); if(data[type]){ webshims.warn(type +' already implemented for element #'+elem.id); return false;