diff options
author | David DeSandro <desandrocodes@gmail.com> | 2016-06-15 14:19:12 -0400 |
---|---|---|
committer | David DeSandro <desandrocodes@gmail.com> | 2016-06-15 15:12:02 -0400 |
commit | d08338c77a69266df1ec0248ddf543eb3b4b040e (patch) | |
tree | d01cfbffebf55880327fbff76fa9e03a7aecd74a | |
parent | 93779a1d6868230a02be9f088bc1deb678617723 (diff) | |
download | flickity-d08338c77a69266df1ec0248ddf543eb3b4b040e.zip flickity-d08338c77a69266df1ec0248ddf543eb3b4b040e.tar.gz flickity-d08338c77a69266df1ec0248ddf543eb3b4b040e.tar.bz2 |
🛠proto
-rw-r--r-- | js/add-remove-cell.js | 16 | ||||
-rw-r--r-- | js/cell.js | 19 | ||||
-rw-r--r-- | js/drag.js | 43 | ||||
-rw-r--r-- | js/flickity.js | 91 | ||||
-rw-r--r-- | js/lazyload.js | 5 | ||||
-rw-r--r-- | js/page-dots.js | 10 | ||||
-rw-r--r-- | js/player.js | 19 | ||||
-rw-r--r-- | js/prev-next-button.js | 7 | ||||
-rw-r--r-- | js/slide.js | 16 |
9 files changed, 119 insertions, 107 deletions
diff --git a/js/add-remove-cell.js b/js/add-remove-cell.js index aeea0a8..eee8f2a 100644 --- a/js/add-remove-cell.js +++ b/js/add-remove-cell.js @@ -41,12 +41,14 @@ function getCellsFragment( cells ) { // -------------------------- add/remove cell prototype -------------------------- // +var proto = Flickity.prototype; + /** * Insert, prepend, or append cells * @param {Element, Array, NodeList} elems * @param {Integer} index */ -Flickity.prototype.insert = function( elems, index ) { +proto.insert = function( elems, index ) { var cells = this._makeCells( elems ); if ( !cells || !cells.length ) { return; @@ -83,11 +85,11 @@ Flickity.prototype.insert = function( elems, index ) { this._cellAddedRemoved( index, selectedIndexDelta ); }; -Flickity.prototype.append = function( elems ) { +proto.append = function( elems ) { this.insert( elems, this.cells.length ); }; -Flickity.prototype.prepend = function( elems ) { +proto.prepend = function( elems ) { this.insert( elems, 0 ); }; @@ -95,7 +97,7 @@ Flickity.prototype.prepend = function( elems ) { * Remove cells * @param {Element, Array, NodeList} elems */ -Flickity.prototype.remove = function( elems ) { +proto.remove = function( elems ) { var cells = this.getCells( elems ); var selectedIndexDelta = 0; var len = cells.length; @@ -121,7 +123,7 @@ Flickity.prototype.remove = function( elems ) { }; // updates when cells are added or removed -Flickity.prototype._cellAddedRemoved = function( changedCellIndex, selectedIndexDelta ) { +proto._cellAddedRemoved = function( changedCellIndex, selectedIndexDelta ) { // TODO this math isn't perfect with grouped slides selectedIndexDelta = selectedIndexDelta || 0; this.selectedIndex += selectedIndexDelta; @@ -135,7 +137,7 @@ Flickity.prototype._cellAddedRemoved = function( changedCellIndex, selectedIndex * logic to be run after a cell's size changes * @param {Element} elem - cell's element */ -Flickity.prototype.cellSizeChange = function( elem ) { +proto.cellSizeChange = function( elem ) { var cell = this.getCell( elem ); if ( !cell ) { return; @@ -150,7 +152,7 @@ Flickity.prototype.cellSizeChange = function( elem ) { * logic any time a cell is changed: added, removed, or size changed * @param {Integer} changedCellIndex - index of the changed cell, optional */ -Flickity.prototype.cellChange = function( changedCellIndex, isPositioningSlider ) { +proto.cellChange = function( changedCellIndex, isPositioningSlider ) { var prevSlideableWidth = this.slideableWidth; this._positionCells( changedCellIndex ); this._getWrapShiftCells(); @@ -35,9 +35,11 @@ function Cell( elem, parent ) { this.create(); } +var proto = Cell.prototype; + var isIE8 = 'attachEvent' in window; -Cell.prototype.create = function() { +proto.create = function() { this.element.style.position = 'absolute'; // IE8 prevent child from changing focus http://stackoverflow.com/a/17525223/182183 if ( isIE8 ) { @@ -47,32 +49,31 @@ Cell.prototype.create = function() { this.shift = 0; }; -Cell.prototype.destroy = function() { +proto.destroy = function() { // reset style this.element.style.position = ''; var side = this.parent.originSide; this.element.style[ side ] = ''; }; -Cell.prototype.getSize = function() { +proto.getSize = function() { this.size = getSize( this.element ); }; -Cell.prototype.setPosition = function( x ) { +proto.setPosition = function( x ) { this.x = x; this.updateTarget(); this.renderPosition( x ); }; -Cell.prototype.updateTarget = // setDefaultTarget v1 method, backwards compatibility, remove in v3 -Cell.prototype.setDefaultTarget = function() { +proto.updateTarget = proto.setDefaultTarget = function() { var marginProperty = this.parent.originSide == 'left' ? 'marginLeft' : 'marginRight'; this.target = this.x + this.size[ marginProperty ] + this.size.width * this.parent.cellAlign; }; -Cell.prototype.renderPosition = function( x ) { +proto.renderPosition = function( x ) { // render position of cell with in slider var side = this.parent.originSide; this.element.style[ side ] = this.parent.getPositionValue( x ); @@ -81,12 +82,12 @@ Cell.prototype.renderPosition = function( x ) { /** * @param {Integer} factor - 0, 1, or -1 **/ -Cell.prototype.wrapShift = function( shift ) { +proto.wrapShift = function( shift ) { this.shift = shift; this.renderPosition( this.x + this.parent.slideableWidth * shift ); }; -Cell.prototype.remove = function() { +proto.remove = function() { this.element.parentNode.removeChild( this.element ); }; @@ -45,18 +45,19 @@ Flickity.createMethods.push('_createDrag'); // -------------------------- drag prototype -------------------------- // -utils.extend( Flickity.prototype, Unidragger.prototype ); +var proto = Flickity.prototype; +utils.extend( proto, Unidragger.prototype ); // -------------------------- -------------------------- // -Flickity.prototype._createDrag = function() { +proto._createDrag = function() { this.on( 'activate', this.bindDrag ); this.on( 'uiChange', this._uiChangeDrag ); this.on( 'childUIPointerDown', this._childUIPointerDownDrag ); this.on( 'deactivate', this.unbindDrag ); }; -Flickity.prototype.bindDrag = function() { +proto.bindDrag = function() { if ( !this.options.draggable || this.isDragBound ) { return; } @@ -66,7 +67,7 @@ Flickity.prototype.bindDrag = function() { this.isDragBound = true; }; -Flickity.prototype.unbindDrag = function() { +proto.unbindDrag = function() { if ( !this.isDragBound ) { return; } @@ -75,18 +76,18 @@ Flickity.prototype.unbindDrag = function() { delete this.isDragBound; }; -Flickity.prototype._uiChangeDrag = function() { +proto._uiChangeDrag = function() { delete this.isFreeScrolling; }; -Flickity.prototype._childUIPointerDownDrag = function( event ) { +proto._childUIPointerDownDrag = function( event ) { event.preventDefault(); this.pointerDownFocus( event ); }; // -------------------------- pointer events -------------------------- // -Flickity.prototype.pointerDown = function( event, pointer ) { +proto.pointerDown = function( event, pointer ) { // dismiss range sliders if ( event.target.nodeName == 'INPUT' && event.target.type == 'range' ) { // reset pointerDown logic @@ -127,7 +128,7 @@ var focusNodes = { SELECT: true }; -Flickity.prototype.pointerDownFocus = function( event ) { +proto.pointerDownFocus = function( event ) { // focus element, if not touch, and its not an input or select if ( !this.options.accessibility || touchStartEvents[ event.type ] || focusNodes[ event.target.nodeName ] ) { @@ -141,7 +142,7 @@ Flickity.prototype.pointerDownFocus = function( event ) { } }; -Flickity.prototype.canPreventDefaultOnPointerDown = function( event ) { +proto.canPreventDefaultOnPointerDown = function( event ) { // prevent default, unless touchstart or <select> var isTouchstart = event.type == 'touchstart'; var targetNodeName = event.target.nodeName; @@ -150,33 +151,33 @@ Flickity.prototype.canPreventDefaultOnPointerDown = function( event ) { // ----- move ----- // -Flickity.prototype.hasDragStarted = function( moveVector ) { +proto.hasDragStarted = function( moveVector ) { return Math.abs( moveVector.x ) > 3; }; // ----- up ----- // -Flickity.prototype.pointerUp = function( event, pointer ) { +proto.pointerUp = function( event, pointer ) { delete this.isTouchScrolling; this.viewport.classList.remove('is-pointer-down'); this.dispatchEvent( 'pointerUp', event, [ pointer ] ); this._dragPointerUp( event, pointer ); }; -Flickity.prototype.pointerDone = function() { +proto.pointerDone = function() { window.removeEventListener( 'scroll', this ); delete this.pointerDownScroll; }; // -------------------------- dragging -------------------------- // -Flickity.prototype.dragStart = function( event, pointer ) { +proto.dragStart = function( event, pointer ) { this.dragStartPosition = this.x; this.startAnimation(); this.dispatchEvent( 'dragStart', event, [ pointer ] ); }; -Flickity.prototype.dragMove = function( event, pointer, moveVector ) { +proto.dragMove = function( event, pointer, moveVector ) { event.preventDefault(); this.previousDragX = this.dragX; @@ -198,7 +199,7 @@ Flickity.prototype.dragMove = function( event, pointer, moveVector ) { this.dispatchEvent( 'dragMove', event, [ pointer, moveVector ] ); }; -Flickity.prototype.dragEnd = function( event, pointer ) { +proto.dragEnd = function( event, pointer ) { if ( this.options.freeScroll ) { this.isFreeScrolling = true; } @@ -223,7 +224,7 @@ Flickity.prototype.dragEnd = function( event, pointer ) { this.dispatchEvent( 'dragEnd', event, [ pointer ] ); }; -Flickity.prototype.dragEndRestingSelect = function() { +proto.dragEndRestingSelect = function() { var restingX = this.getRestingPosition(); // how far away from selected slide var distance = Math.abs( this.getSlideDistance( -restingX, this.selectedIndex ) ); @@ -244,7 +245,7 @@ Flickity.prototype.dragEndRestingSelect = function() { * @param {Integer} increment - +1 or -1, going up or down * @returns {Object} - { distance: {Number}, index: {Integer} } */ -Flickity.prototype._getClosestResting = function( restingX, distance, increment ) { +proto._getClosestResting = function( restingX, distance, increment ) { var index = this.selectedIndex; var minDistance = Infinity; var condition = this.options.contain && !this.options.wrapAround ? @@ -272,7 +273,7 @@ Flickity.prototype._getClosestResting = function( restingX, distance, increment * @param {Number} x * @param {Integer} index - slide index */ -Flickity.prototype.getSlideDistance = function( x, index ) { +proto.getSlideDistance = function( x, index ) { var len = this.slides.length; // wrap around if at least 2 slides var isWrapAround = this.options.wrapAround && len > 1; @@ -286,7 +287,7 @@ Flickity.prototype.getSlideDistance = function( x, index ) { return x - ( slide.target + wrap ); }; -Flickity.prototype.dragEndBoostSelect = function() { +proto.dragEndBoostSelect = function() { // do not boost if no previousDragX or dragMoveTime if ( this.previousDragX === undefined || !this.dragMoveTime || // or if drag was held for 100 ms @@ -308,7 +309,7 @@ Flickity.prototype.dragEndBoostSelect = function() { // ----- staticClick ----- // -Flickity.prototype.staticClick = function( event, pointer ) { +proto.staticClick = function( event, pointer ) { // get clickedCell, if cell was clicked var clickedCell = this.getParentCell( event.target ); var cellElem = clickedCell && clickedCell.element; @@ -318,7 +319,7 @@ Flickity.prototype.staticClick = function( event, pointer ) { // ----- scroll ----- // -Flickity.prototype.onscroll = function() { +proto.onscroll = function() { var scroll = getScrollPosition(); var scrollMoveX = this.pointerDownScroll.x - scroll.x; var scrollMoveY = this.pointerDownScroll.y - scroll.y; diff --git a/js/flickity.js b/js/flickity.js index 0bb5543..acec708 100644 --- a/js/flickity.js +++ b/js/flickity.js @@ -104,10 +104,11 @@ Flickity.defaults = { // hash of methods triggered on _create() Flickity.createMethods = []; +var proto = Flickity.prototype; // inherit EventEmitter -utils.extend( Flickity.prototype, EvEmitter.prototype ); +utils.extend( proto, EvEmitter.prototype ); -Flickity.prototype._create = function() { +proto._create = function() { // add id for Flickity.data var id = this.guid = ++GUID; this.element.flickityGUID = id; // expando @@ -147,11 +148,11 @@ Flickity.prototype._create = function() { * set options * @param {Object} opts */ -Flickity.prototype.option = function( opts ) { +proto.option = function( opts ) { utils.extend( this.options, opts ); }; -Flickity.prototype.activate = function() { +proto.activate = function() { if ( this.isActive ) { return; } @@ -195,7 +196,7 @@ Flickity.prototype.activate = function() { }; // slider positions the cells -Flickity.prototype._createSlider = function() { +proto._createSlider = function() { // slider element does all the positioning var slider = document.createElement('div'); slider.className = 'flickity-slider'; @@ -203,12 +204,12 @@ Flickity.prototype._createSlider = function() { this.slider = slider; }; -Flickity.prototype._filterFindCellElements = function( elems ) { +proto._filterFindCellElements = function( elems ) { return utils.filterFindElements( elems, this.options.cellSelector ); }; // goes through all children -Flickity.prototype.reloadCells = function() { +proto.reloadCells = function() { // collection of item elements this.cells = this._makeCells( this.slider.children ); this.positionCells(); @@ -221,7 +222,7 @@ Flickity.prototype.reloadCells = function() { * @param {Array or NodeList or HTMLElement} elems * @returns {Array} items - collection of new Flickity Cells */ -Flickity.prototype._makeCells = function( elems ) { +proto._makeCells = function( elems ) { var cellElems = this._filterFindCellElements( elems ); // create new Flickity for collection @@ -232,16 +233,16 @@ Flickity.prototype._makeCells = function( elems ) { return cells; }; -Flickity.prototype.getLastCell = function() { +proto.getLastCell = function() { return this.cells[ this.cells.length - 1 ]; }; -Flickity.prototype.getLastSlide = function() { +proto.getLastSlide = function() { return this.slides[ this.slides.length - 1 ]; }; // positions all cells -Flickity.prototype.positionCells = function() { +proto.positionCells = function() { // size all cells this._sizeCells( this.cells ); // position all cells @@ -252,7 +253,7 @@ Flickity.prototype.positionCells = function() { * position certain cells * @param {Integer} index - which cell to start with */ -Flickity.prototype._positionCells = function( index ) { +proto._positionCells = function( index ) { index = index || 0; // also measure maxCellHeight // start 0 if positioning all cells @@ -282,7 +283,7 @@ Flickity.prototype._positionCells = function( index ) { * cell.getSize() on multiple cells * @param {Array} cells */ -Flickity.prototype._sizeCells = function( cells ) { +proto._sizeCells = function( cells ) { cells.forEach( function( cell ) { cell.getSize(); }); @@ -290,7 +291,7 @@ Flickity.prototype._sizeCells = function( cells ) { // -------------------------- -------------------------- // -Flickity.prototype.updateSlides = function() { +proto.updateSlides = function() { this.slides = []; if ( !this.cells.length ) { return; @@ -328,7 +329,7 @@ Flickity.prototype.updateSlides = function() { slide.updateTarget(); }; -Flickity.prototype._getCanCellFit = function() { +proto._getCanCellFit = function() { var groupCells = this.options.groupCells; if ( !groupCells ) { return function() { @@ -352,13 +353,13 @@ Flickity.prototype._getCanCellFit = function() { }; // alias _init for jQuery plugin .flickity() -Flickity.prototype._init = -Flickity.prototype.reposition = function() { +proto._init = +proto.reposition = function() { this.positionCells(); this.positionSliderAtSelected(); }; -Flickity.prototype.getSize = function() { +proto.getSize = function() { this.size = getSize( this.element ); this.setCellAlign(); this.cursorPosition = this.size.innerWidth * this.cellAlign; @@ -380,18 +381,18 @@ var cellAlignShorthands = { } }; -Flickity.prototype.setCellAlign = function() { +proto.setCellAlign = function() { var shorthand = cellAlignShorthands[ this.options.cellAlign ]; this.cellAlign = shorthand ? shorthand[ this.originSide ] : this.options.cellAlign; }; -Flickity.prototype.setGallerySize = function() { +proto.setGallerySize = function() { if ( this.options.setGallerySize ) { this.viewport.style.height = this.maxCellHeight + 'px'; } }; -Flickity.prototype._getWrapShiftCells = function() { +proto._getWrapShiftCells = function() { // only for wrap-around if ( !this.options.wrapAround ) { return; @@ -411,7 +412,7 @@ Flickity.prototype._getWrapShiftCells = function() { this.afterShiftCells = this._getGapCells( gapX, 0, 1 ); }; -Flickity.prototype._getGapCells = function( gapX, cellIndex, increment ) { +proto._getGapCells = function( gapX, cellIndex, increment ) { // keep adding cells until the cover the initial gap var cells = []; while ( gapX > 0 ) { @@ -429,7 +430,7 @@ Flickity.prototype._getGapCells = function( gapX, cellIndex, increment ) { // ----- contain ----- // // contain cell targets so no excess sliding -Flickity.prototype._containSlides = function() { +proto._containSlides = function() { if ( !this.options.contain || this.options.wrapAround || !this.cells.length ) { return; } @@ -463,7 +464,7 @@ Flickity.prototype._containSlides = function() { * @param {Event} event - original event * @param {Array} args - extra arguments */ -Flickity.prototype.dispatchEvent = function( type, event, args ) { +proto.dispatchEvent = function( type, event, args ) { var emitArgs = [ event ].concat( args ); this.emitEvent( type, emitArgs ); @@ -487,7 +488,7 @@ Flickity.prototype.dispatchEvent = function( type, event, args ) { * @param {Boolean} isWrap - will wrap-around to last/first if at the end * @param {Boolean} isInstant - will immediately set position at selected cell */ -Flickity.prototype.select = function( index, isWrap, isInstant ) { +proto.select = function( index, isWrap, isInstant ) { if ( !this.isActive ) { return; } @@ -520,15 +521,15 @@ Flickity.prototype.select = function( index, isWrap, isInstant ) { this.dispatchEvent('cellSelect'); }; -Flickity.prototype.previous = function( isWrap ) { +proto.previous = function( isWrap ) { this.select( this.selectedIndex - 1, isWrap ); }; -Flickity.prototype.next = function( isWrap ) { +proto.next = function( isWrap ) { this.select( this.selectedIndex + 1, isWrap ); }; -Flickity.prototype.updateSelectedSlide = function() { +proto.updateSelectedSlide = function() { // unselect previous selected slide this.unselectSelectedSlide(); // update new selected slide @@ -542,7 +543,7 @@ Flickity.prototype.updateSelectedSlide = function() { this.selectedElement = this.selectedElements[0]; }; -Flickity.prototype.unselectSelectedSlide = function() { +proto.unselectSelectedSlide = function() { if ( this.selectedSlide ) { this.selectedSlide.unselect(); } @@ -552,7 +553,7 @@ Flickity.prototype.unselectSelectedSlide = function() { * select slide from number or cell element * @param {Element or Number} elem */ -Flickity.prototype.selectCell = function( value, isWrap, isInstant ) { +proto.selectCell = function( value, isWrap, isInstant ) { // get cell var cell = typeof value == 'number' ? this.cells[ value ] : this.getCell( value ); @@ -574,7 +575,7 @@ Flickity.prototype.selectCell = function( value, isWrap, isInstant ) { * @param {Element} elem * @returns {Flickity.Cell} item */ -Flickity.prototype.getCell = function( elem ) { +proto.getCell = function( elem ) { // loop through cells to get the one that matches for ( var i=0; i < this.cells.length; i++ ) { var cell = this.cells[i]; @@ -589,7 +590,7 @@ Flickity.prototype.getCell = function( elem ) { * @param {Element, Array, NodeList} elems * @returns {Array} cells - Flickity.Cells */ -Flickity.prototype.getCells = function( elems ) { +proto.getCells = function( elems ) { elems = utils.makeArray( elems ); var cells = []; elems.forEach( function( elem ) { @@ -605,7 +606,7 @@ Flickity.prototype.getCells = function( elems ) { * get cell elements * @returns {Array} cellElems */ -Flickity.prototype.getCellElements = function() { +proto.getCellElements = function() { return this.cells.map( function( cell ) { return cell.element; }); @@ -616,7 +617,7 @@ Flickity.prototype.getCellElements = function() { * @param {Element} elem * @returns {Flickit.Cell} cell */ -Flickity.prototype.getParentCell = function( elem ) { +proto.getParentCell = function( elem ) { // first check if elem is cell var cell = this.getCell( elem ); if ( cell ) { @@ -633,7 +634,7 @@ Flickity.prototype.getParentCell = function( elem ) { * @param {Integer} index - index of cell to start * @returns {Array} cells - array of Flickity.Cells */ -Flickity.prototype.getAdjacentCellElements = function( adjCount, index ) { +proto.getAdjacentCellElements = function( adjCount, index ) { if ( !adjCount ) { return [ this.selectedElement ]; } @@ -657,24 +658,24 @@ Flickity.prototype.getAdjacentCellElements = function( adjCount, index ) { // -------------------------- events -------------------------- // -Flickity.prototype.uiChange = function() { +proto.uiChange = function() { this.emitEvent('uiChange'); }; -Flickity.prototype.childUIPointerDown = function( event ) { +proto.childUIPointerDown = function( event ) { this.emitEvent( 'childUIPointerDown', [ event ] ); }; // ----- resize ----- // -Flickity.prototype.onresize = function() { +proto.onresize = function() { this.watchCSS(); this.resize(); }; utils.debounceMethod( Flickity, 'onresize', 150 ); -Flickity.prototype.resize = function() { +proto.resize = function() { if ( !this.isActive ) { return; } @@ -689,12 +690,12 @@ Flickity.prototype.resize = function() { this.emitEvent('resize'); // update selected index for group slides, instant // TODO: position can be lost between groups of various numbers - var selectedElement = this.selectedElements && this.selectedElements[0] + var selectedElement = this.selectedElements && this.selectedElements[0]; this.selectCell( selectedElement, false, true ); }; // watches the :after property, activates/deactivates -Flickity.prototype.watchCSS = function() { +proto.watchCSS = function() { var watchOption = this.options.watchCSS; if ( !watchOption ) { return; @@ -712,7 +713,7 @@ Flickity.prototype.watchCSS = function() { // ----- keydown ----- // // go previous/next if left/right keys pressed -Flickity.prototype.onkeydown = function( event ) { +proto.onkeydown = function( event ) { // only work if element is in focus if ( !this.options.accessibility || ( document.activeElement && document.activeElement != this.element ) ) { @@ -735,7 +736,7 @@ Flickity.prototype.onkeydown = function( event ) { // -------------------------- destroy -------------------------- // // deactivate all Flickity functionality, but keep stuff available -Flickity.prototype.deactivate = function() { +proto.deactivate = function() { if ( !this.isActive ) { return; } @@ -758,7 +759,7 @@ Flickity.prototype.deactivate = function() { this.emitEvent('deactivate'); }; -Flickity.prototype.destroy = function() { +proto.destroy = function() { this.deactivate(); window.removeEventListener( 'resize', this ); this.emitEvent('destroy'); @@ -771,7 +772,7 @@ Flickity.prototype.destroy = function() { // -------------------------- prototype -------------------------- // -utils.extend( Flickity.prototype, animatePrototype ); +utils.extend( proto, animatePrototype ); // -------------------------- extras -------------------------- // diff --git a/js/lazyload.js b/js/lazyload.js index bf3c129..fa1f76d 100644 --- a/js/lazyload.js +++ b/js/lazyload.js @@ -30,12 +30,13 @@ 'use strict'; Flickity.createMethods.push('_createLazyload'); +var proto = Flickity.prototype; -Flickity.prototype._createLazyload = function() { +proto._createLazyload = function() { this.on( 'cellSelect', this.lazyLoad ); }; -Flickity.prototype.lazyLoad = function() { +proto.lazyLoad = function() { var lazyLoad = this.options.lazyLoad; if ( !lazyLoad ) { return; diff --git a/js/page-dots.js b/js/page-dots.js index a633368..7dff438 100644 --- a/js/page-dots.js +++ b/js/page-dots.js @@ -150,7 +150,9 @@ utils.extend( Flickity.defaults, { Flickity.createMethods.push('_createPageDots'); -Flickity.prototype._createPageDots = function() { +var proto = Flickity.prototype; + +proto._createPageDots = function() { if ( !this.options.pageDots ) { return; } @@ -160,15 +162,15 @@ Flickity.prototype._createPageDots = function() { this.on( 'deactivate', this.deactivatePageDots ); }; -Flickity.prototype.activatePageDots = function() { +proto.activatePageDots = function() { this.pageDots.activate(); }; -Flickity.prototype.onCellAddedRemovedPageDots = function() { +proto.onCellAddedRemovedPageDots = function() { this.pageDots.setDots(); }; -Flickity.prototype.deactivatePageDots = function() { +proto.deactivatePageDots = function() { this.pageDots.deactivate(); }; diff --git a/js/player.js b/js/player.js index c6f0da7..ef1d9d6 100644 --- a/js/player.js +++ b/js/player.js @@ -130,8 +130,9 @@ utils.extend( Flickity.defaults, { }); Flickity.createMethods.push('_createPlayer'); +var proto = Flickity.prototype; -Flickity.prototype._createPlayer = function() { +proto._createPlayer = function() { this.player = new Player( this ); this.on( 'activate', this.activatePlayer ); @@ -140,7 +141,7 @@ Flickity.prototype._createPlayer = function() { this.on( 'deactivate', this.deactivatePlayer ); }; -Flickity.prototype.activatePlayer = function() { +proto.activatePlayer = function() { if ( !this.options.autoPlay ) { return; } @@ -150,23 +151,23 @@ Flickity.prototype.activatePlayer = function() { // Player API, don't hate the ... thanks I know where the door is -Flickity.prototype.playPlayer = function() { +proto.playPlayer = function() { this.player.play(); }; -Flickity.prototype.stopPlayer = function() { +proto.stopPlayer = function() { this.player.stop(); }; -Flickity.prototype.pausePlayer = function() { +proto.pausePlayer = function() { this.player.pause(); }; -Flickity.prototype.unpausePlayer = function() { +proto.unpausePlayer = function() { this.player.unpause(); }; -Flickity.prototype.deactivatePlayer = function() { +proto.deactivatePlayer = function() { this.player.stop(); this.element.removeEventListener( 'mouseenter', this ); }; @@ -174,7 +175,7 @@ Flickity.prototype.deactivatePlayer = function() { // ----- mouseenter/leave ----- // // pause auto-play on hover -Flickity.prototype.onmouseenter = function() { +proto.onmouseenter = function() { if ( !this.options.pauseAutoPlayOnHover ) { return; } @@ -183,7 +184,7 @@ Flickity.prototype.onmouseenter = function() { }; // resume auto-play on hover off -Flickity.prototype.onmouseleave = function() { +proto.onmouseleave = function() { this.player.unpause(); this.element.removeEventListener( 'mouseleave', this ); }; diff --git a/js/prev-next-button.js b/js/prev-next-button.js index 0cdbc88..ff55c41 100644 --- a/js/prev-next-button.js +++ b/js/prev-next-button.js @@ -225,8 +225,9 @@ utils.extend( Flickity.defaults, { }); Flickity.createMethods.push('_createPrevNextButtons'); +var proto = Flickity.prototype; -Flickity.prototype._createPrevNextButtons = function() { +proto._createPrevNextButtons = function() { if ( !this.options.prevNextButtons ) { return; } @@ -237,13 +238,13 @@ Flickity.prototype._createPrevNextButtons = function() { this.on( 'activate', this.activatePrevNextButtons ); }; -Flickity.prototype.activatePrevNextButtons = function() { +proto.activatePrevNextButtons = function() { this.prevButton.activate(); this.nextButton.activate(); this.on( 'deactivate', this.deactivatePrevNextButtons ); }; -Flickity.prototype.deactivatePrevNextButtons = function() { +proto.deactivatePrevNextButtons = function() { this.prevButton.deactivate(); this.nextButton.deactivate(); this.off( 'deactivate', this.deactivatePrevNextButtons ); diff --git a/js/slide.js b/js/slide.js index e64f460..8650b0d 100644 --- a/js/slide.js +++ b/js/slide.js @@ -25,7 +25,9 @@ function Slide( parent ) { this.height = 0; } -Slide.prototype.addCell = function( cell ) { +var proto = Slide.prototype; + +proto.addCell = function( cell ) { this.cells.push( cell ); this.outerWidth += cell.size.outerWidth; this.height = Math.max( cell.size.outerHeight, this.height ); @@ -37,7 +39,7 @@ Slide.prototype.addCell = function( cell ) { } }; -Slide.prototype.updateTarget = function() { +proto.updateTarget = function() { var endMargin = this.isOriginLeft ? 'marginRight' : 'marginLeft'; var lastCell = this.getLastCell(); var lastMargin = lastCell ? lastCell.size[ endMargin ] : 0; @@ -45,25 +47,25 @@ Slide.prototype.updateTarget = function() { this.target = this.x + this.firstMargin + slideWidth * this.parent.cellAlign; }; -Slide.prototype.getLastCell = function() { +proto.getLastCell = function() { return this.cells[ this.cells.length - 1 ]; }; -Slide.prototype.select = function() { +proto.select = function() { this.changeSelectedClass('add'); }; -Slide.prototype.unselect = function() { +proto.unselect = function() { this.changeSelectedClass('remove'); }; -Slide.prototype.changeSelectedClass = function( method ) { +proto.changeSelectedClass = function( method ) { this.cells.forEach( function( cell ) { cell.element.classList[ method ]('is-selected'); }); }; -Slide.prototype.getCellElements = function() { +proto.getCellElements = function() { return this.cells.map( function( cell ) { return cell.element; }); |