├── .gitignore ├── .project ├── Gruntfile.js ├── README.md ├── demoer ├── beautify.js ├── bootstrap-combined.min.css ├── bootstrap.min.js ├── demoer.css ├── demoer.html ├── demoer.js └── jquery.min.js ├── index.html ├── package.json ├── perf ├── README.md ├── index.html ├── lib │ ├── Benchmark.js │ ├── Faker.js │ └── underscore.min.js ├── main.css ├── main.js ├── test.html └── tests │ ├── 10_TransactionReadWriteIsolation.js │ ├── 11_IndexKeyObjectCursor.js │ ├── 12_CursorContinueAdvance.js │ ├── 13_OpenDBVersions.js │ ├── 14_TransactionObjectStore.js │ ├── 15_TransactionRead.js │ ├── 16_TransactionWrite.js │ ├── 17_AddUpdate.js │ ├── 1_KeyCompare.js │ ├── 2_TableSchema_Write.js │ ├── 3_TransactionRead.js │ ├── 4_TransactionWrite.js │ ├── 5_Cursor_ParallelWrite.js │ ├── 6_Cursor_ParallelRead.js │ ├── 8_IndexUnused.js │ ├── 9_CursorIndexCursor.js │ └── Template.js ├── polyfill └── index.html ├── style.css ├── test.html └── trialtool ├── all.html ├── ie.html ├── ie10.html ├── index.html ├── moz_indexedDB.html ├── test.html └── webkitIndexedDB.html /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | linq4idb 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /Gruntfile.js: -------------------------------------------------------------------------------- 1 | module.exports = function(grunt) { 2 | 3 | // project configuration. 4 | grunt.initConfig({ 5 | pkg: grunt.file.readJSON('package.json'), 6 | connect: { 7 | server: { 8 | options: { 9 | base: ".", 10 | port: 8000 11 | } 12 | } 13 | }, 14 | watch: {} 15 | }); 16 | 17 | grunt.loadNpmTasks('grunt-contrib-watch'); 18 | grunt.loadNpmTasks('grunt-contrib-connect'); 19 | 20 | 21 | // default task (no deploy) 22 | grunt.registerTask('default', ['connect', 'watch']); 23 | }; -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # IndexedDB 2 | 3 | [IndexedDB](http://www.w3.org/TR/IndexedDB/) is a client side sorage specification. -------------------------------------------------------------------------------- /demoer/beautify.js: -------------------------------------------------------------------------------- 1 | /*jslint onevar: false, plusplus: false */ 2 | /* 3 | 4 | JS Beautifier 5 | --------------- 6 | 7 | 8 | Written by Einar Lielmanis, 9 | http://jsbeautifier.org/ 10 | 11 | Originally converted to javascript by Vital, 12 | "End braces on own line" added by Chris J. Shull, 13 | 14 | You are free to use this in any way you want, in case you find this useful or working for you. 15 | 16 | Usage: 17 | js_beautify(js_source_text); 18 | js_beautify(js_source_text, options); 19 | 20 | The options are: 21 | indent_size (default 4) — indentation size, 22 | indent_char (default space) — character to indent with, 23 | preserve_newlines (default true) — whether existing line breaks should be preserved, 24 | preserve_max_newlines (default unlimited) - maximum number of line breaks to be preserved in one chunk, 25 | indent_level (default 0) — initial indentation level, you probably won't need this ever, 26 | 27 | jslint_happy (default false) — if true, then jslint-stricter mode is enforced. 28 | 29 | jslint_happy !jslint_happy 30 | --------------------------------- 31 | function () function() 32 | 33 | brace_style (default "collapse") - "collapse" | "expand" | "end-expand" 34 | put braces on the same line as control statements (default), or put braces on own line (Allman / ANSI style), or just put end braces on own line. 35 | 36 | e.g 37 | 38 | js_beautify(js_source_text, { 39 | 'indent_size': 1, 40 | 'indent_char': '\t' 41 | }); 42 | 43 | 44 | */ 45 | 46 | 47 | 48 | function js_beautify(js_source_text, options) { 49 | 50 | var input, output, token_text, last_type, last_text, last_last_text, last_word, flags, flag_store, indent_string; 51 | var whitespace, wordchar, punct, parser_pos, line_starters, digits; 52 | var prefix, token_type, do_block_just_closed; 53 | var wanted_newline, just_added_newline, n_newlines; 54 | 55 | 56 | // Some interpreters have unexpected results with foo = baz || bar; 57 | options = options ? options : {}; 58 | 59 | var opt_brace_style; 60 | 61 | // compatibility 62 | if (options.space_after_anon_function !== undefined && options.jslint_happy === undefined) { 63 | options.jslint_happy = options.space_after_anon_function; 64 | } 65 | if (options.braces_on_own_line !== undefined) { //graceful handling of depricated option 66 | opt_brace_style = options.braces_on_own_line ? "expand" : "collapse"; 67 | } 68 | opt_brace_style = options.brace_style ? options.brace_style : (opt_brace_style ? opt_brace_style : "collapse"); 69 | 70 | 71 | var opt_indent_size = options.indent_size ? options.indent_size : 4; 72 | var opt_indent_char = options.indent_char ? options.indent_char : ' '; 73 | var opt_preserve_newlines = typeof options.preserve_newlines === 'undefined' ? true : options.preserve_newlines; 74 | var opt_max_preserve_newlines = typeof options.max_preserve_newlines === 'undefined' ? false : options.max_preserve_newlines; 75 | var opt_indent_level = options.indent_level ? options.indent_level : 0; // starting indentation 76 | var opt_jslint_happy = options.jslint_happy === 'undefined' ? false : options.jslint_happy; 77 | var opt_keep_array_indentation = typeof options.keep_array_indentation === 'undefined' ? false : options.keep_array_indentation; 78 | 79 | just_added_newline = false; 80 | 81 | // cache the source's length. 82 | var input_length = js_source_text.length; 83 | 84 | function trim_output(eat_newlines) { 85 | eat_newlines = typeof eat_newlines === 'undefined' ? false : eat_newlines; 86 | while (output.length && (output[output.length - 1] === ' ' 87 | || output[output.length - 1] === indent_string 88 | || (eat_newlines && (output[output.length - 1] === '\n' || output[output.length - 1] === '\r')))) { 89 | output.pop(); 90 | } 91 | } 92 | 93 | function trim(s) { 94 | return s.replace(/^\s\s*|\s\s*$/, ''); 95 | } 96 | 97 | function print_newline(ignore_repeated) { 98 | 99 | flags.eat_next_space = false; 100 | if (opt_keep_array_indentation && is_array(flags.mode)) { 101 | return; 102 | } 103 | 104 | ignore_repeated = typeof ignore_repeated === 'undefined' ? true : ignore_repeated; 105 | 106 | flags.if_line = false; 107 | trim_output(); 108 | 109 | if (!output.length) { 110 | return; // no newline on start of file 111 | } 112 | 113 | if (output[output.length - 1] !== "\n" || !ignore_repeated) { 114 | just_added_newline = true; 115 | output.push("\n"); 116 | } 117 | for (var i = 0; i < flags.indentation_level; i += 1) { 118 | output.push(indent_string); 119 | } 120 | if (flags.var_line && flags.var_line_reindented) { 121 | if (opt_indent_char === ' ') { 122 | output.push(' '); // var_line always pushes 4 spaces, so that the variables would be one under another 123 | } else { 124 | output.push(indent_string); // skip space-stuffing, if indenting with a tab 125 | } 126 | } 127 | } 128 | 129 | 130 | 131 | function print_single_space() { 132 | if (flags.eat_next_space) { 133 | flags.eat_next_space = false; 134 | return; 135 | } 136 | var last_output = ' '; 137 | if (output.length) { 138 | last_output = output[output.length - 1]; 139 | } 140 | if (last_output !== ' ' && last_output !== '\n' && last_output !== indent_string) { // prevent occassional duplicate space 141 | output.push(' '); 142 | } 143 | } 144 | 145 | 146 | function print_token() { 147 | just_added_newline = false; 148 | flags.eat_next_space = false; 149 | output.push(token_text); 150 | } 151 | 152 | function indent() { 153 | flags.indentation_level += 1; 154 | } 155 | 156 | 157 | function remove_indent() { 158 | if (output.length && output[output.length - 1] === indent_string) { 159 | output.pop(); 160 | } 161 | } 162 | 163 | function set_mode(mode) { 164 | if (flags) { 165 | flag_store.push(flags); 166 | } 167 | flags = { 168 | previous_mode: flags ? flags.mode : 'BLOCK', 169 | mode: mode, 170 | var_line: false, 171 | var_line_tainted: false, 172 | var_line_reindented: false, 173 | in_html_comment: false, 174 | if_line: false, 175 | in_case: false, 176 | eat_next_space: false, 177 | indentation_baseline: -1, 178 | indentation_level: (flags ? flags.indentation_level + ((flags.var_line && flags.var_line_reindented) ? 1 : 0) : opt_indent_level), 179 | ternary_depth: 0 180 | }; 181 | } 182 | 183 | function is_array(mode) { 184 | return mode === '[EXPRESSION]' || mode === '[INDENTED-EXPRESSION]'; 185 | } 186 | 187 | function is_expression(mode) { 188 | return mode === '[EXPRESSION]' || mode === '[INDENTED-EXPRESSION]' || mode === '(EXPRESSION)'; 189 | } 190 | 191 | function restore_mode() { 192 | do_block_just_closed = flags.mode === 'DO_BLOCK'; 193 | if (flag_store.length > 0) { 194 | flags = flag_store.pop(); 195 | } 196 | } 197 | 198 | 199 | function in_array(what, arr) { 200 | for (var i = 0; i < arr.length; i += 1) { 201 | if (arr[i] === what) { 202 | return true; 203 | } 204 | } 205 | return false; 206 | } 207 | 208 | function get_next_token() { 209 | n_newlines = 0; 210 | 211 | if (parser_pos >= input_length) { 212 | return ['', 'TK_EOF']; 213 | } 214 | 215 | wanted_newline = false; 216 | 217 | var c = input.charAt(parser_pos); 218 | parser_pos += 1; 219 | 220 | 221 | var keep_whitespace = opt_keep_array_indentation && is_array(flags.mode); 222 | 223 | if (keep_whitespace) { 224 | 225 | // 226 | // slight mess to allow nice preservation of array indentation and reindent that correctly 227 | // first time when we get to the arrays: 228 | // var a = [ 229 | // ....'something' 230 | // we make note of whitespace_count = 4 into flags.indentation_baseline 231 | // so we know that 4 whitespaces in original source match indent_level of reindented source 232 | // 233 | // and afterwards, when we get to 234 | // 'something, 235 | // .......'something else' 236 | // we know that this should be indented to indent_level + (7 - indentation_baseline) spaces 237 | // 238 | var whitespace_count = 0; 239 | 240 | while (in_array(c, whitespace)) { 241 | 242 | if (c === "\n") { 243 | trim_output(); 244 | output.push("\n"); 245 | just_added_newline = true; 246 | whitespace_count = 0; 247 | } else { 248 | if (c === '\t') { 249 | whitespace_count += 4; 250 | } else if (c === '\r') { 251 | // nothing 252 | } else { 253 | whitespace_count += 1; 254 | } 255 | } 256 | 257 | if (parser_pos >= input_length) { 258 | return ['', 'TK_EOF']; 259 | } 260 | 261 | c = input.charAt(parser_pos); 262 | parser_pos += 1; 263 | 264 | } 265 | if (flags.indentation_baseline === -1) { 266 | flags.indentation_baseline = whitespace_count; 267 | } 268 | 269 | if (just_added_newline) { 270 | var i; 271 | for (i = 0; i < flags.indentation_level + 1; i += 1) { 272 | output.push(indent_string); 273 | } 274 | if (flags.indentation_baseline !== -1) { 275 | for (i = 0; i < whitespace_count - flags.indentation_baseline; i++) { 276 | output.push(' '); 277 | } 278 | } 279 | } 280 | 281 | } else { 282 | while (in_array(c, whitespace)) { 283 | 284 | if (c === "\n") { 285 | n_newlines += ( (opt_max_preserve_newlines) ? (n_newlines <= opt_max_preserve_newlines) ? 1: 0: 1 ); 286 | } 287 | 288 | 289 | if (parser_pos >= input_length) { 290 | return ['', 'TK_EOF']; 291 | } 292 | 293 | c = input.charAt(parser_pos); 294 | parser_pos += 1; 295 | 296 | } 297 | 298 | if (opt_preserve_newlines) { 299 | if (n_newlines > 1) { 300 | for (i = 0; i < n_newlines; i += 1) { 301 | print_newline(i === 0); 302 | just_added_newline = true; 303 | } 304 | } 305 | } 306 | wanted_newline = n_newlines > 0; 307 | } 308 | 309 | 310 | if (in_array(c, wordchar)) { 311 | if (parser_pos < input_length) { 312 | while (in_array(input.charAt(parser_pos), wordchar)) { 313 | c += input.charAt(parser_pos); 314 | parser_pos += 1; 315 | if (parser_pos === input_length) { 316 | break; 317 | } 318 | } 319 | } 320 | 321 | // small and surprisingly unugly hack for 1E-10 representation 322 | if (parser_pos !== input_length && c.match(/^[0-9]+[Ee]$/) && (input.charAt(parser_pos) === '-' || input.charAt(parser_pos) === '+')) { 323 | 324 | var sign = input.charAt(parser_pos); 325 | parser_pos += 1; 326 | 327 | var t = get_next_token(parser_pos); 328 | c += sign + t[0]; 329 | return [c, 'TK_WORD']; 330 | } 331 | 332 | if (c === 'in') { // hack for 'in' operator 333 | return [c, 'TK_OPERATOR']; 334 | } 335 | if (wanted_newline && last_type !== 'TK_OPERATOR' 336 | && last_type !== 'TK_EQUALS' 337 | && !flags.if_line && (opt_preserve_newlines || last_text !== 'var')) { 338 | print_newline(); 339 | } 340 | return [c, 'TK_WORD']; 341 | } 342 | 343 | if (c === '(' || c === '[') { 344 | return [c, 'TK_START_EXPR']; 345 | } 346 | 347 | if (c === ')' || c === ']') { 348 | return [c, 'TK_END_EXPR']; 349 | } 350 | 351 | if (c === '{') { 352 | return [c, 'TK_START_BLOCK']; 353 | } 354 | 355 | if (c === '}') { 356 | return [c, 'TK_END_BLOCK']; 357 | } 358 | 359 | if (c === ';') { 360 | return [c, 'TK_SEMICOLON']; 361 | } 362 | 363 | if (c === '/') { 364 | var comment = ''; 365 | // peek for comment /* ... */ 366 | var inline_comment = true; 367 | if (input.charAt(parser_pos) === '*') { 368 | parser_pos += 1; 369 | if (parser_pos < input_length) { 370 | while (! (input.charAt(parser_pos) === '*' && input.charAt(parser_pos + 1) && input.charAt(parser_pos + 1) === '/') && parser_pos < input_length) { 371 | c = input.charAt(parser_pos); 372 | comment += c; 373 | if (c === '\x0d' || c === '\x0a') { 374 | inline_comment = false; 375 | } 376 | parser_pos += 1; 377 | if (parser_pos >= input_length) { 378 | break; 379 | } 380 | } 381 | } 382 | parser_pos += 2; 383 | if (inline_comment) { 384 | return ['/*' + comment + '*/', 'TK_INLINE_COMMENT']; 385 | } else { 386 | return ['/*' + comment + '*/', 'TK_BLOCK_COMMENT']; 387 | } 388 | } 389 | // peek for comment // ... 390 | if (input.charAt(parser_pos) === '/') { 391 | comment = c; 392 | while (input.charAt(parser_pos) !== '\r' && input.charAt(parser_pos) !== '\n') { 393 | comment += input.charAt(parser_pos); 394 | parser_pos += 1; 395 | if (parser_pos >= input_length) { 396 | break; 397 | } 398 | } 399 | parser_pos += 1; 400 | if (wanted_newline) { 401 | print_newline(); 402 | } 403 | return [comment, 'TK_COMMENT']; 404 | } 405 | 406 | } 407 | 408 | if (c === "'" || // string 409 | c === '"' || // string 410 | (c === '/' && 411 | ((last_type === 'TK_WORD' && in_array(last_text, ['return', 'do'])) || 412 | (last_type === 'TK_COMMENT' || last_type === 'TK_START_EXPR' || last_type === 'TK_START_BLOCK' || last_type === 'TK_END_BLOCK' || last_type === 'TK_OPERATOR' || last_type === 'TK_EQUALS' || last_type === 'TK_EOF' || last_type === 'TK_SEMICOLON')))) { // regexp 413 | var sep = c; 414 | var esc = false; 415 | var resulting_string = c; 416 | 417 | if (parser_pos < input_length) { 418 | if (sep === '/') { 419 | // 420 | // handle regexp separately... 421 | // 422 | var in_char_class = false; 423 | while (esc || in_char_class || input.charAt(parser_pos) !== sep) { 424 | resulting_string += input.charAt(parser_pos); 425 | if (!esc) { 426 | esc = input.charAt(parser_pos) === '\\'; 427 | if (input.charAt(parser_pos) === '[') { 428 | in_char_class = true; 429 | } else if (input.charAt(parser_pos) === ']') { 430 | in_char_class = false; 431 | } 432 | } else { 433 | esc = false; 434 | } 435 | parser_pos += 1; 436 | if (parser_pos >= input_length) { 437 | // incomplete string/rexp when end-of-file reached. 438 | // bail out with what had been received so far. 439 | return [resulting_string, 'TK_STRING']; 440 | } 441 | } 442 | 443 | } else { 444 | // 445 | // and handle string also separately 446 | // 447 | while (esc || input.charAt(parser_pos) !== sep) { 448 | resulting_string += input.charAt(parser_pos); 449 | if (!esc) { 450 | esc = input.charAt(parser_pos) === '\\'; 451 | } else { 452 | esc = false; 453 | } 454 | parser_pos += 1; 455 | if (parser_pos >= input_length) { 456 | // incomplete string/rexp when end-of-file reached. 457 | // bail out with what had been received so far. 458 | return [resulting_string, 'TK_STRING']; 459 | } 460 | } 461 | } 462 | 463 | 464 | 465 | } 466 | 467 | parser_pos += 1; 468 | 469 | resulting_string += sep; 470 | 471 | if (sep === '/') { 472 | // regexps may have modifiers /regexp/MOD , so fetch those, too 473 | while (parser_pos < input_length && in_array(input.charAt(parser_pos), wordchar)) { 474 | resulting_string += input.charAt(parser_pos); 475 | parser_pos += 1; 476 | } 477 | } 478 | return [resulting_string, 'TK_STRING']; 479 | } 480 | 481 | if (c === '#') { 482 | 483 | 484 | if (output.length === 0 && input.charAt(parser_pos) === '!') { 485 | // shebang 486 | resulting_string = c; 487 | while (parser_pos < input_length && c != '\n') { 488 | c = input.charAt(parser_pos); 489 | resulting_string += c; 490 | parser_pos += 1; 491 | } 492 | output.push(trim(resulting_string) + '\n'); 493 | print_newline(); 494 | return get_next_token(); 495 | } 496 | 497 | 498 | 499 | // Spidermonkey-specific sharp variables for circular references 500 | // https://developer.mozilla.org/En/Sharp_variables_in_JavaScript 501 | // http://mxr.mozilla.org/mozilla-central/source/js/src/jsscan.cpp around line 1935 502 | var sharp = '#'; 503 | if (parser_pos < input_length && in_array(input.charAt(parser_pos), digits)) { 504 | do { 505 | c = input.charAt(parser_pos); 506 | sharp += c; 507 | parser_pos += 1; 508 | } while (parser_pos < input_length && c !== '#' && c !== '='); 509 | if (c === '#') { 510 | // 511 | } else if (input.charAt(parser_pos) === '[' && input.charAt(parser_pos + 1) === ']') { 512 | sharp += '[]'; 513 | parser_pos += 2; 514 | } else if (input.charAt(parser_pos) === '{' && input.charAt(parser_pos + 1) === '}') { 515 | sharp += '{}'; 516 | parser_pos += 2; 517 | } 518 | return [sharp, 'TK_WORD']; 519 | } 520 | } 521 | 522 | if (c === '<' && input.substring(parser_pos - 1, parser_pos + 3) === '') { 529 | flags.in_html_comment = false; 530 | parser_pos += 2; 531 | if (wanted_newline) { 532 | print_newline(); 533 | } 534 | return ['-->', 'TK_COMMENT']; 535 | } 536 | 537 | if (in_array(c, punct)) { 538 | while (parser_pos < input_length && in_array(c + input.charAt(parser_pos), punct)) { 539 | c += input.charAt(parser_pos); 540 | parser_pos += 1; 541 | if (parser_pos >= input_length) { 542 | break; 543 | } 544 | } 545 | 546 | if (c === '=') { 547 | return [c, 'TK_EQUALS']; 548 | } else { 549 | return [c, 'TK_OPERATOR']; 550 | } 551 | } 552 | 553 | return [c, 'TK_UNKNOWN']; 554 | } 555 | 556 | //---------------------------------- 557 | indent_string = ''; 558 | while (opt_indent_size > 0) { 559 | indent_string += opt_indent_char; 560 | opt_indent_size -= 1; 561 | } 562 | 563 | input = js_source_text; 564 | 565 | last_word = ''; // last 'TK_WORD' passed 566 | last_type = 'TK_START_EXPR'; // last token type 567 | last_text = ''; // last token text 568 | last_last_text = ''; // pre-last token text 569 | output = []; 570 | 571 | do_block_just_closed = false; 572 | 573 | whitespace = "\n\r\t ".split(''); 574 | wordchar = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_$'.split(''); 575 | digits = '0123456789'.split(''); 576 | 577 | punct = '+ - * / % & ++ -- = += -= *= /= %= == === != !== > < >= <= >> << >>> >>>= >>= <<= && &= | || ! !! , : ? ^ ^= |= ::'.split(' '); 578 | 579 | // words which should always start on new line. 580 | line_starters = 'continue,try,throw,return,var,if,switch,case,default,for,while,break,function'.split(','); 581 | 582 | // states showing if we are currently in expression (i.e. "if" case) - 'EXPRESSION', or in usual block (like, procedure), 'BLOCK'. 583 | // some formatting depends on that. 584 | flag_store = []; 585 | set_mode('BLOCK'); 586 | 587 | parser_pos = 0; 588 | while (true) { 589 | var t = get_next_token(parser_pos); 590 | token_text = t[0]; 591 | token_type = t[1]; 592 | if (token_type === 'TK_EOF') { 593 | break; 594 | } 595 | 596 | switch (token_type) { 597 | 598 | case 'TK_START_EXPR': 599 | 600 | if (token_text === '[') { 601 | 602 | if (last_type === 'TK_WORD' || last_text === ')') { 603 | // this is array index specifier, break immediately 604 | // a[x], fn()[x] 605 | if (in_array(last_text, line_starters)) { 606 | print_single_space(); 607 | } 608 | set_mode('(EXPRESSION)'); 609 | print_token(); 610 | break; 611 | } 612 | 613 | if (flags.mode === '[EXPRESSION]' || flags.mode === '[INDENTED-EXPRESSION]') { 614 | if (last_last_text === ']' && last_text === ',') { 615 | // ], [ goes to new line 616 | if (flags.mode === '[EXPRESSION]') { 617 | flags.mode = '[INDENTED-EXPRESSION]'; 618 | if (!opt_keep_array_indentation) { 619 | indent(); 620 | } 621 | } 622 | set_mode('[EXPRESSION]'); 623 | if (!opt_keep_array_indentation) { 624 | print_newline(); 625 | } 626 | } else if (last_text === '[') { 627 | if (flags.mode === '[EXPRESSION]') { 628 | flags.mode = '[INDENTED-EXPRESSION]'; 629 | if (!opt_keep_array_indentation) { 630 | indent(); 631 | } 632 | } 633 | set_mode('[EXPRESSION]'); 634 | 635 | if (!opt_keep_array_indentation) { 636 | print_newline(); 637 | } 638 | } else { 639 | set_mode('[EXPRESSION]'); 640 | } 641 | } else { 642 | set_mode('[EXPRESSION]'); 643 | } 644 | 645 | 646 | 647 | } else { 648 | set_mode('(EXPRESSION)'); 649 | } 650 | 651 | if (last_text === ';' || last_type === 'TK_START_BLOCK') { 652 | print_newline(); 653 | } else if (last_type === 'TK_END_EXPR' || last_type === 'TK_START_EXPR' || last_type === 'TK_END_BLOCK' || last_text === '.') { 654 | // do nothing on (( and )( and ][ and ]( and .( 655 | } else if (last_type !== 'TK_WORD' && last_type !== 'TK_OPERATOR') { 656 | print_single_space(); 657 | } else if (last_word === 'function' || last_word === 'typeof') { 658 | // function() vs function () 659 | if (opt_jslint_happy) { 660 | print_single_space(); 661 | } 662 | } else if (in_array(last_text, line_starters) || last_text === 'catch') { 663 | print_single_space(); 664 | } 665 | print_token(); 666 | 667 | break; 668 | 669 | case 'TK_END_EXPR': 670 | if (token_text === ']') { 671 | if (opt_keep_array_indentation) { 672 | if (last_text === '}') { 673 | // trim_output(); 674 | // print_newline(true); 675 | remove_indent(); 676 | print_token(); 677 | restore_mode(); 678 | break; 679 | } 680 | } else { 681 | if (flags.mode === '[INDENTED-EXPRESSION]') { 682 | if (last_text === ']') { 683 | restore_mode(); 684 | print_newline(); 685 | print_token(); 686 | break; 687 | } 688 | } 689 | } 690 | } 691 | restore_mode(); 692 | print_token(); 693 | break; 694 | 695 | case 'TK_START_BLOCK': 696 | 697 | if (last_word === 'do') { 698 | set_mode('DO_BLOCK'); 699 | } else { 700 | set_mode('BLOCK'); 701 | } 702 | if (opt_brace_style=="expand") { 703 | if (last_type !== 'TK_OPERATOR') { 704 | if (last_text === 'return' || last_text === '=') { 705 | print_single_space(); 706 | } else { 707 | print_newline(true); 708 | } 709 | } 710 | print_token(); 711 | indent(); 712 | } else { 713 | if (last_type !== 'TK_OPERATOR' && last_type !== 'TK_START_EXPR') { 714 | if (last_type === 'TK_START_BLOCK') { 715 | print_newline(); 716 | } else { 717 | print_single_space(); 718 | } 719 | } else { 720 | // if TK_OPERATOR or TK_START_EXPR 721 | if (is_array(flags.previous_mode) && last_text === ',') { 722 | if (last_last_text === '}') { 723 | // }, { in array context 724 | print_single_space(); 725 | } else { 726 | print_newline(); // [a, b, c, { 727 | } 728 | } 729 | } 730 | indent(); 731 | print_token(); 732 | } 733 | 734 | break; 735 | 736 | case 'TK_END_BLOCK': 737 | restore_mode(); 738 | if (opt_brace_style=="expand") { 739 | if (last_text !== '{') { 740 | print_newline(); 741 | } 742 | print_token(); 743 | } else { 744 | if (last_type === 'TK_START_BLOCK') { 745 | // nothing 746 | if (just_added_newline) { 747 | remove_indent(); 748 | } else { 749 | // {} 750 | trim_output(); 751 | } 752 | } else { 753 | if (is_array(flags.mode) && opt_keep_array_indentation) { 754 | // we REALLY need a newline here, but newliner would skip that 755 | opt_keep_array_indentation = false; 756 | print_newline(); 757 | opt_keep_array_indentation = true; 758 | 759 | } else { 760 | print_newline(); 761 | } 762 | } 763 | print_token(); 764 | } 765 | break; 766 | 767 | case 'TK_WORD': 768 | 769 | // no, it's not you. even I have problems understanding how this works 770 | // and what does what. 771 | if (do_block_just_closed) { 772 | // do {} ## while () 773 | print_single_space(); 774 | print_token(); 775 | print_single_space(); 776 | do_block_just_closed = false; 777 | break; 778 | } 779 | 780 | if (token_text === 'function') { 781 | if (flags.var_line) { 782 | flags.var_line_reindented = true; 783 | } 784 | if ((just_added_newline || last_text === ';') && last_text !== '{') { 785 | // make sure there is a nice clean space of at least one blank line 786 | // before a new function definition 787 | n_newlines = just_added_newline ? n_newlines : 0; 788 | if ( ! opt_preserve_newlines) { 789 | n_newlines = 1; 790 | } 791 | 792 | for (var i = 0; i < 2 - n_newlines; i++) { 793 | print_newline(false); 794 | } 795 | } 796 | } 797 | 798 | if (token_text === 'case' || token_text === 'default') { 799 | if (last_text === ':') { 800 | // switch cases following one another 801 | remove_indent(); 802 | } else { 803 | // case statement starts in the same line where switch 804 | flags.indentation_level--; 805 | print_newline(); 806 | flags.indentation_level++; 807 | } 808 | print_token(); 809 | flags.in_case = true; 810 | break; 811 | } 812 | 813 | prefix = 'NONE'; 814 | 815 | if (last_type === 'TK_END_BLOCK') { 816 | 817 | if (!in_array(token_text.toLowerCase(), ['else', 'catch', 'finally'])) { 818 | prefix = 'NEWLINE'; 819 | } else { 820 | if (opt_brace_style=="expand" || opt_brace_style=="end-expand") { 821 | prefix = 'NEWLINE'; 822 | } else { 823 | prefix = 'SPACE'; 824 | print_single_space(); 825 | } 826 | } 827 | } else if (last_type === 'TK_SEMICOLON' && (flags.mode === 'BLOCK' || flags.mode === 'DO_BLOCK')) { 828 | prefix = 'NEWLINE'; 829 | } else if (last_type === 'TK_SEMICOLON' && is_expression(flags.mode)) { 830 | prefix = 'SPACE'; 831 | } else if (last_type === 'TK_STRING') { 832 | prefix = 'NEWLINE'; 833 | } else if (last_type === 'TK_WORD') { 834 | if (last_text === 'else') { 835 | // eat newlines between ...else *** some_op... 836 | // won't preserve extra newlines in this place (if any), but don't care that much 837 | trim_output(true); 838 | } 839 | prefix = 'SPACE'; 840 | } else if (last_type === 'TK_START_BLOCK') { 841 | prefix = 'NEWLINE'; 842 | } else if (last_type === 'TK_END_EXPR') { 843 | print_single_space(); 844 | prefix = 'NEWLINE'; 845 | } 846 | 847 | if (in_array(token_text, line_starters) && last_text !== ')') { 848 | if (last_text == 'else') { 849 | prefix = 'SPACE'; 850 | } else { 851 | prefix = 'NEWLINE'; 852 | } 853 | } 854 | 855 | if (flags.if_line && last_type === 'TK_END_EXPR') { 856 | flags.if_line = false; 857 | } 858 | if (in_array(token_text.toLowerCase(), ['else', 'catch', 'finally'])) { 859 | if (last_type !== 'TK_END_BLOCK' || opt_brace_style=="expand" || opt_brace_style=="end-expand") { 860 | print_newline(); 861 | } else { 862 | trim_output(true); 863 | print_single_space(); 864 | } 865 | } else if (prefix === 'NEWLINE') { 866 | if ((last_type === 'TK_START_EXPR' || last_text === '=' || last_text === ',') && token_text === 'function') { 867 | // no need to force newline on 'function': (function 868 | // DONOTHING 869 | } else if (token_text === 'function' && last_text == 'new') { 870 | print_single_space(); 871 | } else if (last_text === 'return' || last_text === 'throw') { 872 | // no newline between 'return nnn' 873 | print_single_space(); 874 | } else if (last_type !== 'TK_END_EXPR') { 875 | if ((last_type !== 'TK_START_EXPR' || token_text !== 'var') && last_text !== ':') { 876 | // no need to force newline on 'var': for (var x = 0...) 877 | if (token_text === 'if' && last_word === 'else' && last_text !== '{') { 878 | // no newline for } else if { 879 | print_single_space(); 880 | } else { 881 | flags.var_line = false; 882 | flags.var_line_reindented = false; 883 | print_newline(); 884 | } 885 | } 886 | } else if (in_array(token_text, line_starters) && last_text != ')') { 887 | flags.var_line = false; 888 | flags.var_line_reindented = false; 889 | print_newline(); 890 | } 891 | } else if (is_array(flags.mode) && last_text === ',' && last_last_text === '}') { 892 | print_newline(); // }, in lists get a newline treatment 893 | } else if (prefix === 'SPACE') { 894 | print_single_space(); 895 | } 896 | print_token(); 897 | last_word = token_text; 898 | 899 | if (token_text === 'var') { 900 | flags.var_line = true; 901 | flags.var_line_reindented = false; 902 | flags.var_line_tainted = false; 903 | } 904 | 905 | if (token_text === 'if') { 906 | flags.if_line = true; 907 | } 908 | if (token_text === 'else') { 909 | flags.if_line = false; 910 | } 911 | 912 | break; 913 | 914 | case 'TK_SEMICOLON': 915 | 916 | print_token(); 917 | flags.var_line = false; 918 | flags.var_line_reindented = false; 919 | if (flags.mode == 'OBJECT') { 920 | // OBJECT mode is weird and doesn't get reset too well. 921 | flags.mode = 'BLOCK'; 922 | } 923 | break; 924 | 925 | case 'TK_STRING': 926 | 927 | if (last_type === 'TK_START_BLOCK' || last_type === 'TK_END_BLOCK' || last_type === 'TK_SEMICOLON') { 928 | print_newline(); 929 | } else if (last_type === 'TK_WORD') { 930 | print_single_space(); 931 | } 932 | print_token(); 933 | break; 934 | 935 | case 'TK_EQUALS': 936 | if (flags.var_line) { 937 | // just got an '=' in a var-line, different formatting/line-breaking, etc will now be done 938 | flags.var_line_tainted = true; 939 | } 940 | print_single_space(); 941 | print_token(); 942 | print_single_space(); 943 | break; 944 | 945 | case 'TK_OPERATOR': 946 | 947 | var space_before = true; 948 | var space_after = true; 949 | 950 | if (flags.var_line && token_text === ',' && (is_expression(flags.mode))) { 951 | // do not break on comma, for(var a = 1, b = 2) 952 | flags.var_line_tainted = false; 953 | } 954 | 955 | if (flags.var_line) { 956 | if (token_text === ',') { 957 | if (flags.var_line_tainted) { 958 | print_token(); 959 | flags.var_line_reindented = true; 960 | flags.var_line_tainted = false; 961 | print_newline(); 962 | break; 963 | } else { 964 | flags.var_line_tainted = false; 965 | } 966 | // } else if (token_text === ':') { 967 | // hmm, when does this happen? tests don't catch this 968 | // flags.var_line = false; 969 | } 970 | } 971 | 972 | if (last_text === 'return' || last_text === 'throw') { 973 | // "return" had a special handling in TK_WORD. Now we need to return the favor 974 | print_single_space(); 975 | print_token(); 976 | break; 977 | } 978 | 979 | if (token_text === ':' && flags.in_case) { 980 | print_token(); // colon really asks for separate treatment 981 | print_newline(); 982 | flags.in_case = false; 983 | break; 984 | } 985 | 986 | if (token_text === '::') { 987 | // no spaces around exotic namespacing syntax operator 988 | print_token(); 989 | break; 990 | } 991 | 992 | if (token_text === ',') { 993 | if (flags.var_line) { 994 | if (flags.var_line_tainted) { 995 | print_token(); 996 | print_newline(); 997 | flags.var_line_tainted = false; 998 | } else { 999 | print_token(); 1000 | print_single_space(); 1001 | } 1002 | } else if (last_type === 'TK_END_BLOCK' && flags.mode !== "(EXPRESSION)") { 1003 | print_token(); 1004 | if (flags.mode === 'OBJECT' && last_text === '}') { 1005 | print_newline(); 1006 | } else { 1007 | print_single_space(); 1008 | } 1009 | } else { 1010 | if (flags.mode === 'OBJECT') { 1011 | print_token(); 1012 | print_newline(); 1013 | } else { 1014 | // EXPR or DO_BLOCK 1015 | print_token(); 1016 | print_single_space(); 1017 | } 1018 | } 1019 | break; 1020 | // } else if (in_array(token_text, ['--', '++', '!']) || (in_array(token_text, ['-', '+']) && (in_array(last_type, ['TK_START_BLOCK', 'TK_START_EXPR', 'TK_EQUALS']) || in_array(last_text, line_starters) || in_array(last_text, ['==', '!=', '+=', '-=', '*=', '/=', '+', '-'])))) { 1021 | } else if (in_array(token_text, ['--', '++', '!']) || (in_array(token_text, ['-', '+']) && (in_array(last_type, ['TK_START_BLOCK', 'TK_START_EXPR', 'TK_EQUALS', 'TK_OPERATOR']) || in_array(last_text, line_starters)))) { 1022 | // unary operators (and binary +/- pretending to be unary) special cases 1023 | 1024 | space_before = false; 1025 | space_after = false; 1026 | 1027 | if (last_text === ';' && is_expression(flags.mode)) { 1028 | // for (;; ++i) 1029 | // ^^^ 1030 | space_before = true; 1031 | } 1032 | if (last_type === 'TK_WORD' && in_array(last_text, line_starters)) { 1033 | space_before = true; 1034 | } 1035 | 1036 | if (flags.mode === 'BLOCK' && (last_text === '{' || last_text === ';')) { 1037 | // { foo; --i } 1038 | // foo(); --bar; 1039 | print_newline(); 1040 | } 1041 | } else if (token_text === '.') { 1042 | // decimal digits or object.property 1043 | space_before = false; 1044 | 1045 | } else if (token_text === ':') { 1046 | if (flags.ternary_depth == 0) { 1047 | flags.mode = 'OBJECT'; 1048 | space_before = false; 1049 | } else { 1050 | flags.ternary_depth -= 1; 1051 | } 1052 | } else if (token_text === '?') { 1053 | flags.ternary_depth += 1; 1054 | } 1055 | if (space_before) { 1056 | print_single_space(); 1057 | } 1058 | 1059 | print_token(); 1060 | 1061 | if (space_after) { 1062 | print_single_space(); 1063 | } 1064 | 1065 | if (token_text === '!') { 1066 | // flags.eat_next_space = true; 1067 | } 1068 | 1069 | break; 1070 | 1071 | case 'TK_BLOCK_COMMENT': 1072 | 1073 | var lines = token_text.split(/\x0a|\x0d\x0a/); 1074 | 1075 | if (/^\/\*\*/.test(token_text)) { 1076 | // javadoc: reformat and reindent 1077 | print_newline(); 1078 | output.push(lines[0]); 1079 | for (i = 1; i < lines.length; i++) { 1080 | print_newline(); 1081 | output.push(' '); 1082 | output.push(trim(lines[i])); 1083 | } 1084 | 1085 | } else { 1086 | 1087 | // simple block comment: leave intact 1088 | if (lines.length > 1) { 1089 | // multiline comment block starts with a new line 1090 | print_newline(); 1091 | trim_output(); 1092 | } else { 1093 | // single-line /* comment */ stays where it is 1094 | print_single_space(); 1095 | 1096 | } 1097 | 1098 | for (i = 0; i < lines.length; i++) { 1099 | output.push(lines[i]); 1100 | output.push('\n'); 1101 | } 1102 | 1103 | } 1104 | print_newline(); 1105 | break; 1106 | 1107 | case 'TK_INLINE_COMMENT': 1108 | 1109 | print_single_space(); 1110 | print_token(); 1111 | if (is_expression(flags.mode)) { 1112 | print_single_space(); 1113 | } else { 1114 | print_newline(); 1115 | } 1116 | break; 1117 | 1118 | case 'TK_COMMENT': 1119 | 1120 | // print_newline(); 1121 | if (wanted_newline) { 1122 | print_newline(); 1123 | } else { 1124 | print_single_space(); 1125 | } 1126 | print_token(); 1127 | print_newline(); 1128 | break; 1129 | 1130 | case 'TK_UNKNOWN': 1131 | if (last_text === 'return' || last_text === 'throw') { 1132 | print_single_space(); 1133 | } 1134 | print_token(); 1135 | break; 1136 | } 1137 | 1138 | last_last_text = last_text; 1139 | last_type = token_type; 1140 | last_text = token_text; 1141 | } 1142 | 1143 | return output.join('').replace(/[\n ]+$/, ''); 1144 | 1145 | } 1146 | 1147 | // Add support for CommonJS. Just put this file somewhere on your require.paths 1148 | // and you will be able to `var js_beautify = require("beautify").js_beautify`. 1149 | if (typeof exports !== "undefined") 1150 | exports.js_beautify = js_beautify; 1151 | -------------------------------------------------------------------------------- /demoer/bootstrap.min.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Bootstrap.js by @fat & @mdo 3 | * plugins: bootstrap-transition.js, bootstrap-modal.js, bootstrap-dropdown.js, bootstrap-scrollspy.js, bootstrap-tab.js, bootstrap-tooltip.js, bootstrap-popover.js, bootstrap-affix.js, bootstrap-alert.js, bootstrap-button.js, bootstrap-collapse.js, bootstrap-carousel.js, bootstrap-typeahead.js 4 | * Copyright 2012 Twitter, Inc. 5 | * http://www.apache.org/licenses/LICENSE-2.0.txt 6 | */ 7 | !function(a){a(function(){a.support.transition=function(){var a=function(){var a=document.createElement("bootstrap"),b={WebkitTransition:"webkitTransitionEnd",MozTransition:"transitionend",OTransition:"oTransitionEnd otransitionend",transition:"transitionend"},c;for(c in b)if(a.style[c]!==undefined)return b[c]}();return a&&{end:a}}()})}(window.jQuery),!function(a){var b=function(b,c){this.options=c,this.$element=a(b).delegate('[data-dismiss="modal"]',"click.dismiss.modal",a.proxy(this.hide,this)),this.options.remote&&this.$element.find(".modal-body").load(this.options.remote)};b.prototype={constructor:b,toggle:function(){return this[this.isShown?"hide":"show"]()},show:function(){var b=this,c=a.Event("show");this.$element.trigger(c);if(this.isShown||c.isDefaultPrevented())return;this.isShown=!0,this.escape(),this.backdrop(function(){var c=a.support.transition&&b.$element.hasClass("fade");b.$element.parent().length||b.$element.appendTo(document.body),b.$element.show(),c&&b.$element[0].offsetWidth,b.$element.addClass("in").attr("aria-hidden",!1),b.enforceFocus(),c?b.$element.one(a.support.transition.end,function(){b.$element.focus().trigger("shown")}):b.$element.focus().trigger("shown")})},hide:function(b){b&&b.preventDefault();var c=this;b=a.Event("hide"),this.$element.trigger(b);if(!this.isShown||b.isDefaultPrevented())return;this.isShown=!1,this.escape(),a(document).off("focusin.modal"),this.$element.removeClass("in").attr("aria-hidden",!0),a.support.transition&&this.$element.hasClass("fade")?this.hideWithTransition():this.hideModal()},enforceFocus:function(){var b=this;a(document).on("focusin.modal",function(a){b.$element[0]!==a.target&&!b.$element.has(a.target).length&&b.$element.focus()})},escape:function(){var a=this;this.isShown&&this.options.keyboard?this.$element.on("keyup.dismiss.modal",function(b){b.which==27&&a.hide()}):this.isShown||this.$element.off("keyup.dismiss.modal")},hideWithTransition:function(){var b=this,c=setTimeout(function(){b.$element.off(a.support.transition.end),b.hideModal()},500);this.$element.one(a.support.transition.end,function(){clearTimeout(c),b.hideModal()})},hideModal:function(){var a=this;this.$element.hide(),this.backdrop(function(){a.removeBackdrop(),a.$element.trigger("hidden")})},removeBackdrop:function(){this.$backdrop&&this.$backdrop.remove(),this.$backdrop=null},backdrop:function(b){var c=this,d=this.$element.hasClass("fade")?"fade":"";if(this.isShown&&this.options.backdrop){var e=a.support.transition&&d;this.$backdrop=a('