Merge remote-tracking branch 'upstream/master'

This commit is contained in:
gstamac
2013-08-24 21:59:55 +02:00
18 changed files with 1745 additions and 170 deletions
+3 -2
View File
@@ -128,7 +128,8 @@ List of Definitions
* [KeyboardJS](https://github.com/RobertWHurst/KeyboardJS) (by [Vincent Bortone](https://github.com/vbortone/))
* [Knockback](http://kmalakoff.github.com/knockback/) (by [Marcel Binot](https://github.com/docgit))
* [Knockout.js](http://knockoutjs.com/) (by [Boris Yankov](https://github.com/borisyankov))
* [Knockout.ES5](http://github.com/SteveSanderson/knockout-es5/) (by [Sebastián Galiano](https://github.com/sgaliano))
* [Knockout.DeferredUpdates](https://github.com/mbest/knockout-deferred-updates) (by [Sebastián Galiano](https://github.com/sgaliano))
* [Knockout.ES5](https://github.com/SteveSanderson/knockout-es5) (by [Sebastián Galiano](https://github.com/sgaliano))
* [Knockout.Mapping](https://github.com/SteveSanderson/knockout.mapping) (by [Boris Yankov](https://github.com/borisyankov))
* [Knockout.Postbox](https://github.com/rniemeyer/knockout-postbox) (by [Judah Gabriel](https://github.com/JudahGabriel))
* [Knockout.Validation](https://github.com/ericmbarnard/Knockout-Validation) (by [Dan Ludwig](https://github.com/danludwig))
@@ -176,7 +177,7 @@ List of Definitions
* [Spin](http://fgnass.github.com/spin.js/) (by [Boris Yankov](https://github.com/borisyankov))
* [Store.js](https://github.com/marcuswestin/store.js/) (by [Vincent Bortone](https://github.com/vbortone))
* [Sugar](http://sugarjs.com/) (by [Josh Baldwin](https://github.com/jbaldwin/))
* [Swiper](http://www.idangero.us/sliders/swiper/) (by [Sebastián Galiano](https://github.com/sgaliano))
* [Swiper](http://www.idangero.us/sliders/swiper) (by [Sebastián Galiano](https://github.com/sgaliano))
* [SwipeView](http://cubiq.org/swipeview) (by [Boris Yankov](https://github.com/borisyankov))
* [Tags Manager](http://welldonethings.com/tags/manager) (by [Vincent Bortone](https://github.com/vbortone))
* [Teechart](http://www.steema.com) (by [Steema](http://www.steema.com))
+246
View File
@@ -0,0 +1,246 @@
// Copied examples directly from AmplifyJs site
// Subscribe and publish with no data
amplify.subscribe("nodataexample", function () {
alert("nodataexample topic published!");
});
// Subscribe and publish with data
amplify.publish("nodataexample");
amplify.subscribe("dataexample", function (data) {
alert(data.foo); // bar
});
amplify.publish("dataexample", { foo: "bar" });
amplify.subscribe("dataexample2", function (param1, param2) {
alert(param1 + param2); // barbaz
});
//...
amplify.publish("dataexample2", "bar", "baz");
// Subscribe and publish with context and data
amplify.subscribe("datacontextexample", $("p:first"), function (data) {
this.text(data.exampleText); // first p element would have "foo bar baz" as text
});
amplify.publish("datacontextexample", { exampleText: "foo bar baz" });
// Subscribe to a topic with high priority
amplify.subscribe("priorityexample", function (data) {
alert(data.foo);
});
amplify.subscribe("priorityexample", function (data) {
if (data.foo === "oops") {
return false;
}
}, 1);
// Store data with amplify storage picking the default storage technology:
amplify.publish("priorityexample", { foo: "bar" });
amplify.publish("priorityexample", { foo: "oops" });
amplify.store("storeExample1", { foo: "bar" });
amplify.store("storeExample2", "baz");
// retrieve the data later via the key
var myStoredValue = amplify.store("storeExample1"),
myStoredValue2 = amplify.store("storeExample2"),
myStoredValues = amplify.store();
myStoredValue.foo; // bar
myStoredValue2; // baz
myStoredValues.storeExample1.foo; // bar
myStoredValues.storeExample2; // baz
// Store data explicitly with session storage
amplify.store.sessionStorage("explicitExample", { foo2: "baz" });
// retrieve the data later via the key
var myStoredValue2 = amplify.store.sessionStorage("explicitExample");
myStoredValue2.foo2; // baz
// REQUEST
// Set up and use a request utilizing Ajax
amplify.request.define("ajaxExample1", "ajax", {
url: "/myApiUrl",
dataType: "json",
type: "GET"
});
// later in code
amplify.request("ajaxExample1", function (data) {
data.foo; // bar
});
// Set up and use a request utilizing Ajax and Caching
amplify.request.define("ajaxExample2", "ajax", {
url: "/myApiUrl",
dataType: "json",
type: "GET",
cache: "persist"
});
// later in code
amplify.request("ajaxExample2", function (data) {
data.foo; // bar
});
// a second call will result in pulling from the cache
amplify.request("ajaxExample2", function (data) {
data.baz; // qux
})
// Set up and use a RESTful request utilizing Ajax
amplify.request.define("ajaxRESTFulExample", "ajax", {
url: "/myRestFulApi/{type}/{id}",
type: "GET"
})
// later in code
amplify.request("ajaxRESTFulExample",
{
type: "foo",
id: "bar"
},
function (data) {
// /myRESTFulApi/foo/bar was the URL used
data.foo; // bar
}
);
// POST data with Ajax
amplify.request.define("ajaxPostExample", "ajax", {
url: "/myRestFulApi",
type: "POST"
})
// later in code
amplify.request("ajaxPostExample",
{
type: "foo",
id: "bar"
},
function (data) {
data.foo; // bar
}
);
// Using data maps
// When searching Twitter, the key for the search phrase is q.If we want a more descriptive name, such as term, we can use a data map:
amplify.request.define("twitter-search", "ajax", {
url: "http://search.twitter.com/search.json",
dataType: "jsonp",
dataMap: {
term: "q"
}
});
amplify.request("twitter-search", { term: "amplifyjs" } );
// Similarly, we can create a request that searches for mentions, by accepting a username:
amplify.request.define("twitter-mentions", "ajax", {
url: "http://search.twitter.com/search.json",
dataType: "jsonp",
dataMap: function (data) {
return {
q: "@" + data.user
};
}
});
amplify.request("twitter-mentions", { user: "amplifyjs" });
// Setting up and using decoders
//Example:
amplify.request.decoders.appEnvelope =
function (data, status, xhr, success, error) {
if (data.status === "success") {
success(data.data);
} else if (data.status === "fail" || data.status === "error") {
error(data.message, data.status);
} else {
error(data.message, "fatal");
}
};
amplify.request.define("decoderExample", "ajax", {
url: "/myAjaxUrl",
type: "POST",
decoder: "appEnvelope"
});
amplify.request({
resourceId: "decoderExample",
success: function (data) {
data.foo; // bar
},
error: function (message, level) {
alert("always handle errors with alerts.");
}
});
// POST with caching and single - use decoder
// Example:
amplify.request.define("decoderSingleExample", "ajax", {
url: "/myAjaxUrl",
type: "POST",
decoder: function (data, status, xhr, success, error) {
if (data.status === "success") {
success(data.data);
} else if (data.status === "fail" || data.status === "error") {
error(data.message, data.status);
} else {
error(data.message, "fatal");
}
}
});
amplify.request({
resourceId: "decoderSingleExample",
success: function (data) {
data.foo; // bar
},
error: function (message, level) {
alert("always handle errors with alerts.");
}
});
// Handling Status
// Status in Success and Error Callbacks
// amplify.request comes with built in support for status.The status parameter appears in the default success or error callbacks when using an ajax definition.
amplify.request.define("statusExample1", "ajax", {
//...
});
amplify.request({
resourceId: "statusExample1",
success: function (data, status) {
},
error: function (data, status) {
}
});
+159
View File
@@ -0,0 +1,159 @@
// Type definitions for AmplifyJs 1.1.0
// Project: http://amplifyjs.com/
// Definitions by: Jonas Eriksson <https://github.com/joeriks/>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
interface amplifyRequestSettings {
resourceId: string;
data?: any;
success?: Function;
error?: Function;
}
interface amplifyRequest {
/***
* Request a resource.
* resourceId: Identifier string for the resource.
* data: A set of key/value pairs of data to be sent to the resource.
* callback: A function to invoke if the resource is retrieved successfully.
*/
(resourceId: string, hash?: any, callback?: Function): void;
/***
* Request a resource.
* settings: A set of key/value pairs of settings for the request.
* resourceId: Identifier string for the resource.
* data (optional): Data associated with the request.
* success (optional): Function to invoke on success.
* error (optional): Function to invoke on error.
*/
(settings: amplifyRequestSettings);
/***
* Define a resource.
* resourceId: Identifier string for the resource.
* requestType: The type of data retrieval method from the server. See the request types sections for more information.
* settings: A set of key/value pairs that relate to the server communication technology. The following settings are available:
* Any settings found in jQuery.ajax().
* cache: See the cache section for more details.
* decoder: See the decoder section for more details.
*/
define(resourceId: string, requestType: string, settings?: any): void;
/***
* Define a custom request.
* resourceId: Identifier string for the resource.
* resource: Function to handle requests. Receives a hash with the following properties:
* resourceId: Identifier string for the resource.
* data: Data provided by the user.
* success: Callback to invoke on success.
* error: Callback to invoke on error.
*/
define(resourceId: string, resource: Function): void;
decoders: any;
cache: any;
}
interface amplifySubscribe {
/***
* Subscribe to a message.
* topic: Name of the message to subscribe to.
* callback: Function to invoke when the message is published.
*/
(topic: string, callback: Function): void;
/***
* Subscribe to a message.
* topic: Name of the message to subscribe to.
* context: What this will be when the callback is invoked.
* callback: Function to invoke when the message is published.
* [priority]: Priority relative to other subscriptions for the same message. Lower values have higher priority. Default is 10.
*/
(topic: string, context: any, callback: Function, priority?: number): void;
/***
* Subscribe to a message.
* topic: Name of the message to subscribe to.
* callback: Function to invoke when the message is published.
* [priority]: Priority relative to other subscriptions for the same message. Lower values have higher priority. Default is 10.
*/
(topic: string, callback: Function, priority?: number): void;
}
interface amplifyStorageTypeStore {
/***
* Stores a value for a given key using the default storage type.
*
* key: Identifier for the value being stored.
* value: The value to store. The value can be anything that can be serialized as JSON.
* [options]: A set of key/value pairs that relate to settings for storing the value.
*/
(key: string, value: any, options?: any): void;
/***
* Gets a stored value based on the key.
*/
(key: string): any;
/***
* Gets a hash of all stored values.
*/
(): any;
}
interface amplifyStore extends amplifyStorageTypeStore{
/***
* IE 8+, Firefox 3.5+, Safari 4+, Chrome, Opera 10.5+, iPhone 2+, Android 2+
*/
localStorage: amplifyStorageTypeStore;
/***
* IE 8+, Firefox 2+, Safari 4+, Chrome, Opera 10.5+, iPhone 2+, Android 2+
*/
sessionStorage: amplifyStorageTypeStore;
/***
* Firefox 2+
*/
globalStorage: amplifyStorageTypeStore;
/***
* IE 5 - 7
*/
userData: amplifyStorageTypeStore;
/***
* An in-memory store is provided as a fallback if none of the other storage types are available.
*/
memory: amplifyStorageTypeStore;
}
interface amplifyStatic {
subscribe: amplifySubscribe;
/***
* Remove a subscription.
* topic: The topic being unsubscribed from.
* callback: The callback that was originally subscribed.
*/
unsubscribe(topic: string, callback: Function): void;
/***
* Publish a message.
* topic: The name of the message to publish.
* Any additional parameters will be passed to the subscriptions.
* amplify.publish returns a boolean indicating whether any subscriptions returned false. The return value is true if none of the subscriptions returned false, and false otherwise. Note that only one subscription can return false because doing so will prevent additional subscriptions from being invoked.
*/
publish(topic: string, ...args: any[]): boolean;
store: amplifyStore;
request: amplifyRequest;
}
declare var amplify: amplifyStatic;
+728 -55
View File
@@ -1,90 +1,763 @@
/// <reference path="chai.d.ts" />
var expect = chai.expect;
declare var err: Function;
function test_be() {
expect(true).to.be.ok;
function chaiVersion() {
expect(chai).to.have.property('version');
}
function assertion() {
expect('test').to.be.a('string');
expect('foo').to.equal('foo');
}
function _true() {
expect(true).to.be.true;
expect(false).to.not.be.true;
expect(1).to.not.be.true;
err(() => {
expect('test').to.be.true;
}, "expected 'test' to be true")
}
function ok() {
expect(true).to.be.ok;
expect(false).to.not.be.ok;
expect(1).to.be.ok;
expect(0).to.not.be.ok;
err(() => {
expect('').to.be.ok;
}, "expected '' to be truthy");
err(() => {
expect('test').to.not.be.ok;
}, "expected 'test' to be falsy");
}
function _false() {
expect(false).to.be.false;
expect(true).to.not.be.false;
expect(0).to.not.be.false;
err(() => {
expect('').to.be.false;
}, "expected '' to be false")
}
function _null() {
expect(null).to.be.null;
expect(false).to.not.be.null;
err(() => {
expect('').to.be.null;
}, "expected '' to be null")
}
function _undefined() {
expect(undefined).to.be.undefined;
expect([]).to.be.empty;
expect([]).to.be.arguments;
expect({}).to.be.an('object');
expect({}).to.be.an.instanceof(Object);
expect(null).to.not.be.undefined;
err(() => {
expect('').to.be.undefined;
}, "expected '' to be undefined")
}
function exist() {
var foo = 'bar'
, bar;
expect(foo).to.exist;
expect(bar).to.not.exist;
}
function arguments() {
var args = arguments;
expect(args).to.be.arguments;
expect([]).to.not.be.arguments;
expect(args).to.be.an('arguments').and.be.arguments;
expect([]).to.be.an('array').and.not.be.Arguments;
}
function equal() {
var foo;
expect(undefined).to.equal(foo);
}
function _typeof() {
expect('test').to.be.a('string');
err(() => {
expect('test').to.not.be.a('string');
}, "expected 'test' not to be a string");
expect(arguments).to.be.an('arguments');
expect(5).to.be.a('number');
expect(new Number(1)).to.be.a('number');
expect(Number(1)).to.be.a('number');
expect(true).to.be.a('boolean');
expect(new Array()).to.be.a('array');
expect(new Object()).to.be.a('object');
expect({}).to.be.a('object');
expect([]).to.be.a('array');
expect(function () { }).to.be.a('function');
expect(null).to.be.a('null');
err(() => {
expect(5).to.not.be.a('number', 'blah');
}, "blah: expected 5 not to be a number");
}
function _instanceof() {
function Foo() { }
expect(new Foo()).to.be.an.instanceof(Foo);
err(() => {
expect(3).to.an.instanceof(Foo, 'blah');
}, "blah: expected 3 to be an instance of Foo");
}
function within(start, finish) {
expect(5).to.be.within(5, 10);
expect(5).to.be.within(3, 6);
expect(5).to.be.within(3, 5);
expect(5).to.not.be.within(1, 3);
expect('foo').to.have.length.within(2, 4);
expect([1, 2, 3]).to.have.length.within(2, 4);
err(() => {
expect(5).to.not.be.within(4, 6, 'blah');
}, "blah: expected 5 to not be within 4..6", 'blah');
err(() => {
expect(10).to.be.within(50, 100, 'blah');
}, "blah: expected 10 to be within 50..100");
err(() => {
expect('foo').to.have.length.within(5, 7, 'blah');
}, "blah: expected \'foo\' to have a length within 5..7");
err(() => {
expect([1, 2, 3]).to.have.length.within(5, 7, 'blah');
}, "blah: expected [ 1, 2, 3 ] to have a length within 5..7");
}
function above(n) {
expect(5).to.be.above(2);
expect(5).to.be.greaterThan(2);
expect(5).to.not.be.above(5);
expect(5).to.not.be.above(6);
expect('foo').to.have.length.above(2);
expect([1, 2, 3]).to.have.length.above(2);
err(() => {
expect(5).to.be.above(6, 'blah');
}, "blah: expected 5 to be above 6", 'blah');
err(() => {
expect(10).to.not.be.above(6, 'blah');
}, "blah: expected 10 to be at most 6");
err(() => {
expect('foo').to.have.length.above(4, 'blah');
}, "blah: expected \'foo\' to have a length above 4 but got 3");
err(() => {
expect([1, 2, 3]).to.have.length.above(4, 'blah');
}, "blah: expected [ 1, 2, 3 ] to have a length above 4 but got 3");
}
function least(n) {
expect(5).to.be.at.least(2);
expect(5).to.be.at.least(5);
expect(5).to.be.at.gte(5);
expect(5).to.be.at.most(5);
expect(5).to.be.at.lte(5);
expect('').to.be.a('string');
expect(5).to.be.within(1, 6);
expect(5.001).to.be.closeTo(5, 0.5);
expect(5).to.not.be.at.least(6);
expect('foo').to.have.length.of.at.least(2);
expect([1, 2, 3]).to.have.length.of.at.least(2);
err(() => {
expect(5).to.be.at.least(6, 'blah');
}, "blah: expected 5 to be at least 6", 'blah');
err(() => {
expect(10).to.not.be.at.least(6, 'blah');
}, "blah: expected 10 to be below 6");
err(() => {
expect('foo').to.have.length.of.at.least(4, 'blah');
}, "blah: expected \'foo\' to have a length at least 4 but got 3");
err(() => {
expect([1, 2, 3]).to.have.length.of.at.least(4, 'blah');
}, "blah: expected [ 1, 2, 3 ] to have a length at least 4 but got 3");
err(() => {
expect([1, 2, 3, 4]).to.not.have.length.of.at.least(4, 'blah');
}, "blah: expected [ 1, 2, 3, 4 ] to have a length below 4");
}
function test_not() {
expect(5).to.not.be.a('string');
function below(n) {
expect(2).to.be.below(5);
expect(2).to.be.lessThan(5);
expect(2).to.not.be.below(2);
expect(2).to.not.be.below(1);
expect('foo').to.have.length.below(4);
expect([1, 2, 3]).to.have.length.below(4);
err(() => {
expect(6).to.be.below(5, 'blah');
}, "blah: expected 6 to be below 5");
err(() => {
expect(6).to.not.be.below(10, 'blah');
}, "blah: expected 6 to be at least 10");
err(() => {
expect('foo').to.have.length.below(2, 'blah');
}, "blah: expected \'foo\' to have a length below 2 but got 3");
err(() => {
expect([1, 2, 3]).to.have.length.below(2, 'blah');
}, "blah: expected [ 1, 2, 3 ] to have a length below 2 but got 3");
}
function test_deep() {
expect(5).to.deep.equal(5);
expect({ foo: 'bar' }).to.deep.property('foo', 'bar');
function most(n) {
expect(2).to.be.at.most(5);
expect(2).to.be.at.most(2);
expect(2).to.not.be.at.most(1);
expect(2).to.not.be.at.most(1);
expect('foo').to.have.length.of.at.most(4);
expect([1, 2, 3]).to.have.length.of.at.most(4);
err(() => {
expect(6).to.be.at.most(5, 'blah');
}, "blah: expected 6 to be at most 5");
err(() => {
expect(6).to.not.be.at.most(10, 'blah');
}, "blah: expected 6 to be above 10");
err(() => {
expect('foo').to.have.length.of.at.most(2, 'blah');
}, "blah: expected \'foo\' to have a length at most 2 but got 3");
err(() => {
expect([1, 2, 3]).to.have.length.of.at.most(2, 'blah');
}, "blah: expected [ 1, 2, 3 ] to have a length at most 2 but got 3");
err(() => {
expect([1, 2]).to.not.have.length.of.at.most(2, 'blah');
}, "blah: expected [ 1, 2 ] to have a length above 2");
}
function test_have() {
expect({ foo: 'bar' }).to.have.property('foo', 'bar');
expect([]).to.have.length(5);
expect({ foo: 'bar' }).to.have.ownProperty('foo');
expect('foo-bar').to.have.string('bar');
expect({ foo: 'bar', baz: 'qux' }).to.have.keys('foo', 'baz');
function match(regexp) {
expect('foobar').to.match(/^foo/);
expect('foobar').to.not.match(/^bar/);
err(() => {
expect('foobar').to.match(/^bar/i, 'blah')
}, "blah: expected 'foobar' to match /^bar/i");
err(() => {
expect('foobar').to.not.match(/^foo/i, 'blah')
}, "blah: expected 'foobar' not to match /^foo/i");
}
function test_exist() {
var obj = { foo: 'bar' };
expect(obj.foo).to.exist;
function length2(n) {
expect('test').to.have.length(4);
expect('test').to.not.have.length(3);
expect([1, 2, 3]).to.have.length(3);
err(() => {
expect(4).to.have.length(3, 'blah');
}, 'blah: expected 4 to have a property \'length\'');
err(() => {
expect('asd').to.not.have.length(3, 'blah');
}, "blah: expected 'asd' to not have a length of 3");
}
function test_equal() {
expect(5).to.equal(5);
function eql(val) {
expect('test').to.eql('test');
expect({ foo: 'bar' }).to.eql({ foo: 'bar' });
expect(1).to.eql(1);
expect('4').to.not.eql(4);
err(() => {
expect(4).to.eql(3, 'blah');
}, 'blah: expected 4 to deeply equal 3');
}
function test_include() {
expect('foo-bar').to.include('o-b');
expect([1,2,3]).to.include(2);
expect({ foo: 'bar', baz: 'qux' }).to.include.keys('foo', 'baz');
function buffer() {
var Buffer;
expect(new Buffer([1])).to.eql(new Buffer([1]));
expect('foo-bar').to.contain('o-b');
expect([1,2,3]).to.contain(2);
expect({ foo: 'bar', baz: 'qux' }).to.contain.keys('foo', 'baz');
err(() => {
expect(new Buffer([0])).to.eql(new Buffer([1]));
}, 'expected <Buffer 00> to deeply equal <Buffer 01>');
}
function test_throw() {
var foo = {
bar: () => { }
function equal2(val) {
expect('test').to.equal('test');
expect(1).to.equal(1);
err(() => {
expect(4).to.equal(3, 'blah');
}, 'blah: expected 4 to equal 3');
err(() => {
expect('4').to.equal(4, 'blah');
}, "blah: expected '4' to equal 4");
}
function deepEqual(val) {
expect({ foo: 'bar' }).to.deep.equal({ foo: 'bar' });
expect({ foo: 'bar' }).not.to.deep.equal({ foo: 'baz' });
}
function deepEqual2() {
expect(/a/).to.deep.equal(/a/);
expect(/a/).not.to.deep.equal(/b/);
expect(/a/).not.to.deep.equal({});
expect(/a/g).to.deep.equal(/a/g);
expect(/a/g).not.to.deep.equal(/b/g);
expect(/a/i).to.deep.equal(/a/i);
expect(/a/i).not.to.deep.equal(/b/i);
expect(/a/m).to.deep.equal(/a/m);
expect(/a/m).not.to.deep.equal(/b/m);
}
function deepEqual3(Date) {
var a = new Date(1, 2, 3)
, b = new Date(4, 5, 6);
expect(a).to.deep.equal(a);
expect(a).not.to.deep.equal(b);
expect(a).not.to.deep.equal({});
}
function empty() {
function FakeArgs() { };
FakeArgs.prototype.length = 0;
expect('').to.be.empty;
expect('foo').not.to.be.empty;
expect([]).to.be.empty;
expect(['foo']).not.to.be.empty;
expect(new FakeArgs).to.be.empty;
expect({ arguments: 0 }).not.to.be.empty;
expect({}).to.be.empty;
expect({ foo: 'bar' }).not.to.be.empty;
err(() => {
expect('').not.to.be.empty;
}, "expected \'\' not to be empty");
err(() => {
expect('foo').to.be.empty;
}, "expected \'foo\' to be empty");
err(() => {
expect([]).not.to.be.empty;
}, "expected [] not to be empty");
err(() => {
expect(['foo']).to.be.empty;
}, "expected [ \'foo\' ] to be empty");
err(() => {
expect(new FakeArgs).not.to.be.empty;
}, "expected { length: 0 } not to be empty");
err(() => {
expect({ arguments: 0 }).to.be.empty;
}, "expected { arguments: 0 } to be empty");
err(() => {
expect({}).not.to.be.empty;
}, "expected {} not to be empty");
err(() => {
expect({ foo: 'bar' }).to.be.empty;
}, "expected { foo: \'bar\' } to be empty");
}
function property(name) {
expect('test').to.have.property('length');
expect(4).to.not.have.property('length');
expect({ 'foo.bar': 'baz' })
.to.have.property('foo.bar');
expect({ foo: { bar: 'baz' } })
.to.not.have.property('foo.bar');
err(() => {
expect('asd').to.have.property('foo');
}, "expected 'asd' to have a property 'foo'");
err(() => {
expect({ foo: { bar: 'baz' } })
.to.have.property('foo.bar');
}, "expected { foo: { bar: 'baz' } } to have a property 'foo.bar'");
}
function deepProperty(name) {
expect({ 'foo.bar': 'baz' })
.to.not.have.deep.property('foo.bar');
expect({ foo: { bar: 'baz' } })
.to.have.deep.property('foo.bar');
err(() => {
expect({ 'foo.bar': 'baz' })
.to.have.deep.property('foo.bar');
}, "expected { 'foo.bar': 'baz' } to have a deep property 'foo.bar'");
}
function property2(name, val) {
expect('test').to.have.property('length', 4);
expect('asd').to.have.property('constructor', String);
err(() => {
expect('asd').to.have.property('length', 4, 'blah');
}, "blah: expected 'asd' to have a property 'length' of 4, but got 3");
err(() => {
expect('asd').to.not.have.property('length', 3, 'blah');
}, "blah: expected 'asd' to not have a property 'length' of 3");
err(() => {
expect('asd').to.not.have.property('foo', 3, 'blah');
}, "blah: 'asd' has no property 'foo'");
err(() => {
expect('asd').to.have.property('constructor', Number, 'blah');
}, "blah: expected 'asd' to have a property 'constructor' of [Function: Number], but got [Function: String]");
}
function deepProperty2(name, val) {
expect({ foo: { bar: 'baz' } })
.to.have.deep.property('foo.bar', 'baz');
err(() => {
expect({ foo: { bar: 'baz' } })
.to.have.deep.property('foo.bar', 'quux', 'blah');
}, "blah: expected { foo: { bar: 'baz' } } to have a deep property 'foo.bar' of 'quux', but got 'baz'");
err(() => {
expect({ foo: { bar: 'baz' } })
.to.not.have.deep.property('foo.bar', 'baz', 'blah');
}, "blah: expected { foo: { bar: 'baz' } } to not have a deep property 'foo.bar' of 'baz'");
err(() => {
expect({ foo: 5 })
.to.not.have.deep.property('foo.bar', 'baz', 'blah');
}, "blah: { foo: 5 } has no deep property 'foo.bar'");
}
function ownProperty(name) {
expect('test').to.have.ownProperty('length');
expect('test').to.haveOwnProperty('length');
expect({ length: 12 }).to.have.ownProperty('length');
err(() => {
expect({ length: 12 }).to.not.have.ownProperty('length', 'blah');
}, "blah: expected { length: 12 } to not have own property 'length'");
}
function string() {
expect('foobar').to.have.string('bar');
expect('foobar').to.have.string('foo');
expect('foobar').to.not.have.string('baz');
err(() => {
expect(3).to.have.string('baz');
}, "expected 3 to be a string");
err(() => {
expect('foobar').to.have.string('baz', 'blah');
}, "blah: expected 'foobar' to contain 'baz'");
err(() => {
expect('foobar').to.not.have.string('bar', 'blah');
}, "blah: expected 'foobar' to not contain 'bar'");
}
function include() {
expect(['foo', 'bar']).to.include('foo');
expect(['foo', 'bar']).to.include('foo');
expect(['foo', 'bar']).to.include('bar');
expect([1, 2]).to.include(1);
expect(['foo', 'bar']).to.not.include('baz');
expect(['foo', 'bar']).to.not.include(1);
err(() => {
expect(['foo']).to.include('bar', 'blah');
}, "blah: expected [ 'foo' ] to include 'bar'");
err(() => {
expect(['bar', 'foo']).to.not.include('foo', 'blah');
}, "blah: expected [ 'bar', 'foo' ] to not include 'foo'");
}
function keys(array) {
expect({ foo: 1 }).to.have.keys(['foo']);
expect({ foo: 1, bar: 2 }).to.have.keys(['foo', 'bar']);
expect({ foo: 1, bar: 2 }).to.have.keys('foo', 'bar');
expect({ foo: 1, bar: 2, baz: 3 }).to.contain.keys('foo', 'bar');
expect({ foo: 1, bar: 2, baz: 3 }).to.contain.keys('bar', 'foo');
expect({ foo: 1, bar: 2, baz: 3 }).to.contain.keys('baz');
expect({ foo: 1, bar: 2 }).to.contain.keys('foo');
expect({ foo: 1, bar: 2 }).to.contain.keys('bar', 'foo');
expect({ foo: 1, bar: 2 }).to.contain.keys(['foo']);
expect({ foo: 1, bar: 2 }).to.contain.keys(['bar']);
expect({ foo: 1, bar: 2 }).to.contain.keys(['bar', 'foo']);
expect({ foo: 1, bar: 2 }).to.not.have.keys('baz');
expect({ foo: 1, bar: 2 }).to.not.have.keys('foo', 'baz');
expect({ foo: 1, bar: 2 }).to.not.contain.keys('baz');
expect({ foo: 1, bar: 2 }).to.not.contain.keys('foo', 'baz');
expect({ foo: 1, bar: 2 }).to.not.contain.keys('baz', 'foo');
err(() => {
expect({ foo: 1 }).to.have.keys();
}, "keys required");
err(() => {
expect({ foo: 1 }).to.have.keys([]);
}, "keys required");
err(() => {
expect({ foo: 1 }).to.not.have.keys([]);
}, "keys required");
err(() => {
expect({ foo: 1 }).to.contain.keys([]);
}, "keys required");
err(() => {
expect({ foo: 1 }).to.have.keys(['bar']);
}, "expected { foo: 1 } to have key 'bar'");
err(() => {
expect({ foo: 1 }).to.have.keys(['bar', 'baz']);
}, "expected { foo: 1 } to have keys 'bar', and 'baz'");
err(() => {
expect({ foo: 1 }).to.have.keys(['foo', 'bar', 'baz']);
}, "expected { foo: 1 } to have keys 'foo', 'bar', and 'baz'");
err(() => {
expect({ foo: 1 }).to.not.have.keys(['foo']);
}, "expected { foo: 1 } to not have key 'foo'");
err(() => {
expect({ foo: 1 }).to.not.have.keys(['foo']);
}, "expected { foo: 1 } to not have key 'foo'");
err(() => {
expect({ foo: 1, bar: 2 }).to.not.have.keys(['foo', 'bar']);
}, "expected { foo: 1, bar: 2 } to not have keys 'foo', and 'bar'");
err(() => {
expect({ foo: 1 }).to.not.contain.keys(['foo']);
}, "expected { foo: 1 } to not contain key 'foo'");
err(() => {
expect({ foo: 1 }).to.contain.keys('foo', 'bar');
}, "expected { foo: 1 } to contain keys 'foo', and 'bar'");
}
function chaining() {
var tea = { name: 'chai', extras: ['milk', 'sugar', 'smile'] };
expect(tea).to.have.property('extras').with.lengthOf(3);
err(() => {
expect(tea).to.have.property('extras').with.lengthOf(4);
}, "expected [ 'milk', 'sugar', 'smile' ] to have a length of 4 but got 3");
expect(tea).to.be.a('object').and.have.property('name', 'chai');
}
function _throw() {
// See GH-45: some poorly-constructed custom errors don't have useful names
// on either their constructor or their constructor prototype, but instead
// only set the name inside the constructor itself.
var PoorlyConstructedError = () => {
this.name = 'PoorlyConstructedError';
};
PoorlyConstructedError.prototype = Object.create(Error.prototype);
var specificError = new RangeError('boo');
var goodFn = () => { 1 == 1; }
, badFn = () => { throw new Error('testing'); }
, refErrFn = () => { throw new ReferenceError('hello'); }
, ickyErrFn = () => { throw new PoorlyConstructedError(); }
, specificErrFn = () => { throw specificError; };
expect(goodFn).to.not.throw();
expect(goodFn).to.not.throw(Error);
expect(goodFn).to.not.throw(specificError);
expect(badFn).to.throw();
expect(badFn).to.throw(Error);
expect(badFn).to.not.throw(ReferenceError);
expect(badFn).to.not.throw(specificError);
expect(refErrFn).to.throw();
expect(refErrFn).to.throw(ReferenceError);
expect(refErrFn).to.throw(Error);
expect(refErrFn).to.not.throw(TypeError);
expect(refErrFn).to.not.throw(specificError);
expect(ickyErrFn).to.throw();
expect(ickyErrFn).to.throw(PoorlyConstructedError);
expect(ickyErrFn).to.throw(Error);
expect(ickyErrFn).to.not.throw(specificError);
expect(specificErrFn).to.throw(specificError);
expect(badFn).to.throw(/testing/);
expect(badFn).to.not.throw(/hello/);
expect(badFn).to.throw('testing');
expect(badFn).to.not.throw('hello');
expect(badFn).to.throw(Error, /testing/);
expect(badFn).to.throw(Error, 'testing');
err(() => {
expect(goodFn).to.throw();
}, "expected [Function] to throw an error");
err(() => {
expect(goodFn).to.throw(ReferenceError);
}, "expected [Function] to throw ReferenceError");
err(() => {
expect(goodFn).to.throw(specificError);
}, "expected [Function] to throw [RangeError: boo]");
err(() => {
expect(badFn).to.not.throw();
}, "expected [Function] to not throw an error but [Error: testing] was thrown");
err(() => {
expect(badFn).to.throw(ReferenceError);
}, "expected [Function] to throw 'ReferenceError' but [Error: testing] was thrown");
err(() => {
expect(badFn).to.throw(specificError);
}, "expected [Function] to throw [RangeError: boo] but [Error: testing] was thrown");
err(() => {
expect(badFn).to.not.throw(Error);
}, "expected [Function] to not throw 'Error' but [Error: testing] was thrown");
err(() => {
expect(refErrFn).to.not.throw(ReferenceError);
}, "expected [Function] to not throw 'ReferenceError' but [ReferenceError: hello] was thrown");
err(() => {
expect(badFn).to.throw(PoorlyConstructedError);
}, "expected [Function] to throw 'PoorlyConstructedError' but [Error: testing] was thrown");
err(() => {
expect(ickyErrFn).to.not.throw(PoorlyConstructedError);
}, /^(expected \[Function\] to not throw 'PoorlyConstructedError' but)(.*)(PoorlyConstructedError|\{ Object \()(.*)(was thrown)$/);
err(() => {
expect(ickyErrFn).to.throw(ReferenceError);
}, /^(expected \[Function\] to throw 'ReferenceError' but)(.*)(PoorlyConstructedError|\{ Object \()(.*)(was thrown)$/);
err(() => {
expect(specificErrFn).to.throw(new ReferenceError('eek'));
}, "expected [Function] to throw [ReferenceError: eek] but [RangeError: boo] was thrown");
err(() => {
expect(specificErrFn).to.not.throw(specificError);
}, "expected [Function] to not throw [RangeError: boo]");
err(() => {
expect(badFn).to.not.throw(/testing/);
}, "expected [Function] to throw error not matching /testing/");
err(() => {
expect(badFn).to.throw(/hello/);
}, "expected [Function] to throw error matching /hello/ but got 'testing'");
err(() => {
expect(badFn).to.throw(Error, /hello/, 'blah');
}, "blah: expected [Function] to throw error matching /hello/ but got 'testing'");
err(() => {
expect(badFn).to.throw(Error, 'hello', 'blah');
}, "blah: expected [Function] to throw error including 'hello' but got 'testing'");
}
function respondTo() {
function Foo() {};
var bar = {};
expect(Foo).to.respondTo('bar');
expect(Foo).to.not.respondTo('foo');
expect(Foo).itself.to.respondTo('func');
expect(Foo).itself.not.to.respondTo('bar');
expect(bar).to.respondTo('foo');
err(() => {
expect(Foo).to.respondTo('baz', 'constructor');
}, /^(constructor: expected)(.*)(\[Function: Foo\])(.*)(to respond to \'baz\')$/);
err(() => {
expect(bar).to.respondTo('baz', 'object');
}, /^(object: expected)(.*)(\{ foo: \[Function\] \}|\{ Object \()(.*)(to respond to \'baz\')$/);
}
function satisfy() {
function matcher(num) {
return num === 1;
};
expect(foo.bar).to.throw(new Error);
expect(foo.bar).to.throw('An error');
expect(foo.bar).to.throw(/error/);
expect(1).to.satisfy(matcher);
err(() => {
expect(2).to.satisfy(matcher, 'blah');
}, "blah: expected 2 to satisfy [Function: matcher]");
}
function test_eql() {
var foo = {}
expect(foo).to.eql({});
expect(foo).to.eqls({});
function closeTo() {
expect(1.5).to.be.closeTo(1.0, 0.5);
expect(10).to.be.closeTo(20, 20);
expect(-10).to.be.closeTo(20, 30);
err(() => {
expect(2).to.be.closeTo(1.0, 0.5, 'blah');
}, "blah: expected 2 to be close to 1 +/- 0.5");
err(() => {
expect(-10).to.be.closeTo(20, 29, 'blah');
}, "blah: expected -10 to be close to 20 +/- 29");
}
function test_match() {
expect('foo-bar').to.match(/foo/);
function includeMembers() {
expect([1, 2, 3]).to.include.members([]);
expect([1, 2, 3]).to.include.members([3, 2]);
expect([1, 2, 3]).to.not.include.members([8, 4]);
expect([1, 2, 3]).to.not.include.members([1, 2, 3, 4]);
}
function test_respondTo() {
var foo = {
bar: () => { }
};
function sameMembers() {
expect([5, 4]).to.have.same.members([4, 5]);
expect([5, 4]).to.have.same.members([5, 4]);
expect(foo).to.respondTo('bar');
expect([5, 4]).to.not.have.same.members([]);
expect([5, 4]).to.not.have.same.members([6, 3]);
expect([5, 4]).to.not.have.same.members([5, 4, 2]);
}
function test_satisfy() {
expect(1).to.satisfy((n) => n > 0);
}
function members() {
expect([5, 4]).members([4, 5]);
expect([5, 4]).members([5, 4]);
expect([5, 4]).not.members([]);
expect([5, 4]).not.members([6, 3]);
expect([5, 4]).not.members([5, 4, 2]);
}
+106 -87
View File
@@ -1,121 +1,140 @@
// Type definitions for chai 1.5.0
// Type definitions for chai 1.7.2
// Project: http://chaijs.com/
// Definitions by: Kazi Manzur Rashid <https://github.com/kazimanzurrashid/>
// Definitions by: Jed Hunsaker <https://github.com/jedhunsaker/>
// DefinitelyTyped: https://github.com/borisyankov/DefinitelyTyped
declare module chai {
interface Equality {
(expected: any, message?: string): boolean;
function expect(target: any): Expect;
interface Expect extends LanguageChains, NumericComparison, TypeComparison {
not: Expect;
deep: Deep;
a: TypeComparison;
an: TypeComparison;
include: Include;
contain: Include;
ok: Expect;
true: Expect;
false: Expect;
null: Expect;
undefined: Expect;
exist: Expect;
empty: Expect;
arguments: Expect;
Arguments: Expect;
equal: Equal;
equals: Equal;
eq: Equal;
eql: Equal;
eqls: Equal;
property: Property;
ownProperty: OwnProperty;
haveOwnProperty: OwnProperty;
length: Length;
lengthOf: Length;
match(RegularExpression: RegExp, message?: string): Expect;
string(string: string, message?: string): Expect;
keys: Keys;
key(string: string): Expect;
throw: Throw;
throws: Throw;
Throw: Throw;
respondTo(method: string, message?: string): Expect;
itself: Expect;
satisfy(matcher: Function, message?: string): Expect;
closeTo(expected: number, delta: number, message?: string): Expect;
members: Members;
}
interface Property {
(name: string, value?: any, message?: string): boolean;
}
interface NumberComparer {
(value: number, message?: string): boolean;
}
interface Eql {
(value: any, message?: string): boolean;
}
interface Include {
(value: Object, message?: string): boolean;
(value: string, message?: string): boolean;
(value: number, message?: string): boolean;
keys(...names: string[]): boolean;
}
interface Throw {
(constructor: Error, message?: string);
(expected: string, message?: string);
(expected: RegExp, message?: string);
}
interface TypeComparison {
(type: string, message?: string): boolean;
instanceof(type: Object): boolean;
interface LanguageChains {
to: Expect;
be: Expect;
been: Expect;
is: Expect;
that: Expect;
and: Expect;
have: Expect;
with: Expect;
at: Expect;
of: Expect;
same: Expect;
}
interface NumericComparison {
above: NumberComparer;
gt: NumberComparer;
greaterThan: NumberComparer;
least: NumberComparer;
gte: NumberComparer;
below: NumberComparer;
lt: NumberComparer;
lessThan: NumberComparer;
most: NumberComparer;
lte: NumberComparer;
within(start: number, finish: number, message?: string): Expect;
}
interface Length extends NumericComparison {
(value: number, message?: string): boolean;
interface NumberComparer {
(value: number, message?: string): Expect;
}
interface TypeComparison {
(type: string, message?: string): Expect;
instanceof: InstanceOf;
instanceOf: InstanceOf;
}
interface InstanceOf {
(constructor: Object, message?: string): Expect;
}
interface Deep {
equal: Equality;
equal: Equal;
property: Property;
}
interface Have {
property: Property;
deep: Deep;
length: Length;
ownProperty(name: string, message?: string): boolean;
string(value: string, message?: string): boolean;
keys(...values: string[]): boolean;
interface Equal {
(value: any, message?: string): Expect;
}
interface At {
least(value: number, message?: string): boolean;
gte(value: number, message?: string): boolean;
most(value: number, message?: string): boolean;
lte(value: number, message?: string): boolean;
interface Property {
(name: string, value?: any, message?: string): Expect;
}
interface Be extends NumericComparison {
ok: boolean;
true: boolean;
false: boolean;
null: boolean;
undefined: boolean;
empty: boolean;
arguments: boolean;
an: TypeComparison;
at: At;
a(type: string, message?: string): boolean;
within(start: number, finish: number, message?: string): boolean;
closeTo(expected: number, delta: number, message?: string): boolean;
interface OwnProperty {
(name: string, message?: string): Expect;
}
interface To {
be: Be;
not: To;
deep: Deep;
have: Have;
exist: boolean;
equal: Equality;
include: Include;
contain: Include;
throw: Throw;
eql: Eql;
eqls: Eql;
match(value: RegExp, message?: string): boolean;
respondTo(method: string, message?: string);
satisfy(matcher: Function, message?: string);
interface Length extends LanguageChains, NumericComparison {
(length: number, message?: string): Expect;
}
interface ExpectMatchers {
to: To;
interface Include {
(value: Object, message?: string): Expect;
(value: string, message?: string): Expect;
(value: number, message?: string): Expect;
keys: Keys;
members: Members;
}
function expect(target: any): chai.ExpectMatchers;
interface Keys {
(...keys: string[]): Expect;
(keys: Array): Expect;
}
interface Members {
(set: Array, message?: string): Expect;
}
interface Throw {
(): Expect;
(expected: string, message?: string): Expect;
(expected: RegExp, message?: string): Expect;
(constructor: Error, expected?: string, message?: string): Expect;
(constructor: Error, expected?: RegExp, message?: string): Expect;
(constructor: Function, expected?: string, message?: string): Expect;
(constructor: Function, expected?: RegExp, message?: string): Expect;
}
}
Vendored
+1 -1
View File
@@ -1388,7 +1388,7 @@ declare module D3 {
/**
* convert the color to a string.
*/
toString(): Color;
toString(): string;
}
export interface RGBColor extends Color{
@@ -0,0 +1,52 @@
/// <reference path="../jquery/jquery.d.ts"/>
/// <reference path="jquery.simplePagination.d.ts"/>
var selector = '#elementId';
$(function () {
$(selector).pagination({
items: 100,
itemsOnPage: 10,
cssStyle: 'light-theme'
});
});
$(function () {
$(selector).pagination('selectPage', 1);
});
$(function () {
$(selector).pagination('prevPage');
});
$(function () {
$(selector).pagination('nextPage');
});
$(function () {
$(selector).pagination('getPagesCount');
});
$(function () {
$(selector).pagination('getCurrentPage');
});
$(function () {
$(selector).pagination('disable');
});
$(function () {
$(selector).pagination('enable');
});
$(function () {
$(selector).pagination('destroy');
});
$(function () {
$(selector).pagination('redraw');
});
$(function () {
$(selector).pagination('updateItems', 100);
});
+13 -1
View File
@@ -18,10 +18,22 @@ interface SimplePaginationOptions {
nextText?: string;
cssStyle?: string;
selectOnClick?: boolean;
onPageClick?: (interger) => void;
onPageClick?: (page?: number, event?: any) => void;
onInit?: () => void;
}
interface JQuery {
pagination(options?: SimplePaginationOptions): JQuery;
pagination(method: string): any;
pagination(method: string, value: any): any;
pagination(method: 'selectPage', pageNumber: number): void;
pagination(method: 'prevPage'): void;
pagination(method: 'nextPage'): void;
pagination(method: 'getPagesCount'): number;
pagination(method: 'getCurrentPage'): number;
pagination(method: 'disable'): void;
pagination(method: 'enable'): void;
pagination(method: 'destroy'): void;
pagination(method: 'redraw'): void;
pagination(method: 'updateItems', items: number): void;
}
+5 -1
View File
@@ -64,7 +64,11 @@ interface TimePickerOptions {
interface JQuery {
timepicker(): JQuery;
timepicker(options: TimePickerOptions): JQuery;
timepicker(methodName: string): JQuery;
timepicker(methodName: string): any;
timepicker(methodName: 'getTime'): string;
timepicker(methodName: 'getTimeAsDate'): Date;
timepicker(methodName: 'getHour'): number;
timepicker(methodName: 'getMinute'): number;
timepicker(methodName: string, methodParameter: any): any;
timepicker(optionLiteral: string, optionName: string): any;
}
+1
View File
@@ -785,6 +785,7 @@ interface JQuery {
parentsUntil(selector?: string, filter?: string): JQuery;
parentsUntil(element?: Element, filter?: string): JQuery;
parentsUntil(obj?: JQuery, filter?: string): JQuery;
prev(selector?: string): JQuery;
@@ -0,0 +1,252 @@
/// <reference path="knockout.deferred.updates.d.ts" />
// Turn *off* deferred updates for computed observables and subscriptions
ko.computed.deferUpdates = false;
var myComputed = ko.computed(() => { /* ... */ });
// Turn *on* deferred updates for this computed observable
myComputed.deferUpdates = true;
var myObservable = ko.observable();
var mySubscription = myObservable.subscribe((value) => { /* ... */ });
// Turn *on* deferred updates for this subscription
mySubscription.deferUpdates = true;
// Turn *off* deferred updates for this computed observable
myComputed.extend({ deferred: false });
//
// Examples
//
function nestedComputedNoPlugin() {
var vm: any = {
a: ko.observable(0),
b: ko.observable(0),
c: ko.observable(0),
d: ko.observable(0),
e: ko.observable(0),
f: ko.observable(0)
};
var startTime = new Date().getTime();
var updateArray = [];
function firstUpdate() {
var updateList = document.getElementById('updates');
while (updateList.firstChild) updateList.removeChild(updateList.firstChild);
}
function pushUpdate(name, value, color) {
var li = document.createElement('li');
li.appendChild(document.createTextNode(name + ' ' + value + '; ' + (new Date().getTime() - startTime) + ' ms'));
li.style.color = color;
document.getElementById('updates').appendChild(li);
}
function lastUpdate() {
}
var updateCounter = 0, plusminus = 1;
vm.doUpdate = function () {
var u = updateCounter += plusminus;
startTime = new Date().getTime();
vm.a(u);
vm.b(u);
vm.c(u);
vm.d(u);
vm.e(u);
vm.f(u);
plusminus = !u ? 1 : (u == 9) ? -1 : plusminus;
};
vm.setThrottle = function (value) {
vm.A.throttleEvaluation = value;
vm._B.throttleEvaluation = value;
vm.C.throttleEvaluation = value;
vm.D.throttleEvaluation = value;
vm.E.throttleEvaluation = value;
vm.F.throttleEvaluation = value;
};
vm.runNormal = function () {
ko.computed.deferUpdates = false;
vm.setThrottle(undefined);
vm.doUpdate();
};
vm.runThrottle = function () {
ko.computed.deferUpdates = false;
vm.setThrottle(1);
vm.doUpdate();
};
vm.A = ko.computed(function () {
var result = '' + vm.a();
firstUpdate();
pushUpdate('A', result, 'green');
return result;
}, null, { deferEvaluation: true });
vm._B = ko.computed(function () {
var result = '' + vm.A() + vm.b();
pushUpdate('B', result, 'darkturquoise');
return result;
}, null, { deferEvaluation: true });
vm.C = ko.computed(function () {
var result = '' + vm._B() + vm.c();
pushUpdate('C', result, 'royalblue');
return result;
}, null, { deferEvaluation: true });
vm.D = ko.computed(function () {
var result = '' + vm.C() + vm.d();
pushUpdate('D', result, 'indigo');
return result;
}, null, { deferEvaluation: true });
vm.E = ko.computed(function () {
var result = '' + vm.D() + vm.e();
pushUpdate('E', result, 'firebrick');
return result;
}, null, { deferEvaluation: true });
vm.F = ko.computed(function () {
var f = vm.f(), result = '' + vm.E() + f;
pushUpdate('F', result, 'orangered');
if (result === '' + f + f + f + f + f + f) lastUpdate();
return result;
}, null, { deferEvaluation: true });
vm.A();
vm._B();
vm.C();
vm.D();
vm.E();
vm.F();
ko.applyBindings(vm);
};
function nestedComputedPlugin() {
var vm: any = {
a: ko.observable(0),
b: ko.observable(0),
c: ko.observable(0),
d: ko.observable(0),
e: ko.observable(0),
f: ko.observable(0)
};
var startTime = new Date().getTime();
var updateArray = [];
function firstUpdate() {
var updateList = document.getElementById('updates');
while (updateList.firstChild)
updateList.removeChild(updateList.firstChild);
}
function pushUpdate(name, value, color) {
var li = document.createElement('li');
li.appendChild(document.createTextNode(name + ' ' + value + '; ' + (new Date().getTime() - startTime) + ' ms'));
li.style.color = color;
document.getElementById('updates').appendChild(li);
}
function lastUpdate() {
}
var updateCounter = 0, plusminus = 1;
vm.doUpdate = function () {
var u = updateCounter += plusminus;
startTime = new Date().getTime();
vm.a(u);
vm.b(u);
vm.c(u);
vm.d(u);
vm.e(u);
vm.f(u);
plusminus = !u ? 1 : (u == 9) ? -1 : plusminus;
};
vm.setThrottle = function (value) {
vm.A.throttleEvaluation = value;
vm._B.throttleEvaluation = value;
vm.C.throttleEvaluation = value;
vm.D.throttleEvaluation = value;
vm.E.throttleEvaluation = value;
vm.F.throttleEvaluation = value;
};
vm.runNormal = function () {
ko.computed.deferUpdates = false;
vm.setThrottle(undefined);
vm.doUpdate();
};
vm.runThrottle = function () {
ko.computed.deferUpdates = false;
vm.setThrottle(1);
vm.doUpdate();
};
vm.runDefer = function () {
ko.computed.deferUpdates = true;
vm.setThrottle(undefined);
vm.doUpdate();
};
vm.runWrappedDefer = ko.tasks.makeProcessedCallback(vm.runDefer);
vm.A = ko.computed(function () {
var result = '' + vm.a();
firstUpdate();
pushUpdate('A', result, 'green');
return result;
}, null, { deferEvaluation: true });
vm._B = ko.computed(function () {
var result = '' + vm.A() + vm.b();
pushUpdate('B', result, 'darkturquoise');
return result;
}, null, { deferEvaluation: true });
vm.C = ko.computed(function () {
var result = '' + vm._B() + vm.c();
pushUpdate('C', result, 'royalblue');
return result;
}, null, { deferEvaluation: true });
vm.D = ko.computed(function () {
var result = '' + vm.C() + vm.d();
pushUpdate('D', result, 'indigo');
return result;
}, null, { deferEvaluation: true });
vm.E = ko.computed(function () {
var result = '' + vm.D() + vm.e();
pushUpdate('E', result, 'firebrick');
return result;
}, null, { deferEvaluation: true });
vm.F = ko.computed(function () {
var f = vm.f(), result = '' + vm.E() + f;
pushUpdate('F', result, 'orangered');
if (result === '' + f + f + f + f + f + f) lastUpdate();
return result;
}, null, { deferEvaluation: true });
vm.A();
vm._B();
vm.C();
vm.D();
vm.E();
vm.F();
ko.applyBindings(vm);
}
@@ -0,0 +1,46 @@
// Type definitions for Knockout Deferred Updates
// Project: https://github.com/mbest/knockout-deferred-updates
// Definitions by: Sebastián Galiano <https://github.com/sgaliano/>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/// <reference path="../knockout/knockout.d.ts" />
interface KnockoutDeferredTasks {
processImmediate(evaluator: Function, object?: any, args?: Array): any;
processDelayed(evaluator: Function, distinct?: boolean, options?: Array): boolean;
makeProcessedCallback(evaluator: Function): void;
}
// Knockout global
interface KnockoutStatic {
tasks: KnockoutDeferredTasks;
processAllDeferredBindingUpdates(): void;
processAllDeferredUpdates(): void;
evaluateAsynchronously(evaluator: Function, timeout?: any): number;
ignoreDependencies(callback: Function, callbackTarget: any, callbackArgs?: Array);
}
// Observables
interface KnockoutSubscribableFunctions {
deferUpdates: boolean;
}
// Computed
interface KnockoutComputedStatic {
deferUpdates: boolean;
}
interface KnockoutComputedFunctions {
deferUpdates: boolean;
}
// Utils
interface KnockoutUtils {
objectForEach(obj: any, action: Function): void;
objectMap(source: any, mapping: Function): any;
}
// Deferred extender
interface KnockoutExtenders {
deferred(target: any, value: boolean): any;
}
+1 -1
View File
@@ -9,6 +9,6 @@ interface KnockoutStatic {
track(obj: any, propertyNames?: Array<string>): any;
defineProperty(obj: any, propertyName: string, evaluator: Function): any;
defineProperty(obj: any, propertyName: string, options: { get: () => any; set?: (value: any) => void; }): any;
getObservable(obj: any, propertyName: string): KnockoutObservable;
getObservable(obj: any, propertyName: string): KnockoutObservable<any>;
valueHasMutated(obj: any, propertyName: string): void;
}
+5 -5
View File
@@ -152,7 +152,7 @@ interface NodeProcess extends EventEmitter {
nextTick(callback: Function): void;
umask(mask?: number): number;
uptime(): number;
hrtime(): number[];
hrtime(time?:number[]): number[];
}
// Buffer class
@@ -1020,8 +1020,8 @@ declare module "util" {
}
declare module "assert" {
function internal (booleanValue: boolean, message?: string): void;
module internal {
function internal (booleanValue: boolean, message?: string): void;
module internal {
export function fail(actual: any, expected: any, message: string, operator: string): void;
export function assert(value: any, message: string): void;
export function ok(value: any, message?: string): void;
@@ -1035,8 +1035,8 @@ declare module "assert" {
export function doesNotThrow(block: any, error?: any, messsage?: string): void;
export function ifError(value: any): void;
}
export = internal;
export = internal;
}
declare module "tty" {
+34 -1
View File
@@ -71,6 +71,27 @@ $("#e6").select2({
formatSelection: movieFormatSelection,
dropdownCssClass: "bigdrop"
});
$("#e6").select2({
placeholder: "Search for a movie",
minimumInputLength: 1,
ajax: {
url: () => { return "http://api.rottentomatoes.com/api/public/v1.0/movies.json"; },
dataType: 'jsonp',
data: function (term, page) {
return {
q: term,
page_limit: 10,
apikey: "ju6z9mjyajq2djue3gbvv26t"
};
},
results: function (data, page) {
return { results: data.movies };
}
},
formatResult: movieFormatResult,
formatSelection: movieFormatSelection,
dropdownCssClass: "bigdrop"
});
$("#e7").select2({
placeholder: "Search for a movie",
minimumInputLength: 3,
@@ -161,4 +182,16 @@ $("#e17_2").select2({
}
});
$("#e18,#e18_2").select2();
alert("Selected value is: " + $("#e8").select2("val")); $("#e8").select2("val", { id: "CA", text: "Califoria" });
alert("Selected value is: " + $("#e8").select2("val")); $("#e8").select2("val", { id: "CA", text: "Califoria" });
$("#e8").select2("val");
$("#e8").select2("val", "CA");
$("#e8").select2("data");
$("#e8").select2("data", { id: "CA", text: "Califoria" });
$("#e8").select2("destroy");
$("#e8").select2("open");
$("#e8").select2("enable", false);
$("#e8").select2("readonly", false);
$("#e8").select2('container');
$("#e8").select2('onSortStart');
$("#e8").select2('onSortEnd');
+60 -5
View File
@@ -20,7 +20,10 @@ interface AjaxFunction {
interface Select2AjaxOptions {
transport?: AjaxFunction;
url?: string;
/**
* Url to make request to, Can be string or a function returning a string.
*/
url?: any;
dataType?: string;
quietMillis?: number;
data?: (term: string, page: number, context: any) => any;
@@ -72,8 +75,60 @@ interface JQuery {
select2(): JQuery;
select2(it: IdTextPair): JQuery;
select2(options: Select2Options): JQuery;
select2(method: string, something: string): JQuery;
select2(method: string, something: string[]): JQuery;
select2(method: string, something: IdTextPair[]): JQuery;
select2(method: string, options: IdTextPair): JQuery;
select2(method: string): any;
select2(method: string, value: any, trigger?: boolean): any;
/**
* Get the id value of the current selection
*/
select2(method: 'val'): any;
/**
* Set the id value of the current selection
* @params value Value to set the id to
* @params triggerChange Should a change event be triggered
*/
select2(method: 'val', value: any, triggerChange?: boolean): any;
/**
* Get the data object of the current selection
*/
select2(method: 'data'): any;
/**
* Set the data of the current selection
* @params value Object to set the data to
* @params triggerChange Should a change event be triggered
*/
select2(method: 'data', value: any, triggerChange?: boolean): any;
/**
* Reverts changes to DOM done by Select2. Any selection done via Select2 will be preserved.
*/
select2(method: 'destroy'): void;
/**
* Opens the dropdown
*/
select2(method: 'open'): void;
/**
* Closes the dropdown
*/
select2(method: 'close'): void;
/**
* Enables or disables Select2 and its underlying form component
* @param value True if it should be enabled false if it should be disabled
*/
select2(method: 'enable', value: boolean): void;
/**
* Toggles readonly mode on Select2 and its underlying form component
* @param value True if it should be readonly false if it should be read write
*/
select2(method: 'readonly', value: boolean): void;
/**
* Retrieves the main container element that wraps all of DOM added by Select2
*/
select2(method: 'container'): HTMLElement;
/**
* Notifies Select2 that a drag and drop sorting operation has started
*/
select2(method: 'onSortStart'): void;
/**
* Notifies Select2 that a drag and drop sorting operation has finished
*/
select2(method: 'onSortEnd'): void;
}
+24 -2
View File
@@ -4,5 +4,27 @@ var spinner = new Spinner().spin();
target.appendChild(spinner.el);
var target = document.getElementById('foo');
var opts = { speed: 5, className: 'awesome' };
var spinner2 = new Spinner(opts).spin(target);
var opts = { speed: 5, color: '#abcdef' };
var spinner2 = new Spinner(opts).spin(target);
var opts2 = {
lines: 10,
length: 20,
width: 7,
radius: 14,
corners: 0.6,
rotate: 0,
direction: 1,
color: ['#aaa', '#fedcba', '#fff', '#aef02b'],
speed: 1.5,
trail: 50,
shadow: true,
hwaccel: true,
className: 'spinner',
zIndex: 5,
top: '28',
left: 'auto'
};
var newTarget = document.getElementById('bar');
var spinner3 = new Spinner(opts2).spin(newTarget);
+9 -9
View File
@@ -1,4 +1,4 @@
// Type definitions for Spin.js 1.3
// Type definitions for Spin.js 1.3.1
// Project: http://fgnass.github.com/spin.js/
// Definitions by: Boris Yankov <https://github.com/borisyankov/> and Theodore Brown <https://github.com/theodorejb/>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
@@ -12,7 +12,7 @@ interface SpinnerOptions {
corners?: number; // Corner roundness (0..1)
rotate?: number; // The rotation offset
direction?: number; // 1: clockwise, -1: counterclockwise
color?: string; // #rgb or #rrggbb
color?: any; // #rgb or #rrggbb or array of colors
speed?: number; // Rounds per second
trail?: number; // Afterglow percentage
shadow?: boolean; // Whether to render a shadow
@@ -29,16 +29,16 @@ declare class Spinner {
public el: HTMLElement;
constructor(options?: SpinnerOptions);
/**
* Adds the spinner to the given target element. If this instance is already
* spinning, it is automatically removed from its previous target by calling
* stop() internally.
/**
* Adds the spinner to the given target element. If this instance is already
* spinning, it is automatically removed from its previous target by calling
* stop() internally.
*/
spin(target?: any): Spinner;
/**
* Stops and removes the Spinner.
* Stopped spinners may be reused by calling spin() again.
/**
* Stops and removes the Spinner.
* Stopped spinners may be reused by calling spin() again.
*/
stop(): Spinner;
lines(el, o);