summaryrefslogtreecommitdiff
path: root/www/external/packery.pkgd.js
diff options
context:
space:
mode:
Diffstat (limited to 'www/external/packery.pkgd.js')
-rw-r--r--www/external/packery.pkgd.js42
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 );