├── .gitignore ├── README.md ├── TypeScriptAngularControllers ├── TypeScriptAngularControllers.sln └── TypeScriptAngularControllers │ ├── TypeScriptAngularControllers.csproj │ ├── angular.d.ts │ ├── app.js │ ├── app.js.map │ ├── app.ts │ ├── default.htm │ ├── jquery.d.ts │ ├── web.Debug.config │ ├── web.Release.config │ └── web.config ├── knockout-chrome-extension ├── app.css ├── app.html ├── app.js ├── icon19.png ├── icon38.png ├── knockout.js ├── manifest.json ├── popup.html └── popup.js ├── react-immutable ├── .gitignore ├── README.md ├── app.js ├── cities.js ├── commandDispatcher.js ├── gulpfile.js ├── index.css ├── index.html ├── index.js ├── package.json └── views │ ├── Building.jsx │ ├── City.jsx │ ├── Floor.jsx │ └── Room.jsx └── twitter-bootstrap-modals-and-knockout ├── .nuget ├── NuGet.Config ├── NuGet.exe └── NuGet.targets ├── Modal.sln └── Modal ├── App_Start ├── FilterConfig.cs └── RouteConfig.cs ├── CassetteConfiguration.cs ├── Client ├── App │ ├── AddNote.html │ ├── AddNoteViewModel.js │ ├── App.css │ ├── App.html │ ├── AppViewModel.js │ ├── EditNote.html │ ├── EditNoteViewModel.js │ ├── NoteViewModel.js │ ├── _start.js │ └── namespace.js └── Shared │ ├── ScriptBundle.txt │ ├── jquery.js │ ├── knockout.js │ ├── knockout.mapping-latest.debug.js │ ├── twitter-bootstrap │ ├── css │ │ └── bootstrap.css │ ├── img │ │ ├── glyphicons-halflings-white.png │ │ └── glyphicons-halflings.png │ └── js │ │ └── bootstrap.js │ └── utils │ ├── namespace.js │ └── showModal.js ├── Controllers └── HomeController.cs ├── Global.asax ├── Global.asax.cs ├── Modal.csproj ├── Properties └── AssemblyInfo.cs ├── Views ├── Home │ └── Index.cshtml └── Web.config ├── Web.Debug.config ├── Web.Release.config ├── Web.config └── packages.config /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | 3 | *.swp 4 | *.suo 5 | *.user 6 | 7 | bin 8 | obj 9 | packages 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | samples 2 | ======= 3 | 4 | Sample code for blog posts -------------------------------------------------------------------------------- /TypeScriptAngularControllers/TypeScriptAngularControllers.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2012 4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TypeScriptAngularControllers", "TypeScriptAngularControllers\TypeScriptAngularControllers.csproj", "{207F5850-A7E5-4D27-A77A-A4ACE9FF3FB1}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Any CPU = Debug|Any CPU 9 | Release|Any CPU = Release|Any CPU 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {207F5850-A7E5-4D27-A77A-A4ACE9FF3FB1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 13 | {207F5850-A7E5-4D27-A77A-A4ACE9FF3FB1}.Debug|Any CPU.Build.0 = Debug|Any CPU 14 | {207F5850-A7E5-4D27-A77A-A4ACE9FF3FB1}.Release|Any CPU.ActiveCfg = Release|Any CPU 15 | {207F5850-A7E5-4D27-A77A-A4ACE9FF3FB1}.Release|Any CPU.Build.0 = Release|Any CPU 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | EndGlobal 21 | -------------------------------------------------------------------------------- /TypeScriptAngularControllers/TypeScriptAngularControllers/TypeScriptAngularControllers.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | {207F5850-A7E5-4D27-A77A-A4ACE9FF3FB1} 6 | {349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} 7 | Library 8 | bin 9 | v4.5 10 | full 11 | true 12 | true 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | web.config 30 | 31 | 32 | web.config 33 | 34 | 35 | 36 | 10.0 37 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 38 | 39 | 40 | TypeScriptAngularControllers 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | True 49 | True 50 | 0 51 | / 52 | http://localhost:48907/ 53 | False 54 | False 55 | 56 | 57 | False 58 | 59 | 60 | 61 | 62 | 63 | ES3 64 | false 65 | true 66 | AMD 67 | 68 | 69 | ES3 70 | true 71 | false 72 | AMD 73 | 74 | 75 | -------------------------------------------------------------------------------- /TypeScriptAngularControllers/TypeScriptAngularControllers/angular.d.ts: -------------------------------------------------------------------------------- 1 | // Type definitions for Angular JS 1.0 2 | // Project: http://angularjs.org 3 | // Definitions by: Diego Vilar 4 | // Definitions: https://github.com/borisyankov/DefinitelyTyped 5 | 6 | 7 | /// 8 | 9 | declare var angular: ng.IAngularStatic; 10 | 11 | /////////////////////////////////////////////////////////////////////////////// 12 | // ng module (angular.js) 13 | /////////////////////////////////////////////////////////////////////////////// 14 | declare module ng { 15 | 16 | // All service providers extend this interface 17 | interface IServiceProvider { 18 | $get(): any; 19 | } 20 | 21 | /////////////////////////////////////////////////////////////////////////// 22 | // AngularStatic 23 | // see http://docs.angularjs.org/api 24 | /////////////////////////////////////////////////////////////////////////// 25 | interface IAngularStatic { 26 | bind(context: any, fn: Function, ...args: any[]): Function; 27 | bootstrap(element: string, modules?: any[]): auto.IInjectorService; 28 | bootstrap(element: JQuery, modules?: any[]): auto.IInjectorService; 29 | bootstrap(element: Element, modules?: any[]): auto.IInjectorService; 30 | copy(source: any, destination?: any): any; 31 | element: JQueryStatic; 32 | equals(value1: any, value2: any): boolean; 33 | extend(destination: any, ...sources: any[]): any; 34 | forEach(obj: any, iterator: (value, key) => any, context?: any): any; 35 | fromJson(json: string): any; 36 | identity(arg?: any): any; 37 | injector(modules?: any[]): auto.IInjectorService; 38 | isArray(value: any): boolean; 39 | isDate(value: any): boolean; 40 | isDefined(value: any): boolean; 41 | isElement(value: any): boolean; 42 | isFunction(value: any): boolean; 43 | isNumber(value: any): boolean; 44 | isObject(value: any): boolean; 45 | isString(value: any): boolean; 46 | isUndefined(value: any): boolean; 47 | lowercase(str: string): string; 48 | /** construct your angular application 49 | official docs: Interface for configuring angular modules. 50 | see: http://docs.angularjs.org/api/angular.Module 51 | */ 52 | module( 53 | /** name of your module you want to create */ 54 | name: string, 55 | /** name of modules yours depends on */ 56 | requires?: string[], 57 | configFunction?: Function): IModule; 58 | noop(...args: any[]): void; 59 | toJson(obj: any, pretty?: boolean): string; 60 | uppercase(str: string): string; 61 | version: { 62 | full: string; 63 | major: number; 64 | minor: number; 65 | dot: number; 66 | codename: string; 67 | }; 68 | scenario: any; 69 | } 70 | 71 | /////////////////////////////////////////////////////////////////////////// 72 | // Module 73 | // see http://docs.angularjs.org/api/angular.Module 74 | /////////////////////////////////////////////////////////////////////////// 75 | interface IModule { 76 | /** configure existing services. 77 | Use this method to register work which needs to be performed on module loading 78 | */ 79 | config(configFn: Function): IModule; 80 | /** configure existing services. 81 | Use this method to register work which needs to be performed on module loading 82 | */ 83 | config(inlineAnnotadedFunction: any[]): IModule; 84 | constant(name: string, value: any): IModule; 85 | controller(name: string, controllerConstructor: Function): IModule; 86 | controller(name: string, inlineAnnotadedConstructor: any[]): IModule; 87 | directive(name: string, directiveFactory: Function): IModule; 88 | directive(name: string, inlineAnnotadedFunction: any[]): IModule; 89 | factory(name: string, serviceFactoryFunction: Function): IModule; 90 | factory(name: string, inlineAnnotadedFunction: any[]): IModule; 91 | filter(name: string, filterFactoryFunction: Function): IModule; 92 | filter(name: string, inlineAnnotadedFunction: any[]): IModule; 93 | provider(name: string, serviceProviderConstructor: Function): IModule; 94 | provider(name: string, inlineAnnotadedConstructor: any[]): IModule; 95 | run(initializationFunction: Function): IModule; 96 | run(inlineAnnotadedFunction: any[]): IModule; 97 | service(name: string, serviceConstructor: Function): IModule; 98 | service(name: string, inlineAnnotadedConstructor: any[]): IModule; 99 | value(name: string, value: any): IModule; 100 | 101 | // Properties 102 | name: string; 103 | requires: string[]; 104 | } 105 | 106 | /////////////////////////////////////////////////////////////////////////// 107 | // Attributes 108 | // see http://docs.angularjs.org/api/ng.$compile.directive.Attributes 109 | /////////////////////////////////////////////////////////////////////////// 110 | interface IAttributes { 111 | $set(name: string, value: any): void; 112 | $attr: any; 113 | } 114 | 115 | /////////////////////////////////////////////////////////////////////////// 116 | // FormController 117 | // see http://docs.angularjs.org/api/ng.directive:form.FormController 118 | /////////////////////////////////////////////////////////////////////////// 119 | interface IFormController { 120 | $pristine: boolean; 121 | $dirty: boolean; 122 | $valid: boolean; 123 | $invalid: boolean; 124 | $error: any; 125 | $setDirty: () => void; 126 | } 127 | 128 | /////////////////////////////////////////////////////////////////////////// 129 | // NgModelController 130 | // see http://docs.angularjs.org/api/ng.directive:ngModel.NgModelController 131 | /////////////////////////////////////////////////////////////////////////// 132 | interface INgModelController { 133 | $render(): void; 134 | $setValidity(validationErrorKey: string, isValid: boolean): void; 135 | $setViewValue(value: any): void; 136 | 137 | // XXX Not sure about the types here. Documentation states it's a string, but 138 | // I've seen it receiving other types throughout the code. 139 | // Falling back to any for now. 140 | $viewValue: any; 141 | 142 | // XXX Same as avove 143 | $modelValue: any; 144 | 145 | $parsers: IModelParser[]; 146 | $formatters: IModelFormatter[]; 147 | $error: any; 148 | $pristine: boolean; 149 | $dirty: boolean; 150 | $valid: boolean; 151 | $invalid: boolean; 152 | } 153 | 154 | interface IModelParser { 155 | (value: any): any; 156 | } 157 | 158 | interface IModelFormatter { 159 | (value: any): any; 160 | } 161 | 162 | /////////////////////////////////////////////////////////////////////////// 163 | // Scope 164 | // see http://docs.angularjs.org/api/ng.$rootScope.Scope 165 | /////////////////////////////////////////////////////////////////////////// 166 | interface IScope { 167 | // Documentation says exp is optional, but actual implementaton counts on it 168 | $apply(exp: string): any; 169 | $apply(exp: (scope: IScope) => any): any; 170 | 171 | $broadcast(name: string, ...args: any[]): IAngularEvent; 172 | $destroy(): void; 173 | $digest(): void; 174 | $emit(name: string, ...args: any[]): IAngularEvent; 175 | 176 | // Documentation says exp is optional, but actual implementaton counts on it 177 | $eval(expression: string): any; 178 | $eval(expression: (scope: IScope) => any): any; 179 | 180 | // Documentation says exp is optional, but actual implementaton counts on it 181 | $evalAsync(expression: string): void; 182 | $evalAsync(expression: (scope: IScope) => any): void; 183 | 184 | // Defaults to false by the implementation checking strategy 185 | $new(isolate?: boolean): IScope; 186 | 187 | $on(name: string, listener: (event: IAngularEvent, ...args: any[]) => any): Function; 188 | 189 | $watch(watchExpression: string, listener?: string, objectEquality?: boolean): Function; 190 | $watch(watchExpression: string, listener?: (newValue: any, oldValue: any, scope: IScope) => any, objectEquality?: boolean): Function; 191 | $watch(watchExpression: (scope: IScope) => any, listener?: string, objectEquality?: boolean): Function; 192 | $watch(watchExpression: (scope: IScope) => any, listener?: (newValue: any, oldValue: any, scope: IScope) => any, objectEquality?: boolean): Function; 193 | 194 | $id: number; 195 | } 196 | 197 | interface IAngularEvent { 198 | targetScope: IScope; 199 | currentScope: IScope; 200 | name: string; 201 | preventDefault: Function; 202 | defaultPrevented: boolean; 203 | 204 | // Available only events that were $emit-ted 205 | stopPropagation?: Function; 206 | } 207 | 208 | /////////////////////////////////////////////////////////////////////////// 209 | // WindowService 210 | // see http://docs.angularjs.org/api/ng.$window 211 | /////////////////////////////////////////////////////////////////////////// 212 | interface IWindowService extends Window {} 213 | 214 | /////////////////////////////////////////////////////////////////////////// 215 | // BrowserService 216 | // TODO undocumented, so we need to get it from the source code 217 | /////////////////////////////////////////////////////////////////////////// 218 | interface IBrowserService {} 219 | 220 | /////////////////////////////////////////////////////////////////////////// 221 | // TimeoutService 222 | // see http://docs.angularjs.org/api/ng.$timeout 223 | /////////////////////////////////////////////////////////////////////////// 224 | interface ITimeoutService { 225 | (func: Function, delay?: number, invokeApply?: boolean): IPromise; 226 | cancel(promise: IPromise): boolean; 227 | } 228 | 229 | /////////////////////////////////////////////////////////////////////////// 230 | // FilterService 231 | // see http://docs.angularjs.org/api/ng.$filter 232 | // see http://docs.angularjs.org/api/ng.$filterProvider 233 | /////////////////////////////////////////////////////////////////////////// 234 | interface IFilterService { 235 | (name: string): Function; 236 | } 237 | 238 | interface IFilterProvider extends IServiceProvider { 239 | register(name: string, filterFactory: Function): IServiceProvider; 240 | } 241 | 242 | /////////////////////////////////////////////////////////////////////////// 243 | // LocaleService 244 | // see http://docs.angularjs.org/api/ng.$locale 245 | /////////////////////////////////////////////////////////////////////////// 246 | interface ILocaleService { 247 | id: string; 248 | 249 | // These are not documented 250 | // Check angular's i18n files for exemples 251 | NUMBER_FORMATS: ILocaleNumberFormatDescriptor; 252 | DATETIME_FORMATS: ILocaleDateTimeFormatDescriptor; 253 | pluralCat: (num: any) => string; 254 | } 255 | 256 | interface ILocaleNumberFormatDescriptor { 257 | DECIMAL_SEP: string; 258 | GROUP_SEP: string; 259 | PATTERNS: ILocaleNumberPatternDescriptor[]; 260 | CURRENCY_SYM: string; 261 | } 262 | 263 | interface ILocaleNumberPatternDescriptor { 264 | minInt: number; 265 | minFrac: number; 266 | maxFrac: number; 267 | posPre: string; 268 | posSuf: string; 269 | negPre: string; 270 | negSuf: string; 271 | gSize: number; 272 | lgSize: number; 273 | } 274 | 275 | interface ILocaleDateTimeFormatDescriptor { 276 | MONTH: string[]; 277 | SHORTMONTH: string[]; 278 | DAY: string[]; 279 | SHORTDAY: string[]; 280 | AMPMS: string[]; 281 | medium: string; 282 | short: string; 283 | fullDate: string; 284 | longDate: string; 285 | mediumDate: string; 286 | shortDate: string; 287 | mediumTime: string; 288 | shortTime: string; 289 | } 290 | 291 | /////////////////////////////////////////////////////////////////////////// 292 | // LogService 293 | // see http://docs.angularjs.org/api/ng.$log 294 | /////////////////////////////////////////////////////////////////////////// 295 | interface ILogService { 296 | error: ILogCall; 297 | info: ILogCall; 298 | log: ILogCall; 299 | warn: ILogCall; 300 | } 301 | 302 | // We define this as separete interface so we can reopen it later for 303 | // the ngMock module. 304 | interface ILogCall { 305 | (...args: any[]): void; 306 | } 307 | 308 | /////////////////////////////////////////////////////////////////////////// 309 | // ParseService 310 | // see http://docs.angularjs.org/api/ng.$parse 311 | /////////////////////////////////////////////////////////////////////////// 312 | interface IParseService { 313 | (expression: string): ICompiledExpression; 314 | } 315 | 316 | interface ICompiledExpression { 317 | (context: any, locals?: any): any; 318 | 319 | // If value is not provided, undefined is gonna be used since the implementation 320 | // does not check the parameter. Let's force a value for consistency. If consumer 321 | // whants to undefine it, pass the undefined value explicitly. 322 | assign(context: any, value: any): any; 323 | } 324 | 325 | /////////////////////////////////////////////////////////////////////////// 326 | // LocationService 327 | // see http://docs.angularjs.org/api/ng.$location 328 | // see http://docs.angularjs.org/api/ng.$locationProvider 329 | // see http://docs.angularjs.org/guide/dev_guide.services.$location 330 | /////////////////////////////////////////////////////////////////////////// 331 | interface ILocationService { 332 | absUrl(): string; 333 | hash(): string; 334 | hash(newHash: string): ILocationService; 335 | host(): string; 336 | path(): string; 337 | path(newPath: string): ILocationService; 338 | port(): number; 339 | protocol(): string; 340 | replace(): ILocationService; 341 | search(): any; 342 | search(parametersMap: any): ILocationService; 343 | search(parameter: string, parameterValue: any): ILocationService; 344 | url(): string; 345 | url(url: string): ILocationService; 346 | } 347 | 348 | interface ILocationProvider extends IServiceProvider { 349 | hashPrefix(): string; 350 | hashPrefix(prefix: string): ILocationProvider; 351 | html5Mode(): boolean; 352 | 353 | // Documentation states that parameter is string, but 354 | // implementation tests it as boolean, which makes more sense 355 | // since this is a toggler 356 | html5Mode(active: boolean): ILocationProvider; 357 | } 358 | 359 | /////////////////////////////////////////////////////////////////////////// 360 | // DocumentService 361 | // see http://docs.angularjs.org/api/ng.$document 362 | /////////////////////////////////////////////////////////////////////////// 363 | interface IDocumentService extends Document {} 364 | 365 | /////////////////////////////////////////////////////////////////////////// 366 | // ExceptionHandlerService 367 | // see http://docs.angularjs.org/api/ng.$exceptionHandler 368 | /////////////////////////////////////////////////////////////////////////// 369 | interface IExceptionHandlerService { 370 | (exception: Error, cause?: string): void; 371 | } 372 | 373 | /////////////////////////////////////////////////////////////////////////// 374 | // RootElementService 375 | // see http://docs.angularjs.org/api/ng.$rootElement 376 | /////////////////////////////////////////////////////////////////////////// 377 | interface IRootElementService extends JQuery {} 378 | 379 | /////////////////////////////////////////////////////////////////////////// 380 | // QService 381 | // see http://docs.angularjs.org/api/ng.$q 382 | /////////////////////////////////////////////////////////////////////////// 383 | interface IQService { 384 | all(promises: IPromise[]): IPromise; 385 | defer(): IDeferred; 386 | reject(reason?: any): IPromise; 387 | when(value: any): IPromise; 388 | } 389 | 390 | interface IPromise { 391 | then(successCallback: Function, errorCallback?: Function): IPromise; 392 | } 393 | 394 | interface IDeferred { 395 | resolve(value?: any): void; 396 | reject(reason?: string): void; 397 | promise: IPromise; 398 | } 399 | 400 | /////////////////////////////////////////////////////////////////////////// 401 | // AnchorScrollService 402 | // see http://docs.angularjs.org/api/ng.$anchorScroll 403 | /////////////////////////////////////////////////////////////////////////// 404 | interface IAnchorScrollService { 405 | (): void; 406 | } 407 | 408 | interface IAnchorScrollProvider extends IServiceProvider { 409 | disableAutoScrolling(): void; 410 | } 411 | 412 | /////////////////////////////////////////////////////////////////////////// 413 | // CacheFactoryService 414 | // see http://docs.angularjs.org/api/ng.$cacheFactory 415 | /////////////////////////////////////////////////////////////////////////// 416 | interface ICacheFactoryService { 417 | // Lets not foce the optionsMap to have the capacity member. Even though 418 | // it's the ONLY option considered by the implementation today, a consumer 419 | // might find it useful to associate some other options to the cache object. 420 | //(cacheId: string, optionsMap?: { capacity: number; }): CacheObject; 421 | (cacheId: string, optionsMap?: { capacity: number; }): ICacheObject; 422 | 423 | // Methods bellow are not documented 424 | info(): any; 425 | get(cacheId: string): ICacheObject; 426 | } 427 | 428 | interface ICacheObject { 429 | info(): { 430 | id: string; 431 | size: number; 432 | 433 | // Not garanteed to have, since it's a non-mandatory option 434 | //capacity: number; 435 | }; 436 | put(key: string, value?: any): void; 437 | get(key: string): any; 438 | remove(key: string): void; 439 | removeAll(): void; 440 | destroy(): void; 441 | } 442 | 443 | /////////////////////////////////////////////////////////////////////////// 444 | // CompileService 445 | // see http://docs.angularjs.org/api/ng.$compile 446 | // see http://docs.angularjs.org/api/ng.$compileProvider 447 | /////////////////////////////////////////////////////////////////////////// 448 | interface ICompileService { 449 | (element: string, transclude?: ITemplateLinkingFunction, maxPriority?: number): ITemplateLinkingFunction; 450 | (element: Element, transclude?: ITemplateLinkingFunction, maxPriority?: number): ITemplateLinkingFunction; 451 | (element: JQuery, transclude?: ITemplateLinkingFunction, maxPriority?: number): ITemplateLinkingFunction; 452 | } 453 | 454 | interface ICompileProvider extends IServiceProvider { 455 | directive(name: string, directiveFactory: Function): ICompileProvider; 456 | 457 | // Undocumented, but it is there... 458 | directive(directivesMap: any): ICompileProvider; 459 | } 460 | 461 | interface ITemplateLinkingFunction { 462 | // Let's hint but not force cloneAttachFn's signature 463 | (scope: IScope, cloneAttachFn?: (clonedElement?: JQuery, scope?: IScope) => any): JQuery; 464 | } 465 | 466 | /////////////////////////////////////////////////////////////////////////// 467 | // ControllerService 468 | // see http://docs.angularjs.org/api/ng.$controller 469 | // see http://docs.angularjs.org/api/ng.$controllerProvider 470 | /////////////////////////////////////////////////////////////////////////// 471 | interface IControllerService { 472 | // Although the documentation doesn't state this, locals are optional 473 | (controllerConstructor: Function, locals?: any): any; 474 | (controllerName: string, locals?: any): any; 475 | } 476 | 477 | interface IControlerProvider extends IServiceProvider { 478 | register(name: string, controllerConstructor: Function): void; 479 | register(name: string, dependencyAnnotadedConstructor: any[]): void; 480 | } 481 | 482 | /////////////////////////////////////////////////////////////////////////// 483 | // HttpService 484 | // see http://docs.angularjs.org/api/ng.$http 485 | /////////////////////////////////////////////////////////////////////////// 486 | interface IHttpService { 487 | // At least moethod and url must be provided... 488 | (config: IRequestConfig): IHttpPromise; 489 | get(url: string, RequestConfig?: any): IHttpPromise; 490 | delete(url: string, RequestConfig?: any): IHttpPromise; 491 | head(url: string, RequestConfig?: any): IHttpPromise; 492 | jsonp(url: string, RequestConfig?: any): IHttpPromise; 493 | post(url: string, data: any, RequestConfig?: any): IHttpPromise; 494 | put(url: string, data: any, RequestConfig?: any): IHttpPromise; 495 | defaults: IRequestConfig; 496 | 497 | // For debugging, BUT it is documented as public, so... 498 | pendingRequests: any[]; 499 | } 500 | 501 | // This is just for hinting. 502 | // Some opetions might not be available depending on the request. 503 | // see http://docs.angularjs.org/api/ng.$http#Usage for options explanations 504 | interface IRequestConfig { 505 | method: string; 506 | url: string; 507 | params?: any; 508 | 509 | // XXX it has it's own structure... perhaps we should define it in the future 510 | headers?: any; 511 | 512 | cache?: any; 513 | timeout?: number; 514 | withCredentials?: boolean; 515 | 516 | // These accept multiple types, so let's defile them as any 517 | data?: any; 518 | transformRequest?: any; 519 | transformResponse?: any; 520 | } 521 | 522 | interface IHttpPromise extends IPromise { 523 | success(callback: (data: any, status: number, headers: (headerName: string) => string, config: IRequestConfig) => any): IHttpPromise; 524 | error(callback: (data: any, status: number, headers: (headerName: string) => string, config: IRequestConfig) => any): IHttpPromise; 525 | } 526 | 527 | interface IHttpProvider extends IServiceProvider { 528 | defaults: IRequestConfig; 529 | responseInterceptors: any[]; 530 | interceptors: any[]; 531 | } 532 | 533 | /////////////////////////////////////////////////////////////////////////// 534 | // HttpBackendService 535 | // see http://docs.angularjs.org/api/ng.$httpBackend 536 | // You should never need to use this service directly. 537 | /////////////////////////////////////////////////////////////////////////// 538 | interface IHttpBackendService { 539 | // XXX Perhaps define callback signature in the future 540 | (method: string, url: string, post?: any, callback?: Function, headers?: any, timeout?: number, withCredentials?: boolean): void; 541 | } 542 | 543 | /////////////////////////////////////////////////////////////////////////// 544 | // InterpolateService 545 | // see http://docs.angularjs.org/api/ng.$interpolate 546 | // see http://docs.angularjs.org/api/ng.$interpolateProvider 547 | /////////////////////////////////////////////////////////////////////////// 548 | interface IInterpolateService { 549 | (text: string, mustHaveExpression?: boolean): IInterpolationFunction; 550 | endSymbol(): string; 551 | startSymbol(): string; 552 | } 553 | 554 | interface IInterpolationFunction { 555 | (context: any): string; 556 | } 557 | 558 | interface IInterpolateProvider extends IServiceProvider { 559 | startSymbol(): string; 560 | startSymbol(value: string): IInterpolateProvider; 561 | endSymbol(): string; 562 | endSymbol(value: string): IInterpolateProvider; 563 | } 564 | 565 | /////////////////////////////////////////////////////////////////////////// 566 | // RouteParamsService 567 | // see http://docs.angularjs.org/api/ng.$routeParams 568 | /////////////////////////////////////////////////////////////////////////// 569 | interface IRouteParamsService {} 570 | 571 | /////////////////////////////////////////////////////////////////////////// 572 | // TemplateCacheService 573 | // see http://docs.angularjs.org/api/ng.$templateCache 574 | /////////////////////////////////////////////////////////////////////////// 575 | interface ITemplateCacheService extends ICacheObject {} 576 | 577 | /////////////////////////////////////////////////////////////////////////// 578 | // RootScopeService 579 | // see http://docs.angularjs.org/api/ng.$rootScope 580 | /////////////////////////////////////////////////////////////////////////// 581 | interface IRootScopeService extends IScope {} 582 | 583 | /////////////////////////////////////////////////////////////////////////// 584 | // RouteService 585 | // see http://docs.angularjs.org/api/ng.$route 586 | // see http://docs.angularjs.org/api/ng.$routeProvider 587 | /////////////////////////////////////////////////////////////////////////// 588 | interface IRouteService { 589 | reload(): void; 590 | routes: any; 591 | 592 | // May not always be available. For instance, current will not be available 593 | // to a controller that was not initialized as a result of a route maching. 594 | current?: ICurrentRoute; 595 | } 596 | 597 | // see http://docs.angularjs.org/api/ng.$routeProvider#when for options explanations 598 | interface IRoute { 599 | controller?: any; 600 | template?: string; 601 | templateUrl?: string; 602 | resolve?: any; 603 | redirectTo?: any; 604 | reloadOnSearch?: boolean; 605 | } 606 | 607 | // see http://docs.angularjs.org/api/ng.$route#current 608 | interface ICurrentRoute extends IRoute { 609 | locals: { 610 | $scope: IScope; 611 | $template: string; 612 | }; 613 | } 614 | 615 | interface IRouteProviderProvider extends IServiceProvider { 616 | otherwise(params: any): IRouteProviderProvider; 617 | when(path: string, route: IRoute): IRouteProviderProvider; 618 | } 619 | 620 | /////////////////////////////////////////////////////////////////////////// 621 | // AUTO module (angular.js) 622 | /////////////////////////////////////////////////////////////////////////// 623 | export module auto { 624 | 625 | /////////////////////////////////////////////////////////////////////// 626 | // InjectorService 627 | // see http://docs.angularjs.org/api/AUTO.$injector 628 | /////////////////////////////////////////////////////////////////////// 629 | interface IInjectorService { 630 | annotate(fn: Function): string[]; 631 | annotate(inlineAnnotadedFunction: any[]): string[]; 632 | get(name: string): any; 633 | instantiate(typeConstructor: Function, locals?: any): any; 634 | invoke(func: Function, context?: any, locals?: any): any; 635 | } 636 | 637 | /////////////////////////////////////////////////////////////////////// 638 | // ProvideService 639 | // see http://docs.angularjs.org/api/AUTO.$provide 640 | /////////////////////////////////////////////////////////////////////// 641 | interface IProvideService { 642 | // Documentation says it returns the registered instance, but actual 643 | // implementation does not return anything. 644 | // constant(name: string, value: any): any; 645 | constant(name: string, value: any): void; 646 | 647 | decorator(name: string, decorator: any): void; 648 | factory(name: string, serviceFactoryFunction: Function): ng.IServiceProvider; 649 | provider(name: string, provider: ng.IServiceProvider): ng.IServiceProvider; 650 | provider(name: string, serviceProviderConstructor: Function): ng.IServiceProvider; 651 | service(name: string, constructor: Function): ng.IServiceProvider; 652 | value(name: string, value: any): ng.IServiceProvider; 653 | } 654 | 655 | } 656 | 657 | } 658 | -------------------------------------------------------------------------------- /TypeScriptAngularControllers/TypeScriptAngularControllers/app.js: -------------------------------------------------------------------------------- 1 | /// 2 | var KittenController = (function () { 3 | function KittenController($scope, debounce) { 4 | this.$scope = $scope; 5 | this.debounce = debounce; 6 | // Public properties we'll bind to in the UI 7 | this.width = 400; 8 | this.height = 300; 9 | this.watchForSizeChanges(); 10 | } 11 | KittenController.prototype.watchForSizeChanges = function () { 12 | var _this = this; 13 | // Use the debounce service to avoid spaming placekitten.com 14 | // with lots of requests at once. 15 | var delayMilliseconds = 250; 16 | var updateImageUrl = this.debounce(function () { 17 | return _this.updateImageUrl(); 18 | }, delayMilliseconds); 19 | 20 | this.$scope.$watch(// When width or height changes 21 | function () { 22 | return [_this.width, _this.height]; 23 | }, updateImageUrl, true); 24 | }; 25 | 26 | KittenController.prototype.updateImageUrl = function () { 27 | var _this = this; 28 | var url = this.getImageUrl(); 29 | if (!url) 30 | return false; 31 | 32 | this.status = "Loading image..."; 33 | 34 | // Pre-load the image before trying to display it. 35 | var image = new Image(); 36 | image.onload = function () { 37 | // This callback is invoked from outside of Angular. 38 | // Use $apply to get back into Angular's digest loop. 39 | _this.$scope.$apply(function () { 40 | _this.imageUrl = url; 41 | _this.status = ""; 42 | }); 43 | }; 44 | image.onerror = function () { 45 | _this.$scope.$apply(function () { 46 | return _this.status = "Error loading image"; 47 | }); 48 | }; 49 | image.src = url; 50 | }; 51 | 52 | KittenController.prototype.getImageUrl = function () { 53 | if (this.width > 0 && this.height > 0) { 54 | return "http://placekitten.com/" + this.width + "/" + this.height; 55 | } else { 56 | return null; 57 | } 58 | }; 59 | return KittenController; 60 | })(); 61 | 62 | function debounceFactory($timeout) { 63 | return function (func, threshold, execAsap) { 64 | var timeoutId; 65 | return function debounced() { 66 | var obj = this, args = arguments; 67 | function delayed() { 68 | if (!execAsap) { 69 | func.apply(obj, args); 70 | } 71 | timeoutId = null; 72 | } 73 | ; 74 | 75 | if (timeoutId) { 76 | $timeout.cancel(timeoutId); 77 | } else if (execAsap) { 78 | func.apply(obj, args); 79 | } 80 | 81 | timeoutId = $timeout(delayed, threshold); 82 | }; 83 | }; 84 | } 85 | 86 | // Define the Angular module for our application. 87 | var app = angular.module("app", []); 88 | app.controller("KittenController", ["$scope", "debounce", KittenController]); 89 | app.factory("debounce", ["$timeout", debounceFactory]); 90 | //# sourceMappingURL=app.js.map 91 | -------------------------------------------------------------------------------- /TypeScriptAngularControllers/TypeScriptAngularControllers/app.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"app.js","sourceRoot":"","sources":["app.ts"],"names":["KittenController","KittenController.constructor","KittenController.watchForSizeChanges","","","KittenController.updateImageUrl","KittenController.updateImageUrl.onload","","KittenController.updateImageUrl.onerror","","KittenController.getImageUrl","debounceFactory","",".debounced",".debounced.delayed"],"mappings":"AAAA,oCAAoC;AAEpC;IAEIA,0BACIA,MAAyBA,EACzBA,QAA2BA;QAD3BC,WAAcA,GAANA,MAAMA;AAAWA,QACzBA,aAAgBA,GAARA,QAAQA;AAAWA,QAK/BA,4CAA4CA;QAC5CA,KAAAA,KAAKA,GAAWA,GAAGA,CAACA;QACpBA,KAAAA,MAAMA,GAAWA,GAAGA,CAACA;QALjBA,IAAIA,CAACA,mBAAmBA,CAACA,CAACA,CAACA;IAC/BA,CAACA;IAQDD,iDAAAA;QAAAE,iBAcCA;QAXGA,4DAF4DA;QAC5DA,iCAAiCA;QAC7BA,IAAAA,iBAAiBA,GAAGA,GAAGA,CAACA;QAC5BA,IAAIA,cAAcA,GAAGA,IAAIA,CAACA,QAAQA,CAACA;mBAAMC,KAAIA,CAACA,cAAcA,CAACA,CAACA;SAAAD,EAAEA,iBAAiBA,CAACA,CAACA;;QAEnFA,IAAIA,CAACA,MAAMA,CAACA,MAAMA,CAEdA,+BAD+BA;QAC/BA;mBAAME,CAACA,KAAIA,CAACA,KAAKA,EAAEA,KAAIA,CAACA,MAAMA,CAACA;SAAAF,EAE/BA,cAAcA,EAEdA,IAAIA,CACPA,CAACA;IACNA,CAACA;;IAEDF,4CAAAA;QAAAK,iBAmBCA;QAlBGA,IAAIA,GAAGA,GAAGA,IAAIA,CAACA,WAAWA,CAACA,CAACA,CAACA;QAC7BA,IAAIA,CAACA,GAAGA;YAAEA,OAAOA,KAAKA,CAACA;;QAEvBA,IAAIA,CAACA,MAAMA,GAAGA,kBAAkBA,CAACA;;QAEjCA,kDADkDA;QAC9CA,IAAAA,KAAKA,GAAGA,IAAIA,KAAKA,CAACA,CAACA,CAACA;QACxBA,KAAKA,CAACA,MAAMA,GAAGA;YACXC,oDAAoDA;YACpDA,qDAAqDA;YACrDA,KAAIA,CAACA,MAAMA,CAACA,MAAMA,CAACA;gBACfC,KAAIA,CAACA,QAAQA,GAAGA,GAAGA,CAACA;gBACpBA,KAAIA,CAACA,MAAMA,GAAGA,EAAEA,CAACA;YACrBA,CAACA,CAACD,CAACA;QACPA,CAACA,CAACD;QACFA,KAAKA,CAACA,OAAOA,GAAGA;YACZG,KAAIA,CAACA,MAAMA,CAACA,MAAMA,CAACA;uBAAMC,KAAIA,CAACA,MAAMA,GAAGA,qBAAqBA;aAAAD,CAACA,CAACA;QAClEA,CAACA,CAACH;QACFA,KAAKA,CAACA,GAAGA,GAAGA,GAAGA,CAACA;IACpBA,CAACA;;IAEDL,yCAAAA;QACIU,IAAIA,IAAIA,CAACA,KAAKA,GAAGA,CAACA,IAAIA,IAAIA,CAACA,MAAMA,GAAGA,CAACA,CAAEA;YACnCA,OAAOA,yBAAyBA,GAAGA,IAAIA,CAACA,KAAKA,GAAGA,GAAGA,GAAGA,IAAIA,CAACA,MAAMA,CAACA;SACrEA,KAAMA;YACHA,OAAOA,IAAIA,CAACA;SACfA;IACLA,CAACA;IACLV;AAACA,CAAAA,IAAA;;AAED,SAAS,eAAe,CAAC,QAA4B;IACjDW,OAAOA,UAAUA,IAAcA,EAAEA,SAAiBA,EAAEA,QAAkBA;QAClEC,IAAIA,SAASA,CAACA;QACdA,OAAOA,SAASA,SAASA;YACrBC,IAAIA,GAAGA,GAAGA,IAAIA,EAAEA,IAAIA,GAAGA,SAASA,CAACA;YACjCA,SAASA,OAAOA;gBACZC,IAAIA,CAACA,QAAQA,CAAEA;oBACXA,IAAIA,CAACA,KAAKA,CAACA,GAAGA,EAAEA,IAAIA,CAACA,CAACA;iBACzBA;gBACDA,SAASA,GAAGA,IAAIA,CAACA;YACrBA,CAACA;YAAAD,CAACA;;YAEFA,IAAIA,SAASA,CAAEA;gBACXA,QAAQA,CAACA,MAAMA,CAACA,SAASA,CAACA,CAACA;aAC9BA,MAAMA,IAAIA,QAAQA,CAAEA;gBACjBA,IAAIA,CAACA,KAAKA,CAACA,GAAGA,EAAEA,IAAIA,CAACA,CAACA;aACzBA;;YAEDA,SAASA,GAAGA,QAAQA,CAACA,OAAOA,EAAEA,SAASA,CAACA,CAACA;QAC7CA,CAACA,CAACD;IACNA,CAACA,CAACD;AACNA,CAACA;;AAOD,iDADiD;AAC7C,IAAA,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;AACpC,GAAG,CAAC,UAAU,CAAC,kBAAkB,EAAE,CAAC,QAAQ,EAAE,UAAU,EAAE,gBAAgB,CAAC,CAAC,CAAC;AAC7E,GAAG,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC,UAAU,EAAE,eAAe,CAAC,CAAC,CAAC"} -------------------------------------------------------------------------------- /TypeScriptAngularControllers/TypeScriptAngularControllers/app.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | class KittenController { 4 | 5 | constructor( 6 | private $scope: ng.IScope, 7 | private debounce: IDebounce 8 | ) { 9 | this.watchForSizeChanges(); 10 | } 11 | 12 | // Public properties we'll bind to in the UI 13 | width: number = 400; 14 | height: number = 300; 15 | status: string; 16 | imageUrl: string; 17 | 18 | private watchForSizeChanges() { 19 | // Use the debounce service to avoid spaming placekitten.com 20 | // with lots of requests at once. 21 | var delayMilliseconds = 250; 22 | var updateImageUrl = this.debounce(() => this.updateImageUrl(), delayMilliseconds); 23 | 24 | this.$scope.$watch( 25 | // When width or height changes 26 | () => [this.width, this.height], 27 | // Invoke this function 28 | updateImageUrl, 29 | // "Deep" watch the array contain width and height for changes 30 | true 31 | ); 32 | } 33 | 34 | private updateImageUrl() { 35 | var url = this.getImageUrl(); 36 | if (!url) return false; 37 | 38 | this.status = "Loading image..."; 39 | // Pre-load the image before trying to display it. 40 | var image = new Image(); 41 | image.onload = () => { 42 | // This callback is invoked from outside of Angular. 43 | // Use $apply to get back into Angular's digest loop. 44 | this.$scope.$apply(() => { 45 | this.imageUrl = url; 46 | this.status = ""; 47 | }); 48 | }; 49 | image.onerror = () => { 50 | this.$scope.$apply(() => this.status = "Error loading image"); 51 | }; 52 | image.src = url; 53 | } 54 | 55 | private getImageUrl() { 56 | if (this.width > 0 && this.height > 0) { 57 | return "http://placekitten.com/" + this.width + "/" + this.height; 58 | } else { 59 | return null; 60 | } 61 | } 62 | } 63 | 64 | function debounceFactory($timeout: ng.ITimeoutService): IDebounce { 65 | return function (func: Function, threshold: number, execAsap?: boolean) { 66 | var timeoutId; 67 | return function debounced() { 68 | var obj = this, args = arguments; 69 | function delayed() { 70 | if (!execAsap) { 71 | func.apply(obj, args); 72 | } 73 | timeoutId = null; 74 | }; 75 | 76 | if (timeoutId) { 77 | $timeout.cancel(timeoutId); 78 | } else if (execAsap) { 79 | func.apply(obj, args); 80 | } 81 | 82 | timeoutId = $timeout(delayed, threshold); 83 | }; 84 | }; 85 | } 86 | 87 | interface IDebounce { 88 | (func: Function, threshold: number, execAsap?: boolean): () => void; 89 | } 90 | 91 | // Define the Angular module for our application. 92 | var app = angular.module("app", []); 93 | app.controller("KittenController", ["$scope", "debounce", KittenController]); 94 | app.factory("debounce", ["$timeout", debounceFactory]); -------------------------------------------------------------------------------- /TypeScriptAngularControllers/TypeScriptAngularControllers/default.htm: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | TypeScript AngularJS Controller Example 7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 |
16 |

TypeScript AngularJS Controller Example

17 |
18 | 19 |
20 |
21 |
22 |
23 | 24 | 25 |
26 |
27 | 28 | 29 |
30 |

{{kitten.status}}

31 |
32 |
33 |
34 |
35 |
{{kitten.imageUrl}}
36 |
37 | Kitten 38 |
39 |
40 |
41 |
42 | 43 |
44 | 45 | 46 | -------------------------------------------------------------------------------- /TypeScriptAngularControllers/TypeScriptAngularControllers/jquery.d.ts: -------------------------------------------------------------------------------- 1 | /* ***************************************************************************** 2 | Copyright (c) Microsoft Corporation. All rights reserved. 3 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use 4 | this file except in compliance with the License. You may obtain a copy of the 5 | License at http://www.apache.org/licenses/LICENSE-2.0 6 | 7 | THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 8 | KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED 9 | WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, 10 | MERCHANTABLITY OR NON-INFRINGEMENT. 11 | 12 | See the Apache Version 2.0 License for specific language governing permissions 13 | and limitations under the License. 14 | ***************************************************************************** */ 15 | 16 | // Typing for the jQuery library, version 2.0.x 17 | 18 | /* 19 | Interface for the AJAX setting that will configure the AJAX request 20 | */ 21 | interface JQueryAjaxSettings { 22 | accepts?: any; 23 | async?: boolean; 24 | beforeSend? (jqXHR: JQueryXHR, settings: JQueryAjaxSettings); 25 | cache?: boolean; 26 | complete? (jqXHR: JQueryXHR, textStatus: string); 27 | contents?: { [key: string]: any; }; 28 | contentType?: string; 29 | context?: any; 30 | converters?: { [key: string]: any; }; 31 | crossDomain?: boolean; 32 | data?: any; 33 | dataFilter? (data: any, ty: any): any; 34 | dataType?: string; 35 | error? (jqXHR: JQueryXHR, textStatus: string, errorThrow: string): any; 36 | global?: boolean; 37 | headers?: { [key: string]: any; }; 38 | ifModified?: boolean; 39 | isLocal?: boolean; 40 | jsonp?: string; 41 | jsonpCallback?: any; 42 | mimeType?: string; 43 | password?: string; 44 | processData?: boolean; 45 | scriptCharset?: string; 46 | statusCode?: { [key: string]: any; }; 47 | success? (data: any, textStatus: string, jqXHR: JQueryXHR); 48 | timeout?: number; 49 | traditional?: boolean; 50 | type?: string; 51 | url?: string; 52 | username?: string; 53 | xhr?: any; 54 | xhrFields?: { [key: string]: any; }; 55 | } 56 | 57 | /* 58 | Interface for the jqXHR object 59 | */ 60 | interface JQueryXHR extends XMLHttpRequest, JQueryPromise { 61 | overrideMimeType(mimeType: string); 62 | abort(statusText?: string): void; 63 | } 64 | 65 | /* 66 | Interface for the JQuery callback 67 | */ 68 | interface JQueryCallback { 69 | add(...callbacks: any[]): any; 70 | disable(): any; 71 | empty(): any; 72 | fire(...arguments: any[]): any; 73 | fired(): boolean; 74 | fireWith(context: any, ...args: any[]): any; 75 | has(callback: any): boolean; 76 | lock(): any; 77 | locked(): boolean; 78 | remove(...callbacks: any[]): any; 79 | } 80 | 81 | /* 82 | Interface for the JQuery promise, part of callbacks 83 | */ 84 | interface JQueryPromise { 85 | always(...alwaysCallbacks: any[]): JQueryDeferred; 86 | done(...doneCallbacks: any[]): JQueryDeferred; 87 | fail(...failCallbacks: any[]): JQueryDeferred; 88 | pipe(doneFilter?: (x: any) => any, failFilter?: (x: any) => any, progressFilter?: (x: any) => any): JQueryPromise; 89 | then(doneCallbacks: any, failCallbacks?: any, progressCallbacks?: any): JQueryDeferred; 90 | } 91 | 92 | /* 93 | Interface for the JQuery deferred, part of callbacks 94 | */ 95 | interface JQueryDeferred extends JQueryPromise { 96 | notify(...args: any[]): JQueryDeferred; 97 | notifyWith(context: any, ...args: any[]): JQueryDeferred; 98 | 99 | pipe(doneFilter?: any, failFilter?: any, progressFilter?: any): JQueryPromise; 100 | progress(...progressCallbacks: any[]): JQueryDeferred; 101 | reject(...args: any[]): JQueryDeferred; 102 | rejectWith(context: any, ...args: any[]): JQueryDeferred; 103 | resolve(...args: any[]): JQueryDeferred; 104 | resolveWith(context: any, ...args: any[]): JQueryDeferred; 105 | state(): string; 106 | then(doneCallbacks: any, failCallbacks?: any, progressCallbacks?: any): JQueryDeferred; 107 | promise(target?: any): JQueryPromise; 108 | } 109 | 110 | /* 111 | Interface of the JQuery extension of the W3C event object 112 | */ 113 | 114 | interface BaseJQueryEventObject extends Event { 115 | data: any; 116 | delegateTarget: Element; 117 | isDefaultPrevented(): boolean; 118 | isImmediatePropogationStopped(): boolean; 119 | isPropagationStopped(): boolean; 120 | namespace: string; 121 | preventDefault(): any; 122 | relatedTarget: Element; 123 | result: any; 124 | stopImmediatePropagation(); 125 | stopPropagation(); 126 | pageX: number; 127 | pageY: number; 128 | which: number; 129 | metaKey: any; 130 | } 131 | 132 | interface JQueryInputEventObject extends BaseJQueryEventObject { 133 | altKey: boolean; 134 | ctrlKey: boolean; 135 | metaKey: boolean; 136 | shiftKey: boolean; 137 | } 138 | 139 | interface JQueryMouseEventObject extends JQueryInputEventObject { 140 | button: number; 141 | clientX: number; 142 | clientY: number; 143 | offsetX: number; 144 | offsetY: number; 145 | pageX: number; 146 | pageY: number; 147 | screenX: number; 148 | screenY: number; 149 | } 150 | 151 | interface JQueryKeyEventObject extends JQueryInputEventObject { 152 | char: any; 153 | charCode: number; 154 | key: any; 155 | keyCode: number; 156 | } 157 | 158 | interface JQueryPopStateEventObject extends BaseJQueryEventObject { 159 | originalEvent: PopStateEvent; 160 | } 161 | 162 | interface JQueryEventObject extends BaseJQueryEventObject, JQueryInputEventObject, JQueryMouseEventObject, JQueryKeyEventObject, JQueryPopStateEventObject { 163 | } 164 | 165 | /* 166 | Collection of properties of the current browser 167 | */ 168 | 169 | interface JQuerySupport { 170 | ajax?: boolean; 171 | boxModel?: boolean; 172 | changeBubbles?: boolean; 173 | checkClone?: boolean; 174 | checkOn?: boolean; 175 | cors?: boolean; 176 | cssFloat?: boolean; 177 | hrefNormalized?: boolean; 178 | htmlSerialize?: boolean; 179 | leadingWhitespace?: boolean; 180 | noCloneChecked?: boolean; 181 | noCloneEvent?: boolean; 182 | opacity?: boolean; 183 | optDisabled?: boolean; 184 | optSelected?: boolean; 185 | scriptEval? (): boolean; 186 | style?: boolean; 187 | submitBubbles?: boolean; 188 | tbody?: boolean; 189 | } 190 | 191 | interface JQueryParam { 192 | (obj: any): string; 193 | (obj: any, traditional: boolean): string; 194 | } 195 | 196 | /* 197 | Static members of jQuery (those on $ and jQuery themselves) 198 | */ 199 | interface JQueryStatic { 200 | 201 | /**** 202 | AJAX 203 | *****/ 204 | ajax(settings: JQueryAjaxSettings): JQueryXHR; 205 | ajax(url: string, settings?: JQueryAjaxSettings): JQueryXHR; 206 | 207 | ajaxPrefilter(dataTypes: string, handler: (opts: any, originalOpts: any, jqXHR: JQueryXHR) => any): any; 208 | ajaxPrefilter(handler: (opts: any, originalOpts: any, jqXHR: JQueryXHR) => any): any; 209 | 210 | ajaxSettings: JQueryAjaxSettings; 211 | 212 | ajaxSetup(); 213 | ajaxSetup(options: JQueryAjaxSettings); 214 | 215 | get(url: string, data?: any, success?: any, dataType?: any): JQueryXHR; 216 | getJSON(url: string, data?: any, success?: any): JQueryXHR; 217 | getScript(url: string, success?: any): JQueryXHR; 218 | 219 | param: JQueryParam; 220 | 221 | post(url: string, data?: any, success?: any, dataType?: any): JQueryXHR; 222 | 223 | // Callbacks 224 | Callbacks(flags?: string): JQueryCallback; 225 | 226 | // Core 227 | holdReady(hold: boolean): any; 228 | 229 | (selector: string, context?: any): JQuery; 230 | (element: Element): JQuery; 231 | (object: {}): JQuery; 232 | (elementArray: Element[]): JQuery; 233 | (object: JQuery): JQuery; 234 | (func: Function): JQuery; 235 | (array: any[]): JQuery; 236 | (): JQuery; 237 | 238 | noConflict(removeAll?: boolean): Object; 239 | 240 | when(...deferreds: any[]): JQueryPromise; 241 | 242 | // CSS 243 | css(e: any, propertyName: string, value?: any); 244 | css(e: any, propertyName: any, value?: any); 245 | cssHooks: { [key: string]: any; }; 246 | cssNumber: any; 247 | 248 | // Data 249 | data(element: Element, key: string, value: any): any; 250 | data(element: Element, key: string): any; 251 | data(element: Element): any; 252 | 253 | dequeue(element: Element, queueName?: string): any; 254 | 255 | hasData(element: Element): boolean; 256 | 257 | queue(element: Element, queueName?: string): any[]; 258 | queue(element: Element, queueName: string, newQueueOrCallback: any): JQuery; 259 | 260 | removeData(element: Element, name?: string): JQuery; 261 | 262 | // Deferred 263 | Deferred: { 264 | (beforeStart?: (deferred: JQueryDeferred) => any): JQueryDeferred; 265 | new (beforeStart?: (deferred: JQueryDeferred) => any): JQueryDeferred; 266 | }; 267 | 268 | // Effects 269 | fx: { tick: () => void; interval: number; stop: () => void; speeds: { slow: number; fast: number; }; off: boolean; step: any; }; 270 | 271 | // Events 272 | proxy(fn: (...args: any[]) => any, context: any, ...args: any[]): any; 273 | proxy(context: any, name: string, ...args: any[]): any; 274 | 275 | Event: { 276 | (name: string, eventProperties?: any): JQueryEventObject; 277 | new (name: string, eventProperties?: any): JQueryEventObject; 278 | }; 279 | 280 | // Internals 281 | error(message: any); 282 | 283 | // Miscellaneous 284 | expr: any; 285 | fn: any; //TODO: Decide how we want to type this 286 | isReady: boolean; 287 | 288 | // Properties 289 | support: JQuerySupport; 290 | 291 | // Utilities 292 | contains(container: Element, contained: Element): boolean; 293 | 294 | each(collection: any, callback: (indexInArray: any, valueOfElement: any) => any): any; 295 | each(collection: JQuery, callback: (indexInArray: number, valueOfElement: HTMLElement) => any): any; 296 | each(collection: T[], callback: (indexInArray: number, valueOfElement: T) => any): any; 297 | 298 | extend(target: any, ...objs: any[]): Object; 299 | extend(deep: boolean, target: any, ...objs: any[]): Object; 300 | 301 | globalEval(code: string): any; 302 | 303 | grep(array: T[], func: (elementOfArray: T, indexInArray: number) => boolean, invert?: boolean): T[]; 304 | 305 | inArray(value: T, array: T[], fromIndex?: number): number; 306 | 307 | isArray(obj: any): boolean; 308 | isEmptyObject(obj: any): boolean; 309 | isFunction(obj: any): boolean; 310 | isNumeric(value: any): boolean; 311 | isPlainObject(obj: any): boolean; 312 | isWindow(obj: any): boolean; 313 | isXMLDoc(node: Node): boolean; 314 | 315 | makeArray(obj: any): any[]; 316 | 317 | map(array: T[], callback: (elementOfArray: T, indexInArray: number) => U): U[]; 318 | map(array: any, callback: (elementOfArray: any, indexInArray: any) => any): any; 319 | 320 | merge(first: T[], second: T[]): T[]; 321 | merge(first: T[], second: U[]): any[]; 322 | 323 | noop(): any; 324 | 325 | now(): number; 326 | 327 | parseJSON(json: string): any; 328 | 329 | //FIXME: This should return an XMLDocument 330 | parseXML(data: string): any; 331 | 332 | queue(element: Element, queueName: string, newQueue: any[]): JQuery; 333 | 334 | trim(str: string): string; 335 | 336 | type(obj: any): string; 337 | 338 | unique(arr: any[]): any[]; 339 | 340 | /** 341 | * Parses a string into an array of DOM nodes. 342 | * 343 | * @param data HTML string to be parsed 344 | * @param context DOM element to serve as the context in which the HTML fragment will be created 345 | * @param keepScripts A Boolean indicating whether to include scripts passed in the HTML string 346 | */ 347 | parseHTML(data: string, context?: HTMLElement, keepScripts?: boolean): any[]; 348 | } 349 | 350 | /* 351 | The jQuery instance members 352 | */ 353 | interface JQuery { 354 | // AJAX 355 | ajaxComplete(handler: any): JQuery; 356 | ajaxError(handler: (event: any, jqXHR: any, settings: any, exception: any) => any): JQuery; 357 | ajaxSend(handler: (event: any, jqXHR: any, settings: any, exception: any) => any): JQuery; 358 | ajaxStart(handler: () => any): JQuery; 359 | ajaxStop(handler: () => any): JQuery; 360 | ajaxSuccess(handler: (event: any, jqXHR: any, settings: any, exception: any) => any): JQuery; 361 | 362 | load(url: string, data?: any, complete?: any): JQuery; 363 | 364 | serialize(): string; 365 | serializeArray(): any[]; 366 | 367 | // Attributes 368 | addClass(classNames: string): JQuery; 369 | addClass(func: (index: any, currentClass: any) => string): JQuery; 370 | 371 | // http://api.jquery.com/addBack/ 372 | addBack(selector?: string): JQuery; 373 | 374 | 375 | attr(attributeName: string): string; 376 | attr(attributeName: string, value: any): JQuery; 377 | attr(map: { [key: string]: any; }): JQuery; 378 | attr(attributeName: string, func: (index: any, attr: any) => any): JQuery; 379 | 380 | hasClass(className: string): boolean; 381 | 382 | html(): string; 383 | html(htmlString: string): JQuery; 384 | html(htmlContent: (index: number, oldhtml: string) => string): JQuery; 385 | html(JQuery): JQuery; 386 | 387 | prop(propertyName: string): any; 388 | prop(propertyName: string, value: any): JQuery; 389 | prop(map: any): JQuery; 390 | prop(propertyName: string, func: (index: any, oldPropertyValue: any) => any): JQuery; 391 | 392 | removeAttr(attributeName: any): JQuery; 393 | 394 | removeClass(className?: any): JQuery; 395 | removeClass(func: (index: any, cls: any) => any): JQuery; 396 | 397 | removeProp(propertyName: any): JQuery; 398 | 399 | toggleClass(className: any, swtch?: boolean): JQuery; 400 | toggleClass(swtch?: boolean): JQuery; 401 | toggleClass(func: (index: any, cls: any, swtch: any) => any): JQuery; 402 | 403 | val(): any; 404 | val(value: string[]): JQuery; 405 | val(value: string): JQuery; 406 | val(value: number): JQuery; 407 | val(func: (index: any, value: any) => any): JQuery; 408 | 409 | // CSS 410 | css(propertyName: string): string; 411 | css(propertyNames: string[]): string; 412 | css(properties: any): JQuery; 413 | css(propertyName: string, value: any): JQuery; 414 | css(propertyName: any, value: any): JQuery; 415 | 416 | height(): number; 417 | height(value: number): JQuery; 418 | height(value: string): JQuery; 419 | height(func: (index: any, height: any) => any): JQuery; 420 | 421 | innerHeight(): number; 422 | innerWidth(): number; 423 | 424 | offset(): { left: number; top: number; }; 425 | offset(coordinates: any): JQuery; 426 | offset(func: (index: any, coords: any) => any): JQuery; 427 | 428 | outerHeight(includeMargin?: boolean): number; 429 | outerWidth(includeMargin?: boolean): number; 430 | 431 | position(): { top: number; left: number; }; 432 | 433 | scrollLeft(): number; 434 | scrollLeft(value: number): JQuery; 435 | 436 | scrollTop(): number; 437 | scrollTop(value: number): JQuery; 438 | 439 | width(): number; 440 | width(value: number): JQuery; 441 | width(value: string): JQuery; 442 | width(func: (index: any, height: any) => any): JQuery; 443 | 444 | // Data 445 | clearQueue(queueName?: string): JQuery; 446 | 447 | data(key: string, value: any): JQuery; 448 | data(obj: { [key: string]: any; }): JQuery; 449 | data(key?: string): any; 450 | 451 | dequeue(queueName?: string): JQuery; 452 | 453 | removeData(nameOrList?: any): JQuery; 454 | 455 | // Deferred 456 | promise(type?: any, target?: any): JQueryPromise; 457 | 458 | // Effects 459 | animate(properties: any, duration?: any, complete?: Function): JQuery; 460 | animate(properties: any, duration?: any, easing?: string, complete?: Function): JQuery; 461 | animate(properties: any, options: { duration?: any; easing?: string; complete?: Function; step?: Function; queue?: boolean; specialEasing?: any; }); 462 | 463 | delay(duration: number, queueName?: string): JQuery; 464 | 465 | fadeIn(duration?: any, callback?: any): JQuery; 466 | fadeIn(duration?: any, easing?: string, callback?: any): JQuery; 467 | 468 | fadeOut(duration?: any, callback?: any): JQuery; 469 | fadeOut(duration?: any, easing?: string, callback?: any): JQuery; 470 | 471 | fadeTo(duration: any, opacity: number, callback?: any): JQuery; 472 | fadeTo(duration: any, opacity: number, easing?: string, callback?: any): JQuery; 473 | 474 | fadeToggle(duration?: any, callback?: any): JQuery; 475 | fadeToggle(duration?: any, easing?: string, callback?: any): JQuery; 476 | 477 | finish(): JQuery; 478 | 479 | hide(duration?: any, callback?: any): JQuery; 480 | hide(duration?: any, easing?: string, callback?: any): JQuery; 481 | 482 | show(duration?: any, callback?: any): JQuery; 483 | show(duration?: any, easing?: string, callback?: any): JQuery; 484 | 485 | slideDown(duration?: any, callback?: any): JQuery; 486 | slideDown(duration?: any, easing?: string, callback?: any): JQuery; 487 | 488 | slideToggle(duration?: any, callback?: any): JQuery; 489 | slideToggle(duration?: any, easing?: string, callback?: any): JQuery; 490 | 491 | slideUp(duration?: any, callback?: any): JQuery; 492 | slideUp(duration?: any, easing?: string, callback?: any): JQuery; 493 | 494 | stop(clearQueue?: boolean, jumpToEnd?: boolean): JQuery; 495 | stop(queue?: any, clearQueue?: boolean, jumpToEnd?: boolean): JQuery; 496 | 497 | toggle(duration?: any, callback?: any): JQuery; 498 | toggle(duration?: any, easing?: string, callback?: any): JQuery; 499 | toggle(showOrHide: boolean): JQuery; 500 | 501 | // Events 502 | bind(eventType: string, eventData?: any, handler?: (eventObject: JQueryEventObject) => any): JQuery; 503 | bind(eventType: string, eventData: any, preventBubble: boolean): JQuery; 504 | bind(eventType: string, preventBubble: boolean): JQuery; 505 | bind(...events: any[]); 506 | 507 | blur(eventData?: any, handler?: (eventObject: JQueryEventObject) => any): JQuery; 508 | blur(handler: (eventObject: JQueryEventObject) => any): JQuery; 509 | 510 | change(eventData?: any, handler?: (eventObject: JQueryEventObject) => any): JQuery; 511 | change(handler: (eventObject: JQueryEventObject) => any): JQuery; 512 | 513 | click(eventData?: any, handler?: (eventObject: JQueryEventObject) => any): JQuery; 514 | click(handler: (eventObject: JQueryEventObject) => any): JQuery; 515 | 516 | dblclick(eventData?: any, handler?: (eventObject: JQueryEventObject) => any): JQuery; 517 | dblclick(handler: (eventObject: JQueryEventObject) => any): JQuery; 518 | 519 | delegate(selector: any, eventType: string, handler: (eventObject: JQueryEventObject) => any): JQuery; 520 | 521 | focus(eventData?: any, handler?: (eventObject: JQueryEventObject) => any): JQuery; 522 | focus(handler: (eventObject: JQueryEventObject) => any): JQuery; 523 | 524 | focusin(eventData: any, handler: (eventObject: JQueryEventObject) => any): JQuery; 525 | focusin(handler: (eventObject: JQueryEventObject) => any): JQuery; 526 | 527 | focusout(eventData: any, handler: (eventObject: JQueryEventObject) => any): JQuery; 528 | focusout(handler: (eventObject: JQueryEventObject) => any): JQuery; 529 | 530 | hover(handlerIn: (eventObject: JQueryEventObject) => any, handlerOut: (eventObject: JQueryEventObject) => any): JQuery; 531 | hover(handlerInOut: (eventObject: JQueryEventObject) => any): JQuery; 532 | 533 | keydown(eventData?: any, handler?: (eventObject: JQueryKeyEventObject) => any): JQuery; 534 | keydown(handler: (eventObject: JQueryKeyEventObject) => any): JQuery; 535 | 536 | keypress(eventData?: any, handler?: (eventObject: JQueryKeyEventObject) => any): JQuery; 537 | keypress(handler: (eventObject: JQueryKeyEventObject) => any): JQuery; 538 | 539 | keyup(eventData?: any, handler?: (eventObject: JQueryKeyEventObject) => any): JQuery; 540 | keyup(handler: (eventObject: JQueryKeyEventObject) => any): JQuery; 541 | 542 | load(eventData?: any, handler?: (eventObject: JQueryEventObject) => any): JQuery; 543 | load(handler: (eventObject: JQueryEventObject) => any): JQuery; 544 | 545 | mousedown(): JQuery; 546 | mousedown(eventData: any, handler: (eventObject: JQueryMouseEventObject) => any): JQuery; 547 | mousedown(handler: (eventObject: JQueryMouseEventObject) => any): JQuery; 548 | 549 | mouseevent(eventData: any, handler: (eventObject: JQueryMouseEventObject) => any): JQuery; 550 | mouseevent(handler: (eventObject: JQueryMouseEventObject) => any): JQuery; 551 | 552 | mouseenter(): JQuery; 553 | mouseenter(eventData: any, handler: (eventObject: JQueryMouseEventObject) => any): JQuery; 554 | mouseenter(handler: (eventObject: JQueryMouseEventObject) => any): JQuery; 555 | 556 | mouseleave(): JQuery; 557 | mouseleave(eventData: any, handler: (eventObject: JQueryMouseEventObject) => any): JQuery; 558 | mouseleave(handler: (eventObject: JQueryMouseEventObject) => any): JQuery; 559 | 560 | mousemove(): JQuery; 561 | mousemove(eventData: any, handler: (eventObject: JQueryMouseEventObject) => any): JQuery; 562 | mousemove(handler: (eventObject: JQueryMouseEventObject) => any): JQuery; 563 | 564 | mouseout(): JQuery; 565 | mouseout(eventData: any, handler: (eventObject: JQueryMouseEventObject) => any): JQuery; 566 | mouseout(handler: (eventObject: JQueryMouseEventObject) => any): JQuery; 567 | 568 | mouseover(): JQuery; 569 | mouseover(eventData: any, handler: (eventObject: JQueryMouseEventObject) => any): JQuery; 570 | mouseover(handler: (eventObject: JQueryMouseEventObject) => any): JQuery; 571 | 572 | mouseup(): JQuery; 573 | mouseup(eventData: any, handler: (eventObject: JQueryMouseEventObject) => any): JQuery; 574 | mouseup(handler: (eventObject: JQueryMouseEventObject) => any): JQuery; 575 | 576 | off(events?: string, selector?: any, handler?: (eventObject: JQueryEventObject) => any): JQuery; 577 | off(eventsMap: { [key: string]: any; }, selector?: any): JQuery; 578 | 579 | on(events: string, selector?: any, data?: any, handler?: (eventObject: JQueryEventObject) => any): JQuery; 580 | on(events: string, selector?: any, handler?: (eventObject: JQueryEventObject) => any): JQuery; 581 | on(eventsMap: { [key: string]: any; }, selector?: any, data?: any): JQuery; 582 | 583 | one(events: string, selector?: any, data?: any, handler?: (eventObject: JQueryEventObject) => any): JQuery; 584 | one(eventsMap: { [key: string]: any; }, selector?: any, data?: any): JQuery; 585 | 586 | ready(handler: any): JQuery; 587 | 588 | resize(eventData?: any, handler?: (eventObject: JQueryEventObject) => any): JQuery; 589 | resize(handler: (eventObject: JQueryEventObject) => any): JQuery; 590 | 591 | scroll(eventData?: any, handler?: (eventObject: JQueryEventObject) => any): JQuery; 592 | scroll(handler: (eventObject: JQueryEventObject) => any): JQuery; 593 | 594 | select(eventData?: any, handler?: (eventObject: JQueryEventObject) => any): JQuery; 595 | select(handler: (eventObject: JQueryEventObject) => any): JQuery; 596 | 597 | submit(eventData?: any, handler?: (eventObject: JQueryEventObject) => any): JQuery; 598 | submit(handler: (eventObject: JQueryEventObject) => any): JQuery; 599 | 600 | trigger(eventType: string, ...extraParameters: any[]): JQuery; 601 | trigger(event: JQueryEventObject): JQuery; 602 | 603 | triggerHandler(eventType: string, ...extraParameters: any[]): Object; 604 | 605 | unbind(eventType?: string, handler?: (eventObject: JQueryEventObject) => any): JQuery; 606 | unbind(eventType: string, fls: boolean): JQuery; 607 | unbind(evt: any): JQuery; 608 | 609 | undelegate(): JQuery; 610 | undelegate(selector: any, eventType: string, handler?: (eventObject: JQueryEventObject) => any): JQuery; 611 | undelegate(selector: any, events: any): JQuery; 612 | undelegate(namespace: string): JQuery; 613 | 614 | unload(eventData?: any, handler?: (eventObject: JQueryEventObject) => any): JQuery; 615 | unload(handler: (eventObject: JQueryEventObject) => any): JQuery; 616 | 617 | // Internals 618 | context: Element; 619 | jquery: string; 620 | 621 | error(handler: (eventObject: JQueryEventObject) => any): JQuery; 622 | error(eventData: any, handler: (eventObject: JQueryEventObject) => any): JQuery; 623 | 624 | pushStack(elements: any[]): JQuery; 625 | pushStack(elements: any[], name: any, arguments: any): JQuery; 626 | 627 | // Manipulation 628 | after(...content: any[]): JQuery; 629 | after(func: (index: any) => any); 630 | 631 | append(...content: any[]): JQuery; 632 | append(func: (index: any, html: any) => any); 633 | 634 | appendTo(target: any): JQuery; 635 | 636 | before(...content: any[]): JQuery; 637 | before(func: (index: any) => any); 638 | 639 | clone(withDataAndEvents?: boolean, deepWithDataAndEvents?: boolean): JQuery; 640 | 641 | detach(selector?: any): JQuery; 642 | 643 | empty(): JQuery; 644 | 645 | insertAfter(target: any): JQuery; 646 | insertBefore(target: any): JQuery; 647 | 648 | prepend(...content: any[]): JQuery; 649 | prepend(func: (index: any, html: any) => any): JQuery; 650 | 651 | prependTo(target: any): JQuery; 652 | 653 | remove(selector?: any): JQuery; 654 | 655 | replaceAll(target: any): JQuery; 656 | 657 | replaceWith(func: any): JQuery; 658 | 659 | text(): string; 660 | text(textString: any): JQuery; 661 | text(textString: (index: number, text: string) => string): JQuery; 662 | 663 | toArray(): any[]; 664 | 665 | unwrap(): JQuery; 666 | 667 | wrap(wrappingElement: any): JQuery; 668 | wrap(func: (index: any) => any): JQuery; 669 | 670 | wrapAll(wrappingElement: any): JQuery; 671 | 672 | wrapInner(wrappingElement: any): JQuery; 673 | wrapInner(func: (index: any) => any): JQuery; 674 | 675 | // Miscellaneous 676 | each(func: (index: any, elem: Element) => any): JQuery; 677 | 678 | get(index?: number): any; 679 | 680 | index(): number; 681 | index(selector: string): number; 682 | index(element: any): number; 683 | 684 | // Properties 685 | length: number; 686 | selector: string; 687 | [x: string]: any; 688 | [x: number]: HTMLElement; 689 | 690 | // Traversing 691 | add(selector: string, context?: any): JQuery; 692 | add(...elements: any[]): JQuery; 693 | add(html: string): JQuery; 694 | add(obj: JQuery): JQuery; 695 | 696 | children(selector?: any): JQuery; 697 | 698 | closest(selector: string): JQuery; 699 | closest(selector: string, context?: Element): JQuery; 700 | closest(obj: JQuery): JQuery; 701 | closest(element: any): JQuery; 702 | closest(selectors: any, context?: Element): any[]; 703 | 704 | contents(): JQuery; 705 | 706 | end(): JQuery; 707 | 708 | eq(index: number): JQuery; 709 | 710 | filter(selector: string): JQuery; 711 | filter(func: (index: any) => any): JQuery; 712 | filter(element: any): JQuery; 713 | filter(obj: JQuery): JQuery; 714 | 715 | find(selector: string): JQuery; 716 | find(element: any): JQuery; 717 | find(obj: JQuery): JQuery; 718 | 719 | first(): JQuery; 720 | 721 | has(selector: string): JQuery; 722 | has(contained: Element): JQuery; 723 | 724 | is(selector: string): boolean; 725 | is(func: (index: any) => any): boolean; 726 | is(element: any): boolean; 727 | is(obj: JQuery): boolean; 728 | 729 | last(): JQuery; 730 | 731 | map(callback: (index: any, domElement: Element) => any): JQuery; 732 | 733 | next(selector?: string): JQuery; 734 | 735 | nextAll(selector?: string): JQuery; 736 | 737 | nextUntil(selector?: string, filter?: string): JQuery; 738 | nextUntil(element?: Element, filter?: string): JQuery; 739 | 740 | not(selector: string): JQuery; 741 | not(func: (index: any) => any): JQuery; 742 | not(element: any): JQuery; 743 | not(obj: JQuery): JQuery; 744 | 745 | offsetParent(): JQuery; 746 | 747 | parent(selector?: string): JQuery; 748 | 749 | parents(selector?: string): JQuery; 750 | 751 | parentsUntil(selector?: string, filter?: string): JQuery; 752 | parentsUntil(element?: Element, filter?: string): JQuery; 753 | 754 | prev(selector?: string): JQuery; 755 | 756 | prevAll(selector?: string): JQuery; 757 | 758 | prevUntil(selector?: string, filter?: string): JQuery; 759 | prevUntil(element?: Element, filter?: string): JQuery; 760 | 761 | siblings(selector?: string): JQuery; 762 | 763 | slice(start: number, end?: number): JQuery; 764 | 765 | // Utilities 766 | 767 | queue(queueName?: string): any[]; 768 | queue(queueName: string, newQueueOrCallback: any): JQuery; 769 | queue(newQueueOrCallback: any): JQuery; 770 | } 771 | 772 | declare var jQuery: JQueryStatic; 773 | declare var $: JQueryStatic; 774 | -------------------------------------------------------------------------------- /TypeScriptAngularControllers/TypeScriptAngularControllers/web.Debug.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 17 | 18 | 29 | 30 | -------------------------------------------------------------------------------- /TypeScriptAngularControllers/TypeScriptAngularControllers/web.Release.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 17 | 18 | 19 | 30 | 31 | -------------------------------------------------------------------------------- /TypeScriptAngularControllers/TypeScriptAngularControllers/web.config: -------------------------------------------------------------------------------- 1 |  2 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /knockout-chrome-extension/app.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | font-family: sans-serif; 4 | } 5 | 6 | ul { 7 | margin: 0; 8 | padding: 0; 9 | } 10 | 11 | li { 12 | list-style-type: none; 13 | display: block; 14 | margin-bottom: .5em; 15 | } 16 | 17 | a { 18 | display: block; 19 | } 20 | -------------------------------------------------------------------------------- /knockout-chrome-extension/app.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 |
    8 |
  • 9 |
10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /knockout-chrome-extension/app.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | 3 | function postMessageToParent(message) { 4 | window.parent.postMessage(message, "*"); 5 | } 6 | 7 | var app = { 8 | links: ko.observableArray(), 9 | anyClick: function(_, event) { 10 | // The app is sandboxed so cannot follow links to other pages. 11 | // However, the popup page can, so we'll post it a message 12 | // asking it to open the link. 13 | var clickedElement = event.target; 14 | if (clickedElement.tagName.toLowerCase() === "a") { 15 | event.preventDefault(); 16 | postMessageToParent({ openLink: clickedElement.href }); 17 | } 18 | } 19 | }; 20 | 21 | window.addEventListener( 22 | "message", 23 | function(event) { 24 | if (event.data.displayLinks) { 25 | app.links(event.data.displayLinks); 26 | } 27 | }, 28 | false 29 | ); 30 | 31 | ko.applyBindings(app); 32 | 33 | // Tell the popup we are ready to recieve links to display. 34 | postMessageToParent({ appReady: true }); 35 | 36 | }()); 37 | -------------------------------------------------------------------------------- /knockout-chrome-extension/icon19.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andrewdavey/samples/d00a1d3e4d41b8b9edbd33abc6360a307295b555/knockout-chrome-extension/icon19.png -------------------------------------------------------------------------------- /knockout-chrome-extension/icon38.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andrewdavey/samples/d00a1d3e4d41b8b9edbd33abc6360a307295b555/knockout-chrome-extension/icon38.png -------------------------------------------------------------------------------- /knockout-chrome-extension/knockout.js: -------------------------------------------------------------------------------- 1 | // Knockout JavaScript library v2.2.0 2 | // (c) Steven Sanderson - http://knockoutjs.com/ 3 | // License: MIT (http://www.opensource.org/licenses/mit-license.php) 4 | 5 | (function() {function i(v){throw v;}var l=!0,n=null,q=!1;function t(v){return function(){return v}};var w=window,x=document,fa=navigator,E=window.jQuery,H=void 0; 6 | function K(v){function ga(a,d,c,e,f){var g=[],a=b.j(function(){var a=d(c,f)||[];0",g[0];);m=4b.a.i(d,a[c])&&d.push(a[c]);return d},V:function(a,b){for(var a=a||[],d=[],c=0,e=a.length;cm?a.setAttribute("selected",b):a.selected=b},D:function(a){return(a||"").replace(d,"")},Qb:function(a,d){for(var c=[],e=(a||"").split(d),f=0,g=e.length;fa.length?q:a.substring(0,b.length)===b},sb:function(a,b){if(b.compareDocumentPosition)return 16== 21 | (b.compareDocumentPosition(a)&16);for(;a!=n;){if(a==b)return l;a=a.parentNode}return q},X:function(a){return b.a.sb(a,a.ownerDocument)},u:function(a){return a&&a.tagName&&a.tagName.toLowerCase()},n:function(b,d,c){var e=m&&k[d];if(!e&&"undefined"!=typeof E){if(a(b,d))var f=c,c=function(a,b){var d=this.checked;b&&(this.checked=b.mb!==l);f.call(this,a);this.checked=d};E(b).bind(d,c)}else!e&&"function"==typeof b.addEventListener?b.addEventListener(d,c,q):"undefined"!=typeof b.attachEvent?b.attachEvent("on"+ 22 | d,function(a){c.call(b,a)}):i(Error("Browser doesn't support addEventListener or attachEvent"))},Aa:function(b,d){(!b||!b.nodeType)&&i(Error("element must be a DOM node when calling triggerEvent"));if("undefined"!=typeof E){var c=[];a(b,d)&&c.push({mb:b.checked});E(b).trigger(d,c)}else"function"==typeof x.createEvent?"function"==typeof b.dispatchEvent?(c=x.createEvent(e[d]||"HTMLEvents"),c.initEvent(d,l,l,w,0,0,0,0,0,q,q,q,q,0,b),b.dispatchEvent(c)):i(Error("The supplied element doesn't support dispatchEvent")): 23 | "undefined"!=typeof b.fireEvent?(a(b,d)&&(b.checked=b.checked!==l),b.fireEvent("on"+d)):i(Error("Browser doesn't support triggering events"))},d:function(a){return b.$(a)?a():a},ta:function(a){return b.$(a)?a.t():a},da:function(a,d,c){if(d){var e=/[\w-]+/g,f=a.className.match(e)||[];b.a.o(d.match(e),function(a){var d=b.a.i(f,a);0<=d?c||f.splice(d,1):c&&f.push(a)});a.className=f.join(" ")}},bb:function(a,d){var c=b.a.d(d);if(c===n||c===H)c="";if(3===a.nodeType)a.data=c;else{var e=b.e.firstChild(a); 24 | !e||3!=e.nodeType||b.e.nextSibling(e)?b.e.N(a,[x.createTextNode(c)]):e.data=c;b.a.vb(a)}},$a:function(a,b){a.name=b;if(7>=m)try{a.mergeAttributes(x.createElement(""),q)}catch(d){}},vb:function(a){9<=m&&(a=1==a.nodeType?a:a.parentNode,a.style&&(a.style.zoom=a.style.zoom))},tb:function(a){if(9<=m){var b=a.style.width;a.style.width=0;a.style.width=b}},Kb:function(a,d){for(var a=b.a.d(a),d=b.a.d(d),c=[],e=a;e<=d;e++)c.push(e);return c},L:function(a){for(var b=[],d=0,c=a.length;d< 25 | c;d++)b.push(a[d]);return b},Ob:6===m,Pb:7===m,Z:m,Na:function(a,d){for(var c=b.a.L(a.getElementsByTagName("input")).concat(b.a.L(a.getElementsByTagName("textarea"))),e="string"==typeof d?function(a){return a.name===d}:function(a){return d.test(a.name)},f=[],g=c.length-1;0<=g;g--)e(c[g])&&f.push(c[g]);return f},Hb:function(a){return"string"==typeof a&&(a=b.a.D(a))?w.JSON&&w.JSON.parse?w.JSON.parse(a):(new Function("return "+a))():n},wa:function(a,d,c){("undefined"==typeof JSON||"undefined"==typeof JSON.stringify)&& 26 | i(Error("Cannot find JSON.stringify(). Some browsers (e.g., IE < 8) don't support it natively, but you can overcome this by adding a script reference to json2.js, downloadable from http://www.json.org/json2.js"));return JSON.stringify(b.a.d(a),d,c)},Ib:function(a,d,c){var c=c||{},e=c.params||{},f=c.includeFields||this.Ma,g=a;if("object"==typeof a&&"form"===b.a.u(a))for(var g=a.action,h=f.length-1;0<=h;h--)for(var j=b.a.Na(a,f[h]),k=j.length-1;0<=k;k--)e[j[k].name]=j[k].value;var d=b.a.d(d),m=x.createElement("form"); 27 | m.style.display="none";m.action=g;m.method="post";for(var v in d)a=x.createElement("input"),a.name=v,a.value=b.a.wa(b.a.d(d[v])),m.appendChild(a);for(v in e)a=x.createElement("input"),a.name=v,a.value=e[v],m.appendChild(a);x.body.appendChild(m);c.submitter?c.submitter(m):m.submit();setTimeout(function(){m.parentNode.removeChild(m)},0)}}};b.b("utils",b.a);b.b("utils.arrayForEach",b.a.o);b.b("utils.arrayFirst",b.a.kb);b.b("utils.arrayFilter",b.a.fa);b.b("utils.arrayGetDistinctValues",b.a.Fa);b.b("utils.arrayIndexOf", 28 | b.a.i);b.b("utils.arrayMap",b.a.V);b.b("utils.arrayPushAll",b.a.P);b.b("utils.arrayRemoveItem",b.a.ga);b.b("utils.extend",b.a.extend);b.b("utils.fieldsIncludedWithJsonPost",b.a.Ma);b.b("utils.getFormFields",b.a.Na);b.b("utils.peekObservable",b.a.ta);b.b("utils.postJson",b.a.Ib);b.b("utils.parseJson",b.a.Hb);b.b("utils.registerEventHandler",b.a.n);b.b("utils.stringifyJson",b.a.wa);b.b("utils.range",b.a.Kb);b.b("utils.toggleDomNodeCssClass",b.a.da);b.b("utils.triggerEvent",b.a.Aa);b.b("utils.unwrapObservable", 29 | b.a.d);Function.prototype.bind||(Function.prototype.bind=function(a){var b=this,c=Array.prototype.slice.call(arguments),a=c.shift();return function(){return b.apply(a,c.concat(Array.prototype.slice.call(arguments)))}});b.a.f=new function(){var a=0,d="__ko__"+(new Date).getTime(),c={};return{get:function(a,d){var c=b.a.f.getAll(a,q);return c===H?H:c[d]},set:function(a,d,c){c===H&&b.a.f.getAll(a,q)===H||(b.a.f.getAll(a,l)[d]=c)},getAll:function(b,f){var g=b[d];if(!g||!("null"!==g&&c[g])){if(!f)return H; 30 | g=b[d]="ko"+a++;c[g]={}}return c[g]},clear:function(a){var b=a[d];return b?(delete c[b],a[d]=n,l):q}}};b.b("utils.domData",b.a.f);b.b("utils.domData.clear",b.a.f.clear);b.a.F=new function(){function a(a,d){var e=b.a.f.get(a,c);e===H&&d&&(e=[],b.a.f.set(a,c,e));return e}function d(c){var e=a(c,q);if(e)for(var e=e.slice(0),j=0;j",""]||!c.indexOf("",""]||(!c.indexOf("",""]||[0,"",""];a="ignored
"+c[1]+a+c[2]+"
";for("function"==typeof w.innerShiv?d.appendChild(w.innerShiv(a)):d.innerHTML=a;c[0]--;)d=d.lastChild;d=b.a.L(d.lastChild.childNodes)}return d};b.a.ca=function(a,d){b.a.ka(a);d=b.a.d(d);if(d!==n&&d!==H)if("string"!=typeof d&&(d=d.toString()),"undefined"!=typeof E)E(a).html(d);else for(var c= 34 | b.a.sa(d),e=0;e"},gb:function(a,b){var c=Q[a];c===H&&i(Error("Couldn't find any memo with ID "+a+". Perhaps it's already been unmemoized.")); 35 | try{return c.apply(n,b||[]),l}finally{delete Q[a]}},hb:function(a,d){var c=[];ba(a,c);for(var e=0,f=c.length;ec;c++)a=a();return a})};b.toJSON=function(a,d,c){a=b.fb(a);return b.a.wa(a,d,c)};b.b("toJS",b.fb);b.b("toJSON",b.toJSON);b.k={q:function(a){switch(b.a.u(a)){case "option":return a.__ko__hasDomDataOptionValue__=== 47 | l?b.a.f.get(a,b.c.options.ra):7>=b.a.Z?a.getAttributeNode("value").specified?a.value:a.text:a.value;case "select":return 0<=a.selectedIndex?b.k.q(a.options[a.selectedIndex]):H;default:return a.value}},T:function(a,d){switch(b.a.u(a)){case "option":switch(typeof d){case "string":b.a.f.set(a,b.c.options.ra,H);"__ko__hasDomDataOptionValue__"in a&&delete a.__ko__hasDomDataOptionValue__;a.value=d;break;default:b.a.f.set(a,b.c.options.ra,d),a.__ko__hasDomDataOptionValue__=l,a.value="number"===typeof d? 48 | d:""}break;case "select":for(var c=a.options.length-1;0<=c;c--)if(b.k.q(a.options[c])==d){a.selectedIndex=c;break}break;default:if(d===n||d===H)d="";a.value=d}}};b.b("selectExtensions",b.k);b.b("selectExtensions.readValue",b.k.q);b.b("selectExtensions.writeValue",b.k.T);var ja=/\@ko_token_(\d+)\@/g,ma=["true","false"],na=/^(?:[$_a-z][$\w]*|(.+)(\.\s*[$_a-z][$\w]*|\[.+\]))$/i;b.g={Q:[],aa:function(a){var d=b.a.D(a);if(3>d.length)return[];"{"===d.charAt(0)&&(d=d.substring(1,d.length-1));for(var a=[], 49 | c=n,e,f=0;f$/:/^\s*ko(?:\s+(.+\s*\:[\s\S]*))?\s*$/,ha=J?/^<\!--\s*\/ko\s*--\>$/: 53 | /^\s*\/ko\s*$/,oa={ul:l,ol:l};b.e={I:{},childNodes:function(a){return A(a)?$(a):a.childNodes},Y:function(a){if(A(a))for(var a=b.e.childNodes(a),d=0,c=a.length;d=b.a.Z&&e in ea?(e=ea[e],g?a.removeAttribute(e): 60 | a[e]=f):g||a.setAttribute(e,f.toString());"name"===e&&b.a.$a(a,g?"":f.toString())}}};b.c.checked={init:function(a,d,c){b.a.n(a,"click",function(){var e;if("checkbox"==a.type)e=a.checked;else if("radio"==a.type&&a.checked)e=a.value;else return;var f=d(),g=b.a.d(f);"checkbox"==a.type&&g instanceof Array?(e=b.a.i(g,a.value),a.checked&&0>e?f.push(a.value):!a.checked&&0<=e&&f.splice(e,1)):b.g.ea(f,c,"checked",e,l)});"radio"==a.type&&!a.name&&b.c.uniqueName.init(a,t(l))},update:function(a,d){var c=b.a.d(d()); 61 | "checkbox"==a.type?a.checked=c instanceof Array?0<=b.a.i(c,a.value):c:"radio"==a.type&&(a.checked=a.value==c)}};b.c.css={update:function(a,d){var c=b.a.d(d());if("object"==typeof c)for(var e in c){var f=b.a.d(c[e]);b.a.da(a,e,f)}else c=String(c||""),b.a.da(a,a.__ko__cssValue,q),a.__ko__cssValue=c,b.a.da(a,c,l)}};b.c.enable={update:function(a,d){var c=b.a.d(d());c&&a.disabled?a.removeAttribute("disabled"):!c&&!a.disabled&&(a.disabled=l)}};b.c.disable={update:function(a,d){b.c.enable.update(a,function(){return!b.a.d(d())})}}; 62 | b.c.event={init:function(a,d,c,e){var f=d()||{},g;for(g in f)(function(){var f=g;"string"==typeof f&&b.a.n(a,f,function(a){var g,m=d()[f];if(m){var p=c();try{var r=b.a.L(arguments);r.unshift(e);g=m.apply(e,r)}finally{g!==l&&(a.preventDefault?a.preventDefault():a.returnValue=q)}p[f+"Bubble"]===q&&(a.cancelBubble=l,a.stopPropagation&&a.stopPropagation())}})})()}};b.c.foreach={Ra:function(a){return function(){var d=a(),c=b.a.ta(d);if(!c||"number"==typeof c.length)return{foreach:d,templateEngine:b.C.na}; 63 | b.a.d(d);return{foreach:c.data,as:c.as,includeDestroyed:c.includeDestroyed,afterAdd:c.afterAdd,beforeRemove:c.beforeRemove,afterRender:c.afterRender,beforeMove:c.beforeMove,afterMove:c.afterMove,templateEngine:b.C.na}}},init:function(a,d){return b.c.template.init(a,b.c.foreach.Ra(d))},update:function(a,d,c,e,f){return b.c.template.update(a,b.c.foreach.Ra(d),c,e,f)}};b.g.Q.foreach=q;b.e.I.foreach=l;b.c.hasfocus={init:function(a,d,c){function e(e){a.__ko_hasfocusUpdating=l;var f=a.ownerDocument;"activeElement"in 64 | f&&(e=f.activeElement===a);f=d();b.g.ea(f,c,"hasfocus",e,l);a.__ko_hasfocusUpdating=q}var f=e.bind(n,l),g=e.bind(n,q);b.a.n(a,"focus",f);b.a.n(a,"focusin",f);b.a.n(a,"blur",g);b.a.n(a,"focusout",g)},update:function(a,d){var c=b.a.d(d());a.__ko_hasfocusUpdating||(c?a.focus():a.blur(),b.r.K(b.a.Aa,n,[a,c?"focusin":"focusout"]))}};b.c.html={init:function(){return{controlsDescendantBindings:l}},update:function(a,d){b.a.ca(a,d())}};var ca="__ko_withIfBindingData";P("if");P("ifnot",q,l);P("with",l,q,function(a, 65 | b){return a.createChildContext(b)});b.c.options={update:function(a,d,c){"select"!==b.a.u(a)&&i(Error("options binding applies only to SELECT elements"));for(var e=0==a.length,f=b.a.V(b.a.fa(a.childNodes,function(a){return a.tagName&&"option"===b.a.u(a)&&a.selected}),function(a){return b.k.q(a)||a.innerText||a.textContent}),g=a.scrollTop,h=b.a.d(d());0/g;b.ya={ub:function(a, 73 | d,c){d.isTemplateRewritten(a,c)||d.rewriteTemplate(a,function(a){return b.ya.Fb(a,d)},c)},Fb:function(a,b){return a.replace(pa,function(a,e,f,g,h,j,k){return V(k,e,b)}).replace(qa,function(a,e){return V(e,"<\!-- ko --\>",b)})},jb:function(a){return b.s.qa(function(d,c){d.nextSibling&&b.Ea(d.nextSibling,a,c)})}};b.b("__tr_ambtns",b.ya.jb);b.l={};b.l.h=function(a){this.h=a};b.l.h.prototype.text=function(){var a=b.a.u(this.h),a="script"===a?"text":"textarea"===a?"value":"innerHTML";if(0==arguments.length)return this.h[a]; 74 | var d=arguments[0];"innerHTML"===a?b.a.ca(this.h,d):this.h[a]=d};b.l.h.prototype.data=function(a){if(1===arguments.length)return b.a.f.get(this.h,"templateSourceData_"+a);b.a.f.set(this.h,"templateSourceData_"+a,arguments[1])};b.l.O=function(a){this.h=a};b.l.O.prototype=new b.l.h;b.l.O.prototype.text=function(){if(0==arguments.length){var a=b.a.f.get(this.h,"__ko_anon_template__")||{};a.za===H&&a.ia&&(a.za=a.ia.innerHTML);return a.za}b.a.f.set(this.h,"__ko_anon_template__",{za:arguments[0]})};b.l.h.prototype.nodes= 75 | function(){if(0==arguments.length)return(b.a.f.get(this.h,"__ko_anon_template__")||{}).ia;b.a.f.set(this.h,"__ko_anon_template__",{ia:arguments[0]})};b.b("templateSources",b.l);b.b("templateSources.domElement",b.l.h);b.b("templateSources.anonymousTemplate",b.l.O);var N;b.va=function(a){a!=H&&!(a instanceof b.v)&&i(Error("templateEngine must inherit from ko.templateEngine"));N=a};b.ua=function(a,d,c,e,f){c=c||{};(c.templateEngine||N)==H&&i(Error("Set a template engine before calling renderTemplate")); 76 | f=f||"replaceChildren";if(e){var g=M(e);return b.j(function(){var h=d&&d instanceof b.z?d:new b.z(b.a.d(d)),j="function"==typeof a?a(h.$data,h):a,h=S(e,f,j,h,c);"replaceNode"==f&&(e=h,g=M(e))},n,{Ja:function(){return!g||!b.a.X(g)},W:g&&"replaceNode"==f?g.parentNode:g})}return b.s.qa(function(e){b.ua(a,d,c,e,"replaceNode")})};b.Lb=function(a,d,c,e,f){function g(a,b){T(b,j);c.afterRender&&c.afterRender(b,a)}function h(d,e){j=f.createChildContext(b.a.d(d),c.as);j.$index=e;var g="function"==typeof a? 77 | a(d,j):a;return S(n,"ignoreTargetNode",g,j,c)}var j;return b.j(function(){var a=b.a.d(d)||[];"undefined"==typeof a.length&&(a=[a]);a=b.a.fa(a,function(a){return c.includeDestroyed||a===H||a===n||!b.a.d(a._destroy)});b.r.K(b.a.Za,n,[e,a,h,c,g])},n,{W:e})};b.c.template={init:function(a,d){var c=b.a.d(d());if("string"!=typeof c&&!c.name&&(1==a.nodeType||8==a.nodeType))c=1==a.nodeType?a.childNodes:b.e.childNodes(a),c=b.a.Gb(c),(new b.l.O(a)).nodes(c);return{controlsDescendantBindings:l}},update:function(a, 78 | d,c,e,f){var d=b.a.d(d()),c={},e=l,g,h=n;"string"!=typeof d&&(c=d,d=c.name,"if"in c&&(e=b.a.d(c["if"])),e&&"ifnot"in c&&(e=!b.a.d(c.ifnot)),g=b.a.d(c.data));"foreach"in c?h=b.Lb(d||a,e&&c.foreach||[],c,a,f):e?(f="data"in c?f.createChildContext(g,c.as):f,h=b.ua(d||a,f,c,a)):b.e.Y(a);f=h;(g=b.a.f.get(a,"__ko__templateComputedDomDataKey__"))&&"function"==typeof g.B&&g.B();b.a.f.set(a,"__ko__templateComputedDomDataKey__",f&&f.oa()?f:H)}};b.g.Q.template=function(a){a=b.g.aa(a);return 1==a.length&&a[0].unknown|| 79 | b.g.Db(a,"name")?n:"This template engine does not support anonymous templates nested within its templates"};b.e.I.template=l;b.b("setTemplateEngine",b.va);b.b("renderTemplate",b.ua);b.a.Ia=function(a,b,c){a=a||[];b=b||[];return a.length<=b.length?R(a,b,"added","deleted",c):R(b,a,"deleted","added",c)};b.b("utils.compareArrays",b.a.Ia);b.a.Za=function(a,d,c,e,f){function g(a,b){s=k[b];v!==b&&(y[a]=s);s.ma(v++);L(s.M);r.push(s);z.push(s)}function h(a,c){if(a)for(var d=0,e=c.length;db.a.Z)&&a.nodes?a.nodes():n;if(d)return b.a.L(d.cloneNode(l).childNodes);a=a.text();return b.a.sa(a)};b.C.na=new b.C;b.va(b.C.na);b.b("nativeTemplateEngine",b.C);b.pa=function(){var a=this.Cb=function(){if("undefined"==typeof E||!E.tmpl)return 0;try{if(0<=E.tmpl.tag.tmpl.open.toString().indexOf("__"))return 2}catch(a){}return 1}();this.renderTemplateSource=function(b,c,e){e=e||{};2>a&&i(Error("Your version of jQuery.tmpl is too old. Please upgrade to jQuery.tmpl 1.0.0pre or later.")); 83 | var f=b.data("precompiled");f||(f=b.text()||"",f=E.template(n,"{{ko_with $item.koBindingContext}}"+f+"{{/ko_with}}"),b.data("precompiled",f));b=[c.$data];c=E.extend({koBindingContext:c},e.templateOptions);c=E.tmpl(f,b,c);c.appendTo(x.createElement("div"));E.fragments={};return c};this.createJavaScriptEvaluatorBlock=function(a){return"{{ko_code ((function() { return "+a+" })()) }}"};this.addTemplate=function(a,b){x.write(" 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /knockout-chrome-extension/popup.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | var appWindow; 3 | 4 | document.addEventListener("DOMContentLoaded", start, false); 5 | 6 | function start() { 7 | // Get application window, which is inside the "app" iframe. 8 | appWindow = getAppWindow(); 9 | 10 | // The application window can post messages to us 11 | window.addEventListener("message", handleMessage, false); 12 | } 13 | 14 | function getAppWindow() { 15 | return document.getElementById("app").contentWindow; 16 | } 17 | 18 | function handleMessage() { 19 | if (event.data.appReady) { 20 | sendLinksToApp(); 21 | } else if (event.data.openLink) { 22 | openLink(event.data.openLink); 23 | } 24 | } 25 | 26 | function sendLinksToApp() { 27 | // Get the user's top sites. 28 | chrome.topSites.get(function(topSites){ 29 | // topSites is an array of { title, url } objects 30 | // post a message to the app window, 31 | // asking it to display these sites as links. 32 | appWindow.postMessage({ displayLinks: topSites }, "*"); 33 | }); 34 | } 35 | 36 | function openLink(url) { 37 | chrome.tabs.create({ url: url }); 38 | } 39 | 40 | }()); 41 | -------------------------------------------------------------------------------- /react-immutable/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | build 3 | views/*.js 4 | -------------------------------------------------------------------------------- /react-immutable/README.md: -------------------------------------------------------------------------------- 1 | To run this sample: 2 | 3 | ``` 4 | npm install 5 | 6 | gulp 7 | 8 | open index.html 9 | ``` 10 | 11 | -------------------------------------------------------------------------------- /react-immutable/app.js: -------------------------------------------------------------------------------- 1 | var React = require("react"); 2 | var immutable = require("immutable-object"); 3 | 4 | function App(data, createComponent, applicationElement) { 5 | this.createComponent = createComponent; 6 | this.applicationElement = applicationElement; 7 | this.data = data; 8 | this.render(); 9 | } 10 | 11 | App.prototype.update = function(lens, change) { 12 | if (lens) { 13 | if (typeof change === "function") { 14 | this.data = immutable.lens.update(this.data, lens, change); 15 | } else { 16 | this.data = lens.set(this.data, change); 17 | } 18 | } else { 19 | this.data = change(this.data); 20 | } 21 | this.render(); 22 | }; 23 | 24 | App.prototype.render = function() { 25 | React.renderComponent( 26 | this.createComponent(this.data), 27 | this.applicationElement 28 | ); 29 | }; 30 | 31 | module.exports = App; 32 | 33 | -------------------------------------------------------------------------------- /react-immutable/cities.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var immutable = require("immutable-object"); 4 | 5 | // Create lenses that match the city data structure. 6 | // These will let us get/set properties within the data structure. 7 | var cityLens = immutable.lens.build([ 8 | { 9 | floors: [ 10 | { 11 | rooms: [ 12 | { light_on: true } 13 | ] 14 | } 15 | ] 16 | } 17 | ]); 18 | 19 | function randomCity() { 20 | return immutable(repeat(7, randomBuilding)); 21 | } 22 | 23 | function randomBuilding() { 24 | var floorCount = 5 + Math.floor(Math.random() * 10); 25 | var width = 2 + Math.floor(Math.random() * 3); 26 | return immutable({ 27 | floors: repeat(floorCount, function() { 28 | return { 29 | rooms: repeat(width, randomRoom) 30 | }; 31 | }) 32 | }); 33 | } 34 | 35 | function randomFloor() { 36 | return immutable({ 37 | rooms: repeat(3, randomRoom) 38 | }); 39 | } 40 | 41 | function randomRoom() { 42 | return immutable({ 43 | light_on: Math.random() > 0.5 44 | }); 45 | } 46 | 47 | function repeat(n, createItem) { 48 | var array = new Array(n); 49 | for (var i = 0; i < n; i++) { 50 | array[i] = createItem(); 51 | } 52 | return array; 53 | } 54 | 55 | exports.randomRoom = randomRoom; 56 | exports.randomFloor = randomFloor; 57 | exports.randomBuilding = randomBuilding; 58 | exports.randomCity = randomCity; 59 | exports.lens = cityLens; 60 | 61 | -------------------------------------------------------------------------------- /react-immutable/commandDispatcher.js: -------------------------------------------------------------------------------- 1 | var handlers = []; 2 | 3 | exports.dispatch = function(commandId, commandData) { 4 | handlers 5 | .filter(function(h) { return h.id === commandId; }) 6 | .forEach(function(h) { 7 | h.handler(commandData); 8 | }); 9 | }; 10 | 11 | exports.on = function(newHandlers) { 12 | Object.keys(newHandlers).forEach(function(commandId) { 13 | handlers.push({ 14 | id: commandId, 15 | handler: newHandlers[commandId] 16 | }); 17 | }); 18 | }; 19 | 20 | -------------------------------------------------------------------------------- /react-immutable/gulpfile.js: -------------------------------------------------------------------------------- 1 | var gulp = require("gulp"); 2 | var react = require("gulp-react"); 3 | var browserify = require("gulp-browserify"); 4 | 5 | gulp.task("scripts", function() { 6 | gulp.src(["views/*.jsx"]) 7 | .pipe(react()) 8 | .pipe(gulp.dest("views")); 9 | 10 | gulp.src(["index.js"]) 11 | .pipe(browserify()) 12 | .pipe(gulp.dest("build")); 13 | }); 14 | 15 | gulp.task("watch", function() { 16 | gulp.watch(["**/*.js", "**/*.jsx"], ["scripts"]); 17 | }); 18 | 19 | gulp.task("default", ["scripts"]); 20 | 21 | -------------------------------------------------------------------------------- /react-immutable/index.css: -------------------------------------------------------------------------------- 1 | /* Borrowed from https://github.com/mquan/cortex/blob/master/examples/skyline/skyline.css */ 2 | 3 | body{ 4 | margin: 0; 5 | padding: 0; 6 | } 7 | 8 | a { 9 | color: #70e0b6; 10 | } 11 | 12 | div#city { 13 | min-height: 600px; 14 | overflow: auto; 15 | 16 | /* Safari 5.1, Chrome 10+ */ 17 | background: -webkit-linear-gradient(top, #3e0860, #fdd4d7); 18 | 19 | /* Firefox 3.6+ */ 20 | background: -moz-linear-gradient(top, #3e0860, #fdd4d7); 21 | 22 | /* IE 10 */ 23 | background: -ms-linear-gradient(top, #3e0860, #fdd4d7); 24 | 25 | /* Opera 11.10+ */ 26 | background: -o-linear-gradient(top, #3e0860, #fdd4d7); 27 | } 28 | 29 | div.city-container { 30 | height: 100%; 31 | width: auto; 32 | white-space: nowrap; 33 | padding-top: 10px; 34 | } 35 | 36 | div.building-container { 37 | display: table-cell; 38 | height: 600px; 39 | vertical-align: bottom; 40 | } 41 | 42 | div.building { 43 | display: inline-block; 44 | background-color: #000000; 45 | margin: 0 5px; 46 | padding: 5px; 47 | } 48 | 49 | div.city-controls { 50 | position: absolute; 51 | top: 10px; 52 | right: 0; 53 | } 54 | 55 | div.city-controls a { 56 | text-decoration: none; 57 | display: inline-block; 58 | background-color: #70e0b6; 59 | color: #ffffff; 60 | padding: 5px; 61 | } 62 | 63 | a.add-floor { 64 | display: block; 65 | height: 20px; 66 | background-color: #0f0f0f; 67 | color: #0f0f0f; 68 | text-align: center; 69 | text-decoration: none; 70 | } 71 | 72 | a.add-floor:hover { 73 | color: #ffffff; 74 | } 75 | 76 | div.floor { 77 | height: 20px; 78 | } 79 | 80 | div.floor:hover { 81 | background-color: #aaaaaa; 82 | } 83 | span.room { 84 | height: 20px; 85 | width: 20px; 86 | display: inline-block; 87 | } 88 | 89 | a.window { 90 | display: block; 91 | display: block; 92 | margin: 5px; 93 | height: 10px; 94 | width: 10px; 95 | } 96 | 97 | .light-on { 98 | background-color: #f0c802; 99 | } 100 | 101 | .light-off { 102 | background-color: #888888; 103 | } 104 | 105 | #description { 106 | margin: 40px 10px 10px; 107 | color: #333; 108 | font-family: Helvetica Neue; 109 | font-size: 14px; 110 | line-height: 18px; 111 | } 112 | -------------------------------------------------------------------------------- /react-immutable/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 |
9 |

Click the windows to switch the lights on and off.

10 |

Idea for this sample borrowed from github.com/mquan/cortex/tree/master/examples/skyline 11 |

12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /react-immutable/index.js: -------------------------------------------------------------------------------- 1 | var React = require("react"); 2 | var App = require("./App"); 3 | var commandDispatcher = require("./commandDispatcher"); 4 | var cities = require("./cities"); 5 | var cityLens = cities.lens; 6 | var City = require("./views/City"); 7 | 8 | var app = new App( 9 | // The initial data for the app. 10 | cities.randomCity(), 11 | // A function that creates the root component, given the current app data. 12 | function(data) { 13 | return City({ city: data }); 14 | }, 15 | // The document element to render the component into. 16 | document.getElementById("city") 17 | ); 18 | 19 | // Components will dispatch commands when they want changes to happen 20 | // to the application's data. 21 | // Handle these commands here, updating the application. 22 | // A real app would probably communicate with a back-end here too. 23 | commandDispatcher.on({ 24 | switchLight: function(command) { 25 | var ids = command.roomId; 26 | app.update( 27 | // Create a lens that targets the light_on property 28 | // of the referenced buildling, floor and room. 29 | cityLens(ids[0]).floors(ids[1]).rooms(ids[2]).light_on, 30 | // Pass the new value 31 | command.light_on 32 | ); 33 | }, 34 | 35 | addRoom: function(command) { 36 | var ids = command.floorId; 37 | app.update( 38 | // Create a lense that targets the rooms array 39 | // of the referenced building and floor. 40 | cityLens(ids[0]).floors(ids[1]).rooms, 41 | // Pass a function from current-state to new-state. 42 | function(rooms) { 43 | return rooms.concat(cities.randomRoom()); 44 | } 45 | ); 46 | }, 47 | 48 | addFloor: function(command) { 49 | var newFloor = cities.randomFloor(); 50 | var ids = command.buildingId; 51 | app.update( 52 | cityLens(ids[0]).floors, 53 | function(floors) { 54 | return floors.concat(newFloor); 55 | } 56 | ); 57 | }, 58 | 59 | addBuilding: function(command) { 60 | // Passing null lens means update the entire app data. 61 | app.update(null, function(city) { 62 | return city.concat(cities.randomBuilding()); 63 | }); 64 | } 65 | }); 66 | 67 | -------------------------------------------------------------------------------- /react-immutable/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-immutable", 3 | "version": "0.0.0", 4 | "description": "Sample code", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "", 10 | "license": "MIT", 11 | "dependencies": { 12 | "envify": "~0.2.0", 13 | "react": "~0.8.0", 14 | "immutable-object": "0.0.3" 15 | }, 16 | "devDependencies": { 17 | "gulp": "~3.5.0", 18 | "gulp-react": "~0.1.2", 19 | "gulp-browserify": "~0.4.1" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /react-immutable/views/Building.jsx: -------------------------------------------------------------------------------- 1 | /** @jsx React.DOM */ 2 | var React = require("react"); 3 | var Floor = require("./Floor"); 4 | var commandDispatcher = require("../commandDispatcher"); 5 | 6 | var Building = React.createClass({ 7 | shouldComponentUpdate: function(nextProps, nextState) { 8 | return nextProps.building !== this.props.building; 9 | }, 10 | 11 | render: function() { 12 | return ( 13 |
14 |
15 | {this.renderFloors()} 16 |
17 | + 18 |
19 | ); 20 | }, 21 | 22 | renderFloors: function() { 23 | var buildingId = this.props.buildingId; 24 | return this.props.building.floors.map(function(floor, index) { 25 | return 26 | }); 27 | }, 28 | 29 | handleAddFloorClick: function(e) { 30 | e.preventDefault(); 31 | commandDispatcher.dispatch("addFloor", { 32 | buildingId: this.props.buildingId 33 | }); 34 | return false; 35 | } 36 | }); 37 | 38 | module.exports = Building; 39 | 40 | -------------------------------------------------------------------------------- /react-immutable/views/City.jsx: -------------------------------------------------------------------------------- 1 | /** @jsx React.DOM */ 2 | var React = require("react"); 3 | var Building = require("./Building"); 4 | var commandDispatcher = require("../commandDispatcher"); 5 | 6 | var City = React.createClass({ 7 | shouldComponentUpdate: function(nextProps, nextState) { 8 | return nextProps.city !== this.props.city; 9 | }, 10 | 11 | render: function() { 12 | return ( 13 |
14 | {this.renderBuildings()} 15 |
16 | Add Building 17 |
18 |
19 | ); 20 | }, 21 | 22 | renderBuildings: function() { 23 | return this.props.city.map(function(building, index) { 24 | return 25 | }); 26 | }, 27 | 28 | addBuilding: function(e) { 29 | e.preventDefault(); 30 | commandDispatcher.dispatch("addBuilding"); 31 | return false; 32 | } 33 | }); 34 | 35 | module.exports = City; 36 | 37 | -------------------------------------------------------------------------------- /react-immutable/views/Floor.jsx: -------------------------------------------------------------------------------- 1 | /** @jsx React.DOM */ 2 | var React = require("react"); 3 | var Room = require("./Room"); 4 | var commandDispatcher = require("../commandDispatcher"); 5 | 6 | var Floor = React.createClass({ 7 | shouldComponentUpdate: function(nextProps, nextState) { 8 | return nextProps.floor !== this.props.floor; 9 | }, 10 | 11 | render: function() { 12 | return ( 13 |
14 | {this.renderRooms()} 15 |
16 | ); 17 | }, 18 | 19 | renderRooms: function() { 20 | var floorId = this.props.floorId; 21 | return this.props.floor.rooms.map(function(room, index) { 22 | return ; 23 | }); 24 | }, 25 | 26 | handleFloorClick: function(e) { 27 | e.preventDefault(); 28 | commandDispatcher.dispatch("addRoom", { 29 | floorId: this.props.floorId 30 | }); 31 | return false; 32 | } 33 | }); 34 | 35 | module.exports = Floor; 36 | 37 | -------------------------------------------------------------------------------- /react-immutable/views/Room.jsx: -------------------------------------------------------------------------------- 1 | /** @jsx React.DOM */ 2 | var React = require("react"); 3 | var commandDispatcher = require("../commandDispatcher"); 4 | 5 | var Room = React.createClass({ 6 | shouldComponentUpdate: function(nextProps, nextState) { 7 | // We have no state, and props are immutable, so can make this 8 | // "should update" test really efficient. 9 | return nextProps.room !== this.props.room; 10 | }, 11 | 12 | render: function() { 13 | return ( 14 | 15 | 16 | 17 | ); 18 | }, 19 | 20 | windowClasses: function() { 21 | return "window " + (this.props.room.light_on ? "light-on" : "light-off"); 22 | }, 23 | 24 | handleWindowClick: function(e) { 25 | e.preventDefault(); 26 | // We'd like to change the app's data. 27 | // So dispatch a command. 28 | commandDispatcher.dispatch("switchLight", { 29 | roomId: this.props.roomId, 30 | light_on: !this.props.room.light_on 31 | }); 32 | return false; 33 | } 34 | }); 35 | 36 | module.exports = Room; 37 | 38 | -------------------------------------------------------------------------------- /twitter-bootstrap-modals-and-knockout/.nuget/NuGet.Config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /twitter-bootstrap-modals-and-knockout/.nuget/NuGet.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andrewdavey/samples/d00a1d3e4d41b8b9edbd33abc6360a307295b555/twitter-bootstrap-modals-and-knockout/.nuget/NuGet.exe -------------------------------------------------------------------------------- /twitter-bootstrap-modals-and-knockout/.nuget/NuGet.targets: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | $(MSBuildProjectDirectory)\..\ 5 | 6 | 7 | false 8 | 9 | 10 | false 11 | 12 | 13 | true 14 | 15 | 16 | false 17 | 18 | 19 | 20 | 21 | 22 | 26 | 27 | 28 | 29 | 30 | $([System.IO.Path]::Combine($(SolutionDir), ".nuget")) 31 | $([System.IO.Path]::Combine($(ProjectDir), "packages.config")) 32 | $([System.IO.Path]::Combine($(SolutionDir), "packages")) 33 | 34 | 35 | 36 | 37 | $(SolutionDir).nuget 38 | packages.config 39 | $(SolutionDir)packages 40 | 41 | 42 | 43 | 44 | $(NuGetToolsPath)\nuget.exe 45 | @(PackageSource) 46 | 47 | "$(NuGetExePath)" 48 | mono --runtime=v4.0.30319 $(NuGetExePath) 49 | 50 | $(TargetDir.Trim('\\')) 51 | 52 | -RequireConsent 53 | 54 | $(NuGetCommand) install "$(PackagesConfig)" -source "$(PackageSources)" $(RequireConsentSwitch) -o "$(PackagesDir)" 55 | $(NuGetCommand) pack "$(ProjectPath)" -p Configuration=$(Configuration) -o "$(PackageOutputDir)" -symbols 56 | 57 | 58 | 59 | RestorePackages; 60 | $(ResolveReferencesDependsOn); 61 | 62 | 63 | 64 | 65 | $(BuildDependsOn); 66 | BuildPackage; 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 89 | 90 | 93 | 94 | 95 | 96 | 98 | 99 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 150 | 151 | 152 | 153 | -------------------------------------------------------------------------------- /twitter-bootstrap-modals-and-knockout/Modal.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2012 4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Modal", "Modal\Modal.csproj", "{A20A0B5D-C88A-43C4-88C0-07BB72A8DE61}" 5 | EndProject 6 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{AE48E852-9499-4A5B-BFAE-744C255F5EA0}" 7 | ProjectSection(SolutionItems) = preProject 8 | .nuget\NuGet.Config = .nuget\NuGet.Config 9 | .nuget\NuGet.exe = .nuget\NuGet.exe 10 | .nuget\NuGet.targets = .nuget\NuGet.targets 11 | EndProjectSection 12 | EndProject 13 | Global 14 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 15 | Debug|Any CPU = Debug|Any CPU 16 | Release|Any CPU = Release|Any CPU 17 | EndGlobalSection 18 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 19 | {A20A0B5D-C88A-43C4-88C0-07BB72A8DE61}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 20 | {A20A0B5D-C88A-43C4-88C0-07BB72A8DE61}.Debug|Any CPU.Build.0 = Debug|Any CPU 21 | {A20A0B5D-C88A-43C4-88C0-07BB72A8DE61}.Release|Any CPU.ActiveCfg = Release|Any CPU 22 | {A20A0B5D-C88A-43C4-88C0-07BB72A8DE61}.Release|Any CPU.Build.0 = Release|Any CPU 23 | EndGlobalSection 24 | GlobalSection(SolutionProperties) = preSolution 25 | HideSolutionNode = FALSE 26 | EndGlobalSection 27 | EndGlobal 28 | -------------------------------------------------------------------------------- /twitter-bootstrap-modals-and-knockout/Modal/App_Start/FilterConfig.cs: -------------------------------------------------------------------------------- 1 | using System.Web.Mvc; 2 | 3 | namespace Modal.App_Start 4 | { 5 | public class FilterConfig 6 | { 7 | public static void RegisterGlobalFilters(GlobalFilterCollection filters) 8 | { 9 | filters.Add(new HandleErrorAttribute()); 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /twitter-bootstrap-modals-and-knockout/Modal/App_Start/RouteConfig.cs: -------------------------------------------------------------------------------- 1 | using System.Web.Mvc; 2 | using System.Web.Routing; 3 | 4 | namespace Modal.App_Start 5 | { 6 | public class RouteConfig 7 | { 8 | public static void RegisterRoutes(RouteCollection routes) 9 | { 10 | routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 11 | 12 | routes.MapRoute( 13 | name: "Default", 14 | url: "{controller}/{action}/{id}", 15 | defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } 16 | ); 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /twitter-bootstrap-modals-and-knockout/Modal/CassetteConfiguration.cs: -------------------------------------------------------------------------------- 1 | using Cassette; 2 | using Cassette.HtmlTemplates; 3 | using Cassette.Scripts; 4 | using Cassette.Stylesheets; 5 | 6 | namespace Modal 7 | { 8 | /// 9 | /// Configures the Cassette asset bundles for the web application. 10 | /// 11 | public class CassetteBundleConfiguration : IConfiguration 12 | { 13 | public void Configure(BundleCollection bundles) 14 | { 15 | bundles.AddPerSubDirectory("Client"); 16 | bundles.AddPerSubDirectory("Client"); 17 | bundles.AddPerSubDirectory("Client"); 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /twitter-bootstrap-modals-and-knockout/Modal/Client/App/AddNote.html: -------------------------------------------------------------------------------- 1 |  -------------------------------------------------------------------------------- /twitter-bootstrap-modals-and-knockout/Modal/Client/App/AddNoteViewModel.js: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | 4 | (function () { 5 | "use strict"; 6 | 7 | // Allows the user to enter the text and importance of a new note. 8 | var AddNoteViewModel = function() { 9 | this.text = ko.observable(); 10 | this.important = ko.observable(); 11 | }; 12 | 13 | AddNoteViewModel.prototype.template = "AddNote"; 14 | 15 | AddNoteViewModel.prototype.add = function () { 16 | this._requireModal(); 17 | 18 | var newNote = { 19 | text: this.text(), 20 | important: this.important() 21 | }; 22 | // Close the modal, passing the new note object as the result data. 23 | this.modal.close(newNote); 24 | }; 25 | 26 | AddNoteViewModel.prototype.cancel = function () { 27 | this._requireModal(); 28 | 29 | // Close the modal without passing any result data. 30 | this.modal.close(); 31 | }; 32 | 33 | AddNoteViewModel.prototype._requireModal = function() { 34 | if (!this.modal) { 35 | throw new Error("AddNoteViewModel must be used with the `showModal` helper function."); 36 | } 37 | }; 38 | 39 | 40 | app.AddNoteViewModel = AddNoteViewModel; 41 | 42 | }()); -------------------------------------------------------------------------------- /twitter-bootstrap-modals-and-knockout/Modal/Client/App/App.css: -------------------------------------------------------------------------------- 1 | .note.important { 2 | color: #a00; 3 | font-weight: bold; 4 | } 5 | 6 | .modal textarea { 7 | width: 100%; 8 | box-sizing: border-box; 9 | } -------------------------------------------------------------------------------- /twitter-bootstrap-modals-and-knockout/Modal/Client/App/App.html: -------------------------------------------------------------------------------- 1 | 

Demo Application

2 | 3 |
    4 |
  • 5 | 6 | Edit 7 |
  • 8 |
9 | 10 |
11 | 12 |
-------------------------------------------------------------------------------- /twitter-bootstrap-modals-and-knockout/Modal/Client/App/AppViewModel.js: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | /// 4 | /// 5 | 6 | (function () { 7 | "use strict"; 8 | 9 | // Imports 10 | var showModal = utils.showModal; 11 | var AddNoteViewModel = app.AddNoteViewModel; 12 | var NoteViewModel = app.NoteViewModel; 13 | 14 | // The root view model for the application 15 | var AppViewModel = function() { 16 | this.notes = ko.observableArray(); 17 | }; 18 | 19 | AppViewModel.prototype.addNote = function() { 20 | showModal({ 21 | viewModel: new AddNoteViewModel(), 22 | context: this // Set context so we don't need to bind the callback function 23 | }).then(this._addNoteToNotes); 24 | }; 25 | 26 | AppViewModel.prototype._addNoteToNotes = function(newNoteData) { 27 | this.notes.push(new NoteViewModel(newNoteData)); 28 | }; 29 | 30 | 31 | // Exports 32 | app.AppViewModel = AppViewModel; 33 | 34 | }()); -------------------------------------------------------------------------------- /twitter-bootstrap-modals-and-knockout/Modal/Client/App/EditNote.html: -------------------------------------------------------------------------------- 1 |  -------------------------------------------------------------------------------- /twitter-bootstrap-modals-and-knockout/Modal/Client/App/EditNoteViewModel.js: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | /// 4 | 5 | (function() { 6 | "use strict"; 7 | 8 | var EditNoteViewModel = function (note) { 9 | // Copy note properties into this object. 10 | // An observable property is created for each. 11 | // e.g. this.text = ko.observable(note.text); 12 | ko.mapping.fromJS(note, {}, this); 13 | }; 14 | 15 | EditNoteViewModel.prototype.template = "EditNote"; 16 | 17 | EditNoteViewModel.prototype.save = function () { 18 | this._requireModal(); 19 | 20 | // Convert this view model's observable properties into a plain JavaScript object. 21 | // Then pass that back to the calling code. 22 | var updatedNote = ko.mapping.toJS(this); 23 | this.modal.close(updatedNote); 24 | }; 25 | 26 | EditNoteViewModel.prototype.cancel = function () { 27 | this._requireModal(); 28 | 29 | // Close the modal without passing any result data. 30 | this.modal.close(); 31 | }; 32 | 33 | EditNoteViewModel.prototype._requireModal = function () { 34 | if (!this.modal) { 35 | throw new Error("EditNoteViewModel must be used with the `showModal` helper function."); 36 | } 37 | }; 38 | 39 | 40 | // Exports 41 | app.EditNoteViewModel = EditNoteViewModel; 42 | 43 | }()); -------------------------------------------------------------------------------- /twitter-bootstrap-modals-and-knockout/Modal/Client/App/NoteViewModel.js: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | /// 4 | /// 5 | 6 | (function() { 7 | "use strict"; 8 | 9 | // Imports 10 | var EditNoteViewModel = app.EditNoteViewModel; 11 | var showModal = utils.showModal; 12 | 13 | 14 | var NoteViewModel = function(data) { 15 | this.text = ko.observable(data.text); 16 | this.important = ko.observable(data.important); 17 | }; 18 | 19 | NoteViewModel.prototype.edit = function () { 20 | // Convert this view model's observable properties into a plain JavaScript object. 21 | var noteData = ko.mapping.toJS(this); 22 | // Create an editor view model that will be initialized with the note data. 23 | var editNoteViewModel = new EditNoteViewModel(noteData); 24 | showModal({ 25 | viewModel: editNoteViewModel, 26 | context: this 27 | }).then(function (updatedNoteData) { 28 | // Update the note view model (this) with the data 29 | // returned from the modal dialog. 30 | ko.mapping.fromJS(updatedNoteData, {}, this); 31 | }); 32 | }; 33 | 34 | 35 | // Exports 36 | app.NoteViewModel = NoteViewModel; 37 | 38 | }()); -------------------------------------------------------------------------------- /twitter-bootstrap-modals-and-knockout/Modal/Client/App/_start.js: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | /// 4 | 5 | (function () { 6 | "use strict"; 7 | 8 | ko.applyBindings(new app.AppViewModel()); 9 | }()); -------------------------------------------------------------------------------- /twitter-bootstrap-modals-and-knockout/Modal/Client/App/namespace.js: -------------------------------------------------------------------------------- 1 | var app = { }; -------------------------------------------------------------------------------- /twitter-bootstrap-modals-and-knockout/Modal/Client/Shared/ScriptBundle.txt: -------------------------------------------------------------------------------- 1 | jquery.js 2 | knockout.js 3 | utils/namespace.js 4 | * -------------------------------------------------------------------------------- /twitter-bootstrap-modals-and-knockout/Modal/Client/Shared/knockout.mapping-latest.debug.js: -------------------------------------------------------------------------------- 1 | /// Knockout Mapping plugin v2.3.5 2 | /// (c) 2012 Steven Sanderson, Roy Jacobs - http://knockoutjs.com/ 3 | /// License: MIT (http://www.opensource.org/licenses/mit-license.php) 4 | (function (factory) { 5 | // Module systems magic dance. 6 | 7 | if (typeof require === "function" && typeof exports === "object" && typeof module === "object") { 8 | // CommonJS or Node: hard-coded dependency on "knockout" 9 | factory(require("knockout"), exports); 10 | } else if (typeof define === "function" && define["amd"]) { 11 | // AMD anonymous module with hard-coded dependency on "knockout" 12 | define(["knockout", "exports"], factory); 13 | } else { 14 | //