Add typings file.

pull/160/head
Glen Cheney 7 years ago
parent 15b3738d7b
commit ded5ff2546

75
dist/shuffle.js vendored

@ -855,7 +855,6 @@ var Shuffle = function (_TinyEmitter) {
_this.options = Object.assign({}, Shuffle.options, options);
_this.useSizer = false;
_this.lastSort = {};
_this.group = Shuffle.ALL_ITEMS;
_this.lastFilter = Shuffle.ALL_ITEMS;
@ -888,10 +887,6 @@ var Shuffle = function (_TinyEmitter) {
this.options.sizer = this._getElementOption(this.options.sizer);
if (this.options.sizer) {
this.useSizer = true;
}
// Add class and invalidate styles
this.element.classList.add(Shuffle.Classes.BASE);
@ -1032,7 +1027,7 @@ var Shuffle = function (_TinyEmitter) {
/**
* Returns an object containing the visible and hidden elements.
* @param {string|Function} category Category or function to filter by.
* @param {Array.<Element>} items A collection of items to filter.
* @param {Element[]} items A collection of items to filter.
* @return {!{visible: Array, hidden: Array}}
* @private
*/
@ -1123,7 +1118,7 @@ var Shuffle = function (_TinyEmitter) {
/**
* Set the initial css for each item
* @param {Array.<ShuffleItem>} items Set to initialize.
* @param {ShuffleItem[]} items Set to initialize.
* @private
*/
@ -1137,7 +1132,7 @@ var Shuffle = function (_TinyEmitter) {
/**
* Remove element reference and styles.
* @param {Array.<ShuffleItem>} items Set to dispose.
* @param {ShuffleItem[]} items Set to dispose.
* @private
*/
@ -1164,7 +1159,7 @@ var Shuffle = function (_TinyEmitter) {
* Sets css transform transition on a group of elements. This is not executed
* at the same time as `item.init` so that transitions don't occur upon
* initialization of Shuffle.
* @param {Array.<ShuffleItem>} items Shuffle items to set transitions on.
* @param {ShuffleItem[]} items Shuffle items to set transitions on.
* @protected
*/
@ -1195,7 +1190,7 @@ var Shuffle = function (_TinyEmitter) {
/**
* When new elements are added to the shuffle container, update the array of
* items because that is the order `_layout` calls them.
* @param {Array.<ShuffleItem>} items Items to track.
* @param {ShuffleItem[]} items Items to track.
*/
}, {
@ -1241,7 +1236,7 @@ var Shuffle = function (_TinyEmitter) {
size = this.options.columnWidth(containerWidth);
// columnWidth option isn't a function, are they using a sizing element?
} else if (this.useSizer) {
} else if (this.options.sizer) {
size = Shuffle.getSize(this.options.sizer).width;
// if not, how about the explicitly set option?
@ -1278,7 +1273,7 @@ var Shuffle = function (_TinyEmitter) {
var size = void 0;
if (typeof this.options.gutterWidth === 'function') {
size = this.options.gutterWidth(containerWidth);
} else if (this.useSizer) {
} else if (this.options.sizer) {
size = getNumberStyle(this.options.sizer, 'marginLeft');
} else {
size = this.options.gutterWidth;
@ -1384,7 +1379,7 @@ var Shuffle = function (_TinyEmitter) {
/**
* Loops through each item that should be shown and calculates the x, y position.
* @param {Array.<ShuffleItem>} items Array of items that will be shown/layed
* @param {ShuffleItem[]} items Array of items that will be shown/layed
* out in order in their array.
*/
@ -1435,8 +1430,8 @@ var Shuffle = function (_TinyEmitter) {
/**
* Return an array of Point instances representing the future positions of
* each item.
* @param {Array.<ShuffleItem>} items Array of sorted shuffle items.
* @return {Array.<Point>}
* @param {ShuffleItem[]} items Array of sorted shuffle items.
* @return {Point[]}
* @private
*/
@ -1486,9 +1481,9 @@ var Shuffle = function (_TinyEmitter) {
/**
* Mutate positions before they're applied.
* @param {Array.<Rect>} itemRects Item data objects.
* @param {Rect[]} itemRects Item data objects.
* @param {number} containerWidth Width of the containing element.
* @return {Array.<Point>}
* @return {Point[]}
* @protected
*/
@ -1500,7 +1495,7 @@ var Shuffle = function (_TinyEmitter) {
/**
* Hides the elements that don't match our filter.
* @param {Array.<ShuffleItem>} collection Collection to shrink.
* @param {ShuffleItem[]} collection Collection to shrink.
* @private
*/
@ -1662,7 +1657,7 @@ var Shuffle = function (_TinyEmitter) {
/**
* Wait for each transition to finish, the emit the layout event.
* @param {Array.<Object>} transitions Array of transition objects.
* @param {Object[]} transitions Array of transition objects.
*/
}, {
@ -1695,7 +1690,7 @@ var Shuffle = function (_TinyEmitter) {
/**
* Apply styles without a transition.
* @param {Array.<Object>} objects Array of transition objects.
* @param {Object[]} objects Array of transition objects.
* @private
*/
@ -1727,7 +1722,7 @@ var Shuffle = function (_TinyEmitter) {
/**
* The magic. This is what makes the plugin 'shuffle'
* @param {string|Function|Array.<string>} [category] Category to filter by.
* @param {string|Function|string[]} [category] Category to filter by.
* Can be a function, string, or array of strings.
* @param {Object} [sortObj] A sort object which can sort the visible set
*/
@ -1787,13 +1782,14 @@ var Shuffle = function (_TinyEmitter) {
/**
* Reposition everything.
* @param {boolean} isOnlyLayout If true, column and gutter widths won't be
* recalculated.
* @param {boolean} [isOnlyLayout=false] If true, column and gutter widths won't be recalculated.
*/
}, {
key: 'update',
value: function update(isOnlyLayout) {
value: function update() {
var isOnlyLayout = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
if (this.isEnabled) {
if (!isOnlyLayout) {
// Get updated colCount
@ -1820,7 +1816,7 @@ var Shuffle = function (_TinyEmitter) {
/**
* New items have been appended to shuffle. Mix them in with the current
* filter or sort status.
* @param {Array.<Element>} newItems Collection of new items.
* @param {Element[]} newItems Collection of new items.
*/
}, {
@ -1870,10 +1866,10 @@ var Shuffle = function (_TinyEmitter) {
}
/**
* Remove 1 or more shuffle items
* @param {Array.<Element>} elements An array containing one or more
* Remove 1 or more shuffle items.
* @param {Element[]} elements An array containing one or more
* elements in shuffle
* @return {Shuffle} The shuffle object
* @return {Shuffle} The shuffle instance.
*/
}, {
@ -1927,7 +1923,7 @@ var Shuffle = function (_TinyEmitter) {
/**
* Retrieve a shuffle item by its element.
* @param {Element} element Element to look for.
* @return {?ShuffleItem} A shuffle item or null if it's not found.
* @return {?ShuffleItem} A shuffle item or undefined if it's not found.
*/
}, {
@ -2017,13 +2013,15 @@ var Shuffle = function (_TinyEmitter) {
* follow the W3C spec here.
*
* @param {Element} element The element.
* @param {boolean} [includeMargins] Whether to include margins. Default is false.
* @param {boolean} [includeMargins=false] Whether to include margins.
* @return {{width: number, height: number}} The width and height.
*/
}], [{
key: 'getSize',
value: function getSize(element, includeMargins) {
value: function getSize(element) {
var includeMargins = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
// Store the styles so that they can be used by others without asking for it again.
var styles = window.getComputedStyle(element, null);
var width = getNumberStyle(element, 'width', styles);
@ -2046,7 +2044,7 @@ var Shuffle = function (_TinyEmitter) {
/**
* Change a property or execute a function which will not have a transition
* @param {Array.<Element>} elements DOM elements that won't be transitioned.
* @param {Element[]} elements DOM elements that won't be transitioned.
* @param {Function} callback A function which will be called while transition
* is set to 0ms.
* @private
@ -2093,9 +2091,7 @@ Shuffle.ShuffleItem = ShuffleItem;
Shuffle.ALL_ITEMS = 'all';
Shuffle.FILTER_ATTRIBUTE_KEY = 'groups';
/**
* @enum {string}
*/
/** @enum {string} */
Shuffle.EventType = {
LAYOUT: 'shuffle:layout',
REMOVED: 'shuffle:removed'
@ -2104,9 +2100,7 @@ Shuffle.EventType = {
/** @enum {string} */
Shuffle.Classes = Classes;
/**
* @enum {string}
*/
/** @enum {string} */
Shuffle.FilterMode = {
ANY: 'any',
ALL: 'all'
@ -2179,9 +2173,10 @@ Shuffle.options = {
isCentered: false
};
Shuffle.Point = Point;
Shuffle.Rect = Rect;
// Expose for testing. Hack at your own risk.
Shuffle.__Point = Point;
Shuffle.__Rect = Rect;
Shuffle.__sorter = sorter;
Shuffle.__getColumnSpan = getColumnSpan;
Shuffle.__getAvailablePositions = getAvailablePositions;

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

339
index.d.ts vendored

@ -0,0 +1,339 @@
// Type definitions for Shuffle 5.0
// Project: https://github.com/Vestride/Shuffle
// Definitions by: Glen Cheney <https://github.com/Vestride>
export as namespace Shuffle;
export = Shuffle;
interface FilterMode {
ALL: string;
ANY: string;
}
declare class ShuffleItem {
constructor(element: Element);
addClasses(classes: string[]): void;
applyCss(obj: object): void;
dispose(): void;
hide(): void;
init(): void;
removeClasses(classes: string[]): void;
show(): void;
id: number;
element: Element;
isVisible: boolean;
}
declare namespace ShuffleItem {
const Css: {
HIDDEN: {
after: object;
before: object;
};
INITIAL: object;
VISIBLE: {
after: object;
before: object;
};
};
const Scale: {
HIDDEN: number;
VISIBLE: number;
};
}
declare class Shuffle {
constructor(element: Element, options?: Shuffle.ShuffleOptions);
/**
* New items have been appended to shuffle. Mix them in with the current filter or sort status.
* @param {Element[]} newItems Collection of new items.
*/
add(newItems: Element[]): void;
/**
* Destroys shuffle, removes events, styles, and classes
*/
destroy(): void;
/**
* Disables shuffle from updating dimensions and layout on resize
*/
disable(): void;
/**
* Enables shuffle again.
* @param {boolean} [isUpdateLayout=true] if undefined, shuffle will update columns and gutters
*/
enable(isUpdateLayout?: true): void;
/**
* Filter items.
* @param {string|string[]|Function} [category] Category to filter by.
* Can be a function, string, or array of strings.
* @param {Object} [sortObj] A sort object which can sort the visible set
*/
filter(category?: string|string[]|Function, sortObj?: object): void;
/**
* Retrieve a shuffle item by its element.
* @param {Element} element Element to look for.
*/
getItemByElement(element: Element): ShuffleItem|null;
/**
* Use this instead of `update()` if you don't need the columns and gutters updated
* Maybe an image inside `shuffle` loaded (and now has a height), which means calculations
* could be off.
*/
layout(): void;
/**
* Remove 1 or more shuffle items.
* @param {Element[]} elements An array containing one or more
* elements in shuffle
*/
remove(elements: Element[]): Shuffle;
/**
* Dump the elements currently stored and reinitialize all child elements which
* match the `itemSelector`.
*/
resetItems(): void;
/**
* Gets the visible elements, sorts them, and passes them to layout.
* @param {Object} sortOptions The options object to pass to `sorter`.
*/
sort(sortOptions?): void;
/**
* Reposition everything.
* @param {boolean} [isOnlyLayout=false] If true, column and gutter widths won't be recalculated.
*/
update(isOnlyLayout?: false): void;
/**
* Returns styles which will be applied to the an item for a transition.
* @param {object} obj Transition options.
*/
protected getStylesForTransition({ item: ShuffleItem, styles: object }): object;
/**
* Mutate positions before they're applied.
* @param {Shuffle.Rect[]} itemRects Item data objects.
* @param {number} containerWidth Width of the containing element.
*/
protected getTransformedPositions(itemRects: Shuffle.Rect[], containerWidth: number): Shuffle.Point[];
/**
* Sets css transform transition on a group of elements. This is not executed
* at the same time as `item.init` so that transitions don't occur upon
* initialization of Shuffle.
* @param {ShuffleItem[]} items Shuffle items to set transitions on.
*/
protected setItemTransitions(items: ShuffleItem[]): void;
/** Width of one column */
colWidth: number;
/** Total number of columns */
cols: number;
/** Width of `element` */
containerWidth: number;
/** Main element */
element: Element;
/** Current filter group */
group: string;
/** Unique identifier for this instance */
id: string;
/** Whether this instance has been destroyed */
isDestroyed: boolean;
/** Whether this instance is enabled */
isEnabled: boolean;
/** Whether this instance has been initialized */
isInitialized: boolean;
/** Whether items are currently transitioning */
isTransitioning: boolean;
/** ShuffleItems being kept track of */
items: ShuffleItem[];
lastFilter: any;
lastSort: any;
/** Current (merged) options */
options: Shuffle.ShuffleOptions;
/** Item positions */
positions: number[];
/** Number of currently visible items */
visibleItems: number;
}
declare namespace Shuffle {
/** Filter string for all items */
let ALL_ITEMS: 'all';
/** Data attribute key to use. */
let FILTER_ATTRIBUTE_KEY: 'groups';
/** Class name strings */
const Classes: {
BASE: string;
HIDDEN: string;
SHUFFLE_ITEM: string;
VISIBLE: string;
};
/** Event types emitted by the instance */
const EventType: {
LAYOUT: string;
REMOVED: string;
};
/** Available filter modes. */
const FilterMode: FilterMode;
/** ShuffleItem class */
const ShuffleItem: ShuffleItem;
/**
* Returns the outer width of an element, optionally including its margins.
* @param {Element} element The element.
* @param {boolean} [includeMargins=false] Whether to include margins.
*/
function getSize(element: Element, includeMargins?: false): {width: number, height: number};
class Rect {
constructor(x: number, y: number, w: number, h: number, id?: number);
id: number;
left: number;
top: number;
width: number;
height: number;
}
namespace Rect {
function intersects(a: Rect, b: Rect): boolean;
}
class Point {
constructor(x?: number, y?: number);
x: number;
y: number;
}
namespace Point {
function equals(a: Point, b: Point): boolean;
}
/** Default options that can be overridden. */
interface ShuffleOptions {
/**
* Useful for percentage based heights when they might not always be exactly
* the same (in pixels).
*/
buffer?: number;
/**
* Reading the width of elements isn't precise enough and can cause columns to
* jump between values.
*/
columnThreshold?: number;
/**
* A static number or function that returns a number which tells the plugin
* how wide the columns are (in pixels).
*/
columnWidth?: number;
/**
* If your group is not json, and is comma delimeted, you could set delimeter to ','.
*/
delimeter?: string;
/**
* CSS easing function to use.
*/
easing?: string;
/**
* Affects using an array with filter. e.g. `filter(['one', 'two'])`. With "any",
* the element passes the test if any of its groups are in the array. With "all",
* the element only passes if all groups are in the array.
*/
filterMode?: FilterMode;
/**
* Initial filter group.
*/
group?: string;
/**
* A static number or function that tells the plugin how wide the gutters
* between columns are (in pixels).
*/
gutterWidth?: number;
/**
* Shuffle can be isInitialized with a sort object. It is the same object
* given to the sort method.
*/
initialSort?: object;
/**
* Whether to center grid items in the row with the leftover space.
*/
isCentered?: boolean;
/**
* e.g. '.picture-item'.
*/
itemSelector?: string;
/**
* Element or selector string. Use an element to determine the size of columns and gutters.
*/
sizer?: Element|string;
/**
* Transition/animation speed (milliseconds).
*/
speed?: number;
/**
* Transition delay offset for each item in milliseconds.
*/
staggerAmount?: number;
/**
* Maximum stagger delay in milliseconds.
*/
staggerAmountMax?: number;
/**
* How often shuffle can be called on resize (in milliseconds).
*/
throttleTime?: number;
/**
* Whether to use transforms or absolute positioning.
*/
useTransforms?: boolean;
/**
* By default, shuffle will throttle resize events. This can be changed or removed.
*/
throttle?(func: Function, wait: number): Function;
}
}

@ -16,6 +16,7 @@
],
"main": "dist/shuffle.js",
"moduleSource": "src/shuffle.js",
"types": "index.d.ts",
"scripts": {
"compile": "gulp scripts",
"css": "gulp css",
@ -37,7 +38,8 @@
"homepage": "https://github.com/Vestride/Shuffle",
"files": [
"dist",
"src"
"src",
"index.d.ts"
],
"dependencies": {
"array-parallel": "^0.1.3",

@ -39,7 +39,6 @@ class Shuffle extends TinyEmitter {
super();
this.options = Object.assign({}, Shuffle.options, options);
this.useSizer = false;
this.lastSort = {};
this.group = Shuffle.ALL_ITEMS;
this.lastFilter = Shuffle.ALL_ITEMS;
@ -69,10 +68,6 @@ class Shuffle extends TinyEmitter {
this.options.sizer = this._getElementOption(this.options.sizer);
if (this.options.sizer) {
this.useSizer = true;
}
// Add class and invalidate styles
this.element.classList.add(Shuffle.Classes.BASE);
@ -200,7 +195,7 @@ class Shuffle extends TinyEmitter {
/**
* Returns an object containing the visible and hidden elements.
* @param {string|Function} category Category or function to filter by.
* @param {Array.<Element>} items A collection of items to filter.
* @param {Element[]} items A collection of items to filter.
* @return {!{visible: Array, hidden: Array}}
* @private
*/
@ -279,7 +274,7 @@ class Shuffle extends TinyEmitter {
/**
* Set the initial css for each item
* @param {Array.<ShuffleItem>} items Set to initialize.
* @param {ShuffleItem[]} items Set to initialize.
* @private
*/
_initItems(items) {
@ -290,7 +285,7 @@ class Shuffle extends TinyEmitter {
/**
* Remove element reference and styles.
* @param {Array.<ShuffleItem>} items Set to dispose.
* @param {ShuffleItem[]} items Set to dispose.
* @private
*/
_disposeItems(items) {
@ -311,7 +306,7 @@ class Shuffle extends TinyEmitter {
* Sets css transform transition on a group of elements. This is not executed
* at the same time as `item.init` so that transitions don't occur upon
* initialization of Shuffle.
* @param {Array.<ShuffleItem>} items Shuffle items to set transitions on.
* @param {ShuffleItem[]} items Shuffle items to set transitions on.
* @protected
*/
setItemTransitions(items) {
@ -336,7 +331,7 @@ class Shuffle extends TinyEmitter {
/**
* When new elements are added to the shuffle container, update the array of
* items because that is the order `_layout` calls them.
* @param {Array.<ShuffleItem>} items Items to track.
* @param {ShuffleItem[]} items Items to track.
*/
_saveNewItems(items) {
const children = Array.from(this.element.children);
@ -370,7 +365,7 @@ class Shuffle extends TinyEmitter {
size = this.options.columnWidth(containerWidth);
// columnWidth option isn't a function, are they using a sizing element?
} else if (this.useSizer) {
} else if (this.options.sizer) {
size = Shuffle.getSize(this.options.sizer).width;
// if not, how about the explicitly set option?
@ -404,7 +399,7 @@ class Shuffle extends TinyEmitter {
let size;
if (typeof this.options.gutterWidth === 'function') {
size = this.options.gutterWidth(containerWidth);
} else if (this.useSizer) {
} else if (this.options.sizer) {
size = getNumberStyle(this.options.sizer, 'marginLeft');
} else {
size = this.options.gutterWidth;
@ -489,7 +484,7 @@ class Shuffle extends TinyEmitter {
/**
* Loops through each item that should be shown and calculates the x, y position.
* @param {Array.<ShuffleItem>} items Array of items that will be shown/layed
* @param {ShuffleItem[]} items Array of items that will be shown/layed
* out in order in their array.
*/
_layout(items) {
@ -535,8 +530,8 @@ class Shuffle extends TinyEmitter {
/**
* Return an array of Point instances representing the future positions of
* each item.
* @param {Array.<ShuffleItem>} items Array of sorted shuffle items.
* @return {Array.<Point>}
* @param {ShuffleItem[]} items Array of sorted shuffle items.
* @return {Point[]}
* @private
*/
_getNextPositions(items) {
@ -576,9 +571,9 @@ class Shuffle extends TinyEmitter {
/**
* Mutate positions before they're applied.
* @param {Array.<Rect>} itemRects Item data objects.
* @param {Rect[]} itemRects Item data objects.
* @param {number} containerWidth Width of the containing element.
* @return {Array.<Point>}
* @return {Point[]}
* @protected
*/
getTransformedPositions(itemRects, containerWidth) {
@ -587,7 +582,7 @@ class Shuffle extends TinyEmitter {
/**
* Hides the elements that don't match our filter.
* @param {Array.<ShuffleItem>} collection Collection to shrink.
* @param {ShuffleItem[]} collection Collection to shrink.
* @private
*/
_shrink(collection = this._getConcealedItems()) {
@ -722,7 +717,7 @@ class Shuffle extends TinyEmitter {
/**
* Wait for each transition to finish, the emit the layout event.
* @param {Array.<Object>} transitions Array of transition objects.
* @param {Object[]} transitions Array of transition objects.
*/
_startTransitions(transitions) {
// Set flag that shuffle is currently in motion.
@ -747,7 +742,7 @@ class Shuffle extends TinyEmitter {
/**
* Apply styles without a transition.
* @param {Array.<Object>} objects Array of transition objects.
* @param {Object[]} objects Array of transition objects.
* @private
*/
_styleImmediately(objects) {
@ -771,7 +766,7 @@ class Shuffle extends TinyEmitter {
/**
* The magic. This is what makes the plugin 'shuffle'
* @param {string|Function|Array.<string>} [category] Category to filter by.
* @param {string|Function|string[]} [category] Category to filter by.
* Can be a function, string, or array of strings.
* @param {Object} [sortObj] A sort object which can sort the visible set
*/
@ -823,10 +818,9 @@ class Shuffle extends TinyEmitter {
/**
* Reposition everything.
* @param {boolean} isOnlyLayout If true, column and gutter widths won't be
* recalculated.
* @param {boolean} [isOnlyLayout=false] If true, column and gutter widths won't be recalculated.
*/
update(isOnlyLayout) {
update(isOnlyLayout = false) {
if (this.isEnabled) {
if (!isOnlyLayout) {
// Get updated colCount
@ -850,7 +844,7 @@ class Shuffle extends TinyEmitter {
/**
* New items have been appended to shuffle. Mix them in with the current
* filter or sort status.
* @param {Array.<Element>} newItems Collection of new items.
* @param {Element[]} newItems Collection of new items.
*/
add(newItems) {
const items = arrayUnique(newItems).map(el => new ShuffleItem(el));
@ -887,10 +881,10 @@ class Shuffle extends TinyEmitter {
}
/**
* Remove 1 or more shuffle items
* @param {Array.<Element>} elements An array containing one or more
* Remove 1 or more shuffle items.
* @param {Element[]} elements An array containing one or more
* elements in shuffle
* @return {Shuffle} The shuffle object
* @return {Shuffle} The shuffle instance.
*/
remove(elements) {
if (!elements.length) {
@ -935,7 +929,7 @@ class Shuffle extends TinyEmitter {
/**
* Retrieve a shuffle item by its element.
* @param {Element} element Element to look for.
* @return {?ShuffleItem} A shuffle item or null if it's not found.
* @return {?ShuffleItem} A shuffle item or undefined if it's not found.
*/
getItemByElement(element) {
return this.items.find(item => item.element === element);
@ -1012,10 +1006,10 @@ class Shuffle extends TinyEmitter {
* follow the W3C spec here.
*
* @param {Element} element The element.
* @param {boolean} [includeMargins] Whether to include margins. Default is false.
* @param {boolean} [includeMargins=false] Whether to include margins.
* @return {{width: number, height: number}} The width and height.
*/
static getSize(element, includeMargins) {
static getSize(element, includeMargins = false) {
// Store the styles so that they can be used by others without asking for it again.
const styles = window.getComputedStyle(element, null);
let width = getNumberStyle(element, 'width', styles);
@ -1038,7 +1032,7 @@ class Shuffle extends TinyEmitter {
/**
* Change a property or execute a function which will not have a transition
* @param {Array.<Element>} elements DOM elements that won't be transitioned.
* @param {Element[]} elements DOM elements that won't be transitioned.
* @param {Function} callback A function which will be called while transition
* is set to 0ms.
* @private
@ -1080,9 +1074,7 @@ Shuffle.ShuffleItem = ShuffleItem;
Shuffle.ALL_ITEMS = 'all';
Shuffle.FILTER_ATTRIBUTE_KEY = 'groups';
/**
* @enum {string}
*/
/** @enum {string} */
Shuffle.EventType = {
LAYOUT: 'shuffle:layout',
REMOVED: 'shuffle:removed',
@ -1091,9 +1083,7 @@ Shuffle.EventType = {
/** @enum {string} */
Shuffle.Classes = Classes;
/**
* @enum {string}
*/
/** @enum {string} */
Shuffle.FilterMode = {
ANY: 'any',
ALL: 'all',
@ -1166,9 +1156,10 @@ Shuffle.options = {
isCentered: false,
};
Shuffle.Point = Point;
Shuffle.Rect = Rect;
// Expose for testing. Hack at your own risk.
Shuffle.__Point = Point;
Shuffle.__Rect = Rect;
Shuffle.__sorter = sorter;
Shuffle.__getColumnSpan = getColumnSpan;
Shuffle.__getAvailablePositions = getAvailablePositions;

@ -97,7 +97,6 @@ describe('shuffle', function () {
expect(instance.options.delimeter).to.equal(null);
expect(instance.options.initialSort).to.equal(null);
expect(instance.options.throttleTime).to.equal(300);
expect(instance.useSizer).to.equal(false);
expect(instance.id).to.equal('shuffle_0');
expect(instance.isInitialized).to.be.true;
@ -307,21 +306,21 @@ describe('shuffle', function () {
it('can center already-positioned items', function() {
// 4-2-1 even heights
expect(Shuffle.__getCenteredPositions([
new Shuffle.__Rect(0, 0, 250, 100, 0),
new Shuffle.__Rect(250, 0, 250, 100, 1),
new Shuffle.__Rect(500, 0, 250, 100, 2),
new Shuffle.__Rect(750, 0, 250, 100, 3),
new Shuffle.__Rect(0, 100, 600, 100, 4),
new Shuffle.__Rect(600, 100, 300, 100, 5),
new Shuffle.__Rect(0, 200, 250, 100, 6),
new Shuffle.Rect(0, 0, 250, 100, 0),
new Shuffle.Rect(250, 0, 250, 100, 1),
new Shuffle.Rect(500, 0, 250, 100, 2),
new Shuffle.Rect(750, 0, 250, 100, 3),
new Shuffle.Rect(0, 100, 600, 100, 4),
new Shuffle.Rect(600, 100, 300, 100, 5),
new Shuffle.Rect(0, 200, 250, 100, 6),
], 1000)).to.deep.equal([
new Shuffle.__Point(0, 0),
new Shuffle.__Point(250, 0),
new Shuffle.__Point(500, 0),
new Shuffle.__Point(750, 0),
new Shuffle.__Point(50, 100),
new Shuffle.__Point(650, 100),
new Shuffle.__Point(375, 200),
new Shuffle.Point(0, 0),
new Shuffle.Point(250, 0),
new Shuffle.Point(500, 0),
new Shuffle.Point(750, 0),
new Shuffle.Point(50, 100),
new Shuffle.Point(650, 100),
new Shuffle.Point(375, 200),
]);
// 4 columns:
@ -330,13 +329,13 @@ describe('shuffle', function () {
// Centers the first row, but then finds that the 3rd item will overlap
// the 2x2 and resets the first row.
expect(Shuffle.__getCenteredPositions([
new Shuffle.__Rect(0, 0, 500, 200, 0),
new Shuffle.__Rect(500, 0, 250, 100, 1),
new Shuffle.__Rect(500, 100, 500, 100, 2),
new Shuffle.Rect(0, 0, 500, 200, 0),
new Shuffle.Rect(500, 0, 250, 100, 1),
new Shuffle.Rect(500, 100, 500, 100, 2),
], 1000)).to.deep.equal([
new Shuffle.__Point(0, 0),
new Shuffle.__Point(500, 0),
new Shuffle.__Point(500, 100),
new Shuffle.Point(0, 0),
new Shuffle.Point(500, 0),
new Shuffle.Point(500, 100),
]);
});

Loading…
Cancel
Save