diff options
| author | pliablepixels <pliablepixels@gmail.com> | 2016-03-06 16:38:03 -0500 |
|---|---|---|
| committer | pliablepixels <pliablepixels@gmail.com> | 2016-03-06 16:38:03 -0500 |
| commit | 8c6f9dfb14d23970ef715f2f785db8ef90d8ccfe (patch) | |
| tree | d2ec3dfb8df273e31b1fe05a8abea1176536da8b /www/external | |
| parent | 856e977356f0a70839f323deef44671fb3f6f533 (diff) | |
#179, made packery drag and drop mode evident, added ability to save and restore
Former-commit-id: f4335f3beab8f47d5b91af929e5053a03a2d1df2
Diffstat (limited to 'www/external')
| -rw-r--r-- | www/external/packery.pkgd.js | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/www/external/packery.pkgd.js b/www/external/packery.pkgd.js index c8353909..cd5b2a2c 100644 --- a/www/external/packery.pkgd.js +++ b/www/external/packery.pkgd.js @@ -2743,6 +2743,48 @@ Packery.Item = Item; var proto = Packery.prototype; +// get JSON-friendly data for items positions +Packery.prototype.getShiftPositions = function( attrName ) { + attrName = attrName || 'id'; + var _this = this; + return this.items.map( function( item ) { + return { + attr: item.element.getAttribute( attrName ), + x: item.rect.x / _this.packer.width + } + }); +}; + +Packery.prototype.initShiftLayout = function( positions, attr ) { + if ( !positions ) { + // if no initial positions, run packery layout + this.layout(); + return; + } + // parse string to JSON + if ( typeof positions == 'string' ) { + try { + positions = JSON.parse( positions ); + } catch( error ) { + console.error( 'JSON parse error: ' + error ); + this.layout(); + return; + } + } + + attr = attr || 'id'; // default to id attribute + this._resetLayout(); + // set item order and horizontal position from saved positions + this.items = positions.map( function( itemPosition ) { + var selector = '[' + attr + '="' + itemPosition.attr + '"]' + var itemElem = this.element.querySelector( selector ); + var item = this.getItem( itemElem ); + item.rect.x = itemPosition.x * this.packer.width; + return item; + }, this ); + this.shiftLayout(); +}; + proto._create = function() { // call super Outlayer.prototype._create.call( this ); |
