From 47b26b2c433c770df7d4b5963f35ee2c943d580a Mon Sep 17 00:00:00 2001 From: JaySunSyn Date: Mon, 16 Apr 2018 14:29:14 +0800 Subject: [PATCH 1/3] copy properties after cloning node --- iron-swiper.html | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/iron-swiper.html b/iron-swiper.html index b4f44f5..fbe189d 100644 --- a/iron-swiper.html +++ b/iron-swiper.html @@ -351,6 +351,10 @@ e.preventDefault(); } + _copyProperties(node1, node2) { + Object.keys(node1.constructor.properties).forEach(key => node2[key] = node1[key]); + } + init() { clearTimeout(this._initializer); this._initializer = setTimeout(function() { @@ -377,6 +381,7 @@ } var node = wrapper.appendChild(slides[i].cloneNode(true)); + this._copyProperties(slides[i], node); node.classList.add('swiper-slide'); node.setAttribute('index', i.toString()); node.removeEventListener('click', this._nodeClicked); From a51e74d9e2cbcb129f79f76b9187013adf83177f Mon Sep 17 00:00:00 2001 From: JaySunSyn Date: Mon, 16 Apr 2018 14:43:42 +0800 Subject: [PATCH 2/3] exclude 'DOM-REPEAT', ... from nodes --- iron-swiper.html | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/iron-swiper.html b/iron-swiper.html index fbe189d..66a2680 100644 --- a/iron-swiper.html +++ b/iron-swiper.html @@ -359,18 +359,17 @@ clearTimeout(this._initializer); this._initializer = setTimeout(function() { // First clone real nodes into the wrapper - var _nodes = []; - + const _nodes = []; + const excludeTagNames = ['TEMPLATE', 'DOM-REPEAT', 'DOM-IF']; let slides = Polymer.FlattenedNodesObserver.getFlattenedNodes(this) .filter( function(node) { return node.tagName && - node.tagName !== 'TEMPLATE' && + excludeTagNames.indexOf(node.tagName) === -1 && !node.classList.contains('swiper-slide'); }); - var wrapper = this.$.wrapper; - + const wrapper = this.$.wrapper; wrapper.innerHTML = ''; wrapper.removeAttribute('style'); @@ -432,7 +431,6 @@ } this._swiper = new window.Swiper(this.$.swiper, this.getOptions()); - // this.scopeSubtree(this.$.swiper); // for polymer 2.x this process should be automatic now. See https://github.com/webcomponents/shadycss/issues/114#issuecomment-321936467 } _nodeClicked(e) { From f95b9503106aa17b01db19fa32abeb8c10b59d42 Mon Sep 17 00:00:00 2001 From: JaySunSyn Date: Mon, 16 Apr 2018 14:56:58 +0800 Subject: [PATCH 3/3] cleanup --- iron-swiper.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iron-swiper.html b/iron-swiper.html index b6e29e6..cab1a03 100644 --- a/iron-swiper.html +++ b/iron-swiper.html @@ -394,7 +394,7 @@ slides[i].classList.add('swiper-no-swiping'); } - var node = wrapper.appendChild(slides[i].cloneNode(true)); + const node = wrapper.appendChild(slides[i].cloneNode(true)); this._copyProperties(slides[i], node); node.classList.add('swiper-slide'); node.setAttribute('index', i.toString());