forked from SignalStudios/SigTrello
/
sigtrello-core.ts
48 lines (38 loc) · 1.23 KB
/
sigtrello-core.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*!
* SigTrello
*
* Copyright (C) 2014 Signal Studios
* Released under the MIT license
* See LICENSE.txt
*/
///<reference path='jquery-2.1.0.d.ts'/>
///<reference path='chrome.d.ts'/>
///<reference path='mutation-observer.d.ts'/>
interface JQueryXHR extends JQueryPromise {} // Some missing methods from jquery-2.1.0.d.ts
module SigTrello {
export interface NamedThing {
name : string;
}
var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver || null;
export function getBestByNameIndex< T extends NamedThing >( name : string, index : number, items : T[] ) : T {
if( items.length > index && items[ index ].name == name )
return items[ index ];
var matchingName = $.grep( items, (i) => i.name == name, false );
if( matchingName.length == 1 )
return matchingName[ 0 ];
return null; // Ambiguous due to move of duplicately named list item, or no such item.
}
export function authorize( ) : boolean{
if( Trello.authorized( ) )
return true;
Trello.authorize({
type: "popup",
name: "SigTrello",
persist: true,
interactive: true,
scope: { read: true, write: true, account: false },
expiration: "never"
});
return Trello.authorized( );
}
}