mirror of
https://git.tt-rss.org/git/tt-rss.git
synced 2025-12-25 22:31:29 +00:00
upgrade dojo to 1.8.3 (refs #570)
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
/*
|
||||
Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved.
|
||||
Copyright (c) 2004-2012, The Dojo Foundation All Rights Reserved.
|
||||
Available via Academic Free License >= 2.1 OR the modified BSD license.
|
||||
see: http://dojotoolkit.org/license for details
|
||||
*/
|
||||
|
||||
//>>built
|
||||
define("dojo/data/util/filter",["dojo/_base/lang"],function(_1){var _2=_1.getObject("dojo.data.util.filter",true);_2.patternToRegExp=function(_3,_4){var _5="^";var c=null;for(var i=0;i<_3.length;i++){c=_3.charAt(i);switch(c){case "\\":_5+=c;i++;_5+=_3.charAt(i);break;case "*":_5+=".*";break;case "?":_5+=".";break;case "$":case "^":case "/":case "+":case ".":case "|":case "(":case ")":case "{":case "}":case "[":case "]":_5+="\\";default:_5+=c;}}_5+="$";if(_4){return new RegExp(_5,"mi");}else{return new RegExp(_5,"m");}};return _2;});
|
||||
define("dojo/data/util/filter",["../../_base/lang"],function(_1){var _2={};_1.setObject("dojo.data.util.filter",_2);_2.patternToRegExp=function(_3,_4){var _5="^";var c=null;for(var i=0;i<_3.length;i++){c=_3.charAt(i);switch(c){case "\\":_5+=c;i++;_5+=_3.charAt(i);break;case "*":_5+=".*";break;case "?":_5+=".";break;case "$":case "^":case "/":case "+":case ".":case "|":case "(":case ")":case "{":case "}":case "[":case "]":_5+="\\";default:_5+=c;}}_5+="$";if(_4){return new RegExp(_5,"mi");}else{return new RegExp(_5,"m");}};return _2;});
|
||||
77
lib/dojo/data/util/filter.js.uncompressed.js
Normal file
77
lib/dojo/data/util/filter.js.uncompressed.js
Normal file
@@ -0,0 +1,77 @@
|
||||
define("dojo/data/util/filter", ["../../_base/lang"], function(lang){
|
||||
// module:
|
||||
// dojo/data/util/filter
|
||||
// summary:
|
||||
// TODOC
|
||||
|
||||
var filter = {};
|
||||
lang.setObject("dojo.data.util.filter", filter);
|
||||
|
||||
filter.patternToRegExp = function(/*String*/pattern, /*boolean?*/ ignoreCase){
|
||||
// summary:
|
||||
// Helper function to convert a simple pattern to a regular expression for matching.
|
||||
// description:
|
||||
// Returns a regular expression object that conforms to the defined conversion rules.
|
||||
// For example:
|
||||
//
|
||||
// - ca* -> /^ca.*$/
|
||||
// - *ca* -> /^.*ca.*$/
|
||||
// - *c\*a* -> /^.*c\*a.*$/
|
||||
// - *c\*a?* -> /^.*c\*a..*$/
|
||||
//
|
||||
// and so on.
|
||||
// pattern: string
|
||||
// A simple matching pattern to convert that follows basic rules:
|
||||
//
|
||||
// - * Means match anything, so ca* means match anything starting with ca
|
||||
// - ? Means match single character. So, b?b will match to bob and bab, and so on.
|
||||
// - \ is an escape character. So for example, \* means do not treat * as a match, but literal character *.
|
||||
//
|
||||
// To use a \ as a character in the string, it must be escaped. So in the pattern it should be
|
||||
// represented by \\ to be treated as an ordinary \ character instead of an escape.
|
||||
// ignoreCase:
|
||||
// An optional flag to indicate if the pattern matching should be treated as case-sensitive or not when comparing
|
||||
// By default, it is assumed case sensitive.
|
||||
|
||||
var rxp = "^";
|
||||
var c = null;
|
||||
for(var i = 0; i < pattern.length; i++){
|
||||
c = pattern.charAt(i);
|
||||
switch(c){
|
||||
case '\\':
|
||||
rxp += c;
|
||||
i++;
|
||||
rxp += pattern.charAt(i);
|
||||
break;
|
||||
case '*':
|
||||
rxp += ".*"; break;
|
||||
case '?':
|
||||
rxp += "."; break;
|
||||
case '$':
|
||||
case '^':
|
||||
case '/':
|
||||
case '+':
|
||||
case '.':
|
||||
case '|':
|
||||
case '(':
|
||||
case ')':
|
||||
case '{':
|
||||
case '}':
|
||||
case '[':
|
||||
case ']':
|
||||
rxp += "\\"; //fallthrough
|
||||
default:
|
||||
rxp += c;
|
||||
}
|
||||
}
|
||||
rxp += "$";
|
||||
if(ignoreCase){
|
||||
return new RegExp(rxp,"mi"); //RegExp
|
||||
}else{
|
||||
return new RegExp(rxp,"m"); //RegExp
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
return filter;
|
||||
});
|
||||
@@ -1,8 +1,8 @@
|
||||
/*
|
||||
Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved.
|
||||
Copyright (c) 2004-2012, The Dojo Foundation All Rights Reserved.
|
||||
Available via Academic Free License >= 2.1 OR the modified BSD license.
|
||||
see: http://dojotoolkit.org/license for details
|
||||
*/
|
||||
|
||||
//>>built
|
||||
define("dojo/data/util/simpleFetch",["dojo/_base/lang","dojo/_base/window","./sorter"],function(_1,_2,_3){var _4=_1.getObject("dojo.data.util.simpleFetch",true);_4.fetch=function(_5){_5=_5||{};if(!_5.store){_5.store=this;}var _6=this;var _7=function(_8,_9){if(_9.onError){var _a=_9.scope||_2.global;_9.onError.call(_a,_8,_9);}};var _b=function(_c,_d){var _e=_d.abort||null;var _f=false;var _10=_d.start?_d.start:0;var _11=(_d.count&&(_d.count!==Infinity))?(_10+_d.count):_c.length;_d.abort=function(){_f=true;if(_e){_e.call(_d);}};var _12=_d.scope||_2.global;if(!_d.store){_d.store=_6;}if(_d.onBegin){_d.onBegin.call(_12,_c.length,_d);}if(_d.sort){_c.sort(_3.createSortFunction(_d.sort,_6));}if(_d.onItem){for(var i=_10;(i<_c.length)&&(i<_11);++i){var _13=_c[i];if(!_f){_d.onItem.call(_12,_13,_d);}}}if(_d.onComplete&&!_f){var _14=null;if(!_d.onItem){_14=_c.slice(_10,_11);}_d.onComplete.call(_12,_14,_d);}};this._fetchItems(_5,_b,_7);return _5;};return _4;});
|
||||
define("dojo/data/util/simpleFetch",["../../_base/lang","../../_base/kernel","./sorter"],function(_1,_2,_3){var _4={};_1.setObject("dojo.data.util.simpleFetch",_4);_4.errorHandler=function(_5,_6){if(_6.onError){var _7=_6.scope||_2.global;_6.onError.call(_7,_5,_6);}};_4.fetchHandler=function(_8,_9){var _a=_9.abort||null,_b=false,_c=_9.start?_9.start:0,_d=(_9.count&&(_9.count!==Infinity))?(_c+_9.count):_8.length;_9.abort=function(){_b=true;if(_a){_a.call(_9);}};var _e=_9.scope||_2.global;if(!_9.store){_9.store=this;}if(_9.onBegin){_9.onBegin.call(_e,_8.length,_9);}if(_9.sort){_8.sort(_3.createSortFunction(_9.sort,this));}if(_9.onItem){for(var i=_c;(i<_8.length)&&(i<_d);++i){var _f=_8[i];if(!_b){_9.onItem.call(_e,_f,_9);}}}if(_9.onComplete&&!_b){var _10=null;if(!_9.onItem){_10=_8.slice(_c,_d);}_9.onComplete.call(_e,_10,_9);}};_4.fetch=function(_11){_11=_11||{};if(!_11.store){_11.store=this;}this._fetchItems(_11,_1.hitch(this,"fetchHandler"),_1.hitch(this,"errorHandler"));return _11;};return _4;});
|
||||
240
lib/dojo/data/util/simpleFetch.js.uncompressed.js
Normal file
240
lib/dojo/data/util/simpleFetch.js.uncompressed.js
Normal file
@@ -0,0 +1,240 @@
|
||||
define("dojo/data/util/simpleFetch", ["../../_base/lang", "../../_base/kernel", "./sorter"],
|
||||
function(lang, kernel, sorter){
|
||||
// module:
|
||||
// dojo/data/util/simpleFetch
|
||||
// summary:
|
||||
// The simpleFetch mixin is designed to serve as a set of function(s) that can
|
||||
// be mixed into other datastore implementations to accelerate their development.
|
||||
|
||||
var simpleFetch = {};
|
||||
lang.setObject("dojo.data.util.simpleFetch", simpleFetch);
|
||||
|
||||
simpleFetch.errorHandler = function(/*Object*/ errorData, /*Object*/ requestObject){
|
||||
// summary:
|
||||
// The error handler when there is an error fetching items. This function should not be called
|
||||
// directly and is used by simpleFetch.fetch().
|
||||
if(requestObject.onError){
|
||||
var scope = requestObject.scope || kernel.global;
|
||||
requestObject.onError.call(scope, errorData, requestObject);
|
||||
}
|
||||
};
|
||||
|
||||
simpleFetch.fetchHandler = function(/*Array*/ items, /*Object*/ requestObject){
|
||||
// summary:
|
||||
// The handler when items are sucessfully fetched. This function should not be called directly
|
||||
// and is used by simpleFetch.fetch().
|
||||
var oldAbortFunction = requestObject.abort || null,
|
||||
aborted = false,
|
||||
|
||||
startIndex = requestObject.start?requestObject.start: 0,
|
||||
endIndex = (requestObject.count && (requestObject.count !== Infinity))?(startIndex + requestObject.count):items.length;
|
||||
|
||||
requestObject.abort = function(){
|
||||
aborted = true;
|
||||
if(oldAbortFunction){
|
||||
oldAbortFunction.call(requestObject);
|
||||
}
|
||||
};
|
||||
|
||||
var scope = requestObject.scope || kernel.global;
|
||||
if(!requestObject.store){
|
||||
requestObject.store = this;
|
||||
}
|
||||
if(requestObject.onBegin){
|
||||
requestObject.onBegin.call(scope, items.length, requestObject);
|
||||
}
|
||||
if(requestObject.sort){
|
||||
items.sort(sorter.createSortFunction(requestObject.sort, this));
|
||||
}
|
||||
if(requestObject.onItem){
|
||||
for(var i = startIndex; (i < items.length) && (i < endIndex); ++i){
|
||||
var item = items[i];
|
||||
if(!aborted){
|
||||
requestObject.onItem.call(scope, item, requestObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(requestObject.onComplete && !aborted){
|
||||
var subset = null;
|
||||
if(!requestObject.onItem){
|
||||
subset = items.slice(startIndex, endIndex);
|
||||
}
|
||||
requestObject.onComplete.call(scope, subset, requestObject);
|
||||
}
|
||||
};
|
||||
|
||||
simpleFetch.fetch = function(/* Object? */ request){
|
||||
// summary:
|
||||
// The simpleFetch mixin is designed to serve as a set of function(s) that can
|
||||
// be mixed into other datastore implementations to accelerate their development.
|
||||
// description:
|
||||
// The simpleFetch mixin should work well for any datastore that can respond to a _fetchItems()
|
||||
// call by returning an array of all the found items that matched the query. The simpleFetch mixin
|
||||
// is not designed to work for datastores that respond to a fetch() call by incrementally
|
||||
// loading items, or sequentially loading partial batches of the result
|
||||
// set. For datastores that mixin simpleFetch, simpleFetch
|
||||
// implements a fetch method that automatically handles eight of the fetch()
|
||||
// arguments -- onBegin, onItem, onComplete, onError, start, count, sort and scope
|
||||
// The class mixing in simpleFetch should not implement fetch(),
|
||||
// but should instead implement a _fetchItems() method. The _fetchItems()
|
||||
// method takes three arguments, the keywordArgs object that was passed
|
||||
// to fetch(), a callback function to be called when the result array is
|
||||
// available, and an error callback to be called if something goes wrong.
|
||||
// The _fetchItems() method should ignore any keywordArgs parameters for
|
||||
// start, count, onBegin, onItem, onComplete, onError, sort, and scope.
|
||||
// The _fetchItems() method needs to correctly handle any other keywordArgs
|
||||
// parameters, including the query parameter and any optional parameters
|
||||
// (such as includeChildren). The _fetchItems() method should create an array of
|
||||
// result items and pass it to the fetchHandler along with the original request object --
|
||||
// or, the _fetchItems() method may, if it wants to, create an new request object
|
||||
// with other specifics about the request that are specific to the datastore and pass
|
||||
// that as the request object to the handler.
|
||||
//
|
||||
// For more information on this specific function, see dojo/data/api/Read.fetch()
|
||||
//
|
||||
// request:
|
||||
// The keywordArgs parameter may either be an instance of
|
||||
// conforming to dojo/data/api/Request or may be a simple anonymous object
|
||||
// that may contain any of the following:
|
||||
// | {
|
||||
// | query: query-object or query-string,
|
||||
// | queryOptions: object,
|
||||
// | onBegin: Function,
|
||||
// | onItem: Function,
|
||||
// | onComplete: Function,
|
||||
// | onError: Function,
|
||||
// | scope: object,
|
||||
// | start: int
|
||||
// | count: int
|
||||
// | sort: array
|
||||
// | }
|
||||
// All implementations should accept keywordArgs objects with any of
|
||||
// the 9 standard properties: query, onBegin, onItem, onComplete, onError
|
||||
// scope, sort, start, and count. Some implementations may accept additional
|
||||
// properties in the keywordArgs object as valid parameters, such as
|
||||
// {includeOutliers:true}.
|
||||
//
|
||||
// ####The *query* parameter
|
||||
//
|
||||
// The query may be optional in some data store implementations.
|
||||
// The dojo/data/api/Read API does not specify the syntax or semantics
|
||||
// of the query itself -- each different data store implementation
|
||||
// may have its own notion of what a query should look like.
|
||||
// However, as of dojo 0.9, 1.0, and 1.1, all the provided datastores in dojo.data
|
||||
// and dojox.data support an object structure query, where the object is a set of
|
||||
// name/value parameters such as { attrFoo: valueBar, attrFoo1: valueBar1}. Most of the
|
||||
// dijit widgets, such as ComboBox assume this to be the case when working with a datastore
|
||||
// when they dynamically update the query. Therefore, for maximum compatibility with dijit
|
||||
// widgets the recommended query parameter is a key/value object. That does not mean that the
|
||||
// the datastore may not take alternative query forms, such as a simple string, a Date, a number,
|
||||
// or a mix of such. Ultimately, The dojo/data/api/Read API is agnostic about what the query
|
||||
// format.
|
||||
//
|
||||
// Further note: In general for query objects that accept strings as attribute
|
||||
// value matches, the store should also support basic filtering capability, such as *
|
||||
// (match any character) and ? (match single character). An example query that is a query object
|
||||
// would be like: { attrFoo: "value*"}. Which generally means match all items where they have
|
||||
// an attribute named attrFoo, with a value that starts with 'value'.
|
||||
//
|
||||
// ####The *queryOptions* parameter
|
||||
//
|
||||
// The queryOptions parameter is an optional parameter used to specify options that may modify
|
||||
// the query in some fashion, such as doing a case insensitive search, or doing a deep search
|
||||
// where all items in a hierarchical representation of data are scanned instead of just the root
|
||||
// items. It currently defines two options that all datastores should attempt to honor if possible:
|
||||
// | {
|
||||
// | ignoreCase: boolean, // Whether or not the query should match case sensitively or not. Default behaviour is false.
|
||||
// | deep: boolean // Whether or not a fetch should do a deep search of items and all child
|
||||
// | // items instead of just root-level items in a datastore. Default is false.
|
||||
// | }
|
||||
//
|
||||
// ####The *onBegin* parameter.
|
||||
//
|
||||
// function(size, request);
|
||||
// If an onBegin callback function is provided, the callback function
|
||||
// will be called just once, before the first onItem callback is called.
|
||||
// The onBegin callback function will be passed two arguments, the
|
||||
// the total number of items identified and the Request object. If the total number is
|
||||
// unknown, then size will be -1. Note that size is not necessarily the size of the
|
||||
// collection of items returned from the query, as the request may have specified to return only a
|
||||
// subset of the total set of items through the use of the start and count parameters.
|
||||
//
|
||||
// ####The *onItem* parameter.
|
||||
//
|
||||
// function(item, request);
|
||||
//
|
||||
// If an onItem callback function is provided, the callback function
|
||||
// will be called as each item in the result is received. The callback
|
||||
// function will be passed two arguments: the item itself, and the
|
||||
// Request object.
|
||||
//
|
||||
// ####The *onComplete* parameter.
|
||||
//
|
||||
// function(items, request);
|
||||
//
|
||||
// If an onComplete callback function is provided, the callback function
|
||||
// will be called just once, after the last onItem callback is called.
|
||||
// Note that if the onItem callback is not present, then onComplete will be passed
|
||||
// an array containing all items which matched the query and the request object.
|
||||
// If the onItem callback is present, then onComplete is called as:
|
||||
// onComplete(null, request).
|
||||
//
|
||||
// ####The *onError* parameter.
|
||||
//
|
||||
// function(errorData, request);
|
||||
//
|
||||
// If an onError callback function is provided, the callback function
|
||||
// will be called if there is any sort of error while attempting to
|
||||
// execute the query.
|
||||
// The onError callback function will be passed two arguments:
|
||||
// an Error object and the Request object.
|
||||
//
|
||||
// ####The *scope* parameter.
|
||||
//
|
||||
// If a scope object is provided, all of the callback functions (onItem,
|
||||
// onComplete, onError, etc) will be invoked in the context of the scope
|
||||
// object. In the body of the callback function, the value of the "this"
|
||||
// keyword will be the scope object. If no scope object is provided,
|
||||
// the callback functions will be called in the context of dojo.global().
|
||||
// For example, onItem.call(scope, item, request) vs.
|
||||
// onItem.call(dojo.global(), item, request)
|
||||
//
|
||||
// ####The *start* parameter.
|
||||
//
|
||||
// If a start parameter is specified, this is a indication to the datastore to
|
||||
// only start returning items once the start number of items have been located and
|
||||
// skipped. When this parameter is paired with 'count', the store should be able
|
||||
// to page across queries with millions of hits by only returning subsets of the
|
||||
// hits for each query
|
||||
//
|
||||
// ####The *count* parameter.
|
||||
//
|
||||
// If a count parameter is specified, this is a indication to the datastore to
|
||||
// only return up to that many items. This allows a fetch call that may have
|
||||
// millions of item matches to be paired down to something reasonable.
|
||||
//
|
||||
// ####The *sort* parameter.
|
||||
//
|
||||
// If a sort parameter is specified, this is a indication to the datastore to
|
||||
// sort the items in some manner before returning the items. The array is an array of
|
||||
// javascript objects that must conform to the following format to be applied to the
|
||||
// fetching of items:
|
||||
// | {
|
||||
// | attribute: attribute || attribute-name-string,
|
||||
// | descending: true|false; // Optional. Default is false.
|
||||
// | }
|
||||
// Note that when comparing attributes, if an item contains no value for the attribute
|
||||
// (undefined), then it the default ascending sort logic should push it to the bottom
|
||||
// of the list. In the descending order case, it such items should appear at the top of the list.
|
||||
|
||||
request = request || {};
|
||||
if(!request.store){
|
||||
request.store = this;
|
||||
}
|
||||
|
||||
this._fetchItems(request, lang.hitch(this, "fetchHandler"), lang.hitch(this, "errorHandler"));
|
||||
return request; // Object
|
||||
};
|
||||
|
||||
return simpleFetch;
|
||||
});
|
||||
@@ -1,8 +1,8 @@
|
||||
/*
|
||||
Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved.
|
||||
Copyright (c) 2004-2012, The Dojo Foundation All Rights Reserved.
|
||||
Available via Academic Free License >= 2.1 OR the modified BSD license.
|
||||
see: http://dojotoolkit.org/license for details
|
||||
*/
|
||||
|
||||
//>>built
|
||||
define("dojo/data/util/sorter",["dojo/_base/lang"],function(_1){var _2=_1.getObject("dojo.data.util.sorter",true);_2.basicComparator=function(a,b){var r=-1;if(a===null){a=undefined;}if(b===null){b=undefined;}if(a==b){r=0;}else{if(a>b||a==null){r=1;}}return r;};_2.createSortFunction=function(_3,_4){var _5=[];function _6(_7,_8,_9,s){return function(_a,_b){var a=s.getValue(_a,_7);var b=s.getValue(_b,_7);return _8*_9(a,b);};};var _c;var _d=_4.comparatorMap;var bc=_2.basicComparator;for(var i=0;i<_3.length;i++){_c=_3[i];var _e=_c.attribute;if(_e){var _f=(_c.descending)?-1:1;var _10=bc;if(_d){if(typeof _e!=="string"&&("toString" in _e)){_e=_e.toString();}_10=_d[_e]||bc;}_5.push(_6(_e,_f,_10,_4));}}return function(_11,_12){var i=0;while(i<_5.length){var ret=_5[i++](_11,_12);if(ret!==0){return ret;}}return 0;};};return _2;});
|
||||
define("dojo/data/util/sorter",["../../_base/lang"],function(_1){var _2={};_1.setObject("dojo.data.util.sorter",_2);_2.basicComparator=function(a,b){var r=-1;if(a===null){a=undefined;}if(b===null){b=undefined;}if(a==b){r=0;}else{if(a>b||a==null){r=1;}}return r;};_2.createSortFunction=function(_3,_4){var _5=[];function _6(_7,_8,_9,s){return function(_a,_b){var a=s.getValue(_a,_7);var b=s.getValue(_b,_7);return _8*_9(a,b);};};var _c;var _d=_4.comparatorMap;var bc=_2.basicComparator;for(var i=0;i<_3.length;i++){_c=_3[i];var _e=_c.attribute;if(_e){var _f=(_c.descending)?-1:1;var _10=bc;if(_d){if(typeof _e!=="string"&&("toString" in _e)){_e=_e.toString();}_10=_d[_e]||bc;}_5.push(_6(_e,_f,_10,_4));}}return function(_11,_12){var i=0;while(i<_5.length){var ret=_5[i++](_11,_12);if(ret!==0){return ret;}}return 0;};};return _2;});
|
||||
99
lib/dojo/data/util/sorter.js.uncompressed.js
Normal file
99
lib/dojo/data/util/sorter.js.uncompressed.js
Normal file
@@ -0,0 +1,99 @@
|
||||
define("dojo/data/util/sorter", ["../../_base/lang"], function(lang){
|
||||
// module:
|
||||
// dojo/data/util/sorter
|
||||
// summary:
|
||||
// TODOC
|
||||
|
||||
var sorter = {};
|
||||
lang.setObject("dojo.data.util.sorter", sorter);
|
||||
|
||||
sorter.basicComparator = function( /*anything*/ a,
|
||||
/*anything*/ b){
|
||||
// summary:
|
||||
// Basic comparison function that compares if an item is greater or less than another item
|
||||
// description:
|
||||
// returns 1 if a > b, -1 if a < b, 0 if equal.
|
||||
// 'null' values (null, undefined) are treated as larger values so that they're pushed to the end of the list.
|
||||
// And compared to each other, null is equivalent to undefined.
|
||||
|
||||
//null is a problematic compare, so if null, we set to undefined.
|
||||
//Makes the check logic simple, compact, and consistent
|
||||
//And (null == undefined) === true, so the check later against null
|
||||
//works for undefined and is less bytes.
|
||||
var r = -1;
|
||||
if(a === null){
|
||||
a = undefined;
|
||||
}
|
||||
if(b === null){
|
||||
b = undefined;
|
||||
}
|
||||
if(a == b){
|
||||
r = 0;
|
||||
}else if(a > b || a == null){
|
||||
r = 1;
|
||||
}
|
||||
return r; //int {-1,0,1}
|
||||
};
|
||||
|
||||
sorter.createSortFunction = function( /* attributes[] */sortSpec, /*dojo/data/api/Read*/ store){
|
||||
// summary:
|
||||
// Helper function to generate the sorting function based off the list of sort attributes.
|
||||
// description:
|
||||
// The sort function creation will look for a property on the store called 'comparatorMap'. If it exists
|
||||
// it will look in the mapping for comparisons function for the attributes. If one is found, it will
|
||||
// use it instead of the basic comparator, which is typically used for strings, ints, booleans, and dates.
|
||||
// Returns the sorting function for this particular list of attributes and sorting directions.
|
||||
// sortSpec:
|
||||
// A JS object that array that defines out what attribute names to sort on and whether it should be descenting or asending.
|
||||
// The objects should be formatted as follows:
|
||||
// | {
|
||||
// | attribute: "attributeName-string" || attribute,
|
||||
// | descending: true|false; // Default is false.
|
||||
// | }
|
||||
// store:
|
||||
// The datastore object to look up item values from.
|
||||
|
||||
var sortFunctions=[];
|
||||
|
||||
function createSortFunction(attr, dir, comp, s){
|
||||
//Passing in comp and s (comparator and store), makes this
|
||||
//function much faster.
|
||||
return function(itemA, itemB){
|
||||
var a = s.getValue(itemA, attr);
|
||||
var b = s.getValue(itemB, attr);
|
||||
return dir * comp(a,b); //int
|
||||
};
|
||||
}
|
||||
var sortAttribute;
|
||||
var map = store.comparatorMap;
|
||||
var bc = sorter.basicComparator;
|
||||
for(var i = 0; i < sortSpec.length; i++){
|
||||
sortAttribute = sortSpec[i];
|
||||
var attr = sortAttribute.attribute;
|
||||
if(attr){
|
||||
var dir = (sortAttribute.descending) ? -1 : 1;
|
||||
var comp = bc;
|
||||
if(map){
|
||||
if(typeof attr !== "string" && ("toString" in attr)){
|
||||
attr = attr.toString();
|
||||
}
|
||||
comp = map[attr] || bc;
|
||||
}
|
||||
sortFunctions.push(createSortFunction(attr,
|
||||
dir, comp, store));
|
||||
}
|
||||
}
|
||||
return function(rowA, rowB){
|
||||
var i=0;
|
||||
while(i < sortFunctions.length){
|
||||
var ret = sortFunctions[i++](rowA, rowB);
|
||||
if(ret !== 0){
|
||||
return ret;//int
|
||||
}
|
||||
}
|
||||
return 0; //int
|
||||
}; // Function
|
||||
};
|
||||
|
||||
return sorter;
|
||||
});
|
||||
Reference in New Issue
Block a user