From 100357635eab97a407752717a56dd71f3c0b2f34 Mon Sep 17 00:00:00 2001 From: Igor Ippolitov Date: Thu, 19 May 2016 12:03:54 +0300 Subject: [PATCH 1/9] noDomMod option added --- js/flickity.js | 42 ++++++++++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/js/flickity.js b/js/flickity.js index 5704a6f3..9017835c 100644 --- a/js/flickity.js +++ b/js/flickity.js @@ -105,7 +105,8 @@ Flickity.defaults = { selectedAttraction: 0.025, setGallerySize: true // watchCSS: false, - // wrapAround: false + // wrapAround: false, + // noDomMod: false }; // hash of methods triggered on _create() @@ -129,8 +130,16 @@ Flickity.prototype._create = function() { this.accel = 0; this.originSide = this.options.rightToLeft ? 'right' : 'left'; // create viewport & slider - this.viewport = document.createElement('div'); - this.viewport.className = 'flickity-viewport'; + if (this.options.noDomMod) { + this.viewport = document.querySelector('.flickity-viewport'); + if ( !this.viewport && console ) { + console.error( 'Could not find ".flickity-viewport"' ); + return + } + } else { + this.viewport = document.createElement('div'); + this.viewport.className = 'flickity-viewport'; + } Flickity.setUnselectable( this.viewport ); this._createSlider(); @@ -173,9 +182,11 @@ Flickity.prototype.activate = function() { this.getSize(); // move initial cell elements so they can be loaded as cells var cellElems = this._filterFindCellElements( this.element.children ); - moveElements( cellElems, this.slider ); - this.viewport.appendChild( this.slider ); - this.element.appendChild( this.viewport ); + if (! this.options.noDomMod) { + moveElements( cellElems, this.slider ); + this.viewport.appendChild( this.slider ); + this.element.appendChild( this.viewport ); + } // get cells from children this.reloadCells(); @@ -206,10 +217,17 @@ Flickity.prototype.activate = function() { // slider positions the cells Flickity.prototype._createSlider = function() { // slider element does all the positioning - var slider = document.createElement('div'); - slider.className = 'flickity-slider'; - slider.style[ this.originSide ] = 0; - this.slider = slider; + if (this.options.noDomMod) { + this.slider = document.querySelector('.flickity-slider'); + if ( !this.slider && console ) { + console.error( 'Could not find ".flickity-slider"' ); + return + } + } else { + this.slider = document.createElement('div'); + this.slider.className = 'flickity-slider'; + } + this.slider.style[ this.originSide ] = 0; }; Flickity.prototype._filterFindCellElements = function( elems ) { @@ -695,9 +713,9 @@ Flickity.prototype.deactivate = function() { cell.destroy(); } this._removeSelectedCellClass(); - this.element.removeChild( this.viewport ); + this.options.noDomMod || this.element.removeChild( this.viewport ); // move child elements back into element - moveElements( this.slider.children, this.element ); + this.options.noDomMod || moveElements( this.slider.children, this.element ); if ( this.options.accessibility ) { this.element.removeAttribute('tabIndex'); eventie.unbind( this.element, 'keydown', this ); From c1e2f9f3011cd347af9ecd7f2aa8341d0c5593a7 Mon Sep 17 00:00:00 2001 From: Igor Ippolitov Date: Thu, 19 May 2016 12:04:31 +0300 Subject: [PATCH 2/9] should I reset shif cells inside realoadCells? --- js/flickity.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/js/flickity.js b/js/flickity.js index 9017835c..1d568b28 100644 --- a/js/flickity.js +++ b/js/flickity.js @@ -237,6 +237,8 @@ Flickity.prototype._filterFindCellElements = function( elems ) { // goes through all children Flickity.prototype.reloadCells = function() { // collection of item elements + this.afterShiftCells=[]; + this.beforeShiftCells=[]; this.cells = this._makeCells( this.slider.children ); this.positionCells(); this._getWrapShiftCells(); From 044f6a3a94ab8d57b0518fadb15995aac3bb2f92 Mon Sep 17 00:00:00 2001 From: Igor Ippolitov Date: Fri, 20 May 2016 11:33:02 +0300 Subject: [PATCH 3/9] allow multiple Flickity instances to look for a slider inside bind interface --- js/flickity.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/js/flickity.js b/js/flickity.js index 1d568b28..89e73e2b 100644 --- a/js/flickity.js +++ b/js/flickity.js @@ -131,7 +131,7 @@ Flickity.prototype._create = function() { this.originSide = this.options.rightToLeft ? 'right' : 'left'; // create viewport & slider if (this.options.noDomMod) { - this.viewport = document.querySelector('.flickity-viewport'); + this.viewport = this.element.querySelector('.flickity-viewport'); if ( !this.viewport && console ) { console.error( 'Could not find ".flickity-viewport"' ); return @@ -218,7 +218,7 @@ Flickity.prototype.activate = function() { Flickity.prototype._createSlider = function() { // slider element does all the positioning if (this.options.noDomMod) { - this.slider = document.querySelector('.flickity-slider'); + this.slider = this.element.querySelector('.flickity-slider'); if ( !this.slider && console ) { console.error( 'Could not find ".flickity-slider"' ); return From 1a1960ac565ca91ef4025b9d6a09ee49ad02955d Mon Sep 17 00:00:00 2001 From: Igor Ippolitov Date: Wed, 27 Jul 2016 14:44:09 +0300 Subject: [PATCH 4/9] fixed a typo --- js/flickity.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/flickity.js b/js/flickity.js index cb3aa230..b7e0f363 100644 --- a/js/flickity.js +++ b/js/flickity.js @@ -816,7 +816,7 @@ proto.deactivate = function() { // destroy cells this.cells.forEach( function( cell ) { cell.destroy(); - }) + }); this.unselectSelectedSlide(); this.options.noDomMod || this.element.removeChild( this.viewport ); // move child elements back into element From 170ff6534ab4c8d999f5519f203ea94beec1e91a Mon Sep 17 00:00:00 2001 From: Igor Ippolitov Date: Wed, 27 Jul 2016 14:45:34 +0300 Subject: [PATCH 5/9] removed anneeded actions appeared on merge --- js/flickity.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/js/flickity.js b/js/flickity.js index b7e0f363..3bd769bc 100644 --- a/js/flickity.js +++ b/js/flickity.js @@ -237,8 +237,6 @@ proto._filterFindCellElements = function( elems ) { // goes through all children proto.reloadCells = function() { // collection of item elements - this.afterShiftCells=[]; - this.beforeShiftCells=[]; this.cells = this._makeCells( this.slider.children ); this.positionCells(); this._getWrapShiftCells(); From 65d63a8318511e1596f73ea341065f98194f6a38 Mon Sep 17 00:00:00 2001 From: Igor Ippolitov Date: Wed, 27 Jul 2016 15:17:03 +0300 Subject: [PATCH 6/9] removed obsolete function call --- js/flickity.js | 1 - 1 file changed, 1 deletion(-) diff --git a/js/flickity.js b/js/flickity.js index 3bd769bc..4b418cbf 100644 --- a/js/flickity.js +++ b/js/flickity.js @@ -142,7 +142,6 @@ proto._create = function() { this.viewport = document.createElement('div'); this.viewport.className = 'flickity-viewport'; } - Flickity.setUnselectable( this.viewport ); this._createSlider(); if ( this.options.resize || this.options.watchCSS ) { From f9810a9400a5ed52ca74c84cf4f200da86ee195b Mon Sep 17 00:00:00 2001 From: oxpa Date: Tue, 2 Aug 2016 12:57:16 +0000 Subject: [PATCH 7/9] Revert "removed anneeded actions appeared on merge" This reverts commit 170ff6534ab4c8d999f5519f203ea94beec1e91a. removing these results in messed up cells on flickity enabling-disabling --- js/flickity.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/js/flickity.js b/js/flickity.js index 3bd769bc..b7e0f363 100644 --- a/js/flickity.js +++ b/js/flickity.js @@ -237,6 +237,8 @@ proto._filterFindCellElements = function( elems ) { // goes through all children proto.reloadCells = function() { // collection of item elements + this.afterShiftCells=[]; + this.beforeShiftCells=[]; this.cells = this._makeCells( this.slider.children ); this.positionCells(); this._getWrapShiftCells(); From b5eb8cb948704c8de5cf165d3f797ed0634c87f8 Mon Sep 17 00:00:00 2001 From: oxpa Date: Wed, 7 Feb 2018 17:29:34 +0000 Subject: [PATCH 8/9] minor changes to make lint happy --- js/flickity.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/js/flickity.js b/js/flickity.js index 5ae3fe87..1b9e4027 100644 --- a/js/flickity.js +++ b/js/flickity.js @@ -136,7 +136,7 @@ proto._create = function() { this.viewport = this.element.querySelector('.flickity-viewport'); if ( !this.viewport && console ) { console.error( 'Could not find ".flickity-viewport"' ); - return + return; } } else { this.viewport = document.createElement('div'); @@ -220,7 +220,7 @@ proto._createSlider = function() { this.slider = this.element.querySelector('.flickity-slider'); if ( !this.slider && console ) { console.error( 'Could not find ".flickity-slider"' ); - return + return; } } else { this.slider = document.createElement('div'); @@ -817,9 +817,9 @@ proto.deactivate = function() { cell.destroy(); }); this.unselectSelectedSlide(); - this.options.noDomMod || this.element.removeChild( this.viewport ); + if (! this.options.noDomMod ) this.element.removeChild( this.viewport ); // move child elements back into element - this.options.noDomMod || moveElements( this.slider.children, this.element ); + if (! this.options.noDomMod ) moveElements( this.slider.children, this.element ); if ( this.options.accessibility ) { this.element.removeAttribute('tabIndex'); this.element.removeEventListener( 'keydown', this ); From b48bd0dcda515846fd79d5d90c3704e5f788db8b Mon Sep 17 00:00:00 2001 From: Michael Rehse Date: Tue, 1 May 2018 12:04:38 -0400 Subject: [PATCH 9/9] Updated to allow NoDomMod on Page Dots --- js/page-dots.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/js/page-dots.js b/js/page-dots.js index ce1db204..a2dfe9b9 100644 --- a/js/page-dots.js +++ b/js/page-dots.js @@ -44,8 +44,16 @@ PageDots.prototype = new TapListener(); PageDots.prototype._create = function() { // create holder element - this.holder = document.createElement('ol'); - this.holder.className = 'flickity-page-dots'; + if (this.parent.options.noDomMod) { + this.holder = this.parent.element.querySelector('.flickity-page-dots'); + if ( !this.holder && console ) { + console.error( 'Could not find ".flickity-page-dots"' ); + return; + } + } else { + this.holder = document.createElement('ol'); + this.holder.className = 'flickity-page-dots'; + } // create dots, array of elements this.dots = []; // events