From 2b73fb4a6a53fe729f21b9b50036b788676cc1cc Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Thu, 23 Feb 2012 11:23:23 +0100 Subject: [PATCH 01/39] [imp] restored nivjs bzr revid: nicolas.vanhoren@openerp.com-20120223102323-1sa7s7sieicgprfp --- addons/web/static/lib/nivjs/src/niv.js | 128 ++ addons/web/static/lib/nivjs/test/qunit.css | 226 +++ addons/web/static/lib/nivjs/test/qunit.js | 1597 ++++++++++++++++++++ addons/web/static/lib/nivjs/test/test.html | 22 + addons/web/static/lib/nivjs/test/test.js | 8 + 5 files changed, 1981 insertions(+) create mode 100644 addons/web/static/lib/nivjs/src/niv.js create mode 100755 addons/web/static/lib/nivjs/test/qunit.css create mode 100755 addons/web/static/lib/nivjs/test/qunit.js create mode 100644 addons/web/static/lib/nivjs/test/test.html create mode 100644 addons/web/static/lib/nivjs/test/test.js diff --git a/addons/web/static/lib/nivjs/src/niv.js b/addons/web/static/lib/nivjs/src/niv.js new file mode 100644 index 00000000000..773f1a49f47 --- /dev/null +++ b/addons/web/static/lib/nivjs/src/niv.js @@ -0,0 +1,128 @@ +/* +Copyright (c) 2011, OpenERP S.A. +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +niv = (function() { + var niv = {}; + + /* + * Simple JavaScript Inheritance By John Resig http://ejohn.org/ MIT + * Licensed. + */ + // Inspired by base2 and Prototype + (function(){ + var initializing = false, fnTest = /xyz/.test(function(){xyz;}) ? /\b_super\b/ : /.*/; + // The base Class implementation (does nothing) + this.Class = function(){}; + + // Create a new Class that inherits from this class + this.Class.extend = function(prop) { + var _super = this.prototype; + + // Instantiate a base class (but only create the instance, + // don't run the init constructor) + initializing = true; + var prototype = new this(); + initializing = false; + + // Copy the properties over onto the new prototype + for (var name in prop) { + // Check if we're overwriting an existing function + prototype[name] = typeof prop[name] == "function" && + typeof _super[name] == "function" && fnTest.test(prop[name]) ? + (function(name, fn){ + return function() { + var tmp = this._super; + + // Add a new ._super() method that is the same method + // but on the super-class + this._super = _super[name]; + + // The method only need to be bound temporarily, so we + // remove it when we're done executing + var ret = fn.apply(this, arguments); + this._super = tmp; + + return ret; + }; + })(name, prop[name]) : + prop[name]; + } + + // The dummy class constructor + function Class() { + // All construction is actually done in the init method + if ( !initializing && this.init ) + this.init.apply(this, arguments); + } + + // Populate our constructed prototype object + Class.prototype = prototype; + + // Enforce the constructor to be what we expect + Class.prototype.constructor = Class; + + // And make this class extendable + Class.extend = arguments.callee; + + return Class; + }; + }).call(niv); + + niv.ParentedMixin = { + __parented_mixin: true, + setParent: function(parent) { + if(this.getParent()) { + if (this.getParent().__parented_mixin) { + this.getParent().__parented_children = _.without(this.getParent().getChildren(), this); + } + this.__parented_parent = undefined; + } + this.__parented_parent = parent; + if(parent && parent.__parented_mixin) { + if (!parent.getChildren()) + parent.__parented_children = []; + parent.getChildren().push(this); + } + }, + getParent: function() { + return this.__parented_parent; + }, + getChildren: function() { + return this.__parented_children ? _.clone(this.__parented_children) : []; + }, + isDestroyed: function() { + return this.__parented_stopped; + }, + destroy: function() { + _.each(this.getChildren(), function(el) { + el.destroy(); + }); + this.setParent(undefined); + this.__parented_stopped = true; + }, + }; + + return niv; +})(); diff --git a/addons/web/static/lib/nivjs/test/qunit.css b/addons/web/static/lib/nivjs/test/qunit.css new file mode 100755 index 00000000000..bcecc4c0daf --- /dev/null +++ b/addons/web/static/lib/nivjs/test/qunit.css @@ -0,0 +1,226 @@ +/** + * QUnit v1.2.0 - A JavaScript Unit Testing Framework + * + * http://docs.jquery.com/QUnit + * + * Copyright (c) 2011 John Resig, Jörn Zaefferer + * Dual licensed under the MIT (MIT-LICENSE.txt) + * or GPL (GPL-LICENSE.txt) licenses. + */ + +/** Font Family and Sizes */ + +#qunit-tests, #qunit-header, #qunit-banner, #qunit-testrunner-toolbar, #qunit-userAgent, #qunit-testresult { + font-family: "Helvetica Neue Light", "HelveticaNeue-Light", "Helvetica Neue", Calibri, Helvetica, Arial, sans-serif; +} + +#qunit-testrunner-toolbar, #qunit-userAgent, #qunit-testresult, #qunit-tests li { font-size: small; } +#qunit-tests { font-size: smaller; } + + +/** Resets */ + +#qunit-tests, #qunit-tests ol, #qunit-header, #qunit-banner, #qunit-userAgent, #qunit-testresult { + margin: 0; + padding: 0; +} + + +/** Header */ + +#qunit-header { + padding: 0.5em 0 0.5em 1em; + + color: #8699a4; + background-color: #0d3349; + + font-size: 1.5em; + line-height: 1em; + font-weight: normal; + + border-radius: 15px 15px 0 0; + -moz-border-radius: 15px 15px 0 0; + -webkit-border-top-right-radius: 15px; + -webkit-border-top-left-radius: 15px; +} + +#qunit-header a { + text-decoration: none; + color: #c2ccd1; +} + +#qunit-header a:hover, +#qunit-header a:focus { + color: #fff; +} + +#qunit-banner { + height: 5px; +} + +#qunit-testrunner-toolbar { + padding: 0.5em 0 0.5em 2em; + color: #5E740B; + background-color: #eee; +} + +#qunit-userAgent { + padding: 0.5em 0 0.5em 2.5em; + background-color: #2b81af; + color: #fff; + text-shadow: rgba(0, 0, 0, 0.5) 2px 2px 1px; +} + + +/** Tests: Pass/Fail */ + +#qunit-tests { + list-style-position: inside; +} + +#qunit-tests li { + padding: 0.4em 0.5em 0.4em 2.5em; + border-bottom: 1px solid #fff; + list-style-position: inside; +} + +#qunit-tests.hidepass li.pass, #qunit-tests.hidepass li.running { + display: none; +} + +#qunit-tests li strong { + cursor: pointer; +} + +#qunit-tests li a { + padding: 0.5em; + color: #c2ccd1; + text-decoration: none; +} +#qunit-tests li a:hover, +#qunit-tests li a:focus { + color: #000; +} + +#qunit-tests ol { + margin-top: 0.5em; + padding: 0.5em; + + background-color: #fff; + + border-radius: 15px; + -moz-border-radius: 15px; + -webkit-border-radius: 15px; + + box-shadow: inset 0px 2px 13px #999; + -moz-box-shadow: inset 0px 2px 13px #999; + -webkit-box-shadow: inset 0px 2px 13px #999; +} + +#qunit-tests table { + border-collapse: collapse; + margin-top: .2em; +} + +#qunit-tests th { + text-align: right; + vertical-align: top; + padding: 0 .5em 0 0; +} + +#qunit-tests td { + vertical-align: top; +} + +#qunit-tests pre { + margin: 0; + white-space: pre-wrap; + word-wrap: break-word; +} + +#qunit-tests del { + background-color: #e0f2be; + color: #374e0c; + text-decoration: none; +} + +#qunit-tests ins { + background-color: #ffcaca; + color: #500; + text-decoration: none; +} + +/*** Test Counts */ + +#qunit-tests b.counts { color: black; } +#qunit-tests b.passed { color: #5E740B; } +#qunit-tests b.failed { color: #710909; } + +#qunit-tests li li { + margin: 0.5em; + padding: 0.4em 0.5em 0.4em 0.5em; + background-color: #fff; + border-bottom: none; + list-style-position: inside; +} + +/*** Passing Styles */ + +#qunit-tests li li.pass { + color: #5E740B; + background-color: #fff; + border-left: 26px solid #C6E746; +} + +#qunit-tests .pass { color: #528CE0; background-color: #D2E0E6; } +#qunit-tests .pass .test-name { color: #366097; } + +#qunit-tests .pass .test-actual, +#qunit-tests .pass .test-expected { color: #999999; } + +#qunit-banner.qunit-pass { background-color: #C6E746; } + +/*** Failing Styles */ + +#qunit-tests li li.fail { + color: #710909; + background-color: #fff; + border-left: 26px solid #EE5757; + white-space: pre; +} + +#qunit-tests > li:last-child { + border-radius: 0 0 15px 15px; + -moz-border-radius: 0 0 15px 15px; + -webkit-border-bottom-right-radius: 15px; + -webkit-border-bottom-left-radius: 15px; +} + +#qunit-tests .fail { color: #000000; background-color: #EE5757; } +#qunit-tests .fail .test-name, +#qunit-tests .fail .module-name { color: #000000; } + +#qunit-tests .fail .test-actual { color: #EE5757; } +#qunit-tests .fail .test-expected { color: green; } + +#qunit-banner.qunit-fail { background-color: #EE5757; } + + +/** Result */ + +#qunit-testresult { + padding: 0.5em 0.5em 0.5em 2.5em; + + color: #2b81af; + background-color: #D2E0E6; + + border-bottom: 1px solid white; +} + +/** Fixture */ + +#qunit-fixture { + position: absolute; + top: -10000px; + left: -10000px; +} diff --git a/addons/web/static/lib/nivjs/test/qunit.js b/addons/web/static/lib/nivjs/test/qunit.js new file mode 100755 index 00000000000..6d2a8a7b8ab --- /dev/null +++ b/addons/web/static/lib/nivjs/test/qunit.js @@ -0,0 +1,1597 @@ +/** + * QUnit v1.2.0 - A JavaScript Unit Testing Framework + * + * http://docs.jquery.com/QUnit + * + * Copyright (c) 2011 John Resig, Jörn Zaefferer + * Dual licensed under the MIT (MIT-LICENSE.txt) + * or GPL (GPL-LICENSE.txt) licenses. + */ + +(function(window) { + +var defined = { + setTimeout: typeof window.setTimeout !== "undefined", + sessionStorage: (function() { + try { + return !!sessionStorage.getItem; + } catch(e) { + return false; + } + })() +}; + +var testId = 0, + toString = Object.prototype.toString, + hasOwn = Object.prototype.hasOwnProperty; + +var Test = function(name, testName, expected, testEnvironmentArg, async, callback) { + this.name = name; + this.testName = testName; + this.expected = expected; + this.testEnvironmentArg = testEnvironmentArg; + this.async = async; + this.callback = callback; + this.assertions = []; +}; +Test.prototype = { + init: function() { + var tests = id("qunit-tests"); + if (tests) { + var b = document.createElement("strong"); + b.innerHTML = "Running " + this.name; + var li = document.createElement("li"); + li.appendChild( b ); + li.className = "running"; + li.id = this.id = "test-output" + testId++; + tests.appendChild( li ); + } + }, + setup: function() { + if (this.module != config.previousModule) { + if ( config.previousModule ) { + runLoggingCallbacks('moduleDone', QUnit, { + name: config.previousModule, + failed: config.moduleStats.bad, + passed: config.moduleStats.all - config.moduleStats.bad, + total: config.moduleStats.all + } ); + } + config.previousModule = this.module; + config.moduleStats = { all: 0, bad: 0 }; + runLoggingCallbacks( 'moduleStart', QUnit, { + name: this.module + } ); + } + + config.current = this; + this.testEnvironment = extend({ + setup: function() {}, + teardown: function() {} + }, this.moduleTestEnvironment); + if (this.testEnvironmentArg) { + extend(this.testEnvironment, this.testEnvironmentArg); + } + + runLoggingCallbacks( 'testStart', QUnit, { + name: this.testName, + module: this.module + }); + + // allow utility functions to access the current test environment + // TODO why?? + QUnit.current_testEnvironment = this.testEnvironment; + + try { + if ( !config.pollution ) { + saveGlobal(); + } + + this.testEnvironment.setup.call(this.testEnvironment); + } catch(e) { + QUnit.ok( false, "Setup failed on " + this.testName + ": " + e.message ); + } + }, + run: function() { + config.current = this; + if ( this.async ) { + QUnit.stop(); + } + + if ( config.notrycatch ) { + this.callback.call(this.testEnvironment); + return; + } + try { + this.callback.call(this.testEnvironment); + } catch(e) { + fail("Test " + this.testName + " died, exception and test follows", e, this.callback); + QUnit.ok( false, "Died on test #" + (this.assertions.length + 1) + ": " + e.message + " - " + QUnit.jsDump.parse(e) ); + // else next test will carry the responsibility + saveGlobal(); + + // Restart the tests if they're blocking + if ( config.blocking ) { + QUnit.start(); + } + } + }, + teardown: function() { + config.current = this; + try { + this.testEnvironment.teardown.call(this.testEnvironment); + checkPollution(); + } catch(e) { + QUnit.ok( false, "Teardown failed on " + this.testName + ": " + e.message ); + } + }, + finish: function() { + config.current = this; + if ( this.expected != null && this.expected != this.assertions.length ) { + QUnit.ok( false, "Expected " + this.expected + " assertions, but " + this.assertions.length + " were run" ); + } + + var good = 0, bad = 0, + tests = id("qunit-tests"); + + config.stats.all += this.assertions.length; + config.moduleStats.all += this.assertions.length; + + if ( tests ) { + var ol = document.createElement("ol"); + + for ( var i = 0; i < this.assertions.length; i++ ) { + var assertion = this.assertions[i]; + + var li = document.createElement("li"); + li.className = assertion.result ? "pass" : "fail"; + li.innerHTML = assertion.message || (assertion.result ? "okay" : "failed"); + ol.appendChild( li ); + + if ( assertion.result ) { + good++; + } else { + bad++; + config.stats.bad++; + config.moduleStats.bad++; + } + } + + // store result when possible + if ( QUnit.config.reorder && defined.sessionStorage ) { + if (bad) { + sessionStorage.setItem("qunit-" + this.module + "-" + this.testName, bad); + } else { + sessionStorage.removeItem("qunit-" + this.module + "-" + this.testName); + } + } + + if (bad == 0) { + ol.style.display = "none"; + } + + var b = document.createElement("strong"); + b.innerHTML = this.name + " (" + bad + ", " + good + ", " + this.assertions.length + ")"; + + var a = document.createElement("a"); + a.innerHTML = "Rerun"; + a.href = QUnit.url({ filter: getText([b]).replace(/\([^)]+\)$/, "").replace(/(^\s*|\s*$)/g, "") }); + + addEvent(b, "click", function() { + var next = b.nextSibling.nextSibling, + display = next.style.display; + next.style.display = display === "none" ? "block" : "none"; + }); + + addEvent(b, "dblclick", function(e) { + var target = e && e.target ? e.target : window.event.srcElement; + if ( target.nodeName.toLowerCase() == "span" || target.nodeName.toLowerCase() == "b" ) { + target = target.parentNode; + } + if ( window.location && target.nodeName.toLowerCase() === "strong" ) { + window.location = QUnit.url({ filter: getText([target]).replace(/\([^)]+\)$/, "").replace(/(^\s*|\s*$)/g, "") }); + } + }); + + var li = id(this.id); + li.className = bad ? "fail" : "pass"; + li.removeChild( li.firstChild ); + li.appendChild( b ); + li.appendChild( a ); + li.appendChild( ol ); + + } else { + for ( var i = 0; i < this.assertions.length; i++ ) { + if ( !this.assertions[i].result ) { + bad++; + config.stats.bad++; + config.moduleStats.bad++; + } + } + } + + try { + QUnit.reset(); + } catch(e) { + fail("reset() failed, following Test " + this.testName + ", exception and reset fn follows", e, QUnit.reset); + } + + runLoggingCallbacks( 'testDone', QUnit, { + name: this.testName, + module: this.module, + failed: bad, + passed: this.assertions.length - bad, + total: this.assertions.length + } ); + }, + + queue: function() { + var test = this; + synchronize(function() { + test.init(); + }); + function run() { + // each of these can by async + synchronize(function() { + test.setup(); + }); + synchronize(function() { + test.run(); + }); + synchronize(function() { + test.teardown(); + }); + synchronize(function() { + test.finish(); + }); + } + // defer when previous test run passed, if storage is available + var bad = QUnit.config.reorder && defined.sessionStorage && +sessionStorage.getItem("qunit-" + this.module + "-" + this.testName); + if (bad) { + run(); + } else { + synchronize(run, true); + }; + } + +}; + +var QUnit = { + + // call on start of module test to prepend name to all tests + module: function(name, testEnvironment) { + config.currentModule = name; + config.currentModuleTestEnviroment = testEnvironment; + }, + + asyncTest: function(testName, expected, callback) { + if ( arguments.length === 2 ) { + callback = expected; + expected = null; + } + + QUnit.test(testName, expected, callback, true); + }, + + test: function(testName, expected, callback, async) { + var name = '' + testName + '', testEnvironmentArg; + + if ( arguments.length === 2 ) { + callback = expected; + expected = null; + } + // is 2nd argument a testEnvironment? + if ( expected && typeof expected === 'object') { + testEnvironmentArg = expected; + expected = null; + } + + if ( config.currentModule ) { + name = '' + config.currentModule + ": " + name; + } + + if ( !validTest(config.currentModule + ": " + testName) ) { + return; + } + + var test = new Test(name, testName, expected, testEnvironmentArg, async, callback); + test.module = config.currentModule; + test.moduleTestEnvironment = config.currentModuleTestEnviroment; + test.queue(); + }, + + /** + * Specify the number of expected assertions to gurantee that failed test (no assertions are run at all) don't slip through. + */ + expect: function(asserts) { + config.current.expected = asserts; + }, + + /** + * Asserts true. + * @example ok( "asdfasdf".length > 5, "There must be at least 5 chars" ); + */ + ok: function(a, msg) { + a = !!a; + var details = { + result: a, + message: msg + }; + msg = escapeInnerText(msg); + runLoggingCallbacks( 'log', QUnit, details ); + config.current.assertions.push({ + result: a, + message: msg + }); + }, + + /** + * Checks that the first two arguments are equal, with an optional message. + * Prints out both actual and expected values. + * + * Prefered to ok( actual == expected, message ) + * + * @example equal( format("Received {0} bytes.", 2), "Received 2 bytes." ); + * + * @param Object actual + * @param Object expected + * @param String message (optional) + */ + equal: function(actual, expected, message) { + QUnit.push(expected == actual, actual, expected, message); + }, + + notEqual: function(actual, expected, message) { + QUnit.push(expected != actual, actual, expected, message); + }, + + deepEqual: function(actual, expected, message) { + QUnit.push(QUnit.equiv(actual, expected), actual, expected, message); + }, + + notDeepEqual: function(actual, expected, message) { + QUnit.push(!QUnit.equiv(actual, expected), actual, expected, message); + }, + + strictEqual: function(actual, expected, message) { + QUnit.push(expected === actual, actual, expected, message); + }, + + notStrictEqual: function(actual, expected, message) { + QUnit.push(expected !== actual, actual, expected, message); + }, + + raises: function(block, expected, message) { + var actual, ok = false; + + if (typeof expected === 'string') { + message = expected; + expected = null; + } + + try { + block(); + } catch (e) { + actual = e; + } + + if (actual) { + // we don't want to validate thrown error + if (!expected) { + ok = true; + // expected is a regexp + } else if (QUnit.objectType(expected) === "regexp") { + ok = expected.test(actual); + // expected is a constructor + } else if (actual instanceof expected) { + ok = true; + // expected is a validation function which returns true is validation passed + } else if (expected.call({}, actual) === true) { + ok = true; + } + } + + QUnit.ok(ok, message); + }, + + start: function(count) { + config.semaphore -= count || 1; + if (config.semaphore > 0) { + // don't start until equal number of stop-calls + return; + } + if (config.semaphore < 0) { + // ignore if start is called more often then stop + config.semaphore = 0; + } + // A slight delay, to avoid any current callbacks + if ( defined.setTimeout ) { + window.setTimeout(function() { + if (config.semaphore > 0) { + return; + } + if ( config.timeout ) { + clearTimeout(config.timeout); + } + + config.blocking = false; + process(true); + }, 13); + } else { + config.blocking = false; + process(true); + } + }, + + stop: function(count) { + config.semaphore += count || 1; + config.blocking = true; + + if ( config.testTimeout && defined.setTimeout ) { + clearTimeout(config.timeout); + config.timeout = window.setTimeout(function() { + QUnit.ok( false, "Test timed out" ); + config.semaphore = 1; + QUnit.start(); + }, config.testTimeout); + } + } +}; + +//We want access to the constructor's prototype +(function() { + function F(){}; + F.prototype = QUnit; + QUnit = new F(); + //Make F QUnit's constructor so that we can add to the prototype later + QUnit.constructor = F; +})(); + +// Backwards compatibility, deprecated +QUnit.equals = QUnit.equal; +QUnit.same = QUnit.deepEqual; + +// Maintain internal state +var config = { + // The queue of tests to run + queue: [], + + // block until document ready + blocking: true, + + // when enabled, show only failing tests + // gets persisted through sessionStorage and can be changed in UI via checkbox + hidepassed: false, + + // by default, run previously failed tests first + // very useful in combination with "Hide passed tests" checked + reorder: true, + + // by default, modify document.title when suite is done + altertitle: true, + + urlConfig: ['noglobals', 'notrycatch'], + + //logging callback queues + begin: [], + done: [], + log: [], + testStart: [], + testDone: [], + moduleStart: [], + moduleDone: [] +}; + +// Load paramaters +(function() { + var location = window.location || { search: "", protocol: "file:" }, + params = location.search.slice( 1 ).split( "&" ), + length = params.length, + urlParams = {}, + current; + + if ( params[ 0 ] ) { + for ( var i = 0; i < length; i++ ) { + current = params[ i ].split( "=" ); + current[ 0 ] = decodeURIComponent( current[ 0 ] ); + // allow just a key to turn on a flag, e.g., test.html?noglobals + current[ 1 ] = current[ 1 ] ? decodeURIComponent( current[ 1 ] ) : true; + urlParams[ current[ 0 ] ] = current[ 1 ]; + } + } + + QUnit.urlParams = urlParams; + config.filter = urlParams.filter; + + // Figure out if we're running the tests from a server or not + QUnit.isLocal = !!(location.protocol === 'file:'); +})(); + +// Expose the API as global variables, unless an 'exports' +// object exists, in that case we assume we're in CommonJS +if ( typeof exports === "undefined" || typeof require === "undefined" ) { + extend(window, QUnit); + window.QUnit = QUnit; +} else { + extend(exports, QUnit); + exports.QUnit = QUnit; +} + +// define these after exposing globals to keep them in these QUnit namespace only +extend(QUnit, { + config: config, + + // Initialize the configuration options + init: function() { + extend(config, { + stats: { all: 0, bad: 0 }, + moduleStats: { all: 0, bad: 0 }, + started: +new Date, + updateRate: 1000, + blocking: false, + autostart: true, + autorun: false, + filter: "", + queue: [], + semaphore: 0 + }); + + var tests = id( "qunit-tests" ), + banner = id( "qunit-banner" ), + result = id( "qunit-testresult" ); + + if ( tests ) { + tests.innerHTML = ""; + } + + if ( banner ) { + banner.className = ""; + } + + if ( result ) { + result.parentNode.removeChild( result ); + } + + if ( tests ) { + result = document.createElement( "p" ); + result.id = "qunit-testresult"; + result.className = "result"; + tests.parentNode.insertBefore( result, tests ); + result.innerHTML = 'Running...
 '; + } + }, + + /** + * Resets the test setup. Useful for tests that modify the DOM. + * + * If jQuery is available, uses jQuery's html(), otherwise just innerHTML. + */ + reset: function() { + if ( window.jQuery ) { + jQuery( "#qunit-fixture" ).html( config.fixture ); + } else { + var main = id( 'qunit-fixture' ); + if ( main ) { + main.innerHTML = config.fixture; + } + } + }, + + /** + * Trigger an event on an element. + * + * @example triggerEvent( document.body, "click" ); + * + * @param DOMElement elem + * @param String type + */ + triggerEvent: function( elem, type, event ) { + if ( document.createEvent ) { + event = document.createEvent("MouseEvents"); + event.initMouseEvent(type, true, true, elem.ownerDocument.defaultView, + 0, 0, 0, 0, 0, false, false, false, false, 0, null); + elem.dispatchEvent( event ); + + } else if ( elem.fireEvent ) { + elem.fireEvent("on"+type); + } + }, + + // Safe object type checking + is: function( type, obj ) { + return QUnit.objectType( obj ) == type; + }, + + objectType: function( obj ) { + if (typeof obj === "undefined") { + return "undefined"; + + // consider: typeof null === object + } + if (obj === null) { + return "null"; + } + + var type = toString.call( obj ).match(/^\[object\s(.*)\]$/)[1] || ''; + + switch (type) { + case 'Number': + if (isNaN(obj)) { + return "nan"; + } else { + return "number"; + } + case 'String': + case 'Boolean': + case 'Array': + case 'Date': + case 'RegExp': + case 'Function': + return type.toLowerCase(); + } + if (typeof obj === "object") { + return "object"; + } + return undefined; + }, + + push: function(result, actual, expected, message) { + var details = { + result: result, + message: message, + actual: actual, + expected: expected + }; + + message = escapeInnerText(message) || (result ? "okay" : "failed"); + message = '' + message + ""; + expected = escapeInnerText(QUnit.jsDump.parse(expected)); + actual = escapeInnerText(QUnit.jsDump.parse(actual)); + var output = message + ''; + if (actual != expected) { + output += ''; + output += ''; + } + if (!result) { + var source = sourceFromStacktrace(); + if (source) { + details.source = source; + output += ''; + } + } + output += "
Expected:
' + expected + '
Result:
' + actual + '
Diff:
' + QUnit.diff(expected, actual) +'
Source:
' + escapeInnerText(source) + '
"; + + runLoggingCallbacks( 'log', QUnit, details ); + + config.current.assertions.push({ + result: !!result, + message: output + }); + }, + + url: function( params ) { + params = extend( extend( {}, QUnit.urlParams ), params ); + var querystring = "?", + key; + for ( key in params ) { + if ( !hasOwn.call( params, key ) ) { + continue; + } + querystring += encodeURIComponent( key ) + "=" + + encodeURIComponent( params[ key ] ) + "&"; + } + return window.location.pathname + querystring.slice( 0, -1 ); + }, + + extend: extend, + id: id, + addEvent: addEvent +}); + +//QUnit.constructor is set to the empty F() above so that we can add to it's prototype later +//Doing this allows us to tell if the following methods have been overwritten on the actual +//QUnit object, which is a deprecated way of using the callbacks. +extend(QUnit.constructor.prototype, { + // Logging callbacks; all receive a single argument with the listed properties + // run test/logs.html for any related changes + begin: registerLoggingCallback('begin'), + // done: { failed, passed, total, runtime } + done: registerLoggingCallback('done'), + // log: { result, actual, expected, message } + log: registerLoggingCallback('log'), + // testStart: { name } + testStart: registerLoggingCallback('testStart'), + // testDone: { name, failed, passed, total } + testDone: registerLoggingCallback('testDone'), + // moduleStart: { name } + moduleStart: registerLoggingCallback('moduleStart'), + // moduleDone: { name, failed, passed, total } + moduleDone: registerLoggingCallback('moduleDone') +}); + +if ( typeof document === "undefined" || document.readyState === "complete" ) { + config.autorun = true; +} + +QUnit.load = function() { + runLoggingCallbacks( 'begin', QUnit, {} ); + + // Initialize the config, saving the execution queue + var oldconfig = extend({}, config); + QUnit.init(); + extend(config, oldconfig); + + config.blocking = false; + + var urlConfigHtml = '', len = config.urlConfig.length; + for ( var i = 0, val; i < len, val = config.urlConfig[i]; i++ ) { + config[val] = QUnit.urlParams[val]; + urlConfigHtml += ''; + } + + var userAgent = id("qunit-userAgent"); + if ( userAgent ) { + userAgent.innerHTML = navigator.userAgent; + } + var banner = id("qunit-header"); + if ( banner ) { + banner.innerHTML = ' ' + banner.innerHTML + ' ' + urlConfigHtml; + addEvent( banner, "change", function( event ) { + var params = {}; + params[ event.target.name ] = event.target.checked ? true : undefined; + window.location = QUnit.url( params ); + }); + } + + var toolbar = id("qunit-testrunner-toolbar"); + if ( toolbar ) { + var filter = document.createElement("input"); + filter.type = "checkbox"; + filter.id = "qunit-filter-pass"; + addEvent( filter, "click", function() { + var ol = document.getElementById("qunit-tests"); + if ( filter.checked ) { + ol.className = ol.className + " hidepass"; + } else { + var tmp = " " + ol.className.replace( /[\n\t\r]/g, " " ) + " "; + ol.className = tmp.replace(/ hidepass /, " "); + } + if ( defined.sessionStorage ) { + if (filter.checked) { + sessionStorage.setItem("qunit-filter-passed-tests", "true"); + } else { + sessionStorage.removeItem("qunit-filter-passed-tests"); + } + } + }); + if ( config.hidepassed || defined.sessionStorage && sessionStorage.getItem("qunit-filter-passed-tests") ) { + filter.checked = true; + var ol = document.getElementById("qunit-tests"); + ol.className = ol.className + " hidepass"; + } + toolbar.appendChild( filter ); + + var label = document.createElement("label"); + label.setAttribute("for", "qunit-filter-pass"); + label.innerHTML = "Hide passed tests"; + toolbar.appendChild( label ); + } + + var main = id('qunit-fixture'); + if ( main ) { + config.fixture = main.innerHTML; + } + + if (config.autostart) { + QUnit.start(); + } +}; + +addEvent(window, "load", QUnit.load); + +// addEvent(window, "error") gives us a useless event object +window.onerror = function( message, file, line ) { + if ( QUnit.config.current ) { + ok( false, message + ", " + file + ":" + line ); + } else { + test( "global failure", function() { + ok( false, message + ", " + file + ":" + line ); + }); + } +}; + +function done() { + config.autorun = true; + + // Log the last module results + if ( config.currentModule ) { + runLoggingCallbacks( 'moduleDone', QUnit, { + name: config.currentModule, + failed: config.moduleStats.bad, + passed: config.moduleStats.all - config.moduleStats.bad, + total: config.moduleStats.all + } ); + } + + var banner = id("qunit-banner"), + tests = id("qunit-tests"), + runtime = +new Date - config.started, + passed = config.stats.all - config.stats.bad, + html = [ + 'Tests completed in ', + runtime, + ' milliseconds.
', + '', + passed, + ' tests of ', + config.stats.all, + ' passed, ', + config.stats.bad, + ' failed.' + ].join(''); + + if ( banner ) { + banner.className = (config.stats.bad ? "qunit-fail" : "qunit-pass"); + } + + if ( tests ) { + id( "qunit-testresult" ).innerHTML = html; + } + + if ( config.altertitle && typeof document !== "undefined" && document.title ) { + // show ✖ for good, ✔ for bad suite result in title + // use escape sequences in case file gets loaded with non-utf-8-charset + document.title = [ + (config.stats.bad ? "\u2716" : "\u2714"), + document.title.replace(/^[\u2714\u2716] /i, "") + ].join(" "); + } + + runLoggingCallbacks( 'done', QUnit, { + failed: config.stats.bad, + passed: passed, + total: config.stats.all, + runtime: runtime + } ); +} + +function validTest( name ) { + var filter = config.filter, + run = false; + + if ( !filter ) { + return true; + } + + var not = filter.charAt( 0 ) === "!"; + if ( not ) { + filter = filter.slice( 1 ); + } + + if ( name.indexOf( filter ) !== -1 ) { + return !not; + } + + if ( not ) { + run = true; + } + + return run; +} + +// so far supports only Firefox, Chrome and Opera (buggy) +// could be extended in the future to use something like https://github.com/csnover/TraceKit +function sourceFromStacktrace() { + try { + throw new Error(); + } catch ( e ) { + if (e.stacktrace) { + // Opera + return e.stacktrace.split("\n")[6]; + } else if (e.stack) { + // Firefox, Chrome + return e.stack.split("\n")[4]; + } else if (e.sourceURL) { + // Safari, PhantomJS + // TODO sourceURL points at the 'throw new Error' line above, useless + //return e.sourceURL + ":" + e.line; + } + } +} + +function escapeInnerText(s) { + if (!s) { + return ""; + } + s = s + ""; + return s.replace(/[\&<>]/g, function(s) { + switch(s) { + case "&": return "&"; + case "<": return "<"; + case ">": return ">"; + default: return s; + } + }); +} + +function synchronize( callback, last ) { + config.queue.push( callback ); + + if ( config.autorun && !config.blocking ) { + process(last); + } +} + +function process( last ) { + var start = new Date().getTime(); + config.depth = config.depth ? config.depth + 1 : 1; + + while ( config.queue.length && !config.blocking ) { + if ( !defined.setTimeout || config.updateRate <= 0 || ( ( new Date().getTime() - start ) < config.updateRate ) ) { + config.queue.shift()(); + } else { + window.setTimeout( function(){ + process( last ); + }, 13 ); + break; + } + } + config.depth--; + if ( last && !config.blocking && !config.queue.length && config.depth === 0 ) { + done(); + } +} + +function saveGlobal() { + config.pollution = []; + + if ( config.noglobals ) { + for ( var key in window ) { + if ( !hasOwn.call( window, key ) ) { + continue; + } + config.pollution.push( key ); + } + } +} + +function checkPollution( name ) { + var old = config.pollution; + saveGlobal(); + + var newGlobals = diff( config.pollution, old ); + if ( newGlobals.length > 0 ) { + ok( false, "Introduced global variable(s): " + newGlobals.join(", ") ); + } + + var deletedGlobals = diff( old, config.pollution ); + if ( deletedGlobals.length > 0 ) { + ok( false, "Deleted global variable(s): " + deletedGlobals.join(", ") ); + } +} + +// returns a new Array with the elements that are in a but not in b +function diff( a, b ) { + var result = a.slice(); + for ( var i = 0; i < result.length; i++ ) { + for ( var j = 0; j < b.length; j++ ) { + if ( result[i] === b[j] ) { + result.splice(i, 1); + i--; + break; + } + } + } + return result; +} + +function fail(message, exception, callback) { + if ( typeof console !== "undefined" && console.error && console.warn ) { + console.error(message); + console.error(exception); + console.warn(callback.toString()); + + } else if ( window.opera && opera.postError ) { + opera.postError(message, exception, callback.toString); + } +} + +function extend(a, b) { + for ( var prop in b ) { + if ( b[prop] === undefined ) { + delete a[prop]; + + // Avoid "Member not found" error in IE8 caused by setting window.constructor + } else if ( prop !== "constructor" || a !== window ) { + a[prop] = b[prop]; + } + } + + return a; +} + +function addEvent(elem, type, fn) { + if ( elem.addEventListener ) { + elem.addEventListener( type, fn, false ); + } else if ( elem.attachEvent ) { + elem.attachEvent( "on" + type, fn ); + } else { + fn(); + } +} + +function id(name) { + return !!(typeof document !== "undefined" && document && document.getElementById) && + document.getElementById( name ); +} + +function registerLoggingCallback(key){ + return function(callback){ + config[key].push( callback ); + }; +} + +// Supports deprecated method of completely overwriting logging callbacks +function runLoggingCallbacks(key, scope, args) { + //debugger; + var callbacks; + if ( QUnit.hasOwnProperty(key) ) { + QUnit[key].call(scope, args); + } else { + callbacks = config[key]; + for( var i = 0; i < callbacks.length; i++ ) { + callbacks[i].call( scope, args ); + } + } +} + +// Test for equality any JavaScript type. +// Author: Philippe Rathé +QUnit.equiv = function () { + + var innerEquiv; // the real equiv function + var callers = []; // stack to decide between skip/abort functions + var parents = []; // stack to avoiding loops from circular referencing + + // Call the o related callback with the given arguments. + function bindCallbacks(o, callbacks, args) { + var prop = QUnit.objectType(o); + if (prop) { + if (QUnit.objectType(callbacks[prop]) === "function") { + return callbacks[prop].apply(callbacks, args); + } else { + return callbacks[prop]; // or undefined + } + } + } + + var getProto = Object.getPrototypeOf || function (obj) { + return obj.__proto__; + }; + + var callbacks = function () { + + // for string, boolean, number and null + function useStrictEquality(b, a) { + if (b instanceof a.constructor || a instanceof b.constructor) { + // to catch short annotaion VS 'new' annotation of a + // declaration + // e.g. var i = 1; + // var j = new Number(1); + return a == b; + } else { + return a === b; + } + } + + return { + "string" : useStrictEquality, + "boolean" : useStrictEquality, + "number" : useStrictEquality, + "null" : useStrictEquality, + "undefined" : useStrictEquality, + + "nan" : function(b) { + return isNaN(b); + }, + + "date" : function(b, a) { + return QUnit.objectType(b) === "date" + && a.valueOf() === b.valueOf(); + }, + + "regexp" : function(b, a) { + return QUnit.objectType(b) === "regexp" + && a.source === b.source && // the regex itself + a.global === b.global && // and its modifers + // (gmi) ... + a.ignoreCase === b.ignoreCase + && a.multiline === b.multiline; + }, + + // - skip when the property is a method of an instance (OOP) + // - abort otherwise, + // initial === would have catch identical references anyway + "function" : function() { + var caller = callers[callers.length - 1]; + return caller !== Object && typeof caller !== "undefined"; + }, + + "array" : function(b, a) { + var i, j, loop; + var len; + + // b could be an object literal here + if (!(QUnit.objectType(b) === "array")) { + return false; + } + + len = a.length; + if (len !== b.length) { // safe and faster + return false; + } + + // track reference to avoid circular references + parents.push(a); + for (i = 0; i < len; i++) { + loop = false; + for (j = 0; j < parents.length; j++) { + if (parents[j] === a[i]) { + loop = true;// dont rewalk array + } + } + if (!loop && !innerEquiv(a[i], b[i])) { + parents.pop(); + return false; + } + } + parents.pop(); + return true; + }, + + "object" : function(b, a) { + var i, j, loop; + var eq = true; // unless we can proove it + var aProperties = [], bProperties = []; // collection of + // strings + + // comparing constructors is more strict than using + // instanceof + if (a.constructor !== b.constructor) { + // Allow objects with no prototype to be equivalent to + // objects with Object as their constructor. + if (!((getProto(a) === null && getProto(b) === Object.prototype) || + (getProto(b) === null && getProto(a) === Object.prototype))) + { + return false; + } + } + + // stack constructor before traversing properties + callers.push(a.constructor); + // track reference to avoid circular references + parents.push(a); + + for (i in a) { // be strict: don't ensures hasOwnProperty + // and go deep + loop = false; + for (j = 0; j < parents.length; j++) { + if (parents[j] === a[i]) + loop = true; // don't go down the same path + // twice + } + aProperties.push(i); // collect a's properties + + if (!loop && !innerEquiv(a[i], b[i])) { + eq = false; + break; + } + } + + callers.pop(); // unstack, we are done + parents.pop(); + + for (i in b) { + bProperties.push(i); // collect b's properties + } + + // Ensures identical properties name + return eq + && innerEquiv(aProperties.sort(), bProperties + .sort()); + } + }; + }(); + + innerEquiv = function() { // can take multiple arguments + var args = Array.prototype.slice.apply(arguments); + if (args.length < 2) { + return true; // end transition + } + + return (function(a, b) { + if (a === b) { + return true; // catch the most you can + } else if (a === null || b === null || typeof a === "undefined" + || typeof b === "undefined" + || QUnit.objectType(a) !== QUnit.objectType(b)) { + return false; // don't lose time with error prone cases + } else { + return bindCallbacks(a, callbacks, [ b, a ]); + } + + // apply transition with (1..n) arguments + })(args[0], args[1]) + && arguments.callee.apply(this, args.splice(1, + args.length - 1)); + }; + + return innerEquiv; + +}(); + +/** + * jsDump Copyright (c) 2008 Ariel Flesler - aflesler(at)gmail(dot)com | + * http://flesler.blogspot.com Licensed under BSD + * (http://www.opensource.org/licenses/bsd-license.php) Date: 5/15/2008 + * + * @projectDescription Advanced and extensible data dumping for Javascript. + * @version 1.0.0 + * @author Ariel Flesler + * @link {http://flesler.blogspot.com/2008/05/jsdump-pretty-dump-of-any-javascript.html} + */ +QUnit.jsDump = (function() { + function quote( str ) { + return '"' + str.toString().replace(/"/g, '\\"') + '"'; + }; + function literal( o ) { + return o + ''; + }; + function join( pre, arr, post ) { + var s = jsDump.separator(), + base = jsDump.indent(), + inner = jsDump.indent(1); + if ( arr.join ) + arr = arr.join( ',' + s + inner ); + if ( !arr ) + return pre + post; + return [ pre, inner + arr, base + post ].join(s); + }; + function array( arr, stack ) { + var i = arr.length, ret = Array(i); + this.up(); + while ( i-- ) + ret[i] = this.parse( arr[i] , undefined , stack); + this.down(); + return join( '[', ret, ']' ); + }; + + var reName = /^function (\w+)/; + + var jsDump = { + parse:function( obj, type, stack ) { //type is used mostly internally, you can fix a (custom)type in advance + stack = stack || [ ]; + var parser = this.parsers[ type || this.typeOf(obj) ]; + type = typeof parser; + var inStack = inArray(obj, stack); + if (inStack != -1) { + return 'recursion('+(inStack - stack.length)+')'; + } + //else + if (type == 'function') { + stack.push(obj); + var res = parser.call( this, obj, stack ); + stack.pop(); + return res; + } + // else + return (type == 'string') ? parser : this.parsers.error; + }, + typeOf:function( obj ) { + var type; + if ( obj === null ) { + type = "null"; + } else if (typeof obj === "undefined") { + type = "undefined"; + } else if (QUnit.is("RegExp", obj)) { + type = "regexp"; + } else if (QUnit.is("Date", obj)) { + type = "date"; + } else if (QUnit.is("Function", obj)) { + type = "function"; + } else if (typeof obj.setInterval !== undefined && typeof obj.document !== "undefined" && typeof obj.nodeType === "undefined") { + type = "window"; + } else if (obj.nodeType === 9) { + type = "document"; + } else if (obj.nodeType) { + type = "node"; + } else if ( + // native arrays + toString.call( obj ) === "[object Array]" || + // NodeList objects + ( typeof obj.length === "number" && typeof obj.item !== "undefined" && ( obj.length ? obj.item(0) === obj[0] : ( obj.item( 0 ) === null && typeof obj[0] === "undefined" ) ) ) + ) { + type = "array"; + } else { + type = typeof obj; + } + return type; + }, + separator:function() { + return this.multiline ? this.HTML ? '
' : '\n' : this.HTML ? ' ' : ' '; + }, + indent:function( extra ) {// extra can be a number, shortcut for increasing-calling-decreasing + if ( !this.multiline ) + return ''; + var chr = this.indentChar; + if ( this.HTML ) + chr = chr.replace(/\t/g,' ').replace(/ /g,' '); + return Array( this._depth_ + (extra||0) ).join(chr); + }, + up:function( a ) { + this._depth_ += a || 1; + }, + down:function( a ) { + this._depth_ -= a || 1; + }, + setParser:function( name, parser ) { + this.parsers[name] = parser; + }, + // The next 3 are exposed so you can use them + quote:quote, + literal:literal, + join:join, + // + _depth_: 1, + // This is the list of parsers, to modify them, use jsDump.setParser + parsers:{ + window: '[Window]', + document: '[Document]', + error:'[ERROR]', //when no parser is found, shouldn't happen + unknown: '[Unknown]', + 'null':'null', + 'undefined':'undefined', + 'function':function( fn ) { + var ret = 'function', + name = 'name' in fn ? fn.name : (reName.exec(fn)||[])[1];//functions never have name in IE + if ( name ) + ret += ' ' + name; + ret += '('; + + ret = [ ret, QUnit.jsDump.parse( fn, 'functionArgs' ), '){'].join(''); + return join( ret, QUnit.jsDump.parse(fn,'functionCode'), '}' ); + }, + array: array, + nodelist: array, + arguments: array, + object:function( map, stack ) { + var ret = [ ]; + QUnit.jsDump.up(); + for ( var key in map ) { + var val = map[key]; + ret.push( QUnit.jsDump.parse(key,'key') + ': ' + QUnit.jsDump.parse(val, undefined, stack)); + } + QUnit.jsDump.down(); + return join( '{', ret, '}' ); + }, + node:function( node ) { + var open = QUnit.jsDump.HTML ? '<' : '<', + close = QUnit.jsDump.HTML ? '>' : '>'; + + var tag = node.nodeName.toLowerCase(), + ret = open + tag; + + for ( var a in QUnit.jsDump.DOMAttrs ) { + var val = node[QUnit.jsDump.DOMAttrs[a]]; + if ( val ) + ret += ' ' + a + '=' + QUnit.jsDump.parse( val, 'attribute' ); + } + return ret + close + open + '/' + tag + close; + }, + functionArgs:function( fn ) {//function calls it internally, it's the arguments part of the function + var l = fn.length; + if ( !l ) return ''; + + var args = Array(l); + while ( l-- ) + args[l] = String.fromCharCode(97+l);//97 is 'a' + return ' ' + args.join(', ') + ' '; + }, + key:quote, //object calls it internally, the key part of an item in a map + functionCode:'[code]', //function calls it internally, it's the content of the function + attribute:quote, //node calls it internally, it's an html attribute value + string:quote, + date:quote, + regexp:literal, //regex + number:literal, + 'boolean':literal + }, + DOMAttrs:{//attributes to dump from nodes, name=>realName + id:'id', + name:'name', + 'class':'className' + }, + HTML:false,//if true, entities are escaped ( <, >, \t, space and \n ) + indentChar:' ',//indentation unit + multiline:true //if true, items in a collection, are separated by a \n, else just a space. + }; + + return jsDump; +})(); + +// from Sizzle.js +function getText( elems ) { + var ret = "", elem; + + for ( var i = 0; elems[i]; i++ ) { + elem = elems[i]; + + // Get the text from text nodes and CDATA nodes + if ( elem.nodeType === 3 || elem.nodeType === 4 ) { + ret += elem.nodeValue; + + // Traverse everything else, except comment nodes + } else if ( elem.nodeType !== 8 ) { + ret += getText( elem.childNodes ); + } + } + + return ret; +}; + +//from jquery.js +function inArray( elem, array ) { + if ( array.indexOf ) { + return array.indexOf( elem ); + } + + for ( var i = 0, length = array.length; i < length; i++ ) { + if ( array[ i ] === elem ) { + return i; + } + } + + return -1; +} + +/* + * Javascript Diff Algorithm + * By John Resig (http://ejohn.org/) + * Modified by Chu Alan "sprite" + * + * Released under the MIT license. + * + * More Info: + * http://ejohn.org/projects/javascript-diff-algorithm/ + * + * Usage: QUnit.diff(expected, actual) + * + * QUnit.diff("the quick brown fox jumped over", "the quick fox jumps over") == "the quick brown fox jumped jumps over" + */ +QUnit.diff = (function() { + function diff(o, n) { + var ns = {}; + var os = {}; + + for (var i = 0; i < n.length; i++) { + if (ns[n[i]] == null) + ns[n[i]] = { + rows: [], + o: null + }; + ns[n[i]].rows.push(i); + } + + for (var i = 0; i < o.length; i++) { + if (os[o[i]] == null) + os[o[i]] = { + rows: [], + n: null + }; + os[o[i]].rows.push(i); + } + + for (var i in ns) { + if ( !hasOwn.call( ns, i ) ) { + continue; + } + if (ns[i].rows.length == 1 && typeof(os[i]) != "undefined" && os[i].rows.length == 1) { + n[ns[i].rows[0]] = { + text: n[ns[i].rows[0]], + row: os[i].rows[0] + }; + o[os[i].rows[0]] = { + text: o[os[i].rows[0]], + row: ns[i].rows[0] + }; + } + } + + for (var i = 0; i < n.length - 1; i++) { + if (n[i].text != null && n[i + 1].text == null && n[i].row + 1 < o.length && o[n[i].row + 1].text == null && + n[i + 1] == o[n[i].row + 1]) { + n[i + 1] = { + text: n[i + 1], + row: n[i].row + 1 + }; + o[n[i].row + 1] = { + text: o[n[i].row + 1], + row: i + 1 + }; + } + } + + for (var i = n.length - 1; i > 0; i--) { + if (n[i].text != null && n[i - 1].text == null && n[i].row > 0 && o[n[i].row - 1].text == null && + n[i - 1] == o[n[i].row - 1]) { + n[i - 1] = { + text: n[i - 1], + row: n[i].row - 1 + }; + o[n[i].row - 1] = { + text: o[n[i].row - 1], + row: i - 1 + }; + } + } + + return { + o: o, + n: n + }; + } + + return function(o, n) { + o = o.replace(/\s+$/, ''); + n = n.replace(/\s+$/, ''); + var out = diff(o == "" ? [] : o.split(/\s+/), n == "" ? [] : n.split(/\s+/)); + + var str = ""; + + var oSpace = o.match(/\s+/g); + if (oSpace == null) { + oSpace = [" "]; + } + else { + oSpace.push(" "); + } + var nSpace = n.match(/\s+/g); + if (nSpace == null) { + nSpace = [" "]; + } + else { + nSpace.push(" "); + } + + if (out.n.length == 0) { + for (var i = 0; i < out.o.length; i++) { + str += '' + out.o[i] + oSpace[i] + ""; + } + } + else { + if (out.n[0].text == null) { + for (n = 0; n < out.o.length && out.o[n].text == null; n++) { + str += '' + out.o[n] + oSpace[n] + ""; + } + } + + for (var i = 0; i < out.n.length; i++) { + if (out.n[i].text == null) { + str += '' + out.n[i] + nSpace[i] + ""; + } + else { + var pre = ""; + + for (n = out.n[i].row + 1; n < out.o.length && out.o[n].text == null; n++) { + pre += '' + out.o[n] + oSpace[n] + ""; + } + str += " " + out.n[i].text + nSpace[i] + pre; + } + } + } + + return str; + }; +})(); + +})(this); diff --git a/addons/web/static/lib/nivjs/test/test.html b/addons/web/static/lib/nivjs/test/test.html new file mode 100644 index 00000000000..08cd9fce4ab --- /dev/null +++ b/addons/web/static/lib/nivjs/test/test.html @@ -0,0 +1,22 @@ + + + + + + + + + + + + + +

QUnit example

+

+
+

+
    +
    test markup, will be hidden
    + + \ No newline at end of file diff --git a/addons/web/static/lib/nivjs/test/test.js b/addons/web/static/lib/nivjs/test/test.js new file mode 100644 index 00000000000..5ef89fa5da8 --- /dev/null +++ b/addons/web/static/lib/nivjs/test/test.js @@ -0,0 +1,8 @@ + +module("Class"); + +test("Class exists", function() { + ok(!!niv.Class, "Class does not exist"); + ok(!!niv.Class.extend, "extend does not exist"); +}); + From fa510462f4c49d434cd2ed4145eb8c3c99dae0e6 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Thu, 23 Feb 2012 17:10:41 +0100 Subject: [PATCH 02/39] [imp] switched to nivjs bzr revid: nicolas.vanhoren@openerp.com-20120223161041-mymbna11fsp3bo9m --- addons/web/__openerp__.py | 1 + addons/web/static/lib/nivjs/src/niv.js | 194 +++++++++++++------------ addons/web/static/src/js/core.js | 36 +---- 3 files changed, 101 insertions(+), 130 deletions(-) diff --git a/addons/web/__openerp__.py b/addons/web/__openerp__.py index 41a58cd3a07..96fb8b3af71 100644 --- a/addons/web/__openerp__.py +++ b/addons/web/__openerp__.py @@ -36,6 +36,7 @@ "static/lib/underscore/underscore.string.js", "static/lib/labjs/LAB.src.js", "static/lib/py.parse/lib/py.js", + "static/lib/nivjs/src/niv.js", "static/src/js/boot.js", "static/src/js/core.js", "static/src/js/dates.js", diff --git a/addons/web/static/lib/nivjs/src/niv.js b/addons/web/static/lib/nivjs/src/niv.js index 773f1a49f47..893651d8008 100644 --- a/addons/web/static/lib/nivjs/src/niv.js +++ b/addons/web/static/lib/nivjs/src/niv.js @@ -24,105 +24,109 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ niv = (function() { - var niv = {}; + var lib = {}; - /* + /* * Simple JavaScript Inheritance By John Resig http://ejohn.org/ MIT * Licensed. */ - // Inspired by base2 and Prototype - (function(){ - var initializing = false, fnTest = /xyz/.test(function(){xyz;}) ? /\b_super\b/ : /.*/; - // The base Class implementation (does nothing) - this.Class = function(){}; - - // Create a new Class that inherits from this class - this.Class.extend = function(prop) { - var _super = this.prototype; - - // Instantiate a base class (but only create the instance, - // don't run the init constructor) - initializing = true; - var prototype = new this(); - initializing = false; - - // Copy the properties over onto the new prototype - for (var name in prop) { - // Check if we're overwriting an existing function - prototype[name] = typeof prop[name] == "function" && - typeof _super[name] == "function" && fnTest.test(prop[name]) ? - (function(name, fn){ - return function() { - var tmp = this._super; - - // Add a new ._super() method that is the same method - // but on the super-class - this._super = _super[name]; - - // The method only need to be bound temporarily, so we - // remove it when we're done executing - var ret = fn.apply(this, arguments); - this._super = tmp; - - return ret; - }; - })(name, prop[name]) : - prop[name]; - } - - // The dummy class constructor - function Class() { - // All construction is actually done in the init method - if ( !initializing && this.init ) - this.init.apply(this, arguments); - } - - // Populate our constructed prototype object - Class.prototype = prototype; - - // Enforce the constructor to be what we expect - Class.prototype.constructor = Class; + // Inspired by base2 and Prototype + (function() { + var initializing = false, fnTest = /xyz/.test(function() { + xyz; + }) ? /\b_super\b/ : /.*/; + // The base Class implementation (does nothing) + this.Class = function() { + }; - // And make this class extendable - Class.extend = arguments.callee; - - return Class; - }; - }).call(niv); - - niv.ParentedMixin = { - __parented_mixin: true, - setParent: function(parent) { - if(this.getParent()) { - if (this.getParent().__parented_mixin) { - this.getParent().__parented_children = _.without(this.getParent().getChildren(), this); - } - this.__parented_parent = undefined; - } - this.__parented_parent = parent; - if(parent && parent.__parented_mixin) { - if (!parent.getChildren()) - parent.__parented_children = []; - parent.getChildren().push(this); - } - }, - getParent: function() { - return this.__parented_parent; - }, - getChildren: function() { - return this.__parented_children ? _.clone(this.__parented_children) : []; - }, - isDestroyed: function() { - return this.__parented_stopped; - }, - destroy: function() { - _.each(this.getChildren(), function(el) { - el.destroy(); - }); - this.setParent(undefined); - this.__parented_stopped = true; - }, - }; + // Create a new Class that inherits from this class + this.Class.extend = function(prop) { + var _super = this.prototype; - return niv; + // Instantiate a base class (but only create the instance, + // don't run the init constructor) + initializing = true; + var prototype = new this(); + initializing = false; + + // Copy the properties over onto the new prototype + for ( var name in prop) { + // Check if we're overwriting an existing function + prototype[name] = typeof prop[name] == "function" + && typeof _super[name] == "function" + && fnTest.test(prop[name]) ? (function(name, fn) { + return function() { + var tmp = this._super; + + // Add a new ._super() method that is the same method + // but on the super-class + this._super = _super[name]; + + // The method only need to be bound temporarily, so we + // remove it when we're done executing + var ret = fn.apply(this, arguments); + this._super = tmp; + + return ret; + }; + })(name, prop[name]) : prop[name]; + } + + // The dummy class constructor + function Class() { + // All construction is actually done in the init method + if (!initializing && this.init) + this.init.apply(this, arguments); + } + + // Populate our constructed prototype object + Class.prototype = prototype; + + // Enforce the constructor to be what we expect + Class.prototype.constructor = Class; + + // And make this class extendable + Class.extend = arguments.callee; + + return Class; + }; + }).call(lib); + + lib.ParentedMixin = { + __parented_mixin : true, + setParent : function(parent) { + if (this.getParent()) { + if (this.getParent().__parented_mixin) { + this.getParent().__parented_children = _.without(this + .getParent().getChildren(), this); + } + this.__parented_parent = undefined; + } + this.__parented_parent = parent; + if (parent && parent.__parented_mixin) { + if (!parent.__parented_children) + parent.__parented_children = []; + parent.__parented_children.push(this); + } + }, + getParent : function() { + return this.__parented_parent; + }, + getChildren : function() { + return this.__parented_children ? _.clone(this.__parented_children) + : []; + }, + isDestroyed : function() { + return this.__parented_destroyed; + }, + destroy : function() { + _.each(this.getChildren(), function(el) { + el.destroy(); + }); + this.setParent(undefined); + this.__parented_destroyed = true; + } + }; + + return lib; })(); diff --git a/addons/web/static/src/js/core.js b/addons/web/static/src/js/core.js index fd0abcb0eb4..69ec98e7350 100644 --- a/addons/web/static/src/js/core.js +++ b/addons/web/static/src/js/core.js @@ -925,40 +925,6 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp. } }); -openerp.web.ParentedMixin = { - __parented_mixin: true, - setParent: function(parent) { - if(this.getParent()) { - if (this.getParent().__parented_mixin) { - this.getParent().__parented_children = _.without(this.getParent().getChildren(), this); - } - this.__parented_parent = undefined; - } - this.__parented_parent = parent; - if(parent && parent.__parented_mixin) { - if (!parent.__parented_children) - parent.__parented_children = []; - parent.__parented_children.push(this); - } - }, - getParent: function() { - return this.__parented_parent; - }, - getChildren: function() { - return this.__parented_children ? _.clone(this.__parented_children) : []; - }, - isDestroyed: function() { - return this.__parented_destroyed; - }, - destroy: function() { - _.each(this.getChildren(), function(el) { - el.destroy(); - }); - this.setParent(undefined); - this.__parented_destroyed = true; - }, -}; - /** * Base class for all visual components. Provides a lot of functionalities helpful * for the management of a part of the DOM. @@ -1007,7 +973,7 @@ openerp.web.ParentedMixin = { * * That will kill the widget in a clean way and erase its content from the dom. */ -openerp.web.Widget = openerp.web.CallbackEnabled.extend(openerp.web.ParentedMixin).extend(/** @lends openerp.web.Widget# */{ +openerp.web.Widget = openerp.web.CallbackEnabled.extend(niv.ParentedMixin).extend(/** @lends openerp.web.Widget# */{ /** * The name of the QWeb template that will be used for rendering. Must be * redefined in subclasses or the default render() method can not be used. From 8b0380b31858bf237e5fec44657f2e7ed4a7f3fd Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Thu, 23 Feb 2012 17:13:36 +0100 Subject: [PATCH 03/39] [imp] added destroyable mixin bzr revid: nicolas.vanhoren@openerp.com-20120223161336-ea4xbup4teyvereu --- addons/web/static/lib/nivjs/src/niv.js | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/addons/web/static/lib/nivjs/src/niv.js b/addons/web/static/lib/nivjs/src/niv.js index 893651d8008..76707864a91 100644 --- a/addons/web/static/lib/nivjs/src/niv.js +++ b/addons/web/static/lib/nivjs/src/niv.js @@ -26,6 +26,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. niv = (function() { var lib = {}; + /* + * Unmodified John Resig's inheritance + */ /* * Simple JavaScript Inheritance By John Resig http://ejohn.org/ MIT * Licensed. @@ -91,8 +94,17 @@ niv = (function() { return Class; }; }).call(lib); + + lib.DestroyableMixin = { + isDestroyed : function() { + return this.__destroyable_destroyed; + }, + destroy : function() { + this.__destroyable_destroyed = true; + } + }; - lib.ParentedMixin = { + lib.ParentedMixin = _.extend({}, lib.DestroyableMixin, { __parented_mixin : true, setParent : function(parent) { if (this.getParent()) { @@ -116,17 +128,14 @@ niv = (function() { return this.__parented_children ? _.clone(this.__parented_children) : []; }, - isDestroyed : function() { - return this.__parented_destroyed; - }, destroy : function() { _.each(this.getChildren(), function(el) { el.destroy(); }); this.setParent(undefined); - this.__parented_destroyed = true; + lib.DestroyableMixin.destroy.call(this); } - }; + }); return lib; })(); From c14a9ca58c9bcfb26674644b45008441404aeec0 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Thu, 23 Feb 2012 17:29:55 +0100 Subject: [PATCH 04/39] [imp] added events + some tests bzr revid: nicolas.vanhoren@openerp.com-20120223162955-ffs5mun7w8400m4o --- addons/web/static/lib/nivjs/src/niv.js | 105 ++++++++++++++++++++- addons/web/static/lib/nivjs/test/test.html | 2 + addons/web/static/lib/nivjs/test/test.js | 31 ++++++ 3 files changed, 137 insertions(+), 1 deletion(-) diff --git a/addons/web/static/lib/nivjs/src/niv.js b/addons/web/static/lib/nivjs/src/niv.js index 76707864a91..bc8d1564523 100644 --- a/addons/web/static/lib/nivjs/src/niv.js +++ b/addons/web/static/lib/nivjs/src/niv.js @@ -94,7 +94,7 @@ niv = (function() { return Class; }; }).call(lib); - + lib.DestroyableMixin = { isDestroyed : function() { return this.__destroyable_destroyed; @@ -137,5 +137,108 @@ niv = (function() { } }); + /* + * We steal backbone's events :) + */ + // (c) 2010-2012 Jeremy Ashkenas, DocumentCloud Inc. + // Backbone may be freely distributed under the MIT license. + // For all details and documentation: + // http://backbonejs.org + lib.EventDispatcher = lib.Class.extend({ + + // Bind an event, specified by a string name, `ev`, to a `callback` + // function. Passing `"all"` will bind the callback to all events fired. + on : function(events, callback, context) { + var ev; + events = events.split(/\s+/); + var calls = this._callbacks || (this._callbacks = {}); + while (ev = events.shift()) { + // Create an immutable callback list, allowing traversal during + // modification. The tail is an empty object that will always be + // used + // as the next node. + var list = calls[ev] || (calls[ev] = {}); + var tail = list.tail || (list.tail = list.next = {}); + tail.callback = callback; + tail.context = context; + list.tail = tail.next = {}; + } + return this; + }, + + // Remove one or many callbacks. If `context` is null, removes all + // callbacks + // with that function. If `callback` is null, removes all callbacks for + // the + // event. If `ev` is null, removes all bound callbacks for all events. + off : function(events, callback, context) { + var ev, calls, node; + if (!events) { + delete this._callbacks; + } else if (calls = this._callbacks) { + events = events.split(/\s+/); + while (ev = events.shift()) { + node = calls[ev]; + delete calls[ev]; + if (!callback || !node) + continue; + // Create a new list, omitting the indicated event/context + // pairs. + while ((node = node.next) && node.next) { + if (node.callback === callback + && (!context || node.context === context)) + continue; + this.on(ev, node.callback, node.context); + } + } + } + return this; + }, + + // Trigger an event, firing all bound callbacks. Callbacks are passed + // the + // same arguments as `trigger` is, apart from the event name. + // Listening for `"all"` passes the true event name as the first + // argument. + trigger : function(events) { + var event, node, calls, tail, args, all, rest; + if (!(calls = this._callbacks)) + return this; + all = calls['all']; + (events = events.split(/\s+/)).push(null); + // Save references to the current heads & tails. + while (event = events.shift()) { + if (all) + events.push({ + next : all.next, + tail : all.tail, + event : event + }); + if (!(node = calls[event])) + continue; + events.push({ + next : node.next, + tail : node.tail + }); + } + // Traverse each list, stopping when the saved tail is reached. + rest = slice.call(arguments, 1); + while (node = events.pop()) { + tail = node.tail; + args = node.event ? [ node.event ].concat(rest) : rest; + while ((node = node.next) !== tail) { + node.callback.apply(node.context || this, args); + } + } + return this; + }, + bind: function() { + return this.on.apply(this, arguments); + }, + unbind: function() { + return this.on.apply(this, arguments); + } + }); + return lib; })(); diff --git a/addons/web/static/lib/nivjs/test/test.html b/addons/web/static/lib/nivjs/test/test.html index 08cd9fce4ab..a229d373f51 100644 --- a/addons/web/static/lib/nivjs/test/test.html +++ b/addons/web/static/lib/nivjs/test/test.html @@ -6,6 +6,8 @@ + + diff --git a/addons/web/static/lib/nivjs/test/test.js b/addons/web/static/lib/nivjs/test/test.js index 5ef89fa5da8..0328b7d0574 100644 --- a/addons/web/static/lib/nivjs/test/test.js +++ b/addons/web/static/lib/nivjs/test/test.js @@ -6,3 +6,34 @@ test("Class exists", function() { ok(!!niv.Class.extend, "extend does not exist"); }); +test("Inheritance works", function() { + var Claz = niv.Class.extend({ + test: function() { + return "ok"; + } + }) + equal("ok", new Claz().test()); +}); + +module("DestroyableMixin"); + +test("DestroyableMixin works", function() { + var Claz = niv.Class.extend(_.extend({}, niv.DestroyableMixin, {})); + var x = new Claz(); + equal(false, !!x.isDestroyed()); + x.destroy(); + equal(true, x.isDestroyed()); +}); + +module("ParentedMixin"); + +test("ParentedMixin works", function() { + var Claz = niv.Class.extend(_.extend({}, niv.ParentedMixin, {})); + var x = new Claz(); + var y = new Claz(); + y.setParent(x); + equal(x, y.getParent()); + equal(y, x.getChildren()[0]); + x.destroy(); + equal(true, y.isDestroyed()); +}); From 0246ffeee07c952f2ff96ad73e78b94bb2d63f38 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Thu, 23 Feb 2012 18:18:40 +0100 Subject: [PATCH 05/39] [imp] added event dispatcher mixin bzr revid: nicolas.vanhoren@openerp.com-20120223171840-mege8l7aopnbkck2 --- addons/web/static/lib/nivjs/src/niv.js | 68 ++++++++++++++++-------- addons/web/static/lib/nivjs/test/test.js | 16 ++++++ 2 files changed, 63 insertions(+), 21 deletions(-) diff --git a/addons/web/static/lib/nivjs/src/niv.js b/addons/web/static/lib/nivjs/src/niv.js index bc8d1564523..7905e18fbf5 100644 --- a/addons/web/static/lib/nivjs/src/niv.js +++ b/addons/web/static/lib/nivjs/src/niv.js @@ -97,35 +97,35 @@ niv = (function() { lib.DestroyableMixin = { isDestroyed : function() { - return this.__destroyable_destroyed; + return this.__destroyableDestroyed; }, destroy : function() { - this.__destroyable_destroyed = true; + this.__destroyableDestroyed = true; } }; lib.ParentedMixin = _.extend({}, lib.DestroyableMixin, { - __parented_mixin : true, + __parentedMixin : true, setParent : function(parent) { if (this.getParent()) { - if (this.getParent().__parented_mixin) { - this.getParent().__parented_children = _.without(this + if (this.getParent().__parentedMixin) { + this.getParent().__parentedChildren = _.without(this .getParent().getChildren(), this); } - this.__parented_parent = undefined; + this.__parentedParent = undefined; } - this.__parented_parent = parent; - if (parent && parent.__parented_mixin) { - if (!parent.__parented_children) - parent.__parented_children = []; - parent.__parented_children.push(this); + this.__parentedParent = parent; + if (parent && parent.__parentedMixin) { + if (!parent.__parentedChildren) + parent.__parentedChildren = []; + parent.__parentedChildren.push(this); } }, getParent : function() { - return this.__parented_parent; + return this.__parentedParent; }, getChildren : function() { - return this.__parented_children ? _.clone(this.__parented_children) + return this.__parentedChildren ? _.clone(this.__parentedChildren) : []; }, destroy : function() { @@ -136,15 +136,21 @@ niv = (function() { lib.DestroyableMixin.destroy.call(this); } }); + + lib.internal = {}; /* - * We steal backbone's events :) + * Yes, we steal Backbone's events :) + * + * This class just handle the dispatching of events, it is not meant to be extended, + * nor used directly. All integration with parenting and automatic unregistration of + * events is done in EventDispatcherMixin. */ // (c) 2010-2012 Jeremy Ashkenas, DocumentCloud Inc. // Backbone may be freely distributed under the MIT license. // For all details and documentation: // http://backbonejs.org - lib.EventDispatcher = lib.Class.extend({ + lib.internal.Events = lib.Class.extend({ // Bind an event, specified by a string name, `ev`, to a `callback` // function. Passing `"all"` will bind the callback to all events fired. @@ -222,7 +228,7 @@ niv = (function() { }); } // Traverse each list, stopping when the saved tail is reached. - rest = slice.call(arguments, 1); + rest = Array.prototype.slice.call(arguments, 1); while (node = events.pop()) { tail = node.tail; args = node.event ? [ node.event ].concat(rest) : rest; @@ -231,12 +237,32 @@ niv = (function() { } } return this; + } + }); + + var checkEventDispatcher = function(ev) { + if (!ev.__events) { + ev.__events = new lib.internal.Events(); + ev.__registeredEvents = []; + } + }; + lib.EventDispatcherMixin = _.extend({}, lib.ParentedMixin, { + __eventDispatcherMixin: true, + bind: function(eventName, object, func) { + checkEventDispatcher(this); + this.__events.on(eventName, func, object); + if (object && object.__eventDispatcherMixin) { + checkEventDispatcher(object); + object.__registeredEvents.push({name: eventName, func: func, source: this}); + } }, - bind: function() { - return this.on.apply(this, arguments); - }, - unbind: function() { - return this.on.apply(this, arguments); + destroy: function() { + checkEventDispatcher(this); + _.each(this.__registeredEvents, _.bind(function(event) { + event.source.__events.off(event.name, event.func, this); + }, this)); + this.__events.off(); // to ease garbage collector's duty + lib.ParentedMixin.destroy.call(this); } }); diff --git a/addons/web/static/lib/nivjs/test/test.js b/addons/web/static/lib/nivjs/test/test.js index 0328b7d0574..5a350887877 100644 --- a/addons/web/static/lib/nivjs/test/test.js +++ b/addons/web/static/lib/nivjs/test/test.js @@ -37,3 +37,19 @@ test("ParentedMixin works", function() { x.destroy(); equal(true, y.isDestroyed()); }); + +module("Events"); + +test("Events works", function() { + var x = new niv.internal.Events(); + var tmp = 0; + var fct = function() {tmp = 1;}; + x.on("test", fct); + equal(0, tmp); + x.trigger("test"); + equal(1, tmp); + tmp = 0; + x.off("test", fct); + x.trigger("test"); + equal(0, tmp); +}); From 334d3f5875ddd9e499e64ef8cc73f4625f36d531 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Thu, 23 Feb 2012 18:39:59 +0100 Subject: [PATCH 06/39] [imp] added most methods for EventDispatcherMixin bzr revid: nicolas.vanhoren@openerp.com-20120223173959-di5xl97uci1pnz6x --- addons/web/static/lib/nivjs/src/niv.js | 47 +++++++++++++++++++----- addons/web/static/lib/nivjs/test/test.js | 38 ++++++++++++++----- 2 files changed, 66 insertions(+), 19 deletions(-) diff --git a/addons/web/static/lib/nivjs/src/niv.js b/addons/web/static/lib/nivjs/src/niv.js index 7905e18fbf5..4834862db74 100644 --- a/addons/web/static/lib/nivjs/src/niv.js +++ b/addons/web/static/lib/nivjs/src/niv.js @@ -248,20 +248,47 @@ niv = (function() { }; lib.EventDispatcherMixin = _.extend({}, lib.ParentedMixin, { __eventDispatcherMixin: true, - bind: function(eventName, object, func) { + bind: function(events, object, func) { + var self = this; checkEventDispatcher(this); - this.__events.on(eventName, func, object); - if (object && object.__eventDispatcherMixin) { - checkEventDispatcher(object); - object.__registeredEvents.push({name: eventName, func: func, source: this}); - } + events = events.split(/\s+/); + _.each(events, function(eventName) { + self.__events.on(eventName, func, object); + if (object && object.__eventDispatcherMixin) { + checkEventDispatcher(object); + object.__registeredEvents.push({name: eventName, func: func, source: self}); + } + }); + return this; + }, + unbind: function(events, object, func) { + var self = this; + checkEventDispatcher(this); + events = events.split(/\s+/); + _.each(events, function(eventName) { + self.__events.off(eventName, func, object); + if (object && object.__eventDispatcherMixin) { + checkEventDispatcher(object); + object.__registeredEvents = _.filter(object.__registeredEvents, function(el) { + return !(el.name === eventName && el.func === func && el.source === self); + }); + } + }); + return this; + }, + trigger: function(events) { + checkEventDispatcher(this); + this.__events.trigger.apply(this.__events, arguments); + return this; }, destroy: function() { + var self = this; checkEventDispatcher(this); - _.each(this.__registeredEvents, _.bind(function(event) { - event.source.__events.off(event.name, event.func, this); - }, this)); - this.__events.off(); // to ease garbage collector's duty + _.each(this.__registeredEvents, function(event) { + event.source.__events.off(event.name, event.func, self); + }); + this.__registeredEvents = []; + this.__events.off(); lib.ParentedMixin.destroy.call(this); } }); diff --git a/addons/web/static/lib/nivjs/test/test.js b/addons/web/static/lib/nivjs/test/test.js index 5a350887877..60f951a191c 100644 --- a/addons/web/static/lib/nivjs/test/test.js +++ b/addons/web/static/lib/nivjs/test/test.js @@ -1,12 +1,9 @@ module("Class"); -test("Class exists", function() { - ok(!!niv.Class, "Class does not exist"); - ok(!!niv.Class.extend, "extend does not exist"); -}); - -test("Inheritance works", function() { +test("base", function() { + ok(!!niv.Class, "Class does not exist"); + ok(!!niv.Class.extend, "extend does not exist"); var Claz = niv.Class.extend({ test: function() { return "ok"; @@ -17,7 +14,7 @@ test("Inheritance works", function() { module("DestroyableMixin"); -test("DestroyableMixin works", function() { +test("base", function() { var Claz = niv.Class.extend(_.extend({}, niv.DestroyableMixin, {})); var x = new Claz(); equal(false, !!x.isDestroyed()); @@ -27,7 +24,7 @@ test("DestroyableMixin works", function() { module("ParentedMixin"); -test("ParentedMixin works", function() { +test("base", function() { var Claz = niv.Class.extend(_.extend({}, niv.ParentedMixin, {})); var x = new Claz(); var y = new Claz(); @@ -40,7 +37,7 @@ test("ParentedMixin works", function() { module("Events"); -test("Events works", function() { +test("base", function() { var x = new niv.internal.Events(); var tmp = 0; var fct = function() {tmp = 1;}; @@ -53,3 +50,26 @@ test("Events works", function() { x.trigger("test"); equal(0, tmp); }); + +module("EventDispatcherMixin"); + +test("base", function() { + var Claz = niv.Class.extend(_.extend({}, niv.EventDispatcherMixin, {})); + var x = new Claz(); + var y = new Claz(); + var tmp = 0; + var fct = function() {tmp = 1;}; + x.bind("test", y, fct); + equal(0, tmp); + x.trigger("test"); + equal(1, tmp); + tmp = 0; + x.unbind("test", y, fct); + x.trigger("test"); + equal(0, tmp); + tmp = 0; + x.bind("test", y, fct); + y.destroy(); + x.trigger("test"); + equal(0, tmp); +}); From 56b07a90cd4b37c0a1c08e1d045dc109394fb36e Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Thu, 23 Feb 2012 18:54:19 +0100 Subject: [PATCH 07/39] [imp] small messages bzr revid: nicolas.vanhoren@openerp.com-20120223175419-0rjeodw3q8zqeelv --- addons/web/static/lib/nivjs/src/niv.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/addons/web/static/lib/nivjs/src/niv.js b/addons/web/static/lib/nivjs/src/niv.js index 4834862db74..84706d69ace 100644 --- a/addons/web/static/lib/nivjs/src/niv.js +++ b/addons/web/static/lib/nivjs/src/niv.js @@ -94,6 +94,7 @@ niv = (function() { return Class; }; }).call(lib); + // end of John Resig's code lib.DestroyableMixin = { isDestroyed : function() { @@ -239,6 +240,7 @@ niv = (function() { return this; } }); + // end of Backbone's events class var checkEventDispatcher = function(ev) { if (!ev.__events) { From a9368e6eecc60630370ac0bdb5a1a8f6054d8c22 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Fri, 24 Feb 2012 13:31:51 +0100 Subject: [PATCH 08/39] [imp] added GetterSetterMixin bzr revid: nicolas.vanhoren@openerp.com-20120224123151-fmkh3fonswkhtu36 --- addons/web/static/lib/nivjs/src/niv.js | 58 +++++++++++++++++------- addons/web/static/lib/nivjs/test/test.js | 46 +++++++++++++------ 2 files changed, 74 insertions(+), 30 deletions(-) diff --git a/addons/web/static/lib/nivjs/src/niv.js b/addons/web/static/lib/nivjs/src/niv.js index 84706d69ace..35c42a51ce6 100644 --- a/addons/web/static/lib/nivjs/src/niv.js +++ b/addons/web/static/lib/nivjs/src/niv.js @@ -25,6 +25,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. niv = (function() { var lib = {}; + lib.internal = {}; /* * Unmodified John Resig's inheritance @@ -90,7 +91,7 @@ niv = (function() { // And make this class extendable Class.extend = arguments.callee; - + return Class; }; }).call(lib); @@ -137,8 +138,6 @@ niv = (function() { lib.DestroyableMixin.destroy.call(this); } }); - - lib.internal = {}; /* * Yes, we steal Backbone's events :) @@ -242,36 +241,36 @@ niv = (function() { }); // end of Backbone's events class - var checkEventDispatcher = function(ev) { - if (!ev.__events) { - ev.__events = new lib.internal.Events(); - ev.__registeredEvents = []; + var checkEventDispatcher = function(obj) { + if (!obj.__events) { + obj.__events = new lib.internal.Events(); + obj.__registeredEvents = []; } }; lib.EventDispatcherMixin = _.extend({}, lib.ParentedMixin, { __eventDispatcherMixin: true, - bind: function(events, object, func) { + bind: function(events, dest, func) { var self = this; checkEventDispatcher(this); events = events.split(/\s+/); _.each(events, function(eventName) { - self.__events.on(eventName, func, object); - if (object && object.__eventDispatcherMixin) { - checkEventDispatcher(object); - object.__registeredEvents.push({name: eventName, func: func, source: self}); + self.__events.on(eventName, func, dest); + if (dest && dest.__eventDispatcherMixin) { + checkEventDispatcher(dest); + dest.__registeredEvents.push({name: eventName, func: func, source: self}); } }); return this; }, - unbind: function(events, object, func) { + unbind: function(events, dest, func) { var self = this; checkEventDispatcher(this); events = events.split(/\s+/); _.each(events, function(eventName) { - self.__events.off(eventName, func, object); - if (object && object.__eventDispatcherMixin) { - checkEventDispatcher(object); - object.__registeredEvents = _.filter(object.__registeredEvents, function(el) { + self.__events.off(eventName, func, dest); + if (dest && dest.__eventDispatcherMixin) { + checkEventDispatcher(dest); + dest.__registeredEvents = _.filter(dest.__registeredEvents, function(el) { return !(el.name === eventName && el.func === func && el.source === self); }); } @@ -294,6 +293,31 @@ niv = (function() { lib.ParentedMixin.destroy.call(this); } }); + + var checkGetterSetter = function(obj) { + if (!obj.__internal_map) { + obj.__internal_map = {}; + } + }; + lib.GetterSetterMixin = _.extend({}, lib.EventDispatcherMixin, { + set: function(map) { + var self = this; + checkGetterSetter(this); + _.each(map, function(val, key) { + var tmp = self.__internal_map[key]; + self.__internal_map[key] = val; + self.trigger("changed:" + key, { + oldValue: tmp, + newValue: val, + source: self + }); + }); + }, + get: function(key) { + checkGetterSetter(this); + return this.__internal_map[key]; + } + }); return lib; })(); diff --git a/addons/web/static/lib/nivjs/test/test.js b/addons/web/static/lib/nivjs/test/test.js index 60f951a191c..1f4f379697d 100644 --- a/addons/web/static/lib/nivjs/test/test.js +++ b/addons/web/static/lib/nivjs/test/test.js @@ -9,7 +9,7 @@ test("base", function() { return "ok"; } }) - equal("ok", new Claz().test()); + equal(new Claz().test(), "ok"); }); module("DestroyableMixin"); @@ -17,9 +17,9 @@ module("DestroyableMixin"); test("base", function() { var Claz = niv.Class.extend(_.extend({}, niv.DestroyableMixin, {})); var x = new Claz(); - equal(false, !!x.isDestroyed()); + equal(!!x.isDestroyed(), false); x.destroy(); - equal(true, x.isDestroyed()); + equal(x.isDestroyed(), true); }); module("ParentedMixin"); @@ -29,10 +29,10 @@ test("base", function() { var x = new Claz(); var y = new Claz(); y.setParent(x); - equal(x, y.getParent()); - equal(y, x.getChildren()[0]); + equal(y.getParent(), x); + equal(x.getChildren()[0], y); x.destroy(); - equal(true, y.isDestroyed()); + equal(y.isDestroyed(), true); }); module("Events"); @@ -42,13 +42,13 @@ test("base", function() { var tmp = 0; var fct = function() {tmp = 1;}; x.on("test", fct); - equal(0, tmp); + equal(tmp, 0); x.trigger("test"); - equal(1, tmp); + equal(tmp, 1); tmp = 0; x.off("test", fct); x.trigger("test"); - equal(0, tmp); + equal(tmp, 0); }); module("EventDispatcherMixin"); @@ -60,16 +60,36 @@ test("base", function() { var tmp = 0; var fct = function() {tmp = 1;}; x.bind("test", y, fct); - equal(0, tmp); + equal(tmp, 0); x.trigger("test"); - equal(1, tmp); + equal(tmp, 1); tmp = 0; x.unbind("test", y, fct); x.trigger("test"); - equal(0, tmp); + equal(tmp, 0); tmp = 0; x.bind("test", y, fct); y.destroy(); x.trigger("test"); - equal(0, tmp); + equal(tmp, 0); +}); + +module("GetterSetterMixin"); + +test("base", function() { + var Claz = niv.Class.extend(_.extend({}, niv.GetterSetterMixin, {})); + var x = new Claz(); + var y = new Claz(); + x.set({test: 1}); + equal(x.get("test"), 1); + var tmp = 0; + x.bind("changed:test", y, function(arg) { + tmp = 1; + equal(arg.oldValue, 1); + equal(arg.newValue, 2); + equal(x.get("test"), 2); + equal(arg.source, x); + }); + x.set({test: 2}); + equal(tmp, 1); }); From e7f06acb8488e9807c38b578ebfac0ae6c77188f Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Fri, 24 Feb 2012 13:40:31 +0100 Subject: [PATCH 09/39] [imp] added widget bzr revid: nicolas.vanhoren@openerp.com-20120224124031-l31832108z69od4i --- addons/web/static/lib/nivjs/src/niv.js | 116 +++++++++++++++++++++++++ 1 file changed, 116 insertions(+) diff --git a/addons/web/static/lib/nivjs/src/niv.js b/addons/web/static/lib/nivjs/src/niv.js index 35c42a51ce6..0106fceb5fd 100644 --- a/addons/web/static/lib/nivjs/src/niv.js +++ b/addons/web/static/lib/nivjs/src/niv.js @@ -318,6 +318,122 @@ niv = (function() { return this.__internal_map[key]; } }); + + lib.Widget = lib.Class.extend(_.extend({}, lib.GetterSetterMixin, { + /** + * Tag name when creating a default $element. + * @type string + */ + tag_name: 'div', + /** + * Constructs the widget and sets its parent if a parent is given. + * + * @constructs openerp.web.Widget + * @extends openerp.web.CallbackEnabled + * + * @param {openerp.web.Widget} parent Binds the current instance to the given Widget instance. + * When that widget is destroyed by calling destroy(), the current instance will be + * destroyed too. Can be null. + * @param {String} element_id Deprecated. Sets the element_id. Only useful when you want + * to bind the current Widget to an already existing part of the DOM, which is not compatible + * with the DOM insertion methods provided by the current implementation of Widget. So + * for new components this argument should not be provided any more. + */ + init: function(parent) { + this._super(); + + this.$element = $(document.createElement(this.tag_name)); + + this.setParent(parent); + }, + /** + * Destroys the current widget, also destroys all its children before destroying itself. + */ + destroy: function() { + _.each(this.getChildren(), function(el) { + el.destroy(); + }); + if(this.$element != null) { + this.$element.remove(); + } + this._super(); + }, + /** + * Renders the current widget and appends it to the given jQuery object or Widget. + * + * @param target A jQuery object or a Widget instance. + */ + appendTo: function(target) { + var self = this; + return this._render_and_insert(function(t) { + self.$element.appendTo(t); + }, target); + }, + /** + * Renders the current widget and prepends it to the given jQuery object or Widget. + * + * @param target A jQuery object or a Widget instance. + */ + prependTo: function(target) { + var self = this; + return this._render_and_insert(function(t) { + self.$element.prependTo(t); + }, target); + }, + /** + * Renders the current widget and inserts it after to the given jQuery object or Widget. + * + * @param target A jQuery object or a Widget instance. + */ + insertAfter: function(target) { + var self = this; + return this._render_and_insert(function(t) { + self.$element.insertAfter(t); + }, target); + }, + /** + * Renders the current widget and inserts it before to the given jQuery object or Widget. + * + * @param target A jQuery object or a Widget instance. + */ + insertBefore: function(target) { + var self = this; + return this._render_and_insert(function(t) { + self.$element.insertBefore(t); + }, target); + }, + /** + * Renders the current widget and replaces the given jQuery object. + * + * @param target A jQuery object or a Widget instance. + */ + replace: function(target) { + return this._render_and_insert(_.bind(function(t) { + this.$element.replaceAll(t); + }, this), target); + }, + _render_and_insert: function(insertion, target) { + this.render_element(); + if (target instanceof openerp.web.Widget) + target = target.$element; + insertion(target); + return this.start(); + }, + /** + * This is the method to implement to render the Widget. + */ + render_element: function() {}, + /** + * Method called after rendering. Mostly used to bind actions, perform asynchronous + * calls, etc... + * + * By convention, the method should return a promise to inform the caller when + * this widget has been initialized. + * + * @returns {jQuery.Deferred} + */ + start: function() {} + })); return lib; })(); From a2b98743785dc4290e5b5adfac5892c2e0707fda Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Fri, 24 Feb 2012 14:26:39 +0100 Subject: [PATCH 10/39] [imp] adapted widget to new lib bzr revid: nicolas.vanhoren@openerp.com-20120224132639-um1aitu3bymnk7wo --- addons/web/static/src/js/core.js | 108 ++----------------------------- 1 file changed, 7 insertions(+), 101 deletions(-) diff --git a/addons/web/static/src/js/core.js b/addons/web/static/src/js/core.js index 69ec98e7350..9a564c653bb 100644 --- a/addons/web/static/src/js/core.js +++ b/addons/web/static/src/js/core.js @@ -362,7 +362,7 @@ openerp.web.Registry = openerp.web.Class.extend( /** @lends openerp.web.Registry } }); -openerp.web.CallbackEnabled = openerp.web.Class.extend(/** @lends openerp.web.CallbackEnabled# */{ +openerp.web.CallbackEnabledMixin = { /** * @constructs openerp.web.CallbackEnabled * @extends openerp.web.Class @@ -404,7 +404,9 @@ openerp.web.CallbackEnabled = openerp.web.Class.extend(/** @lends openerp.web.Ca return self[method_name].apply(self, arguments); } } -}); +}; + +openerp.web.CallbackEnabled = openerp.web.Class.extend(_.extend({}, openerp.web.CallbackEnabledMixin)); openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp.web.Connection# */{ /** @@ -973,7 +975,7 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp. * * That will kill the widget in a clean way and erase its content from the dom. */ -openerp.web.Widget = openerp.web.CallbackEnabled.extend(niv.ParentedMixin).extend(/** @lends openerp.web.Widget# */{ +openerp.web.Widget = niv.Widget.extend(_.extend({}, openerp.web.CallbackEnabledMixin, { /** * The name of the QWeb template that will be used for rendering. Must be * redefined in subclasses or the default render() method can not be used. @@ -981,11 +983,6 @@ openerp.web.Widget = openerp.web.CallbackEnabled.extend(niv.ParentedMixin).exten * @type string */ template: null, - /** - * Tag name when creating a default $element. - * @type string - */ - tag_name: 'div', /** * Constructs the widget and sets its parent if a parent is given. * @@ -1001,88 +998,10 @@ openerp.web.Widget = openerp.web.CallbackEnabled.extend(niv.ParentedMixin).exten * for new components this argument should not be provided any more. */ init: function(parent) { + openerp.web.CallbackEnabledMixin.init.call(this); this._super(); this.session = openerp.connection; - - this.$element = $(document.createElement(this.tag_name)); - - this.setParent(parent); }, - /** - * Destroys the current widget, also destroys all its children before destroying itself. - */ - destroy: function() { - _.each(this.getChildren(), function(el) { - el.destroy(); - }); - if(this.$element != null) { - this.$element.remove(); - } - this._super(); - }, - /** - * Renders the current widget and appends it to the given jQuery object or Widget. - * - * @param target A jQuery object or a Widget instance. - */ - appendTo: function(target) { - var self = this; - return this._render_and_insert(function(t) { - self.$element.appendTo(t); - }, target); - }, - /** - * Renders the current widget and prepends it to the given jQuery object or Widget. - * - * @param target A jQuery object or a Widget instance. - */ - prependTo: function(target) { - var self = this; - return this._render_and_insert(function(t) { - self.$element.prependTo(t); - }, target); - }, - /** - * Renders the current widget and inserts it after to the given jQuery object or Widget. - * - * @param target A jQuery object or a Widget instance. - */ - insertAfter: function(target) { - var self = this; - return this._render_and_insert(function(t) { - self.$element.insertAfter(t); - }, target); - }, - /** - * Renders the current widget and inserts it before to the given jQuery object or Widget. - * - * @param target A jQuery object or a Widget instance. - */ - insertBefore: function(target) { - var self = this; - return this._render_and_insert(function(t) { - self.$element.insertBefore(t); - }, target); - }, - /** - * Renders the current widget and replaces the given jQuery object. - * - * @param target A jQuery object or a Widget instance. - */ - replace: function(target) { - return this._render_and_insert(_.bind(function(t) { - this.$element.replaceAll(t); - }, this), target); - }, - _render_and_insert: function(insertion, target) { - this.render_element(); - if (target instanceof openerp.web.Widget) - target = target.$element; - insertion(target); - this.on_inserted(this.$element, this); - return this.start(); - }, - on_inserted: function(element, widget) {}, /** * Renders the element. The default implementation renders the widget using QWeb, * `this.template` must be defined. The context given to QWeb contains the "widget" @@ -1098,18 +1017,6 @@ openerp.web.Widget = openerp.web.CallbackEnabled.extend(niv.ParentedMixin).exten this.$element = elem; } }, - /** - * Method called after rendering. Mostly used to bind actions, perform asynchronous - * calls, etc... - * - * By convention, the method should return a promise to inform the caller when - * this widget has been initialized. - * - * @returns {jQuery.Deferred} - */ - start: function() { - return $.Deferred().done().promise(); - }, /** * Informs the action manager to do an action. This supposes that * the action manager can be found amongst the ancestors of the current widget. @@ -1133,7 +1040,6 @@ openerp.web.Widget = openerp.web.CallbackEnabled.extend(niv.ParentedMixin).exten } return false; }, - rpc: function(url, data, success, error) { var def = $.Deferred().then(success, error); var self = this; @@ -1146,7 +1052,7 @@ openerp.web.Widget = openerp.web.CallbackEnabled.extend(niv.ParentedMixin).exten }); return def.promise(); } -}); +})); /** * @deprecated use :class:`openerp.web.Widget` From 8a8da7973a0e7ca62aafdee7a3eae7ed6f757f4a Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Fri, 24 Feb 2012 14:50:27 +0100 Subject: [PATCH 11/39] [imp] added some tests, debugged some bugs bzr revid: nicolas.vanhoren@openerp.com-20120224135027-axsjx7x0ajlzvolh --- addons/web/static/lib/nivjs/src/niv.js | 6 +---- addons/web/static/lib/nivjs/test/test.js | 33 +++++++++++++++++++++--- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/addons/web/static/lib/nivjs/src/niv.js b/addons/web/static/lib/nivjs/src/niv.js index 0106fceb5fd..e572edc73c1 100644 --- a/addons/web/static/lib/nivjs/src/niv.js +++ b/addons/web/static/lib/nivjs/src/niv.js @@ -340,8 +340,6 @@ niv = (function() { * for new components this argument should not be provided any more. */ init: function(parent) { - this._super(); - this.$element = $(document.createElement(this.tag_name)); this.setParent(parent); @@ -356,7 +354,7 @@ niv = (function() { if(this.$element != null) { this.$element.remove(); } - this._super(); + lib.GetterSetterMixin.destroy.call(this); }, /** * Renders the current widget and appends it to the given jQuery object or Widget. @@ -414,8 +412,6 @@ niv = (function() { }, _render_and_insert: function(insertion, target) { this.render_element(); - if (target instanceof openerp.web.Widget) - target = target.$element; insertion(target); return this.start(); }, diff --git a/addons/web/static/lib/nivjs/test/test.js b/addons/web/static/lib/nivjs/test/test.js index 1f4f379697d..c93dea99ac6 100644 --- a/addons/web/static/lib/nivjs/test/test.js +++ b/addons/web/static/lib/nivjs/test/test.js @@ -2,14 +2,20 @@ module("Class"); test("base", function() { - ok(!!niv.Class, "Class does not exist"); - ok(!!niv.Class.extend, "extend does not exist"); + ok(!!niv.Class, "Class does exist"); + ok(!!niv.Class.extend, "extend does exist"); var Claz = niv.Class.extend({ test: function() { return "ok"; } - }) + }); equal(new Claz().test(), "ok"); + var Claz2 = Claz.extend({ + test: function() { + return this._super() + "2"; + } + }); + equal(new Claz2().test(), "ok2"); }); module("DestroyableMixin"); @@ -93,3 +99,24 @@ test("base", function() { x.set({test: 2}); equal(tmp, 1); }); + +module("Widget"); + +test("base", function() { + var Claz = niv.Widget.extend({ + render_element: function() { + this.$element.attr("id", "testdiv"); + this.$element.html("test"); + } + }); + var x = new Claz(); + x.appendTo($("body")); + var $el = $("#testdiv"); + equal($el.length, 1); + equal($el.parents()[0], $("body")[0]); + equal($el.html(), "test"); + x.destroy(); + $el = $("#testdiv"); + equal($el.length, 0); +}); + From b6f93c8fa600b227ed6266e11c91fc7cecde36fa Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Fri, 24 Feb 2012 14:58:59 +0100 Subject: [PATCH 12/39] [fix] some bugs providing the web client to work bzr revid: nicolas.vanhoren@openerp.com-20120224135859-w937wgm51328dbk1 --- addons/web/static/lib/nivjs/src/niv.js | 110 +++++++++++++++-------- addons/web/static/lib/nivjs/test/test.js | 4 + addons/web/static/src/js/core.js | 2 +- 3 files changed, 77 insertions(+), 39 deletions(-) diff --git a/addons/web/static/lib/nivjs/src/niv.js b/addons/web/static/lib/nivjs/src/niv.js index e572edc73c1..e2c997a64a0 100644 --- a/addons/web/static/lib/nivjs/src/niv.js +++ b/addons/web/static/lib/nivjs/src/niv.js @@ -45,54 +45,88 @@ niv = (function() { // Create a new Class that inherits from this class this.Class.extend = function(prop) { - var _super = this.prototype; + var _super = this.prototype; - // Instantiate a base class (but only create the instance, - // don't run the init constructor) - initializing = true; - var prototype = new this(); - initializing = false; + // Instantiate a web class (but only create the instance, + // don't run the init constructor) + initializing = true; + var prototype = new this(); + initializing = false; - // Copy the properties over onto the new prototype - for ( var name in prop) { - // Check if we're overwriting an existing function - prototype[name] = typeof prop[name] == "function" - && typeof _super[name] == "function" - && fnTest.test(prop[name]) ? (function(name, fn) { - return function() { - var tmp = this._super; + // Copy the properties over onto the new prototype + for (var name in prop) { + // Check if we're overwriting an existing function + prototype[name] = typeof prop[name] == "function" && + typeof _super[name] == "function" && + fnTest.test(prop[name]) ? + (function(name, fn) { + return function() { + var tmp = this._super; - // Add a new ._super() method that is the same method - // but on the super-class - this._super = _super[name]; + // Add a new ._super() method that is the same + // method but on the super-class + this._super = _super[name]; - // The method only need to be bound temporarily, so we - // remove it when we're done executing - var ret = fn.apply(this, arguments); - this._super = tmp; + // The method only need to be bound temporarily, so + // we remove it when we're done executing + var ret = fn.apply(this, arguments); + this._super = tmp; - return ret; - }; - })(name, prop[name]) : prop[name]; + return ret; + }; + })(name, prop[name]) : + prop[name]; + } + + // The dummy class constructor + function Class() { + // All construction is actually done in the init method + if (!initializing && this.init) { + var ret = this.init.apply(this, arguments); + if (ret) { return ret; } } - - // The dummy class constructor - function Class() { - // All construction is actually done in the init method - if (!initializing && this.init) - this.init.apply(this, arguments); + return this; + } + Class.include = function (properties) { + for (var name in properties) { + if (typeof properties[name] !== 'function' + || !fnTest.test(properties[name])) { + prototype[name] = properties[name]; + } else if (typeof prototype[name] === 'function' + && prototype.hasOwnProperty(name)) { + prototype[name] = (function (name, fn, previous) { + return function () { + var tmp = this._super; + this._super = previous; + var ret = fn.apply(this, arguments); + this._super = tmp; + return ret; + } + })(name, properties[name], prototype[name]); + } else if (typeof _super[name] === 'function') { + prototype[name] = (function (name, fn) { + return function () { + var tmp = this._super; + this._super = _super[name]; + var ret = fn.apply(this, arguments); + this._super = tmp; + return ret; + } + })(name, properties[name]); + } } + }; - // Populate our constructed prototype object - Class.prototype = prototype; + // Populate our constructed prototype object + Class.prototype = prototype; - // Enforce the constructor to be what we expect - Class.prototype.constructor = Class; + // Enforce the constructor to be what we expect + Class.constructor = Class; - // And make this class extendable - Class.extend = arguments.callee; - - return Class; + // And make this class extendable + Class.extend = arguments.callee; + + return Class; }; }).call(lib); // end of John Resig's code diff --git a/addons/web/static/lib/nivjs/test/test.js b/addons/web/static/lib/nivjs/test/test.js index c93dea99ac6..244ba8d7f26 100644 --- a/addons/web/static/lib/nivjs/test/test.js +++ b/addons/web/static/lib/nivjs/test/test.js @@ -115,6 +115,10 @@ test("base", function() { equal($el.length, 1); equal($el.parents()[0], $("body")[0]); equal($el.html(), "test"); + + var y = new Claz(x); + equal(y.getParent(), x); + x.destroy(); $el = $("#testdiv"); equal($el.length, 0); diff --git a/addons/web/static/src/js/core.js b/addons/web/static/src/js/core.js index 9a564c653bb..7b88279cf16 100644 --- a/addons/web/static/src/js/core.js +++ b/addons/web/static/src/js/core.js @@ -999,7 +999,7 @@ openerp.web.Widget = niv.Widget.extend(_.extend({}, openerp.web.CallbackEnabledM */ init: function(parent) { openerp.web.CallbackEnabledMixin.init.call(this); - this._super(); + this._super(parent); this.session = openerp.connection; }, /** From 4ff154c30856f5ed80589015bf0552a3852f0a9f Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Fri, 24 Feb 2012 15:51:04 +0100 Subject: [PATCH 13/39] [imp] switched openerp's class to lib's class bzr revid: nicolas.vanhoren@openerp.com-20120224145104-iues3wzd4inwywpd --- addons/web/static/src/js/core.js | 104 +------------------------------ 1 file changed, 1 insertion(+), 103 deletions(-) diff --git a/addons/web/static/src/js/core.js b/addons/web/static/src/js/core.js index 7b88279cf16..93b9a237bf0 100644 --- a/addons/web/static/src/js/core.js +++ b/addons/web/static/src/js/core.js @@ -10,110 +10,8 @@ if (!console.debug) { } openerp.web.core = function(openerp) { -/** - * John Resig Class with factory improvement - */ -(function() { - var initializing = false, - fnTest = /xyz/.test(function(){xyz;}) ? /\b_super\b/ : /.*/; - // The web Class implementation (does nothing) - /** - * Extended version of John Resig's Class pattern - * - * @class - */ - openerp.web.Class = function(){}; - /** - * Subclass an existing class - * - * @param {Object} prop class-level properties (class attributes and instance methods) to set on the new class - */ - openerp.web.Class.extend = function(prop) { - var _super = this.prototype; - - // Instantiate a web class (but only create the instance, - // don't run the init constructor) - initializing = true; - var prototype = new this(); - initializing = false; - - // Copy the properties over onto the new prototype - for (var name in prop) { - // Check if we're overwriting an existing function - prototype[name] = typeof prop[name] == "function" && - typeof _super[name] == "function" && - fnTest.test(prop[name]) ? - (function(name, fn) { - return function() { - var tmp = this._super; - - // Add a new ._super() method that is the same - // method but on the super-class - this._super = _super[name]; - - // The method only need to be bound temporarily, so - // we remove it when we're done executing - var ret = fn.apply(this, arguments); - this._super = tmp; - - return ret; - }; - })(name, prop[name]) : - prop[name]; - } - - // The dummy class constructor - function Class() { - // All construction is actually done in the init method - if (!initializing && this.init) { - var ret = this.init.apply(this, arguments); - if (ret) { return ret; } - } - return this; - } - Class.include = function (properties) { - for (var name in properties) { - if (typeof properties[name] !== 'function' - || !fnTest.test(properties[name])) { - prototype[name] = properties[name]; - } else if (typeof prototype[name] === 'function' - && prototype.hasOwnProperty(name)) { - prototype[name] = (function (name, fn, previous) { - return function () { - var tmp = this._super; - this._super = previous; - var ret = fn.apply(this, arguments); - this._super = tmp; - return ret; - } - })(name, properties[name], prototype[name]); - } else if (typeof _super[name] === 'function') { - prototype[name] = (function (name, fn) { - return function () { - var tmp = this._super; - this._super = _super[name]; - var ret = fn.apply(this, arguments); - this._super = tmp; - return ret; - } - })(name, properties[name]); - } - } - }; - - // Populate our constructed prototype object - Class.prototype = prototype; - - // Enforce the constructor to be what we expect - Class.constructor = Class; - - // And make this class extendable - Class.extend = arguments.callee; - - return Class; - }; -})(); +openerp.web.Class = niv.Class; openerp.web.callback = function(obj, method) { var callback = function() { From 7969c1f08003382aa9c3102b79ad2b68da6c3301 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Fri, 24 Feb 2012 15:54:33 +0100 Subject: [PATCH 14/39] [fix] renammed bind to session_bind bzr revid: nicolas.vanhoren@openerp.com-20120224145433-c5bunu2fuciqj2uc --- addons/web/static/src/js/chrome.js | 4 ++-- addons/web/static/src/js/core.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/addons/web/static/src/js/chrome.js b/addons/web/static/src/js/chrome.js index 060abeefc2c..73ea24b1b31 100644 --- a/addons/web/static/src/js/chrome.js +++ b/addons/web/static/src/js/chrome.js @@ -1090,7 +1090,7 @@ openerp.web.WebClient = openerp.web.OldWidget.extend(/** @lends openerp.web.WebC self.$element.toggleClass('clark-gable'); }); } - this.session.bind().then(function() { + this.session.bind_session().then(function() { if (!self.session.session_is_valid()) { self.show_login(); } @@ -1258,7 +1258,7 @@ openerp.web.embed = function (origin, dbname, login, key, action, options) { var sc = document.getElementsByTagName('script'); currentScript = sc[sc.length-1]; } - openerp.connection.bind(origin).then(function () { + openerp.connection.bind_session(origin).then(function () { openerp.connection.session_authenticate(dbname, login, key, true).then(function () { var client = new openerp.web.EmbeddedClient(action, options); client.insertAfter(currentScript); diff --git a/addons/web/static/src/js/core.js b/addons/web/static/src/js/core.js index 93b9a237bf0..da100c19241 100644 --- a/addons/web/static/src/js/core.js +++ b/addons/web/static/src/js/core.js @@ -322,7 +322,7 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp. this.name = openerp._session_id; this.qweb_mutex = new $.Mutex(); }, - bind: function(origin) { + bind_session: function(origin) { var window_origin = location.protocol+"//"+location.host, self=this; this.origin = origin ? _.str.rtrim(origin,'/') : window_origin; this.prefix = this.origin; From f23a5914cab7ea8039f2b42bc5f279152ed5e31a Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Mon, 27 Feb 2012 10:34:13 +0100 Subject: [PATCH 15/39] [imp] cleaned initialization of mixins bzr revid: nicolas.vanhoren@openerp.com-20120227093413-8qp1vo90500h9lrw --- addons/web/static/lib/nivjs/src/niv.js | 43 ++++++++++++-------------- addons/web/static/src/js/core.js | 11 ++++--- 2 files changed, 25 insertions(+), 29 deletions(-) diff --git a/addons/web/static/lib/nivjs/src/niv.js b/addons/web/static/lib/nivjs/src/niv.js index e2c997a64a0..a4eb0e43d70 100644 --- a/addons/web/static/lib/nivjs/src/niv.js +++ b/addons/web/static/lib/nivjs/src/niv.js @@ -132,6 +132,9 @@ niv = (function() { // end of John Resig's code lib.DestroyableMixin = { + init: function() { + this.__destroyableDestroyed = false; + }, isDestroyed : function() { return this.__destroyableDestroyed; }, @@ -142,18 +145,20 @@ niv = (function() { lib.ParentedMixin = _.extend({}, lib.DestroyableMixin, { __parentedMixin : true, + init: function() { + lib.DestroyableMixin.init.call(this); + this.__parentedChildren = []; + this.__parentedParent = null; + }, setParent : function(parent) { if (this.getParent()) { if (this.getParent().__parentedMixin) { this.getParent().__parentedChildren = _.without(this .getParent().getChildren(), this); } - this.__parentedParent = undefined; } this.__parentedParent = parent; if (parent && parent.__parentedMixin) { - if (!parent.__parentedChildren) - parent.__parentedChildren = []; parent.__parentedChildren.push(this); } }, @@ -161,8 +166,7 @@ niv = (function() { return this.__parentedParent; }, getChildren : function() { - return this.__parentedChildren ? _.clone(this.__parentedChildren) - : []; + return _.clone(this.__parentedChildren); }, destroy : function() { _.each(this.getChildren(), function(el) { @@ -275,22 +279,19 @@ niv = (function() { }); // end of Backbone's events class - var checkEventDispatcher = function(obj) { - if (!obj.__events) { - obj.__events = new lib.internal.Events(); - obj.__registeredEvents = []; - } - }; lib.EventDispatcherMixin = _.extend({}, lib.ParentedMixin, { __eventDispatcherMixin: true, + init: function() { + lib.ParentedMixin.init.call(this); + this.__events = new lib.internal.Events(); + this.__registeredEvents = []; + }, bind: function(events, dest, func) { var self = this; - checkEventDispatcher(this); events = events.split(/\s+/); _.each(events, function(eventName) { self.__events.on(eventName, func, dest); if (dest && dest.__eventDispatcherMixin) { - checkEventDispatcher(dest); dest.__registeredEvents.push({name: eventName, func: func, source: self}); } }); @@ -298,12 +299,10 @@ niv = (function() { }, unbind: function(events, dest, func) { var self = this; - checkEventDispatcher(this); events = events.split(/\s+/); _.each(events, function(eventName) { self.__events.off(eventName, func, dest); if (dest && dest.__eventDispatcherMixin) { - checkEventDispatcher(dest); dest.__registeredEvents = _.filter(dest.__registeredEvents, function(el) { return !(el.name === eventName && el.func === func && el.source === self); }); @@ -312,13 +311,11 @@ niv = (function() { return this; }, trigger: function(events) { - checkEventDispatcher(this); this.__events.trigger.apply(this.__events, arguments); return this; }, destroy: function() { var self = this; - checkEventDispatcher(this); _.each(this.__registeredEvents, function(event) { event.source.__events.off(event.name, event.func, self); }); @@ -328,15 +325,13 @@ niv = (function() { } }); - var checkGetterSetter = function(obj) { - if (!obj.__internal_map) { - obj.__internal_map = {}; - } - }; lib.GetterSetterMixin = _.extend({}, lib.EventDispatcherMixin, { + init: function() { + lib.EventDispatcherMixin.init.call(this); + this.__internal_map = {}; + }, set: function(map) { var self = this; - checkGetterSetter(this); _.each(map, function(val, key) { var tmp = self.__internal_map[key]; self.__internal_map[key] = val; @@ -348,7 +343,6 @@ niv = (function() { }); }, get: function(key) { - checkGetterSetter(this); return this.__internal_map[key]; } }); @@ -374,6 +368,7 @@ niv = (function() { * for new components this argument should not be provided any more. */ init: function(parent) { + lib.GetterSetterMixin.init.call(this); this.$element = $(document.createElement(this.tag_name)); this.setParent(parent); diff --git a/addons/web/static/src/js/core.js b/addons/web/static/src/js/core.js index da100c19241..e4d426ac4a0 100644 --- a/addons/web/static/src/js/core.js +++ b/addons/web/static/src/js/core.js @@ -261,10 +261,6 @@ openerp.web.Registry = openerp.web.Class.extend( /** @lends openerp.web.Registry }); openerp.web.CallbackEnabledMixin = { - /** - * @constructs openerp.web.CallbackEnabled - * @extends openerp.web.Class - */ init: function() { // Transform on_* method into openerp.web.callbacks for (var name in this) { @@ -304,7 +300,12 @@ openerp.web.CallbackEnabledMixin = { } }; -openerp.web.CallbackEnabled = openerp.web.Class.extend(_.extend({}, openerp.web.CallbackEnabledMixin)); +openerp.web.CallbackEnabled = openerp.web.Class.extend(_.extend({}, niv.GetterSetterMixin, openerp.web.CallbackEnabledMixin, { + init: function() { + niv.GetterSetterMixin.init.call(this); + openerp.web.CallbackEnabledMixin.init.call(this); + } +})); openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp.web.Connection# */{ /** From 080c9ed7fd7e782a3d2ae41747f0a80204ce2d5e Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Mon, 27 Feb 2012 11:37:15 +0100 Subject: [PATCH 16/39] [imp] renammed niv to nova bzr revid: nicolas.vanhoren@openerp.com-20120227103715-ez6m5bth0spbuupk --- addons/web/__openerp__.py | 2 +- .../{nivjs/src/niv.js => novajs/src/nova.js} | 2 +- .../static/lib/novajs/test/jquery-1.6.4.js | 9046 +++++++++++++++++ .../lib/{nivjs => novajs}/test/qunit.css | 0 .../lib/{nivjs => novajs}/test/qunit.js | 0 .../lib/{nivjs => novajs}/test/test.html | 6 +- .../static/lib/{nivjs => novajs}/test/test.js | 18 +- .../web/static/lib/novajs/test/underscore.js | 999 ++ addons/web/static/src/js/core.js | 10 +- 9 files changed, 10064 insertions(+), 19 deletions(-) rename addons/web/static/lib/{nivjs/src/niv.js => novajs/src/nova.js} (99%) create mode 100644 addons/web/static/lib/novajs/test/jquery-1.6.4.js rename addons/web/static/lib/{nivjs => novajs}/test/qunit.css (100%) rename addons/web/static/lib/{nivjs => novajs}/test/qunit.js (100%) rename addons/web/static/lib/{nivjs => novajs}/test/test.html (74%) rename addons/web/static/lib/{nivjs => novajs}/test/test.js (82%) create mode 100644 addons/web/static/lib/novajs/test/underscore.js diff --git a/addons/web/__openerp__.py b/addons/web/__openerp__.py index 96fb8b3af71..c6185c64744 100644 --- a/addons/web/__openerp__.py +++ b/addons/web/__openerp__.py @@ -36,7 +36,7 @@ "static/lib/underscore/underscore.string.js", "static/lib/labjs/LAB.src.js", "static/lib/py.parse/lib/py.js", - "static/lib/nivjs/src/niv.js", + "static/lib/novajs/src/nova.js", "static/src/js/boot.js", "static/src/js/core.js", "static/src/js/dates.js", diff --git a/addons/web/static/lib/nivjs/src/niv.js b/addons/web/static/lib/novajs/src/nova.js similarity index 99% rename from addons/web/static/lib/nivjs/src/niv.js rename to addons/web/static/lib/novajs/src/nova.js index a4eb0e43d70..4a96092d635 100644 --- a/addons/web/static/lib/nivjs/src/niv.js +++ b/addons/web/static/lib/novajs/src/nova.js @@ -23,7 +23,7 @@ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -niv = (function() { +nova = (function() { var lib = {}; lib.internal = {}; diff --git a/addons/web/static/lib/novajs/test/jquery-1.6.4.js b/addons/web/static/lib/novajs/test/jquery-1.6.4.js new file mode 100644 index 00000000000..2c12adbf3e8 --- /dev/null +++ b/addons/web/static/lib/novajs/test/jquery-1.6.4.js @@ -0,0 +1,9046 @@ +/*! + * jQuery JavaScript Library v1.6.4 + * http://jquery.com/ + * + * Copyright 2011, John Resig + * Dual licensed under the MIT or GPL Version 2 licenses. + * http://jquery.org/license + * + * Includes Sizzle.js + * http://sizzlejs.com/ + * Copyright 2011, The Dojo Foundation + * Released under the MIT, BSD, and GPL Licenses. + * + * Date: Mon Sep 12 18:54:48 2011 -0400 + */ +(function( window, undefined ) { + +// Use the correct document accordingly with window argument (sandbox) +var document = window.document, + navigator = window.navigator, + location = window.location; +var jQuery = (function() { + +// Define a local copy of jQuery +var jQuery = function( selector, context ) { + // The jQuery object is actually just the init constructor 'enhanced' + return new jQuery.fn.init( selector, context, rootjQuery ); + }, + + // Map over jQuery in case of overwrite + _jQuery = window.jQuery, + + // Map over the $ in case of overwrite + _$ = window.$, + + // A central reference to the root jQuery(document) + rootjQuery, + + // A simple way to check for HTML strings or ID strings + // Prioritize #id over to avoid XSS via location.hash (#9521) + quickExpr = /^(?:[^#<]*(<[\w\W]+>)[^>]*$|#([\w\-]*)$)/, + + // Check if a string has a non-whitespace character in it + rnotwhite = /\S/, + + // Used for trimming whitespace + trimLeft = /^\s+/, + trimRight = /\s+$/, + + // Check for digits + rdigit = /\d/, + + // Match a standalone tag + rsingleTag = /^<(\w+)\s*\/?>(?:<\/\1>)?$/, + + // JSON RegExp + rvalidchars = /^[\],:{}\s]*$/, + rvalidescape = /\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, + rvalidtokens = /"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, + rvalidbraces = /(?:^|:|,)(?:\s*\[)+/g, + + // Useragent RegExp + rwebkit = /(webkit)[ \/]([\w.]+)/, + ropera = /(opera)(?:.*version)?[ \/]([\w.]+)/, + rmsie = /(msie) ([\w.]+)/, + rmozilla = /(mozilla)(?:.*? rv:([\w.]+))?/, + + // Matches dashed string for camelizing + rdashAlpha = /-([a-z]|[0-9])/ig, + rmsPrefix = /^-ms-/, + + // Used by jQuery.camelCase as callback to replace() + fcamelCase = function( all, letter ) { + return ( letter + "" ).toUpperCase(); + }, + + // Keep a UserAgent string for use with jQuery.browser + userAgent = navigator.userAgent, + + // For matching the engine and version of the browser + browserMatch, + + // The deferred used on DOM ready + readyList, + + // The ready event handler + DOMContentLoaded, + + // Save a reference to some core methods + toString = Object.prototype.toString, + hasOwn = Object.prototype.hasOwnProperty, + push = Array.prototype.push, + slice = Array.prototype.slice, + trim = String.prototype.trim, + indexOf = Array.prototype.indexOf, + + // [[Class]] -> type pairs + class2type = {}; + +jQuery.fn = jQuery.prototype = { + constructor: jQuery, + init: function( selector, context, rootjQuery ) { + var match, elem, ret, doc; + + // Handle $(""), $(null), or $(undefined) + if ( !selector ) { + return this; + } + + // Handle $(DOMElement) + if ( selector.nodeType ) { + this.context = this[0] = selector; + this.length = 1; + return this; + } + + // The body element only exists once, optimize finding it + if ( selector === "body" && !context && document.body ) { + this.context = document; + this[0] = document.body; + this.selector = selector; + this.length = 1; + return this; + } + + // Handle HTML strings + if ( typeof selector === "string" ) { + // Are we dealing with HTML string or an ID? + if ( selector.charAt(0) === "<" && selector.charAt( selector.length - 1 ) === ">" && selector.length >= 3 ) { + // Assume that strings that start and end with <> are HTML and skip the regex check + match = [ null, selector, null ]; + + } else { + match = quickExpr.exec( selector ); + } + + // Verify a match, and that no context was specified for #id + if ( match && (match[1] || !context) ) { + + // HANDLE: $(html) -> $(array) + if ( match[1] ) { + context = context instanceof jQuery ? context[0] : context; + doc = (context ? context.ownerDocument || context : document); + + // If a single string is passed in and it's a single tag + // just do a createElement and skip the rest + ret = rsingleTag.exec( selector ); + + if ( ret ) { + if ( jQuery.isPlainObject( context ) ) { + selector = [ document.createElement( ret[1] ) ]; + jQuery.fn.attr.call( selector, context, true ); + + } else { + selector = [ doc.createElement( ret[1] ) ]; + } + + } else { + ret = jQuery.buildFragment( [ match[1] ], [ doc ] ); + selector = (ret.cacheable ? jQuery.clone(ret.fragment) : ret.fragment).childNodes; + } + + return jQuery.merge( this, selector ); + + // HANDLE: $("#id") + } else { + elem = document.getElementById( match[2] ); + + // Check parentNode to catch when Blackberry 4.6 returns + // nodes that are no longer in the document #6963 + if ( elem && elem.parentNode ) { + // Handle the case where IE and Opera return items + // by name instead of ID + if ( elem.id !== match[2] ) { + return rootjQuery.find( selector ); + } + + // Otherwise, we inject the element directly into the jQuery object + this.length = 1; + this[0] = elem; + } + + this.context = document; + this.selector = selector; + return this; + } + + // HANDLE: $(expr, $(...)) + } else if ( !context || context.jquery ) { + return (context || rootjQuery).find( selector ); + + // HANDLE: $(expr, context) + // (which is just equivalent to: $(context).find(expr) + } else { + return this.constructor( context ).find( selector ); + } + + // HANDLE: $(function) + // Shortcut for document ready + } else if ( jQuery.isFunction( selector ) ) { + return rootjQuery.ready( selector ); + } + + if (selector.selector !== undefined) { + this.selector = selector.selector; + this.context = selector.context; + } + + return jQuery.makeArray( selector, this ); + }, + + // Start with an empty selector + selector: "", + + // The current version of jQuery being used + jquery: "1.6.4", + + // The default length of a jQuery object is 0 + length: 0, + + // The number of elements contained in the matched element set + size: function() { + return this.length; + }, + + toArray: function() { + return slice.call( this, 0 ); + }, + + // Get the Nth element in the matched element set OR + // Get the whole matched element set as a clean array + get: function( num ) { + return num == null ? + + // Return a 'clean' array + this.toArray() : + + // Return just the object + ( num < 0 ? this[ this.length + num ] : this[ num ] ); + }, + + // Take an array of elements and push it onto the stack + // (returning the new matched element set) + pushStack: function( elems, name, selector ) { + // Build a new jQuery matched element set + var ret = this.constructor(); + + if ( jQuery.isArray( elems ) ) { + push.apply( ret, elems ); + + } else { + jQuery.merge( ret, elems ); + } + + // Add the old object onto the stack (as a reference) + ret.prevObject = this; + + ret.context = this.context; + + if ( name === "find" ) { + ret.selector = this.selector + (this.selector ? " " : "") + selector; + } else if ( name ) { + ret.selector = this.selector + "." + name + "(" + selector + ")"; + } + + // Return the newly-formed element set + return ret; + }, + + // Execute a callback for every element in the matched set. + // (You can seed the arguments with an array of args, but this is + // only used internally.) + each: function( callback, args ) { + return jQuery.each( this, callback, args ); + }, + + ready: function( fn ) { + // Attach the listeners + jQuery.bindReady(); + + // Add the callback + readyList.done( fn ); + + return this; + }, + + eq: function( i ) { + return i === -1 ? + this.slice( i ) : + this.slice( i, +i + 1 ); + }, + + first: function() { + return this.eq( 0 ); + }, + + last: function() { + return this.eq( -1 ); + }, + + slice: function() { + return this.pushStack( slice.apply( this, arguments ), + "slice", slice.call(arguments).join(",") ); + }, + + map: function( callback ) { + return this.pushStack( jQuery.map(this, function( elem, i ) { + return callback.call( elem, i, elem ); + })); + }, + + end: function() { + return this.prevObject || this.constructor(null); + }, + + // For internal use only. + // Behaves like an Array's method, not like a jQuery method. + push: push, + sort: [].sort, + splice: [].splice +}; + +// Give the init function the jQuery prototype for later instantiation +jQuery.fn.init.prototype = jQuery.fn; + +jQuery.extend = jQuery.fn.extend = function() { + var options, name, src, copy, copyIsArray, clone, + target = arguments[0] || {}, + i = 1, + length = arguments.length, + deep = false; + + // Handle a deep copy situation + if ( typeof target === "boolean" ) { + deep = target; + target = arguments[1] || {}; + // skip the boolean and the target + i = 2; + } + + // Handle case when target is a string or something (possible in deep copy) + if ( typeof target !== "object" && !jQuery.isFunction(target) ) { + target = {}; + } + + // extend jQuery itself if only one argument is passed + if ( length === i ) { + target = this; + --i; + } + + for ( ; i < length; i++ ) { + // Only deal with non-null/undefined values + if ( (options = arguments[ i ]) != null ) { + // Extend the base object + for ( name in options ) { + src = target[ name ]; + copy = options[ name ]; + + // Prevent never-ending loop + if ( target === copy ) { + continue; + } + + // Recurse if we're merging plain objects or arrays + if ( deep && copy && ( jQuery.isPlainObject(copy) || (copyIsArray = jQuery.isArray(copy)) ) ) { + if ( copyIsArray ) { + copyIsArray = false; + clone = src && jQuery.isArray(src) ? src : []; + + } else { + clone = src && jQuery.isPlainObject(src) ? src : {}; + } + + // Never move original objects, clone them + target[ name ] = jQuery.extend( deep, clone, copy ); + + // Don't bring in undefined values + } else if ( copy !== undefined ) { + target[ name ] = copy; + } + } + } + } + + // Return the modified object + return target; +}; + +jQuery.extend({ + noConflict: function( deep ) { + if ( window.$ === jQuery ) { + window.$ = _$; + } + + if ( deep && window.jQuery === jQuery ) { + window.jQuery = _jQuery; + } + + return jQuery; + }, + + // Is the DOM ready to be used? Set to true once it occurs. + isReady: false, + + // A counter to track how many items to wait for before + // the ready event fires. See #6781 + readyWait: 1, + + // Hold (or release) the ready event + holdReady: function( hold ) { + if ( hold ) { + jQuery.readyWait++; + } else { + jQuery.ready( true ); + } + }, + + // Handle when the DOM is ready + ready: function( wait ) { + // Either a released hold or an DOMready/load event and not yet ready + if ( (wait === true && !--jQuery.readyWait) || (wait !== true && !jQuery.isReady) ) { + // Make sure body exists, at least, in case IE gets a little overzealous (ticket #5443). + if ( !document.body ) { + return setTimeout( jQuery.ready, 1 ); + } + + // Remember that the DOM is ready + jQuery.isReady = true; + + // If a normal DOM Ready event fired, decrement, and wait if need be + if ( wait !== true && --jQuery.readyWait > 0 ) { + return; + } + + // If there are functions bound, to execute + readyList.resolveWith( document, [ jQuery ] ); + + // Trigger any bound ready events + if ( jQuery.fn.trigger ) { + jQuery( document ).trigger( "ready" ).unbind( "ready" ); + } + } + }, + + bindReady: function() { + if ( readyList ) { + return; + } + + readyList = jQuery._Deferred(); + + // Catch cases where $(document).ready() is called after the + // browser event has already occurred. + if ( document.readyState === "complete" ) { + // Handle it asynchronously to allow scripts the opportunity to delay ready + return setTimeout( jQuery.ready, 1 ); + } + + // Mozilla, Opera and webkit nightlies currently support this event + if ( document.addEventListener ) { + // Use the handy event callback + document.addEventListener( "DOMContentLoaded", DOMContentLoaded, false ); + + // A fallback to window.onload, that will always work + window.addEventListener( "load", jQuery.ready, false ); + + // If IE event model is used + } else if ( document.attachEvent ) { + // ensure firing before onload, + // maybe late but safe also for iframes + document.attachEvent( "onreadystatechange", DOMContentLoaded ); + + // A fallback to window.onload, that will always work + window.attachEvent( "onload", jQuery.ready ); + + // If IE and not a frame + // continually check to see if the document is ready + var toplevel = false; + + try { + toplevel = window.frameElement == null; + } catch(e) {} + + if ( document.documentElement.doScroll && toplevel ) { + doScrollCheck(); + } + } + }, + + // See test/unit/core.js for details concerning isFunction. + // Since version 1.3, DOM methods and functions like alert + // aren't supported. They return false on IE (#2968). + isFunction: function( obj ) { + return jQuery.type(obj) === "function"; + }, + + isArray: Array.isArray || function( obj ) { + return jQuery.type(obj) === "array"; + }, + + // A crude way of determining if an object is a window + isWindow: function( obj ) { + return obj && typeof obj === "object" && "setInterval" in obj; + }, + + isNaN: function( obj ) { + return obj == null || !rdigit.test( obj ) || isNaN( obj ); + }, + + type: function( obj ) { + return obj == null ? + String( obj ) : + class2type[ toString.call(obj) ] || "object"; + }, + + isPlainObject: function( obj ) { + // Must be an Object. + // Because of IE, we also have to check the presence of the constructor property. + // Make sure that DOM nodes and window objects don't pass through, as well + if ( !obj || jQuery.type(obj) !== "object" || obj.nodeType || jQuery.isWindow( obj ) ) { + return false; + } + + try { + // Not own constructor property must be Object + if ( obj.constructor && + !hasOwn.call(obj, "constructor") && + !hasOwn.call(obj.constructor.prototype, "isPrototypeOf") ) { + return false; + } + } catch ( e ) { + // IE8,9 Will throw exceptions on certain host objects #9897 + return false; + } + + // Own properties are enumerated firstly, so to speed up, + // if last one is own, then all properties are own. + + var key; + for ( key in obj ) {} + + return key === undefined || hasOwn.call( obj, key ); + }, + + isEmptyObject: function( obj ) { + for ( var name in obj ) { + return false; + } + return true; + }, + + error: function( msg ) { + throw msg; + }, + + parseJSON: function( data ) { + if ( typeof data !== "string" || !data ) { + return null; + } + + // Make sure leading/trailing whitespace is removed (IE can't handle it) + data = jQuery.trim( data ); + + // Attempt to parse using the native JSON parser first + if ( window.JSON && window.JSON.parse ) { + return window.JSON.parse( data ); + } + + // Make sure the incoming data is actual JSON + // Logic borrowed from http://json.org/json2.js + if ( rvalidchars.test( data.replace( rvalidescape, "@" ) + .replace( rvalidtokens, "]" ) + .replace( rvalidbraces, "")) ) { + + return (new Function( "return " + data ))(); + + } + jQuery.error( "Invalid JSON: " + data ); + }, + + // Cross-browser xml parsing + parseXML: function( data ) { + var xml, tmp; + try { + if ( window.DOMParser ) { // Standard + tmp = new DOMParser(); + xml = tmp.parseFromString( data , "text/xml" ); + } else { // IE + xml = new ActiveXObject( "Microsoft.XMLDOM" ); + xml.async = "false"; + xml.loadXML( data ); + } + } catch( e ) { + xml = undefined; + } + if ( !xml || !xml.documentElement || xml.getElementsByTagName( "parsererror" ).length ) { + jQuery.error( "Invalid XML: " + data ); + } + return xml; + }, + + noop: function() {}, + + // Evaluates a script in a global context + // Workarounds based on findings by Jim Driscoll + // http://weblogs.java.net/blog/driscoll/archive/2009/09/08/eval-javascript-global-context + globalEval: function( data ) { + if ( data && rnotwhite.test( data ) ) { + // We use execScript on Internet Explorer + // We use an anonymous function so that context is window + // rather than jQuery in Firefox + ( window.execScript || function( data ) { + window[ "eval" ].call( window, data ); + } )( data ); + } + }, + + // Convert dashed to camelCase; used by the css and data modules + // Microsoft forgot to hump their vendor prefix (#9572) + camelCase: function( string ) { + return string.replace( rmsPrefix, "ms-" ).replace( rdashAlpha, fcamelCase ); + }, + + nodeName: function( elem, name ) { + return elem.nodeName && elem.nodeName.toUpperCase() === name.toUpperCase(); + }, + + // args is for internal usage only + each: function( object, callback, args ) { + var name, i = 0, + length = object.length, + isObj = length === undefined || jQuery.isFunction( object ); + + if ( args ) { + if ( isObj ) { + for ( name in object ) { + if ( callback.apply( object[ name ], args ) === false ) { + break; + } + } + } else { + for ( ; i < length; ) { + if ( callback.apply( object[ i++ ], args ) === false ) { + break; + } + } + } + + // A special, fast, case for the most common use of each + } else { + if ( isObj ) { + for ( name in object ) { + if ( callback.call( object[ name ], name, object[ name ] ) === false ) { + break; + } + } + } else { + for ( ; i < length; ) { + if ( callback.call( object[ i ], i, object[ i++ ] ) === false ) { + break; + } + } + } + } + + return object; + }, + + // Use native String.trim function wherever possible + trim: trim ? + function( text ) { + return text == null ? + "" : + trim.call( text ); + } : + + // Otherwise use our own trimming functionality + function( text ) { + return text == null ? + "" : + text.toString().replace( trimLeft, "" ).replace( trimRight, "" ); + }, + + // results is for internal usage only + makeArray: function( array, results ) { + var ret = results || []; + + if ( array != null ) { + // The window, strings (and functions) also have 'length' + // The extra typeof function check is to prevent crashes + // in Safari 2 (See: #3039) + // Tweaked logic slightly to handle Blackberry 4.7 RegExp issues #6930 + var type = jQuery.type( array ); + + if ( array.length == null || type === "string" || type === "function" || type === "regexp" || jQuery.isWindow( array ) ) { + push.call( ret, array ); + } else { + jQuery.merge( ret, array ); + } + } + + return ret; + }, + + inArray: function( elem, array ) { + if ( !array ) { + return -1; + } + + if ( indexOf ) { + return indexOf.call( array, elem ); + } + + for ( var i = 0, length = array.length; i < length; i++ ) { + if ( array[ i ] === elem ) { + return i; + } + } + + return -1; + }, + + merge: function( first, second ) { + var i = first.length, + j = 0; + + if ( typeof second.length === "number" ) { + for ( var l = second.length; j < l; j++ ) { + first[ i++ ] = second[ j ]; + } + + } else { + while ( second[j] !== undefined ) { + first[ i++ ] = second[ j++ ]; + } + } + + first.length = i; + + return first; + }, + + grep: function( elems, callback, inv ) { + var ret = [], retVal; + inv = !!inv; + + // Go through the array, only saving the items + // that pass the validator function + for ( var i = 0, length = elems.length; i < length; i++ ) { + retVal = !!callback( elems[ i ], i ); + if ( inv !== retVal ) { + ret.push( elems[ i ] ); + } + } + + return ret; + }, + + // arg is for internal usage only + map: function( elems, callback, arg ) { + var value, key, ret = [], + i = 0, + length = elems.length, + // jquery objects are treated as arrays + isArray = elems instanceof jQuery || length !== undefined && typeof length === "number" && ( ( length > 0 && elems[ 0 ] && elems[ length -1 ] ) || length === 0 || jQuery.isArray( elems ) ) ; + + // Go through the array, translating each of the items to their + if ( isArray ) { + for ( ; i < length; i++ ) { + value = callback( elems[ i ], i, arg ); + + if ( value != null ) { + ret[ ret.length ] = value; + } + } + + // Go through every key on the object, + } else { + for ( key in elems ) { + value = callback( elems[ key ], key, arg ); + + if ( value != null ) { + ret[ ret.length ] = value; + } + } + } + + // Flatten any nested arrays + return ret.concat.apply( [], ret ); + }, + + // A global GUID counter for objects + guid: 1, + + // Bind a function to a context, optionally partially applying any + // arguments. + proxy: function( fn, context ) { + if ( typeof context === "string" ) { + var tmp = fn[ context ]; + context = fn; + fn = tmp; + } + + // Quick check to determine if target is callable, in the spec + // this throws a TypeError, but we will just return undefined. + if ( !jQuery.isFunction( fn ) ) { + return undefined; + } + + // Simulated bind + var args = slice.call( arguments, 2 ), + proxy = function() { + return fn.apply( context, args.concat( slice.call( arguments ) ) ); + }; + + // Set the guid of unique handler to the same of original handler, so it can be removed + proxy.guid = fn.guid = fn.guid || proxy.guid || jQuery.guid++; + + return proxy; + }, + + // Mutifunctional method to get and set values to a collection + // The value/s can optionally be executed if it's a function + access: function( elems, key, value, exec, fn, pass ) { + var length = elems.length; + + // Setting many attributes + if ( typeof key === "object" ) { + for ( var k in key ) { + jQuery.access( elems, k, key[k], exec, fn, value ); + } + return elems; + } + + // Setting one attribute + if ( value !== undefined ) { + // Optionally, function values get executed if exec is true + exec = !pass && exec && jQuery.isFunction(value); + + for ( var i = 0; i < length; i++ ) { + fn( elems[i], key, exec ? value.call( elems[i], i, fn( elems[i], key ) ) : value, pass ); + } + + return elems; + } + + // Getting an attribute + return length ? fn( elems[0], key ) : undefined; + }, + + now: function() { + return (new Date()).getTime(); + }, + + // Use of jQuery.browser is frowned upon. + // More details: http://docs.jquery.com/Utilities/jQuery.browser + uaMatch: function( ua ) { + ua = ua.toLowerCase(); + + var match = rwebkit.exec( ua ) || + ropera.exec( ua ) || + rmsie.exec( ua ) || + ua.indexOf("compatible") < 0 && rmozilla.exec( ua ) || + []; + + return { browser: match[1] || "", version: match[2] || "0" }; + }, + + sub: function() { + function jQuerySub( selector, context ) { + return new jQuerySub.fn.init( selector, context ); + } + jQuery.extend( true, jQuerySub, this ); + jQuerySub.superclass = this; + jQuerySub.fn = jQuerySub.prototype = this(); + jQuerySub.fn.constructor = jQuerySub; + jQuerySub.sub = this.sub; + jQuerySub.fn.init = function init( selector, context ) { + if ( context && context instanceof jQuery && !(context instanceof jQuerySub) ) { + context = jQuerySub( context ); + } + + return jQuery.fn.init.call( this, selector, context, rootjQuerySub ); + }; + jQuerySub.fn.init.prototype = jQuerySub.fn; + var rootjQuerySub = jQuerySub(document); + return jQuerySub; + }, + + browser: {} +}); + +// Populate the class2type map +jQuery.each("Boolean Number String Function Array Date RegExp Object".split(" "), function(i, name) { + class2type[ "[object " + name + "]" ] = name.toLowerCase(); +}); + +browserMatch = jQuery.uaMatch( userAgent ); +if ( browserMatch.browser ) { + jQuery.browser[ browserMatch.browser ] = true; + jQuery.browser.version = browserMatch.version; +} + +// Deprecated, use jQuery.browser.webkit instead +if ( jQuery.browser.webkit ) { + jQuery.browser.safari = true; +} + +// IE doesn't match non-breaking spaces with \s +if ( rnotwhite.test( "\xA0" ) ) { + trimLeft = /^[\s\xA0]+/; + trimRight = /[\s\xA0]+$/; +} + +// All jQuery objects should point back to these +rootjQuery = jQuery(document); + +// Cleanup functions for the document ready method +if ( document.addEventListener ) { + DOMContentLoaded = function() { + document.removeEventListener( "DOMContentLoaded", DOMContentLoaded, false ); + jQuery.ready(); + }; + +} else if ( document.attachEvent ) { + DOMContentLoaded = function() { + // Make sure body exists, at least, in case IE gets a little overzealous (ticket #5443). + if ( document.readyState === "complete" ) { + document.detachEvent( "onreadystatechange", DOMContentLoaded ); + jQuery.ready(); + } + }; +} + +// The DOM ready check for Internet Explorer +function doScrollCheck() { + if ( jQuery.isReady ) { + return; + } + + try { + // If IE is used, use the trick by Diego Perini + // http://javascript.nwbox.com/IEContentLoaded/ + document.documentElement.doScroll("left"); + } catch(e) { + setTimeout( doScrollCheck, 1 ); + return; + } + + // and execute any waiting functions + jQuery.ready(); +} + +return jQuery; + +})(); + + +var // Promise methods + promiseMethods = "done fail isResolved isRejected promise then always pipe".split( " " ), + // Static reference to slice + sliceDeferred = [].slice; + +jQuery.extend({ + // Create a simple deferred (one callbacks list) + _Deferred: function() { + var // callbacks list + callbacks = [], + // stored [ context , args ] + fired, + // to avoid firing when already doing so + firing, + // flag to know if the deferred has been cancelled + cancelled, + // the deferred itself + deferred = { + + // done( f1, f2, ...) + done: function() { + if ( !cancelled ) { + var args = arguments, + i, + length, + elem, + type, + _fired; + if ( fired ) { + _fired = fired; + fired = 0; + } + for ( i = 0, length = args.length; i < length; i++ ) { + elem = args[ i ]; + type = jQuery.type( elem ); + if ( type === "array" ) { + deferred.done.apply( deferred, elem ); + } else if ( type === "function" ) { + callbacks.push( elem ); + } + } + if ( _fired ) { + deferred.resolveWith( _fired[ 0 ], _fired[ 1 ] ); + } + } + return this; + }, + + // resolve with given context and args + resolveWith: function( context, args ) { + if ( !cancelled && !fired && !firing ) { + // make sure args are available (#8421) + args = args || []; + firing = 1; + try { + while( callbacks[ 0 ] ) { + callbacks.shift().apply( context, args ); + } + } + finally { + fired = [ context, args ]; + firing = 0; + } + } + return this; + }, + + // resolve with this as context and given arguments + resolve: function() { + deferred.resolveWith( this, arguments ); + return this; + }, + + // Has this deferred been resolved? + isResolved: function() { + return !!( firing || fired ); + }, + + // Cancel + cancel: function() { + cancelled = 1; + callbacks = []; + return this; + } + }; + + return deferred; + }, + + // Full fledged deferred (two callbacks list) + Deferred: function( func ) { + var deferred = jQuery._Deferred(), + failDeferred = jQuery._Deferred(), + promise; + // Add errorDeferred methods, then and promise + jQuery.extend( deferred, { + then: function( doneCallbacks, failCallbacks ) { + deferred.done( doneCallbacks ).fail( failCallbacks ); + return this; + }, + always: function() { + return deferred.done.apply( deferred, arguments ).fail.apply( this, arguments ); + }, + fail: failDeferred.done, + rejectWith: failDeferred.resolveWith, + reject: failDeferred.resolve, + isRejected: failDeferred.isResolved, + pipe: function( fnDone, fnFail ) { + return jQuery.Deferred(function( newDefer ) { + jQuery.each( { + done: [ fnDone, "resolve" ], + fail: [ fnFail, "reject" ] + }, function( handler, data ) { + var fn = data[ 0 ], + action = data[ 1 ], + returned; + if ( jQuery.isFunction( fn ) ) { + deferred[ handler ](function() { + returned = fn.apply( this, arguments ); + if ( returned && jQuery.isFunction( returned.promise ) ) { + returned.promise().then( newDefer.resolve, newDefer.reject ); + } else { + newDefer[ action + "With" ]( this === deferred ? newDefer : this, [ returned ] ); + } + }); + } else { + deferred[ handler ]( newDefer[ action ] ); + } + }); + }).promise(); + }, + // Get a promise for this deferred + // If obj is provided, the promise aspect is added to the object + promise: function( obj ) { + if ( obj == null ) { + if ( promise ) { + return promise; + } + promise = obj = {}; + } + var i = promiseMethods.length; + while( i-- ) { + obj[ promiseMethods[i] ] = deferred[ promiseMethods[i] ]; + } + return obj; + } + }); + // Make sure only one callback list will be used + deferred.done( failDeferred.cancel ).fail( deferred.cancel ); + // Unexpose cancel + delete deferred.cancel; + // Call given func if any + if ( func ) { + func.call( deferred, deferred ); + } + return deferred; + }, + + // Deferred helper + when: function( firstParam ) { + var args = arguments, + i = 0, + length = args.length, + count = length, + deferred = length <= 1 && firstParam && jQuery.isFunction( firstParam.promise ) ? + firstParam : + jQuery.Deferred(); + function resolveFunc( i ) { + return function( value ) { + args[ i ] = arguments.length > 1 ? sliceDeferred.call( arguments, 0 ) : value; + if ( !( --count ) ) { + // Strange bug in FF4: + // Values changed onto the arguments object sometimes end up as undefined values + // outside the $.when method. Cloning the object into a fresh array solves the issue + deferred.resolveWith( deferred, sliceDeferred.call( args, 0 ) ); + } + }; + } + if ( length > 1 ) { + for( ; i < length; i++ ) { + if ( args[ i ] && jQuery.isFunction( args[ i ].promise ) ) { + args[ i ].promise().then( resolveFunc(i), deferred.reject ); + } else { + --count; + } + } + if ( !count ) { + deferred.resolveWith( deferred, args ); + } + } else if ( deferred !== firstParam ) { + deferred.resolveWith( deferred, length ? [ firstParam ] : [] ); + } + return deferred.promise(); + } +}); + + + +jQuery.support = (function() { + + var div = document.createElement( "div" ), + documentElement = document.documentElement, + all, + a, + select, + opt, + input, + marginDiv, + support, + fragment, + body, + testElementParent, + testElement, + testElementStyle, + tds, + events, + eventName, + i, + isSupported; + + // Preliminary tests + div.setAttribute("className", "t"); + div.innerHTML = "
    a"; + + + all = div.getElementsByTagName( "*" ); + a = div.getElementsByTagName( "a" )[ 0 ]; + + // Can't get basic test support + if ( !all || !all.length || !a ) { + return {}; + } + + // First batch of supports tests + select = document.createElement( "select" ); + opt = select.appendChild( document.createElement("option") ); + input = div.getElementsByTagName( "input" )[ 0 ]; + + support = { + // IE strips leading whitespace when .innerHTML is used + leadingWhitespace: ( div.firstChild.nodeType === 3 ), + + // Make sure that tbody elements aren't automatically inserted + // IE will insert them into empty tables + tbody: !div.getElementsByTagName( "tbody" ).length, + + // Make sure that link elements get serialized correctly by innerHTML + // This requires a wrapper element in IE + htmlSerialize: !!div.getElementsByTagName( "link" ).length, + + // Get the style information from getAttribute + // (IE uses .cssText instead) + style: /top/.test( a.getAttribute("style") ), + + // Make sure that URLs aren't manipulated + // (IE normalizes it by default) + hrefNormalized: ( a.getAttribute( "href" ) === "/a" ), + + // Make sure that element opacity exists + // (IE uses filter instead) + // Use a regex to work around a WebKit issue. See #5145 + opacity: /^0.55$/.test( a.style.opacity ), + + // Verify style float existence + // (IE uses styleFloat instead of cssFloat) + cssFloat: !!a.style.cssFloat, + + // Make sure that if no value is specified for a checkbox + // that it defaults to "on". + // (WebKit defaults to "" instead) + checkOn: ( input.value === "on" ), + + // Make sure that a selected-by-default option has a working selected property. + // (WebKit defaults to false instead of true, IE too, if it's in an optgroup) + optSelected: opt.selected, + + // Test setAttribute on camelCase class. If it works, we need attrFixes when doing get/setAttribute (ie6/7) + getSetAttribute: div.className !== "t", + + // Will be defined later + submitBubbles: true, + changeBubbles: true, + focusinBubbles: false, + deleteExpando: true, + noCloneEvent: true, + inlineBlockNeedsLayout: false, + shrinkWrapBlocks: false, + reliableMarginRight: true + }; + + // Make sure checked status is properly cloned + input.checked = true; + support.noCloneChecked = input.cloneNode( true ).checked; + + // Make sure that the options inside disabled selects aren't marked as disabled + // (WebKit marks them as disabled) + select.disabled = true; + support.optDisabled = !opt.disabled; + + // Test to see if it's possible to delete an expando from an element + // Fails in Internet Explorer + try { + delete div.test; + } catch( e ) { + support.deleteExpando = false; + } + + if ( !div.addEventListener && div.attachEvent && div.fireEvent ) { + div.attachEvent( "onclick", function() { + // Cloning a node shouldn't copy over any + // bound event handlers (IE does this) + support.noCloneEvent = false; + }); + div.cloneNode( true ).fireEvent( "onclick" ); + } + + // Check if a radio maintains it's value + // after being appended to the DOM + input = document.createElement("input"); + input.value = "t"; + input.setAttribute("type", "radio"); + support.radioValue = input.value === "t"; + + input.setAttribute("checked", "checked"); + div.appendChild( input ); + fragment = document.createDocumentFragment(); + fragment.appendChild( div.firstChild ); + + // WebKit doesn't clone checked state correctly in fragments + support.checkClone = fragment.cloneNode( true ).cloneNode( true ).lastChild.checked; + + div.innerHTML = ""; + + // Figure out if the W3C box model works as expected + div.style.width = div.style.paddingLeft = "1px"; + + body = document.getElementsByTagName( "body" )[ 0 ]; + // We use our own, invisible, body unless the body is already present + // in which case we use a div (#9239) + testElement = document.createElement( body ? "div" : "body" ); + testElementStyle = { + visibility: "hidden", + width: 0, + height: 0, + border: 0, + margin: 0, + background: "none" + }; + if ( body ) { + jQuery.extend( testElementStyle, { + position: "absolute", + left: "-1000px", + top: "-1000px" + }); + } + for ( i in testElementStyle ) { + testElement.style[ i ] = testElementStyle[ i ]; + } + testElement.appendChild( div ); + testElementParent = body || documentElement; + testElementParent.insertBefore( testElement, testElementParent.firstChild ); + + // Check if a disconnected checkbox will retain its checked + // value of true after appended to the DOM (IE6/7) + support.appendChecked = input.checked; + + support.boxModel = div.offsetWidth === 2; + + if ( "zoom" in div.style ) { + // Check if natively block-level elements act like inline-block + // elements when setting their display to 'inline' and giving + // them layout + // (IE < 8 does this) + div.style.display = "inline"; + div.style.zoom = 1; + support.inlineBlockNeedsLayout = ( div.offsetWidth === 2 ); + + // Check if elements with layout shrink-wrap their children + // (IE 6 does this) + div.style.display = ""; + div.innerHTML = "
    "; + support.shrinkWrapBlocks = ( div.offsetWidth !== 2 ); + } + + div.innerHTML = "
    t
    "; + tds = div.getElementsByTagName( "td" ); + + // Check if table cells still have offsetWidth/Height when they are set + // to display:none and there are still other visible table cells in a + // table row; if so, offsetWidth/Height are not reliable for use when + // determining if an element has been hidden directly using + // display:none (it is still safe to use offsets if a parent element is + // hidden; don safety goggles and see bug #4512 for more information). + // (only IE 8 fails this test) + isSupported = ( tds[ 0 ].offsetHeight === 0 ); + + tds[ 0 ].style.display = ""; + tds[ 1 ].style.display = "none"; + + // Check if empty table cells still have offsetWidth/Height + // (IE < 8 fail this test) + support.reliableHiddenOffsets = isSupported && ( tds[ 0 ].offsetHeight === 0 ); + div.innerHTML = ""; + + // Check if div with explicit width and no margin-right incorrectly + // gets computed margin-right based on width of container. For more + // info see bug #3333 + // Fails in WebKit before Feb 2011 nightlies + // WebKit Bug 13343 - getComputedStyle returns wrong value for margin-right + if ( document.defaultView && document.defaultView.getComputedStyle ) { + marginDiv = document.createElement( "div" ); + marginDiv.style.width = "0"; + marginDiv.style.marginRight = "0"; + div.appendChild( marginDiv ); + support.reliableMarginRight = + ( parseInt( ( document.defaultView.getComputedStyle( marginDiv, null ) || { marginRight: 0 } ).marginRight, 10 ) || 0 ) === 0; + } + + // Remove the body element we added + testElement.innerHTML = ""; + testElementParent.removeChild( testElement ); + + // Technique from Juriy Zaytsev + // http://thinkweb2.com/projects/prototype/detecting-event-support-without-browser-sniffing/ + // We only care about the case where non-standard event systems + // are used, namely in IE. Short-circuiting here helps us to + // avoid an eval call (in setAttribute) which can cause CSP + // to go haywire. See: https://developer.mozilla.org/en/Security/CSP + if ( div.attachEvent ) { + for( i in { + submit: 1, + change: 1, + focusin: 1 + } ) { + eventName = "on" + i; + isSupported = ( eventName in div ); + if ( !isSupported ) { + div.setAttribute( eventName, "return;" ); + isSupported = ( typeof div[ eventName ] === "function" ); + } + support[ i + "Bubbles" ] = isSupported; + } + } + + // Null connected elements to avoid leaks in IE + testElement = fragment = select = opt = body = marginDiv = div = input = null; + + return support; +})(); + +// Keep track of boxModel +jQuery.boxModel = jQuery.support.boxModel; + + + + +var rbrace = /^(?:\{.*\}|\[.*\])$/, + rmultiDash = /([A-Z])/g; + +jQuery.extend({ + cache: {}, + + // Please use with caution + uuid: 0, + + // Unique for each copy of jQuery on the page + // Non-digits removed to match rinlinejQuery + expando: "jQuery" + ( jQuery.fn.jquery + Math.random() ).replace( /\D/g, "" ), + + // The following elements throw uncatchable exceptions if you + // attempt to add expando properties to them. + noData: { + "embed": true, + // Ban all objects except for Flash (which handle expandos) + "object": "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000", + "applet": true + }, + + hasData: function( elem ) { + elem = elem.nodeType ? jQuery.cache[ elem[jQuery.expando] ] : elem[ jQuery.expando ]; + + return !!elem && !isEmptyDataObject( elem ); + }, + + data: function( elem, name, data, pvt /* Internal Use Only */ ) { + if ( !jQuery.acceptData( elem ) ) { + return; + } + + var thisCache, ret, + internalKey = jQuery.expando, + getByName = typeof name === "string", + + // We have to handle DOM nodes and JS objects differently because IE6-7 + // can't GC object references properly across the DOM-JS boundary + isNode = elem.nodeType, + + // Only DOM nodes need the global jQuery cache; JS object data is + // attached directly to the object so GC can occur automatically + cache = isNode ? jQuery.cache : elem, + + // Only defining an ID for JS objects if its cache already exists allows + // the code to shortcut on the same path as a DOM node with no cache + id = isNode ? elem[ jQuery.expando ] : elem[ jQuery.expando ] && jQuery.expando; + + // Avoid doing any more work than we need to when trying to get data on an + // object that has no data at all + if ( (!id || (pvt && id && (cache[ id ] && !cache[ id ][ internalKey ]))) && getByName && data === undefined ) { + return; + } + + if ( !id ) { + // Only DOM nodes need a new unique ID for each element since their data + // ends up in the global cache + if ( isNode ) { + elem[ jQuery.expando ] = id = ++jQuery.uuid; + } else { + id = jQuery.expando; + } + } + + if ( !cache[ id ] ) { + cache[ id ] = {}; + + // TODO: This is a hack for 1.5 ONLY. Avoids exposing jQuery + // metadata on plain JS objects when the object is serialized using + // JSON.stringify + if ( !isNode ) { + cache[ id ].toJSON = jQuery.noop; + } + } + + // An object can be passed to jQuery.data instead of a key/value pair; this gets + // shallow copied over onto the existing cache + if ( typeof name === "object" || typeof name === "function" ) { + if ( pvt ) { + cache[ id ][ internalKey ] = jQuery.extend(cache[ id ][ internalKey ], name); + } else { + cache[ id ] = jQuery.extend(cache[ id ], name); + } + } + + thisCache = cache[ id ]; + + // Internal jQuery data is stored in a separate object inside the object's data + // cache in order to avoid key collisions between internal data and user-defined + // data + if ( pvt ) { + if ( !thisCache[ internalKey ] ) { + thisCache[ internalKey ] = {}; + } + + thisCache = thisCache[ internalKey ]; + } + + if ( data !== undefined ) { + thisCache[ jQuery.camelCase( name ) ] = data; + } + + // TODO: This is a hack for 1.5 ONLY. It will be removed in 1.6. Users should + // not attempt to inspect the internal events object using jQuery.data, as this + // internal data object is undocumented and subject to change. + if ( name === "events" && !thisCache[name] ) { + return thisCache[ internalKey ] && thisCache[ internalKey ].events; + } + + // Check for both converted-to-camel and non-converted data property names + // If a data property was specified + if ( getByName ) { + + // First Try to find as-is property data + ret = thisCache[ name ]; + + // Test for null|undefined property data + if ( ret == null ) { + + // Try to find the camelCased property + ret = thisCache[ jQuery.camelCase( name ) ]; + } + } else { + ret = thisCache; + } + + return ret; + }, + + removeData: function( elem, name, pvt /* Internal Use Only */ ) { + if ( !jQuery.acceptData( elem ) ) { + return; + } + + var thisCache, + + // Reference to internal data cache key + internalKey = jQuery.expando, + + isNode = elem.nodeType, + + // See jQuery.data for more information + cache = isNode ? jQuery.cache : elem, + + // See jQuery.data for more information + id = isNode ? elem[ jQuery.expando ] : jQuery.expando; + + // If there is already no cache entry for this object, there is no + // purpose in continuing + if ( !cache[ id ] ) { + return; + } + + if ( name ) { + + thisCache = pvt ? cache[ id ][ internalKey ] : cache[ id ]; + + if ( thisCache ) { + + // Support interoperable removal of hyphenated or camelcased keys + if ( !thisCache[ name ] ) { + name = jQuery.camelCase( name ); + } + + delete thisCache[ name ]; + + // If there is no data left in the cache, we want to continue + // and let the cache object itself get destroyed + if ( !isEmptyDataObject(thisCache) ) { + return; + } + } + } + + // See jQuery.data for more information + if ( pvt ) { + delete cache[ id ][ internalKey ]; + + // Don't destroy the parent cache unless the internal data object + // had been the only thing left in it + if ( !isEmptyDataObject(cache[ id ]) ) { + return; + } + } + + var internalCache = cache[ id ][ internalKey ]; + + // Browsers that fail expando deletion also refuse to delete expandos on + // the window, but it will allow it on all other JS objects; other browsers + // don't care + // Ensure that `cache` is not a window object #10080 + if ( jQuery.support.deleteExpando || !cache.setInterval ) { + delete cache[ id ]; + } else { + cache[ id ] = null; + } + + // We destroyed the entire user cache at once because it's faster than + // iterating through each key, but we need to continue to persist internal + // data if it existed + if ( internalCache ) { + cache[ id ] = {}; + // TODO: This is a hack for 1.5 ONLY. Avoids exposing jQuery + // metadata on plain JS objects when the object is serialized using + // JSON.stringify + if ( !isNode ) { + cache[ id ].toJSON = jQuery.noop; + } + + cache[ id ][ internalKey ] = internalCache; + + // Otherwise, we need to eliminate the expando on the node to avoid + // false lookups in the cache for entries that no longer exist + } else if ( isNode ) { + // IE does not allow us to delete expando properties from nodes, + // nor does it have a removeAttribute function on Document nodes; + // we must handle all of these cases + if ( jQuery.support.deleteExpando ) { + delete elem[ jQuery.expando ]; + } else if ( elem.removeAttribute ) { + elem.removeAttribute( jQuery.expando ); + } else { + elem[ jQuery.expando ] = null; + } + } + }, + + // For internal use only. + _data: function( elem, name, data ) { + return jQuery.data( elem, name, data, true ); + }, + + // A method for determining if a DOM node can handle the data expando + acceptData: function( elem ) { + if ( elem.nodeName ) { + var match = jQuery.noData[ elem.nodeName.toLowerCase() ]; + + if ( match ) { + return !(match === true || elem.getAttribute("classid") !== match); + } + } + + return true; + } +}); + +jQuery.fn.extend({ + data: function( key, value ) { + var data = null; + + if ( typeof key === "undefined" ) { + if ( this.length ) { + data = jQuery.data( this[0] ); + + if ( this[0].nodeType === 1 ) { + var attr = this[0].attributes, name; + for ( var i = 0, l = attr.length; i < l; i++ ) { + name = attr[i].name; + + if ( name.indexOf( "data-" ) === 0 ) { + name = jQuery.camelCase( name.substring(5) ); + + dataAttr( this[0], name, data[ name ] ); + } + } + } + } + + return data; + + } else if ( typeof key === "object" ) { + return this.each(function() { + jQuery.data( this, key ); + }); + } + + var parts = key.split("."); + parts[1] = parts[1] ? "." + parts[1] : ""; + + if ( value === undefined ) { + data = this.triggerHandler("getData" + parts[1] + "!", [parts[0]]); + + // Try to fetch any internally stored data first + if ( data === undefined && this.length ) { + data = jQuery.data( this[0], key ); + data = dataAttr( this[0], key, data ); + } + + return data === undefined && parts[1] ? + this.data( parts[0] ) : + data; + + } else { + return this.each(function() { + var $this = jQuery( this ), + args = [ parts[0], value ]; + + $this.triggerHandler( "setData" + parts[1] + "!", args ); + jQuery.data( this, key, value ); + $this.triggerHandler( "changeData" + parts[1] + "!", args ); + }); + } + }, + + removeData: function( key ) { + return this.each(function() { + jQuery.removeData( this, key ); + }); + } +}); + +function dataAttr( elem, key, data ) { + // If nothing was found internally, try to fetch any + // data from the HTML5 data-* attribute + if ( data === undefined && elem.nodeType === 1 ) { + + var name = "data-" + key.replace( rmultiDash, "-$1" ).toLowerCase(); + + data = elem.getAttribute( name ); + + if ( typeof data === "string" ) { + try { + data = data === "true" ? true : + data === "false" ? false : + data === "null" ? null : + !jQuery.isNaN( data ) ? parseFloat( data ) : + rbrace.test( data ) ? jQuery.parseJSON( data ) : + data; + } catch( e ) {} + + // Make sure we set the data so it isn't changed later + jQuery.data( elem, key, data ); + + } else { + data = undefined; + } + } + + return data; +} + +// TODO: This is a hack for 1.5 ONLY to allow objects with a single toJSON +// property to be considered empty objects; this property always exists in +// order to make sure JSON.stringify does not expose internal metadata +function isEmptyDataObject( obj ) { + for ( var name in obj ) { + if ( name !== "toJSON" ) { + return false; + } + } + + return true; +} + + + + +function handleQueueMarkDefer( elem, type, src ) { + var deferDataKey = type + "defer", + queueDataKey = type + "queue", + markDataKey = type + "mark", + defer = jQuery.data( elem, deferDataKey, undefined, true ); + if ( defer && + ( src === "queue" || !jQuery.data( elem, queueDataKey, undefined, true ) ) && + ( src === "mark" || !jQuery.data( elem, markDataKey, undefined, true ) ) ) { + // Give room for hard-coded callbacks to fire first + // and eventually mark/queue something else on the element + setTimeout( function() { + if ( !jQuery.data( elem, queueDataKey, undefined, true ) && + !jQuery.data( elem, markDataKey, undefined, true ) ) { + jQuery.removeData( elem, deferDataKey, true ); + defer.resolve(); + } + }, 0 ); + } +} + +jQuery.extend({ + + _mark: function( elem, type ) { + if ( elem ) { + type = (type || "fx") + "mark"; + jQuery.data( elem, type, (jQuery.data(elem,type,undefined,true) || 0) + 1, true ); + } + }, + + _unmark: function( force, elem, type ) { + if ( force !== true ) { + type = elem; + elem = force; + force = false; + } + if ( elem ) { + type = type || "fx"; + var key = type + "mark", + count = force ? 0 : ( (jQuery.data( elem, key, undefined, true) || 1 ) - 1 ); + if ( count ) { + jQuery.data( elem, key, count, true ); + } else { + jQuery.removeData( elem, key, true ); + handleQueueMarkDefer( elem, type, "mark" ); + } + } + }, + + queue: function( elem, type, data ) { + if ( elem ) { + type = (type || "fx") + "queue"; + var q = jQuery.data( elem, type, undefined, true ); + // Speed up dequeue by getting out quickly if this is just a lookup + if ( data ) { + if ( !q || jQuery.isArray(data) ) { + q = jQuery.data( elem, type, jQuery.makeArray(data), true ); + } else { + q.push( data ); + } + } + return q || []; + } + }, + + dequeue: function( elem, type ) { + type = type || "fx"; + + var queue = jQuery.queue( elem, type ), + fn = queue.shift(), + defer; + + // If the fx queue is dequeued, always remove the progress sentinel + if ( fn === "inprogress" ) { + fn = queue.shift(); + } + + if ( fn ) { + // Add a progress sentinel to prevent the fx queue from being + // automatically dequeued + if ( type === "fx" ) { + queue.unshift("inprogress"); + } + + fn.call(elem, function() { + jQuery.dequeue(elem, type); + }); + } + + if ( !queue.length ) { + jQuery.removeData( elem, type + "queue", true ); + handleQueueMarkDefer( elem, type, "queue" ); + } + } +}); + +jQuery.fn.extend({ + queue: function( type, data ) { + if ( typeof type !== "string" ) { + data = type; + type = "fx"; + } + + if ( data === undefined ) { + return jQuery.queue( this[0], type ); + } + return this.each(function() { + var queue = jQuery.queue( this, type, data ); + + if ( type === "fx" && queue[0] !== "inprogress" ) { + jQuery.dequeue( this, type ); + } + }); + }, + dequeue: function( type ) { + return this.each(function() { + jQuery.dequeue( this, type ); + }); + }, + // Based off of the plugin by Clint Helfers, with permission. + // http://blindsignals.com/index.php/2009/07/jquery-delay/ + delay: function( time, type ) { + time = jQuery.fx ? jQuery.fx.speeds[time] || time : time; + type = type || "fx"; + + return this.queue( type, function() { + var elem = this; + setTimeout(function() { + jQuery.dequeue( elem, type ); + }, time ); + }); + }, + clearQueue: function( type ) { + return this.queue( type || "fx", [] ); + }, + // Get a promise resolved when queues of a certain type + // are emptied (fx is the type by default) + promise: function( type, object ) { + if ( typeof type !== "string" ) { + object = type; + type = undefined; + } + type = type || "fx"; + var defer = jQuery.Deferred(), + elements = this, + i = elements.length, + count = 1, + deferDataKey = type + "defer", + queueDataKey = type + "queue", + markDataKey = type + "mark", + tmp; + function resolve() { + if ( !( --count ) ) { + defer.resolveWith( elements, [ elements ] ); + } + } + while( i-- ) { + if (( tmp = jQuery.data( elements[ i ], deferDataKey, undefined, true ) || + ( jQuery.data( elements[ i ], queueDataKey, undefined, true ) || + jQuery.data( elements[ i ], markDataKey, undefined, true ) ) && + jQuery.data( elements[ i ], deferDataKey, jQuery._Deferred(), true ) )) { + count++; + tmp.done( resolve ); + } + } + resolve(); + return defer.promise(); + } +}); + + + + +var rclass = /[\n\t\r]/g, + rspace = /\s+/, + rreturn = /\r/g, + rtype = /^(?:button|input)$/i, + rfocusable = /^(?:button|input|object|select|textarea)$/i, + rclickable = /^a(?:rea)?$/i, + rboolean = /^(?:autofocus|autoplay|async|checked|controls|defer|disabled|hidden|loop|multiple|open|readonly|required|scoped|selected)$/i, + nodeHook, boolHook; + +jQuery.fn.extend({ + attr: function( name, value ) { + return jQuery.access( this, name, value, true, jQuery.attr ); + }, + + removeAttr: function( name ) { + return this.each(function() { + jQuery.removeAttr( this, name ); + }); + }, + + prop: function( name, value ) { + return jQuery.access( this, name, value, true, jQuery.prop ); + }, + + removeProp: function( name ) { + name = jQuery.propFix[ name ] || name; + return this.each(function() { + // try/catch handles cases where IE balks (such as removing a property on window) + try { + this[ name ] = undefined; + delete this[ name ]; + } catch( e ) {} + }); + }, + + addClass: function( value ) { + var classNames, i, l, elem, + setClass, c, cl; + + if ( jQuery.isFunction( value ) ) { + return this.each(function( j ) { + jQuery( this ).addClass( value.call(this, j, this.className) ); + }); + } + + if ( value && typeof value === "string" ) { + classNames = value.split( rspace ); + + for ( i = 0, l = this.length; i < l; i++ ) { + elem = this[ i ]; + + if ( elem.nodeType === 1 ) { + if ( !elem.className && classNames.length === 1 ) { + elem.className = value; + + } else { + setClass = " " + elem.className + " "; + + for ( c = 0, cl = classNames.length; c < cl; c++ ) { + if ( !~setClass.indexOf( " " + classNames[ c ] + " " ) ) { + setClass += classNames[ c ] + " "; + } + } + elem.className = jQuery.trim( setClass ); + } + } + } + } + + return this; + }, + + removeClass: function( value ) { + var classNames, i, l, elem, className, c, cl; + + if ( jQuery.isFunction( value ) ) { + return this.each(function( j ) { + jQuery( this ).removeClass( value.call(this, j, this.className) ); + }); + } + + if ( (value && typeof value === "string") || value === undefined ) { + classNames = (value || "").split( rspace ); + + for ( i = 0, l = this.length; i < l; i++ ) { + elem = this[ i ]; + + if ( elem.nodeType === 1 && elem.className ) { + if ( value ) { + className = (" " + elem.className + " ").replace( rclass, " " ); + for ( c = 0, cl = classNames.length; c < cl; c++ ) { + className = className.replace(" " + classNames[ c ] + " ", " "); + } + elem.className = jQuery.trim( className ); + + } else { + elem.className = ""; + } + } + } + } + + return this; + }, + + toggleClass: function( value, stateVal ) { + var type = typeof value, + isBool = typeof stateVal === "boolean"; + + if ( jQuery.isFunction( value ) ) { + return this.each(function( i ) { + jQuery( this ).toggleClass( value.call(this, i, this.className, stateVal), stateVal ); + }); + } + + return this.each(function() { + if ( type === "string" ) { + // toggle individual class names + var className, + i = 0, + self = jQuery( this ), + state = stateVal, + classNames = value.split( rspace ); + + while ( (className = classNames[ i++ ]) ) { + // check each className given, space seperated list + state = isBool ? state : !self.hasClass( className ); + self[ state ? "addClass" : "removeClass" ]( className ); + } + + } else if ( type === "undefined" || type === "boolean" ) { + if ( this.className ) { + // store className if set + jQuery._data( this, "__className__", this.className ); + } + + // toggle whole className + this.className = this.className || value === false ? "" : jQuery._data( this, "__className__" ) || ""; + } + }); + }, + + hasClass: function( selector ) { + var className = " " + selector + " "; + for ( var i = 0, l = this.length; i < l; i++ ) { + if ( this[i].nodeType === 1 && (" " + this[i].className + " ").replace(rclass, " ").indexOf( className ) > -1 ) { + return true; + } + } + + return false; + }, + + val: function( value ) { + var hooks, ret, + elem = this[0]; + + if ( !arguments.length ) { + if ( elem ) { + hooks = jQuery.valHooks[ elem.nodeName.toLowerCase() ] || jQuery.valHooks[ elem.type ]; + + if ( hooks && "get" in hooks && (ret = hooks.get( elem, "value" )) !== undefined ) { + return ret; + } + + ret = elem.value; + + return typeof ret === "string" ? + // handle most common string cases + ret.replace(rreturn, "") : + // handle cases where value is null/undef or number + ret == null ? "" : ret; + } + + return undefined; + } + + var isFunction = jQuery.isFunction( value ); + + return this.each(function( i ) { + var self = jQuery(this), val; + + if ( this.nodeType !== 1 ) { + return; + } + + if ( isFunction ) { + val = value.call( this, i, self.val() ); + } else { + val = value; + } + + // Treat null/undefined as ""; convert numbers to string + if ( val == null ) { + val = ""; + } else if ( typeof val === "number" ) { + val += ""; + } else if ( jQuery.isArray( val ) ) { + val = jQuery.map(val, function ( value ) { + return value == null ? "" : value + ""; + }); + } + + hooks = jQuery.valHooks[ this.nodeName.toLowerCase() ] || jQuery.valHooks[ this.type ]; + + // If set returns undefined, fall back to normal setting + if ( !hooks || !("set" in hooks) || hooks.set( this, val, "value" ) === undefined ) { + this.value = val; + } + }); + } +}); + +jQuery.extend({ + valHooks: { + option: { + get: function( elem ) { + // attributes.value is undefined in Blackberry 4.7 but + // uses .value. See #6932 + var val = elem.attributes.value; + return !val || val.specified ? elem.value : elem.text; + } + }, + select: { + get: function( elem ) { + var value, + index = elem.selectedIndex, + values = [], + options = elem.options, + one = elem.type === "select-one"; + + // Nothing was selected + if ( index < 0 ) { + return null; + } + + // Loop through all the selected options + for ( var i = one ? index : 0, max = one ? index + 1 : options.length; i < max; i++ ) { + var option = options[ i ]; + + // Don't return options that are disabled or in a disabled optgroup + if ( option.selected && (jQuery.support.optDisabled ? !option.disabled : option.getAttribute("disabled") === null) && + (!option.parentNode.disabled || !jQuery.nodeName( option.parentNode, "optgroup" )) ) { + + // Get the specific value for the option + value = jQuery( option ).val(); + + // We don't need an array for one selects + if ( one ) { + return value; + } + + // Multi-Selects return an array + values.push( value ); + } + } + + // Fixes Bug #2551 -- select.val() broken in IE after form.reset() + if ( one && !values.length && options.length ) { + return jQuery( options[ index ] ).val(); + } + + return values; + }, + + set: function( elem, value ) { + var values = jQuery.makeArray( value ); + + jQuery(elem).find("option").each(function() { + this.selected = jQuery.inArray( jQuery(this).val(), values ) >= 0; + }); + + if ( !values.length ) { + elem.selectedIndex = -1; + } + return values; + } + } + }, + + attrFn: { + val: true, + css: true, + html: true, + text: true, + data: true, + width: true, + height: true, + offset: true + }, + + attrFix: { + // Always normalize to ensure hook usage + tabindex: "tabIndex" + }, + + attr: function( elem, name, value, pass ) { + var nType = elem.nodeType; + + // don't get/set attributes on text, comment and attribute nodes + if ( !elem || nType === 3 || nType === 8 || nType === 2 ) { + return undefined; + } + + if ( pass && name in jQuery.attrFn ) { + return jQuery( elem )[ name ]( value ); + } + + // Fallback to prop when attributes are not supported + if ( !("getAttribute" in elem) ) { + return jQuery.prop( elem, name, value ); + } + + var ret, hooks, + notxml = nType !== 1 || !jQuery.isXMLDoc( elem ); + + // Normalize the name if needed + if ( notxml ) { + name = jQuery.attrFix[ name ] || name; + + hooks = jQuery.attrHooks[ name ]; + + if ( !hooks ) { + // Use boolHook for boolean attributes + if ( rboolean.test( name ) ) { + hooks = boolHook; + + // Use nodeHook if available( IE6/7 ) + } else if ( nodeHook ) { + hooks = nodeHook; + } + } + } + + if ( value !== undefined ) { + + if ( value === null ) { + jQuery.removeAttr( elem, name ); + return undefined; + + } else if ( hooks && "set" in hooks && notxml && (ret = hooks.set( elem, value, name )) !== undefined ) { + return ret; + + } else { + elem.setAttribute( name, "" + value ); + return value; + } + + } else if ( hooks && "get" in hooks && notxml && (ret = hooks.get( elem, name )) !== null ) { + return ret; + + } else { + + ret = elem.getAttribute( name ); + + // Non-existent attributes return null, we normalize to undefined + return ret === null ? + undefined : + ret; + } + }, + + removeAttr: function( elem, name ) { + var propName; + if ( elem.nodeType === 1 ) { + name = jQuery.attrFix[ name ] || name; + + jQuery.attr( elem, name, "" ); + elem.removeAttribute( name ); + + // Set corresponding property to false for boolean attributes + if ( rboolean.test( name ) && (propName = jQuery.propFix[ name ] || name) in elem ) { + elem[ propName ] = false; + } + } + }, + + attrHooks: { + type: { + set: function( elem, value ) { + // We can't allow the type property to be changed (since it causes problems in IE) + if ( rtype.test( elem.nodeName ) && elem.parentNode ) { + jQuery.error( "type property can't be changed" ); + } else if ( !jQuery.support.radioValue && value === "radio" && jQuery.nodeName(elem, "input") ) { + // Setting the type on a radio button after the value resets the value in IE6-9 + // Reset value to it's default in case type is set after value + // This is for element creation + var val = elem.value; + elem.setAttribute( "type", value ); + if ( val ) { + elem.value = val; + } + return value; + } + } + }, + // Use the value property for back compat + // Use the nodeHook for button elements in IE6/7 (#1954) + value: { + get: function( elem, name ) { + if ( nodeHook && jQuery.nodeName( elem, "button" ) ) { + return nodeHook.get( elem, name ); + } + return name in elem ? + elem.value : + null; + }, + set: function( elem, value, name ) { + if ( nodeHook && jQuery.nodeName( elem, "button" ) ) { + return nodeHook.set( elem, value, name ); + } + // Does not return so that setAttribute is also used + elem.value = value; + } + } + }, + + propFix: { + tabindex: "tabIndex", + readonly: "readOnly", + "for": "htmlFor", + "class": "className", + maxlength: "maxLength", + cellspacing: "cellSpacing", + cellpadding: "cellPadding", + rowspan: "rowSpan", + colspan: "colSpan", + usemap: "useMap", + frameborder: "frameBorder", + contenteditable: "contentEditable" + }, + + prop: function( elem, name, value ) { + var nType = elem.nodeType; + + // don't get/set properties on text, comment and attribute nodes + if ( !elem || nType === 3 || nType === 8 || nType === 2 ) { + return undefined; + } + + var ret, hooks, + notxml = nType !== 1 || !jQuery.isXMLDoc( elem ); + + if ( notxml ) { + // Fix name and attach hooks + name = jQuery.propFix[ name ] || name; + hooks = jQuery.propHooks[ name ]; + } + + if ( value !== undefined ) { + if ( hooks && "set" in hooks && (ret = hooks.set( elem, value, name )) !== undefined ) { + return ret; + + } else { + return (elem[ name ] = value); + } + + } else { + if ( hooks && "get" in hooks && (ret = hooks.get( elem, name )) !== null ) { + return ret; + + } else { + return elem[ name ]; + } + } + }, + + propHooks: { + tabIndex: { + get: function( elem ) { + // elem.tabIndex doesn't always return the correct value when it hasn't been explicitly set + // http://fluidproject.org/blog/2008/01/09/getting-setting-and-removing-tabindex-values-with-javascript/ + var attributeNode = elem.getAttributeNode("tabindex"); + + return attributeNode && attributeNode.specified ? + parseInt( attributeNode.value, 10 ) : + rfocusable.test( elem.nodeName ) || rclickable.test( elem.nodeName ) && elem.href ? + 0 : + undefined; + } + } + } +}); + +// Add the tabindex propHook to attrHooks for back-compat +jQuery.attrHooks.tabIndex = jQuery.propHooks.tabIndex; + +// Hook for boolean attributes +boolHook = { + get: function( elem, name ) { + // Align boolean attributes with corresponding properties + // Fall back to attribute presence where some booleans are not supported + var attrNode; + return jQuery.prop( elem, name ) === true || ( attrNode = elem.getAttributeNode( name ) ) && attrNode.nodeValue !== false ? + name.toLowerCase() : + undefined; + }, + set: function( elem, value, name ) { + var propName; + if ( value === false ) { + // Remove boolean attributes when set to false + jQuery.removeAttr( elem, name ); + } else { + // value is true since we know at this point it's type boolean and not false + // Set boolean attributes to the same name and set the DOM property + propName = jQuery.propFix[ name ] || name; + if ( propName in elem ) { + // Only set the IDL specifically if it already exists on the element + elem[ propName ] = true; + } + + elem.setAttribute( name, name.toLowerCase() ); + } + return name; + } +}; + +// IE6/7 do not support getting/setting some attributes with get/setAttribute +if ( !jQuery.support.getSetAttribute ) { + + // Use this for any attribute in IE6/7 + // This fixes almost every IE6/7 issue + nodeHook = jQuery.valHooks.button = { + get: function( elem, name ) { + var ret; + ret = elem.getAttributeNode( name ); + // Return undefined if nodeValue is empty string + return ret && ret.nodeValue !== "" ? + ret.nodeValue : + undefined; + }, + set: function( elem, value, name ) { + // Set the existing or create a new attribute node + var ret = elem.getAttributeNode( name ); + if ( !ret ) { + ret = document.createAttribute( name ); + elem.setAttributeNode( ret ); + } + return (ret.nodeValue = value + ""); + } + }; + + // Set width and height to auto instead of 0 on empty string( Bug #8150 ) + // This is for removals + jQuery.each([ "width", "height" ], function( i, name ) { + jQuery.attrHooks[ name ] = jQuery.extend( jQuery.attrHooks[ name ], { + set: function( elem, value ) { + if ( value === "" ) { + elem.setAttribute( name, "auto" ); + return value; + } + } + }); + }); +} + + +// Some attributes require a special call on IE +if ( !jQuery.support.hrefNormalized ) { + jQuery.each([ "href", "src", "width", "height" ], function( i, name ) { + jQuery.attrHooks[ name ] = jQuery.extend( jQuery.attrHooks[ name ], { + get: function( elem ) { + var ret = elem.getAttribute( name, 2 ); + return ret === null ? undefined : ret; + } + }); + }); +} + +if ( !jQuery.support.style ) { + jQuery.attrHooks.style = { + get: function( elem ) { + // Return undefined in the case of empty string + // Normalize to lowercase since IE uppercases css property names + return elem.style.cssText.toLowerCase() || undefined; + }, + set: function( elem, value ) { + return (elem.style.cssText = "" + value); + } + }; +} + +// Safari mis-reports the default selected property of an option +// Accessing the parent's selectedIndex property fixes it +if ( !jQuery.support.optSelected ) { + jQuery.propHooks.selected = jQuery.extend( jQuery.propHooks.selected, { + get: function( elem ) { + var parent = elem.parentNode; + + if ( parent ) { + parent.selectedIndex; + + // Make sure that it also works with optgroups, see #5701 + if ( parent.parentNode ) { + parent.parentNode.selectedIndex; + } + } + return null; + } + }); +} + +// Radios and checkboxes getter/setter +if ( !jQuery.support.checkOn ) { + jQuery.each([ "radio", "checkbox" ], function() { + jQuery.valHooks[ this ] = { + get: function( elem ) { + // Handle the case where in Webkit "" is returned instead of "on" if a value isn't specified + return elem.getAttribute("value") === null ? "on" : elem.value; + } + }; + }); +} +jQuery.each([ "radio", "checkbox" ], function() { + jQuery.valHooks[ this ] = jQuery.extend( jQuery.valHooks[ this ], { + set: function( elem, value ) { + if ( jQuery.isArray( value ) ) { + return (elem.checked = jQuery.inArray( jQuery(elem).val(), value ) >= 0); + } + } + }); +}); + + + + +var rnamespaces = /\.(.*)$/, + rformElems = /^(?:textarea|input|select)$/i, + rperiod = /\./g, + rspaces = / /g, + rescape = /[^\w\s.|`]/g, + fcleanup = function( nm ) { + return nm.replace(rescape, "\\$&"); + }; + +/* + * A number of helper functions used for managing events. + * Many of the ideas behind this code originated from + * Dean Edwards' addEvent library. + */ +jQuery.event = { + + // Bind an event to an element + // Original by Dean Edwards + add: function( elem, types, handler, data ) { + if ( elem.nodeType === 3 || elem.nodeType === 8 ) { + return; + } + + if ( handler === false ) { + handler = returnFalse; + } else if ( !handler ) { + // Fixes bug #7229. Fix recommended by jdalton + return; + } + + var handleObjIn, handleObj; + + if ( handler.handler ) { + handleObjIn = handler; + handler = handleObjIn.handler; + } + + // Make sure that the function being executed has a unique ID + if ( !handler.guid ) { + handler.guid = jQuery.guid++; + } + + // Init the element's event structure + var elemData = jQuery._data( elem ); + + // If no elemData is found then we must be trying to bind to one of the + // banned noData elements + if ( !elemData ) { + return; + } + + var events = elemData.events, + eventHandle = elemData.handle; + + if ( !events ) { + elemData.events = events = {}; + } + + if ( !eventHandle ) { + elemData.handle = eventHandle = function( e ) { + // Discard the second event of a jQuery.event.trigger() and + // when an event is called after a page has unloaded + return typeof jQuery !== "undefined" && (!e || jQuery.event.triggered !== e.type) ? + jQuery.event.handle.apply( eventHandle.elem, arguments ) : + undefined; + }; + } + + // Add elem as a property of the handle function + // This is to prevent a memory leak with non-native events in IE. + eventHandle.elem = elem; + + // Handle multiple events separated by a space + // jQuery(...).bind("mouseover mouseout", fn); + types = types.split(" "); + + var type, i = 0, namespaces; + + while ( (type = types[ i++ ]) ) { + handleObj = handleObjIn ? + jQuery.extend({}, handleObjIn) : + { handler: handler, data: data }; + + // Namespaced event handlers + if ( type.indexOf(".") > -1 ) { + namespaces = type.split("."); + type = namespaces.shift(); + handleObj.namespace = namespaces.slice(0).sort().join("."); + + } else { + namespaces = []; + handleObj.namespace = ""; + } + + handleObj.type = type; + if ( !handleObj.guid ) { + handleObj.guid = handler.guid; + } + + // Get the current list of functions bound to this event + var handlers = events[ type ], + special = jQuery.event.special[ type ] || {}; + + // Init the event handler queue + if ( !handlers ) { + handlers = events[ type ] = []; + + // Check for a special event handler + // Only use addEventListener/attachEvent if the special + // events handler returns false + if ( !special.setup || special.setup.call( elem, data, namespaces, eventHandle ) === false ) { + // Bind the global event handler to the element + if ( elem.addEventListener ) { + elem.addEventListener( type, eventHandle, false ); + + } else if ( elem.attachEvent ) { + elem.attachEvent( "on" + type, eventHandle ); + } + } + } + + if ( special.add ) { + special.add.call( elem, handleObj ); + + if ( !handleObj.handler.guid ) { + handleObj.handler.guid = handler.guid; + } + } + + // Add the function to the element's handler list + handlers.push( handleObj ); + + // Keep track of which events have been used, for event optimization + jQuery.event.global[ type ] = true; + } + + // Nullify elem to prevent memory leaks in IE + elem = null; + }, + + global: {}, + + // Detach an event or set of events from an element + remove: function( elem, types, handler, pos ) { + // don't do events on text and comment nodes + if ( elem.nodeType === 3 || elem.nodeType === 8 ) { + return; + } + + if ( handler === false ) { + handler = returnFalse; + } + + var ret, type, fn, j, i = 0, all, namespaces, namespace, special, eventType, handleObj, origType, + elemData = jQuery.hasData( elem ) && jQuery._data( elem ), + events = elemData && elemData.events; + + if ( !elemData || !events ) { + return; + } + + // types is actually an event object here + if ( types && types.type ) { + handler = types.handler; + types = types.type; + } + + // Unbind all events for the element + if ( !types || typeof types === "string" && types.charAt(0) === "." ) { + types = types || ""; + + for ( type in events ) { + jQuery.event.remove( elem, type + types ); + } + + return; + } + + // Handle multiple events separated by a space + // jQuery(...).unbind("mouseover mouseout", fn); + types = types.split(" "); + + while ( (type = types[ i++ ]) ) { + origType = type; + handleObj = null; + all = type.indexOf(".") < 0; + namespaces = []; + + if ( !all ) { + // Namespaced event handlers + namespaces = type.split("."); + type = namespaces.shift(); + + namespace = new RegExp("(^|\\.)" + + jQuery.map( namespaces.slice(0).sort(), fcleanup ).join("\\.(?:.*\\.)?") + "(\\.|$)"); + } + + eventType = events[ type ]; + + if ( !eventType ) { + continue; + } + + if ( !handler ) { + for ( j = 0; j < eventType.length; j++ ) { + handleObj = eventType[ j ]; + + if ( all || namespace.test( handleObj.namespace ) ) { + jQuery.event.remove( elem, origType, handleObj.handler, j ); + eventType.splice( j--, 1 ); + } + } + + continue; + } + + special = jQuery.event.special[ type ] || {}; + + for ( j = pos || 0; j < eventType.length; j++ ) { + handleObj = eventType[ j ]; + + if ( handler.guid === handleObj.guid ) { + // remove the given handler for the given type + if ( all || namespace.test( handleObj.namespace ) ) { + if ( pos == null ) { + eventType.splice( j--, 1 ); + } + + if ( special.remove ) { + special.remove.call( elem, handleObj ); + } + } + + if ( pos != null ) { + break; + } + } + } + + // remove generic event handler if no more handlers exist + if ( eventType.length === 0 || pos != null && eventType.length === 1 ) { + if ( !special.teardown || special.teardown.call( elem, namespaces ) === false ) { + jQuery.removeEvent( elem, type, elemData.handle ); + } + + ret = null; + delete events[ type ]; + } + } + + // Remove the expando if it's no longer used + if ( jQuery.isEmptyObject( events ) ) { + var handle = elemData.handle; + if ( handle ) { + handle.elem = null; + } + + delete elemData.events; + delete elemData.handle; + + if ( jQuery.isEmptyObject( elemData ) ) { + jQuery.removeData( elem, undefined, true ); + } + } + }, + + // Events that are safe to short-circuit if no handlers are attached. + // Native DOM events should not be added, they may have inline handlers. + customEvent: { + "getData": true, + "setData": true, + "changeData": true + }, + + trigger: function( event, data, elem, onlyHandlers ) { + // Event object or event type + var type = event.type || event, + namespaces = [], + exclusive; + + if ( type.indexOf("!") >= 0 ) { + // Exclusive events trigger only for the exact event (no namespaces) + type = type.slice(0, -1); + exclusive = true; + } + + if ( type.indexOf(".") >= 0 ) { + // Namespaced trigger; create a regexp to match event type in handle() + namespaces = type.split("."); + type = namespaces.shift(); + namespaces.sort(); + } + + if ( (!elem || jQuery.event.customEvent[ type ]) && !jQuery.event.global[ type ] ) { + // No jQuery handlers for this event type, and it can't have inline handlers + return; + } + + // Caller can pass in an Event, Object, or just an event type string + event = typeof event === "object" ? + // jQuery.Event object + event[ jQuery.expando ] ? event : + // Object literal + new jQuery.Event( type, event ) : + // Just the event type (string) + new jQuery.Event( type ); + + event.type = type; + event.exclusive = exclusive; + event.namespace = namespaces.join("."); + event.namespace_re = new RegExp("(^|\\.)" + namespaces.join("\\.(?:.*\\.)?") + "(\\.|$)"); + + // triggerHandler() and global events don't bubble or run the default action + if ( onlyHandlers || !elem ) { + event.preventDefault(); + event.stopPropagation(); + } + + // Handle a global trigger + if ( !elem ) { + // TODO: Stop taunting the data cache; remove global events and always attach to document + jQuery.each( jQuery.cache, function() { + // internalKey variable is just used to make it easier to find + // and potentially change this stuff later; currently it just + // points to jQuery.expando + var internalKey = jQuery.expando, + internalCache = this[ internalKey ]; + if ( internalCache && internalCache.events && internalCache.events[ type ] ) { + jQuery.event.trigger( event, data, internalCache.handle.elem ); + } + }); + return; + } + + // Don't do events on text and comment nodes + if ( elem.nodeType === 3 || elem.nodeType === 8 ) { + return; + } + + // Clean up the event in case it is being reused + event.result = undefined; + event.target = elem; + + // Clone any incoming data and prepend the event, creating the handler arg list + data = data != null ? jQuery.makeArray( data ) : []; + data.unshift( event ); + + var cur = elem, + // IE doesn't like method names with a colon (#3533, #8272) + ontype = type.indexOf(":") < 0 ? "on" + type : ""; + + // Fire event on the current element, then bubble up the DOM tree + do { + var handle = jQuery._data( cur, "handle" ); + + event.currentTarget = cur; + if ( handle ) { + handle.apply( cur, data ); + } + + // Trigger an inline bound script + if ( ontype && jQuery.acceptData( cur ) && cur[ ontype ] && cur[ ontype ].apply( cur, data ) === false ) { + event.result = false; + event.preventDefault(); + } + + // Bubble up to document, then to window + cur = cur.parentNode || cur.ownerDocument || cur === event.target.ownerDocument && window; + } while ( cur && !event.isPropagationStopped() ); + + // If nobody prevented the default action, do it now + if ( !event.isDefaultPrevented() ) { + var old, + special = jQuery.event.special[ type ] || {}; + + if ( (!special._default || special._default.call( elem.ownerDocument, event ) === false) && + !(type === "click" && jQuery.nodeName( elem, "a" )) && jQuery.acceptData( elem ) ) { + + // Call a native DOM method on the target with the same name name as the event. + // Can't use an .isFunction)() check here because IE6/7 fails that test. + // IE<9 dies on focus to hidden element (#1486), may want to revisit a try/catch. + try { + if ( ontype && elem[ type ] ) { + // Don't re-trigger an onFOO event when we call its FOO() method + old = elem[ ontype ]; + + if ( old ) { + elem[ ontype ] = null; + } + + jQuery.event.triggered = type; + elem[ type ](); + } + } catch ( ieError ) {} + + if ( old ) { + elem[ ontype ] = old; + } + + jQuery.event.triggered = undefined; + } + } + + return event.result; + }, + + handle: function( event ) { + event = jQuery.event.fix( event || window.event ); + // Snapshot the handlers list since a called handler may add/remove events. + var handlers = ((jQuery._data( this, "events" ) || {})[ event.type ] || []).slice(0), + run_all = !event.exclusive && !event.namespace, + args = Array.prototype.slice.call( arguments, 0 ); + + // Use the fix-ed Event rather than the (read-only) native event + args[0] = event; + event.currentTarget = this; + + for ( var j = 0, l = handlers.length; j < l; j++ ) { + var handleObj = handlers[ j ]; + + // Triggered event must 1) be non-exclusive and have no namespace, or + // 2) have namespace(s) a subset or equal to those in the bound event. + if ( run_all || event.namespace_re.test( handleObj.namespace ) ) { + // Pass in a reference to the handler function itself + // So that we can later remove it + event.handler = handleObj.handler; + event.data = handleObj.data; + event.handleObj = handleObj; + + var ret = handleObj.handler.apply( this, args ); + + if ( ret !== undefined ) { + event.result = ret; + if ( ret === false ) { + event.preventDefault(); + event.stopPropagation(); + } + } + + if ( event.isImmediatePropagationStopped() ) { + break; + } + } + } + return event.result; + }, + + props: "altKey attrChange attrName bubbles button cancelable charCode clientX clientY ctrlKey currentTarget data detail eventPhase fromElement handler keyCode metaKey newValue offsetX offsetY pageX pageY prevValue relatedNode relatedTarget screenX screenY shiftKey srcElement target toElement view wheelDelta which".split(" "), + + fix: function( event ) { + if ( event[ jQuery.expando ] ) { + return event; + } + + // store a copy of the original event object + // and "clone" to set read-only properties + var originalEvent = event; + event = jQuery.Event( originalEvent ); + + for ( var i = this.props.length, prop; i; ) { + prop = this.props[ --i ]; + event[ prop ] = originalEvent[ prop ]; + } + + // Fix target property, if necessary + if ( !event.target ) { + // Fixes #1925 where srcElement might not be defined either + event.target = event.srcElement || document; + } + + // check if target is a textnode (safari) + if ( event.target.nodeType === 3 ) { + event.target = event.target.parentNode; + } + + // Add relatedTarget, if necessary + if ( !event.relatedTarget && event.fromElement ) { + event.relatedTarget = event.fromElement === event.target ? event.toElement : event.fromElement; + } + + // Calculate pageX/Y if missing and clientX/Y available + if ( event.pageX == null && event.clientX != null ) { + var eventDocument = event.target.ownerDocument || document, + doc = eventDocument.documentElement, + body = eventDocument.body; + + event.pageX = event.clientX + (doc && doc.scrollLeft || body && body.scrollLeft || 0) - (doc && doc.clientLeft || body && body.clientLeft || 0); + event.pageY = event.clientY + (doc && doc.scrollTop || body && body.scrollTop || 0) - (doc && doc.clientTop || body && body.clientTop || 0); + } + + // Add which for key events + if ( event.which == null && (event.charCode != null || event.keyCode != null) ) { + event.which = event.charCode != null ? event.charCode : event.keyCode; + } + + // Add metaKey to non-Mac browsers (use ctrl for PC's and Meta for Macs) + if ( !event.metaKey && event.ctrlKey ) { + event.metaKey = event.ctrlKey; + } + + // Add which for click: 1 === left; 2 === middle; 3 === right + // Note: button is not normalized, so don't use it + if ( !event.which && event.button !== undefined ) { + event.which = (event.button & 1 ? 1 : ( event.button & 2 ? 3 : ( event.button & 4 ? 2 : 0 ) )); + } + + return event; + }, + + // Deprecated, use jQuery.guid instead + guid: 1E8, + + // Deprecated, use jQuery.proxy instead + proxy: jQuery.proxy, + + special: { + ready: { + // Make sure the ready event is setup + setup: jQuery.bindReady, + teardown: jQuery.noop + }, + + live: { + add: function( handleObj ) { + jQuery.event.add( this, + liveConvert( handleObj.origType, handleObj.selector ), + jQuery.extend({}, handleObj, {handler: liveHandler, guid: handleObj.handler.guid}) ); + }, + + remove: function( handleObj ) { + jQuery.event.remove( this, liveConvert( handleObj.origType, handleObj.selector ), handleObj ); + } + }, + + beforeunload: { + setup: function( data, namespaces, eventHandle ) { + // We only want to do this special case on windows + if ( jQuery.isWindow( this ) ) { + this.onbeforeunload = eventHandle; + } + }, + + teardown: function( namespaces, eventHandle ) { + if ( this.onbeforeunload === eventHandle ) { + this.onbeforeunload = null; + } + } + } + } +}; + +jQuery.removeEvent = document.removeEventListener ? + function( elem, type, handle ) { + if ( elem.removeEventListener ) { + elem.removeEventListener( type, handle, false ); + } + } : + function( elem, type, handle ) { + if ( elem.detachEvent ) { + elem.detachEvent( "on" + type, handle ); + } + }; + +jQuery.Event = function( src, props ) { + // Allow instantiation without the 'new' keyword + if ( !this.preventDefault ) { + return new jQuery.Event( src, props ); + } + + // Event object + if ( src && src.type ) { + this.originalEvent = src; + this.type = src.type; + + // Events bubbling up the document may have been marked as prevented + // by a handler lower down the tree; reflect the correct value. + this.isDefaultPrevented = (src.defaultPrevented || src.returnValue === false || + src.getPreventDefault && src.getPreventDefault()) ? returnTrue : returnFalse; + + // Event type + } else { + this.type = src; + } + + // Put explicitly provided properties onto the event object + if ( props ) { + jQuery.extend( this, props ); + } + + // timeStamp is buggy for some events on Firefox(#3843) + // So we won't rely on the native value + this.timeStamp = jQuery.now(); + + // Mark it as fixed + this[ jQuery.expando ] = true; +}; + +function returnFalse() { + return false; +} +function returnTrue() { + return true; +} + +// jQuery.Event is based on DOM3 Events as specified by the ECMAScript Language Binding +// http://www.w3.org/TR/2003/WD-DOM-Level-3-Events-20030331/ecma-script-binding.html +jQuery.Event.prototype = { + preventDefault: function() { + this.isDefaultPrevented = returnTrue; + + var e = this.originalEvent; + if ( !e ) { + return; + } + + // if preventDefault exists run it on the original event + if ( e.preventDefault ) { + e.preventDefault(); + + // otherwise set the returnValue property of the original event to false (IE) + } else { + e.returnValue = false; + } + }, + stopPropagation: function() { + this.isPropagationStopped = returnTrue; + + var e = this.originalEvent; + if ( !e ) { + return; + } + // if stopPropagation exists run it on the original event + if ( e.stopPropagation ) { + e.stopPropagation(); + } + // otherwise set the cancelBubble property of the original event to true (IE) + e.cancelBubble = true; + }, + stopImmediatePropagation: function() { + this.isImmediatePropagationStopped = returnTrue; + this.stopPropagation(); + }, + isDefaultPrevented: returnFalse, + isPropagationStopped: returnFalse, + isImmediatePropagationStopped: returnFalse +}; + +// Checks if an event happened on an element within another element +// Used in jQuery.event.special.mouseenter and mouseleave handlers +var withinElement = function( event ) { + + // Check if mouse(over|out) are still within the same parent element + var related = event.relatedTarget, + inside = false, + eventType = event.type; + + event.type = event.data; + + if ( related !== this ) { + + if ( related ) { + inside = jQuery.contains( this, related ); + } + + if ( !inside ) { + + jQuery.event.handle.apply( this, arguments ); + + event.type = eventType; + } + } +}, + +// In case of event delegation, we only need to rename the event.type, +// liveHandler will take care of the rest. +delegate = function( event ) { + event.type = event.data; + jQuery.event.handle.apply( this, arguments ); +}; + +// Create mouseenter and mouseleave events +jQuery.each({ + mouseenter: "mouseover", + mouseleave: "mouseout" +}, function( orig, fix ) { + jQuery.event.special[ orig ] = { + setup: function( data ) { + jQuery.event.add( this, fix, data && data.selector ? delegate : withinElement, orig ); + }, + teardown: function( data ) { + jQuery.event.remove( this, fix, data && data.selector ? delegate : withinElement ); + } + }; +}); + +// submit delegation +if ( !jQuery.support.submitBubbles ) { + + jQuery.event.special.submit = { + setup: function( data, namespaces ) { + if ( !jQuery.nodeName( this, "form" ) ) { + jQuery.event.add(this, "click.specialSubmit", function( e ) { + // Avoid triggering error on non-existent type attribute in IE VML (#7071) + var elem = e.target, + type = jQuery.nodeName( elem, "input" ) || jQuery.nodeName( elem, "button" ) ? elem.type : ""; + + if ( (type === "submit" || type === "image") && jQuery( elem ).closest("form").length ) { + trigger( "submit", this, arguments ); + } + }); + + jQuery.event.add(this, "keypress.specialSubmit", function( e ) { + var elem = e.target, + type = jQuery.nodeName( elem, "input" ) || jQuery.nodeName( elem, "button" ) ? elem.type : ""; + + if ( (type === "text" || type === "password") && jQuery( elem ).closest("form").length && e.keyCode === 13 ) { + trigger( "submit", this, arguments ); + } + }); + + } else { + return false; + } + }, + + teardown: function( namespaces ) { + jQuery.event.remove( this, ".specialSubmit" ); + } + }; + +} + +// change delegation, happens here so we have bind. +if ( !jQuery.support.changeBubbles ) { + + var changeFilters, + + getVal = function( elem ) { + var type = jQuery.nodeName( elem, "input" ) ? elem.type : "", + val = elem.value; + + if ( type === "radio" || type === "checkbox" ) { + val = elem.checked; + + } else if ( type === "select-multiple" ) { + val = elem.selectedIndex > -1 ? + jQuery.map( elem.options, function( elem ) { + return elem.selected; + }).join("-") : + ""; + + } else if ( jQuery.nodeName( elem, "select" ) ) { + val = elem.selectedIndex; + } + + return val; + }, + + testChange = function testChange( e ) { + var elem = e.target, data, val; + + if ( !rformElems.test( elem.nodeName ) || elem.readOnly ) { + return; + } + + data = jQuery._data( elem, "_change_data" ); + val = getVal(elem); + + // the current data will be also retrieved by beforeactivate + if ( e.type !== "focusout" || elem.type !== "radio" ) { + jQuery._data( elem, "_change_data", val ); + } + + if ( data === undefined || val === data ) { + return; + } + + if ( data != null || val ) { + e.type = "change"; + e.liveFired = undefined; + jQuery.event.trigger( e, arguments[1], elem ); + } + }; + + jQuery.event.special.change = { + filters: { + focusout: testChange, + + beforedeactivate: testChange, + + click: function( e ) { + var elem = e.target, type = jQuery.nodeName( elem, "input" ) ? elem.type : ""; + + if ( type === "radio" || type === "checkbox" || jQuery.nodeName( elem, "select" ) ) { + testChange.call( this, e ); + } + }, + + // Change has to be called before submit + // Keydown will be called before keypress, which is used in submit-event delegation + keydown: function( e ) { + var elem = e.target, type = jQuery.nodeName( elem, "input" ) ? elem.type : ""; + + if ( (e.keyCode === 13 && !jQuery.nodeName( elem, "textarea" ) ) || + (e.keyCode === 32 && (type === "checkbox" || type === "radio")) || + type === "select-multiple" ) { + testChange.call( this, e ); + } + }, + + // Beforeactivate happens also before the previous element is blurred + // with this event you can't trigger a change event, but you can store + // information + beforeactivate: function( e ) { + var elem = e.target; + jQuery._data( elem, "_change_data", getVal(elem) ); + } + }, + + setup: function( data, namespaces ) { + if ( this.type === "file" ) { + return false; + } + + for ( var type in changeFilters ) { + jQuery.event.add( this, type + ".specialChange", changeFilters[type] ); + } + + return rformElems.test( this.nodeName ); + }, + + teardown: function( namespaces ) { + jQuery.event.remove( this, ".specialChange" ); + + return rformElems.test( this.nodeName ); + } + }; + + changeFilters = jQuery.event.special.change.filters; + + // Handle when the input is .focus()'d + changeFilters.focus = changeFilters.beforeactivate; +} + +function trigger( type, elem, args ) { + // Piggyback on a donor event to simulate a different one. + // Fake originalEvent to avoid donor's stopPropagation, but if the + // simulated event prevents default then we do the same on the donor. + // Don't pass args or remember liveFired; they apply to the donor event. + var event = jQuery.extend( {}, args[ 0 ] ); + event.type = type; + event.originalEvent = {}; + event.liveFired = undefined; + jQuery.event.handle.call( elem, event ); + if ( event.isDefaultPrevented() ) { + args[ 0 ].preventDefault(); + } +} + +// Create "bubbling" focus and blur events +if ( !jQuery.support.focusinBubbles ) { + jQuery.each({ focus: "focusin", blur: "focusout" }, function( orig, fix ) { + + // Attach a single capturing handler while someone wants focusin/focusout + var attaches = 0; + + jQuery.event.special[ fix ] = { + setup: function() { + if ( attaches++ === 0 ) { + document.addEventListener( orig, handler, true ); + } + }, + teardown: function() { + if ( --attaches === 0 ) { + document.removeEventListener( orig, handler, true ); + } + } + }; + + function handler( donor ) { + // Donor event is always a native one; fix it and switch its type. + // Let focusin/out handler cancel the donor focus/blur event. + var e = jQuery.event.fix( donor ); + e.type = fix; + e.originalEvent = {}; + jQuery.event.trigger( e, null, e.target ); + if ( e.isDefaultPrevented() ) { + donor.preventDefault(); + } + } + }); +} + +jQuery.each(["bind", "one"], function( i, name ) { + jQuery.fn[ name ] = function( type, data, fn ) { + var handler; + + // Handle object literals + if ( typeof type === "object" ) { + for ( var key in type ) { + this[ name ](key, data, type[key], fn); + } + return this; + } + + if ( arguments.length === 2 || data === false ) { + fn = data; + data = undefined; + } + + if ( name === "one" ) { + handler = function( event ) { + jQuery( this ).unbind( event, handler ); + return fn.apply( this, arguments ); + }; + handler.guid = fn.guid || jQuery.guid++; + } else { + handler = fn; + } + + if ( type === "unload" && name !== "one" ) { + this.one( type, data, fn ); + + } else { + for ( var i = 0, l = this.length; i < l; i++ ) { + jQuery.event.add( this[i], type, handler, data ); + } + } + + return this; + }; +}); + +jQuery.fn.extend({ + unbind: function( type, fn ) { + // Handle object literals + if ( typeof type === "object" && !type.preventDefault ) { + for ( var key in type ) { + this.unbind(key, type[key]); + } + + } else { + for ( var i = 0, l = this.length; i < l; i++ ) { + jQuery.event.remove( this[i], type, fn ); + } + } + + return this; + }, + + delegate: function( selector, types, data, fn ) { + return this.live( types, data, fn, selector ); + }, + + undelegate: function( selector, types, fn ) { + if ( arguments.length === 0 ) { + return this.unbind( "live" ); + + } else { + return this.die( types, null, fn, selector ); + } + }, + + trigger: function( type, data ) { + return this.each(function() { + jQuery.event.trigger( type, data, this ); + }); + }, + + triggerHandler: function( type, data ) { + if ( this[0] ) { + return jQuery.event.trigger( type, data, this[0], true ); + } + }, + + toggle: function( fn ) { + // Save reference to arguments for access in closure + var args = arguments, + guid = fn.guid || jQuery.guid++, + i = 0, + toggler = function( event ) { + // Figure out which function to execute + var lastToggle = ( jQuery.data( this, "lastToggle" + fn.guid ) || 0 ) % i; + jQuery.data( this, "lastToggle" + fn.guid, lastToggle + 1 ); + + // Make sure that clicks stop + event.preventDefault(); + + // and execute the function + return args[ lastToggle ].apply( this, arguments ) || false; + }; + + // link all the functions, so any of them can unbind this click handler + toggler.guid = guid; + while ( i < args.length ) { + args[ i++ ].guid = guid; + } + + return this.click( toggler ); + }, + + hover: function( fnOver, fnOut ) { + return this.mouseenter( fnOver ).mouseleave( fnOut || fnOver ); + } +}); + +var liveMap = { + focus: "focusin", + blur: "focusout", + mouseenter: "mouseover", + mouseleave: "mouseout" +}; + +jQuery.each(["live", "die"], function( i, name ) { + jQuery.fn[ name ] = function( types, data, fn, origSelector /* Internal Use Only */ ) { + var type, i = 0, match, namespaces, preType, + selector = origSelector || this.selector, + context = origSelector ? this : jQuery( this.context ); + + if ( typeof types === "object" && !types.preventDefault ) { + for ( var key in types ) { + context[ name ]( key, data, types[key], selector ); + } + + return this; + } + + if ( name === "die" && !types && + origSelector && origSelector.charAt(0) === "." ) { + + context.unbind( origSelector ); + + return this; + } + + if ( data === false || jQuery.isFunction( data ) ) { + fn = data || returnFalse; + data = undefined; + } + + types = (types || "").split(" "); + + while ( (type = types[ i++ ]) != null ) { + match = rnamespaces.exec( type ); + namespaces = ""; + + if ( match ) { + namespaces = match[0]; + type = type.replace( rnamespaces, "" ); + } + + if ( type === "hover" ) { + types.push( "mouseenter" + namespaces, "mouseleave" + namespaces ); + continue; + } + + preType = type; + + if ( liveMap[ type ] ) { + types.push( liveMap[ type ] + namespaces ); + type = type + namespaces; + + } else { + type = (liveMap[ type ] || type) + namespaces; + } + + if ( name === "live" ) { + // bind live handler + for ( var j = 0, l = context.length; j < l; j++ ) { + jQuery.event.add( context[j], "live." + liveConvert( type, selector ), + { data: data, selector: selector, handler: fn, origType: type, origHandler: fn, preType: preType } ); + } + + } else { + // unbind live handler + context.unbind( "live." + liveConvert( type, selector ), fn ); + } + } + + return this; + }; +}); + +function liveHandler( event ) { + var stop, maxLevel, related, match, handleObj, elem, j, i, l, data, close, namespace, ret, + elems = [], + selectors = [], + events = jQuery._data( this, "events" ); + + // Make sure we avoid non-left-click bubbling in Firefox (#3861) and disabled elements in IE (#6911) + if ( event.liveFired === this || !events || !events.live || event.target.disabled || event.button && event.type === "click" ) { + return; + } + + if ( event.namespace ) { + namespace = new RegExp("(^|\\.)" + event.namespace.split(".").join("\\.(?:.*\\.)?") + "(\\.|$)"); + } + + event.liveFired = this; + + var live = events.live.slice(0); + + for ( j = 0; j < live.length; j++ ) { + handleObj = live[j]; + + if ( handleObj.origType.replace( rnamespaces, "" ) === event.type ) { + selectors.push( handleObj.selector ); + + } else { + live.splice( j--, 1 ); + } + } + + match = jQuery( event.target ).closest( selectors, event.currentTarget ); + + for ( i = 0, l = match.length; i < l; i++ ) { + close = match[i]; + + for ( j = 0; j < live.length; j++ ) { + handleObj = live[j]; + + if ( close.selector === handleObj.selector && (!namespace || namespace.test( handleObj.namespace )) && !close.elem.disabled ) { + elem = close.elem; + related = null; + + // Those two events require additional checking + if ( handleObj.preType === "mouseenter" || handleObj.preType === "mouseleave" ) { + event.type = handleObj.preType; + related = jQuery( event.relatedTarget ).closest( handleObj.selector )[0]; + + // Make sure not to accidentally match a child element with the same selector + if ( related && jQuery.contains( elem, related ) ) { + related = elem; + } + } + + if ( !related || related !== elem ) { + elems.push({ elem: elem, handleObj: handleObj, level: close.level }); + } + } + } + } + + for ( i = 0, l = elems.length; i < l; i++ ) { + match = elems[i]; + + if ( maxLevel && match.level > maxLevel ) { + break; + } + + event.currentTarget = match.elem; + event.data = match.handleObj.data; + event.handleObj = match.handleObj; + + ret = match.handleObj.origHandler.apply( match.elem, arguments ); + + if ( ret === false || event.isPropagationStopped() ) { + maxLevel = match.level; + + if ( ret === false ) { + stop = false; + } + if ( event.isImmediatePropagationStopped() ) { + break; + } + } + } + + return stop; +} + +function liveConvert( type, selector ) { + return (type && type !== "*" ? type + "." : "") + selector.replace(rperiod, "`").replace(rspaces, "&"); +} + +jQuery.each( ("blur focus focusin focusout load resize scroll unload click dblclick " + + "mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave " + + "change select submit keydown keypress keyup error").split(" "), function( i, name ) { + + // Handle event binding + jQuery.fn[ name ] = function( data, fn ) { + if ( fn == null ) { + fn = data; + data = null; + } + + return arguments.length > 0 ? + this.bind( name, data, fn ) : + this.trigger( name ); + }; + + if ( jQuery.attrFn ) { + jQuery.attrFn[ name ] = true; + } +}); + + + +/*! + * Sizzle CSS Selector Engine + * Copyright 2011, The Dojo Foundation + * Released under the MIT, BSD, and GPL Licenses. + * More information: http://sizzlejs.com/ + */ +(function(){ + +var chunker = /((?:\((?:\([^()]+\)|[^()]+)+\)|\[(?:\[[^\[\]]*\]|['"][^'"]*['"]|[^\[\]'"]+)+\]|\\.|[^ >+~,(\[\\]+)+|[>+~])(\s*,\s*)?((?:.|\r|\n)*)/g, + done = 0, + toString = Object.prototype.toString, + hasDuplicate = false, + baseHasDuplicate = true, + rBackslash = /\\/g, + rNonWord = /\W/; + +// Here we check if the JavaScript engine is using some sort of +// optimization where it does not always call our comparision +// function. If that is the case, discard the hasDuplicate value. +// Thus far that includes Google Chrome. +[0, 0].sort(function() { + baseHasDuplicate = false; + return 0; +}); + +var Sizzle = function( selector, context, results, seed ) { + results = results || []; + context = context || document; + + var origContext = context; + + if ( context.nodeType !== 1 && context.nodeType !== 9 ) { + return []; + } + + if ( !selector || typeof selector !== "string" ) { + return results; + } + + var m, set, checkSet, extra, ret, cur, pop, i, + prune = true, + contextXML = Sizzle.isXML( context ), + parts = [], + soFar = selector; + + // Reset the position of the chunker regexp (start from head) + do { + chunker.exec( "" ); + m = chunker.exec( soFar ); + + if ( m ) { + soFar = m[3]; + + parts.push( m[1] ); + + if ( m[2] ) { + extra = m[3]; + break; + } + } + } while ( m ); + + if ( parts.length > 1 && origPOS.exec( selector ) ) { + + if ( parts.length === 2 && Expr.relative[ parts[0] ] ) { + set = posProcess( parts[0] + parts[1], context ); + + } else { + set = Expr.relative[ parts[0] ] ? + [ context ] : + Sizzle( parts.shift(), context ); + + while ( parts.length ) { + selector = parts.shift(); + + if ( Expr.relative[ selector ] ) { + selector += parts.shift(); + } + + set = posProcess( selector, set ); + } + } + + } else { + // Take a shortcut and set the context if the root selector is an ID + // (but not if it'll be faster if the inner selector is an ID) + if ( !seed && parts.length > 1 && context.nodeType === 9 && !contextXML && + Expr.match.ID.test(parts[0]) && !Expr.match.ID.test(parts[parts.length - 1]) ) { + + ret = Sizzle.find( parts.shift(), context, contextXML ); + context = ret.expr ? + Sizzle.filter( ret.expr, ret.set )[0] : + ret.set[0]; + } + + if ( context ) { + ret = seed ? + { expr: parts.pop(), set: makeArray(seed) } : + Sizzle.find( parts.pop(), parts.length === 1 && (parts[0] === "~" || parts[0] === "+") && context.parentNode ? context.parentNode : context, contextXML ); + + set = ret.expr ? + Sizzle.filter( ret.expr, ret.set ) : + ret.set; + + if ( parts.length > 0 ) { + checkSet = makeArray( set ); + + } else { + prune = false; + } + + while ( parts.length ) { + cur = parts.pop(); + pop = cur; + + if ( !Expr.relative[ cur ] ) { + cur = ""; + } else { + pop = parts.pop(); + } + + if ( pop == null ) { + pop = context; + } + + Expr.relative[ cur ]( checkSet, pop, contextXML ); + } + + } else { + checkSet = parts = []; + } + } + + if ( !checkSet ) { + checkSet = set; + } + + if ( !checkSet ) { + Sizzle.error( cur || selector ); + } + + if ( toString.call(checkSet) === "[object Array]" ) { + if ( !prune ) { + results.push.apply( results, checkSet ); + + } else if ( context && context.nodeType === 1 ) { + for ( i = 0; checkSet[i] != null; i++ ) { + if ( checkSet[i] && (checkSet[i] === true || checkSet[i].nodeType === 1 && Sizzle.contains(context, checkSet[i])) ) { + results.push( set[i] ); + } + } + + } else { + for ( i = 0; checkSet[i] != null; i++ ) { + if ( checkSet[i] && checkSet[i].nodeType === 1 ) { + results.push( set[i] ); + } + } + } + + } else { + makeArray( checkSet, results ); + } + + if ( extra ) { + Sizzle( extra, origContext, results, seed ); + Sizzle.uniqueSort( results ); + } + + return results; +}; + +Sizzle.uniqueSort = function( results ) { + if ( sortOrder ) { + hasDuplicate = baseHasDuplicate; + results.sort( sortOrder ); + + if ( hasDuplicate ) { + for ( var i = 1; i < results.length; i++ ) { + if ( results[i] === results[ i - 1 ] ) { + results.splice( i--, 1 ); + } + } + } + } + + return results; +}; + +Sizzle.matches = function( expr, set ) { + return Sizzle( expr, null, null, set ); +}; + +Sizzle.matchesSelector = function( node, expr ) { + return Sizzle( expr, null, null, [node] ).length > 0; +}; + +Sizzle.find = function( expr, context, isXML ) { + var set; + + if ( !expr ) { + return []; + } + + for ( var i = 0, l = Expr.order.length; i < l; i++ ) { + var match, + type = Expr.order[i]; + + if ( (match = Expr.leftMatch[ type ].exec( expr )) ) { + var left = match[1]; + match.splice( 1, 1 ); + + if ( left.substr( left.length - 1 ) !== "\\" ) { + match[1] = (match[1] || "").replace( rBackslash, "" ); + set = Expr.find[ type ]( match, context, isXML ); + + if ( set != null ) { + expr = expr.replace( Expr.match[ type ], "" ); + break; + } + } + } + } + + if ( !set ) { + set = typeof context.getElementsByTagName !== "undefined" ? + context.getElementsByTagName( "*" ) : + []; + } + + return { set: set, expr: expr }; +}; + +Sizzle.filter = function( expr, set, inplace, not ) { + var match, anyFound, + old = expr, + result = [], + curLoop = set, + isXMLFilter = set && set[0] && Sizzle.isXML( set[0] ); + + while ( expr && set.length ) { + for ( var type in Expr.filter ) { + if ( (match = Expr.leftMatch[ type ].exec( expr )) != null && match[2] ) { + var found, item, + filter = Expr.filter[ type ], + left = match[1]; + + anyFound = false; + + match.splice(1,1); + + if ( left.substr( left.length - 1 ) === "\\" ) { + continue; + } + + if ( curLoop === result ) { + result = []; + } + + if ( Expr.preFilter[ type ] ) { + match = Expr.preFilter[ type ]( match, curLoop, inplace, result, not, isXMLFilter ); + + if ( !match ) { + anyFound = found = true; + + } else if ( match === true ) { + continue; + } + } + + if ( match ) { + for ( var i = 0; (item = curLoop[i]) != null; i++ ) { + if ( item ) { + found = filter( item, match, i, curLoop ); + var pass = not ^ !!found; + + if ( inplace && found != null ) { + if ( pass ) { + anyFound = true; + + } else { + curLoop[i] = false; + } + + } else if ( pass ) { + result.push( item ); + anyFound = true; + } + } + } + } + + if ( found !== undefined ) { + if ( !inplace ) { + curLoop = result; + } + + expr = expr.replace( Expr.match[ type ], "" ); + + if ( !anyFound ) { + return []; + } + + break; + } + } + } + + // Improper expression + if ( expr === old ) { + if ( anyFound == null ) { + Sizzle.error( expr ); + + } else { + break; + } + } + + old = expr; + } + + return curLoop; +}; + +Sizzle.error = function( msg ) { + throw "Syntax error, unrecognized expression: " + msg; +}; + +var Expr = Sizzle.selectors = { + order: [ "ID", "NAME", "TAG" ], + + match: { + ID: /#((?:[\w\u00c0-\uFFFF\-]|\\.)+)/, + CLASS: /\.((?:[\w\u00c0-\uFFFF\-]|\\.)+)/, + NAME: /\[name=['"]*((?:[\w\u00c0-\uFFFF\-]|\\.)+)['"]*\]/, + ATTR: /\[\s*((?:[\w\u00c0-\uFFFF\-]|\\.)+)\s*(?:(\S?=)\s*(?:(['"])(.*?)\3|(#?(?:[\w\u00c0-\uFFFF\-]|\\.)*)|)|)\s*\]/, + TAG: /^((?:[\w\u00c0-\uFFFF\*\-]|\\.)+)/, + CHILD: /:(only|nth|last|first)-child(?:\(\s*(even|odd|(?:[+\-]?\d+|(?:[+\-]?\d*)?n\s*(?:[+\-]\s*\d+)?))\s*\))?/, + POS: /:(nth|eq|gt|lt|first|last|even|odd)(?:\((\d*)\))?(?=[^\-]|$)/, + PSEUDO: /:((?:[\w\u00c0-\uFFFF\-]|\\.)+)(?:\((['"]?)((?:\([^\)]+\)|[^\(\)]*)+)\2\))?/ + }, + + leftMatch: {}, + + attrMap: { + "class": "className", + "for": "htmlFor" + }, + + attrHandle: { + href: function( elem ) { + return elem.getAttribute( "href" ); + }, + type: function( elem ) { + return elem.getAttribute( "type" ); + } + }, + + relative: { + "+": function(checkSet, part){ + var isPartStr = typeof part === "string", + isTag = isPartStr && !rNonWord.test( part ), + isPartStrNotTag = isPartStr && !isTag; + + if ( isTag ) { + part = part.toLowerCase(); + } + + for ( var i = 0, l = checkSet.length, elem; i < l; i++ ) { + if ( (elem = checkSet[i]) ) { + while ( (elem = elem.previousSibling) && elem.nodeType !== 1 ) {} + + checkSet[i] = isPartStrNotTag || elem && elem.nodeName.toLowerCase() === part ? + elem || false : + elem === part; + } + } + + if ( isPartStrNotTag ) { + Sizzle.filter( part, checkSet, true ); + } + }, + + ">": function( checkSet, part ) { + var elem, + isPartStr = typeof part === "string", + i = 0, + l = checkSet.length; + + if ( isPartStr && !rNonWord.test( part ) ) { + part = part.toLowerCase(); + + for ( ; i < l; i++ ) { + elem = checkSet[i]; + + if ( elem ) { + var parent = elem.parentNode; + checkSet[i] = parent.nodeName.toLowerCase() === part ? parent : false; + } + } + + } else { + for ( ; i < l; i++ ) { + elem = checkSet[i]; + + if ( elem ) { + checkSet[i] = isPartStr ? + elem.parentNode : + elem.parentNode === part; + } + } + + if ( isPartStr ) { + Sizzle.filter( part, checkSet, true ); + } + } + }, + + "": function(checkSet, part, isXML){ + var nodeCheck, + doneName = done++, + checkFn = dirCheck; + + if ( typeof part === "string" && !rNonWord.test( part ) ) { + part = part.toLowerCase(); + nodeCheck = part; + checkFn = dirNodeCheck; + } + + checkFn( "parentNode", part, doneName, checkSet, nodeCheck, isXML ); + }, + + "~": function( checkSet, part, isXML ) { + var nodeCheck, + doneName = done++, + checkFn = dirCheck; + + if ( typeof part === "string" && !rNonWord.test( part ) ) { + part = part.toLowerCase(); + nodeCheck = part; + checkFn = dirNodeCheck; + } + + checkFn( "previousSibling", part, doneName, checkSet, nodeCheck, isXML ); + } + }, + + find: { + ID: function( match, context, isXML ) { + if ( typeof context.getElementById !== "undefined" && !isXML ) { + var m = context.getElementById(match[1]); + // Check parentNode to catch when Blackberry 4.6 returns + // nodes that are no longer in the document #6963 + return m && m.parentNode ? [m] : []; + } + }, + + NAME: function( match, context ) { + if ( typeof context.getElementsByName !== "undefined" ) { + var ret = [], + results = context.getElementsByName( match[1] ); + + for ( var i = 0, l = results.length; i < l; i++ ) { + if ( results[i].getAttribute("name") === match[1] ) { + ret.push( results[i] ); + } + } + + return ret.length === 0 ? null : ret; + } + }, + + TAG: function( match, context ) { + if ( typeof context.getElementsByTagName !== "undefined" ) { + return context.getElementsByTagName( match[1] ); + } + } + }, + preFilter: { + CLASS: function( match, curLoop, inplace, result, not, isXML ) { + match = " " + match[1].replace( rBackslash, "" ) + " "; + + if ( isXML ) { + return match; + } + + for ( var i = 0, elem; (elem = curLoop[i]) != null; i++ ) { + if ( elem ) { + if ( not ^ (elem.className && (" " + elem.className + " ").replace(/[\t\n\r]/g, " ").indexOf(match) >= 0) ) { + if ( !inplace ) { + result.push( elem ); + } + + } else if ( inplace ) { + curLoop[i] = false; + } + } + } + + return false; + }, + + ID: function( match ) { + return match[1].replace( rBackslash, "" ); + }, + + TAG: function( match, curLoop ) { + return match[1].replace( rBackslash, "" ).toLowerCase(); + }, + + CHILD: function( match ) { + if ( match[1] === "nth" ) { + if ( !match[2] ) { + Sizzle.error( match[0] ); + } + + match[2] = match[2].replace(/^\+|\s*/g, ''); + + // parse equations like 'even', 'odd', '5', '2n', '3n+2', '4n-1', '-n+6' + var test = /(-?)(\d*)(?:n([+\-]?\d*))?/.exec( + match[2] === "even" && "2n" || match[2] === "odd" && "2n+1" || + !/\D/.test( match[2] ) && "0n+" + match[2] || match[2]); + + // calculate the numbers (first)n+(last) including if they are negative + match[2] = (test[1] + (test[2] || 1)) - 0; + match[3] = test[3] - 0; + } + else if ( match[2] ) { + Sizzle.error( match[0] ); + } + + // TODO: Move to normal caching system + match[0] = done++; + + return match; + }, + + ATTR: function( match, curLoop, inplace, result, not, isXML ) { + var name = match[1] = match[1].replace( rBackslash, "" ); + + if ( !isXML && Expr.attrMap[name] ) { + match[1] = Expr.attrMap[name]; + } + + // Handle if an un-quoted value was used + match[4] = ( match[4] || match[5] || "" ).replace( rBackslash, "" ); + + if ( match[2] === "~=" ) { + match[4] = " " + match[4] + " "; + } + + return match; + }, + + PSEUDO: function( match, curLoop, inplace, result, not ) { + if ( match[1] === "not" ) { + // If we're dealing with a complex expression, or a simple one + if ( ( chunker.exec(match[3]) || "" ).length > 1 || /^\w/.test(match[3]) ) { + match[3] = Sizzle(match[3], null, null, curLoop); + + } else { + var ret = Sizzle.filter(match[3], curLoop, inplace, true ^ not); + + if ( !inplace ) { + result.push.apply( result, ret ); + } + + return false; + } + + } else if ( Expr.match.POS.test( match[0] ) || Expr.match.CHILD.test( match[0] ) ) { + return true; + } + + return match; + }, + + POS: function( match ) { + match.unshift( true ); + + return match; + } + }, + + filters: { + enabled: function( elem ) { + return elem.disabled === false && elem.type !== "hidden"; + }, + + disabled: function( elem ) { + return elem.disabled === true; + }, + + checked: function( elem ) { + return elem.checked === true; + }, + + selected: function( elem ) { + // Accessing this property makes selected-by-default + // options in Safari work properly + if ( elem.parentNode ) { + elem.parentNode.selectedIndex; + } + + return elem.selected === true; + }, + + parent: function( elem ) { + return !!elem.firstChild; + }, + + empty: function( elem ) { + return !elem.firstChild; + }, + + has: function( elem, i, match ) { + return !!Sizzle( match[3], elem ).length; + }, + + header: function( elem ) { + return (/h\d/i).test( elem.nodeName ); + }, + + text: function( elem ) { + var attr = elem.getAttribute( "type" ), type = elem.type; + // IE6 and 7 will map elem.type to 'text' for new HTML5 types (search, etc) + // use getAttribute instead to test this case + return elem.nodeName.toLowerCase() === "input" && "text" === type && ( attr === type || attr === null ); + }, + + radio: function( elem ) { + return elem.nodeName.toLowerCase() === "input" && "radio" === elem.type; + }, + + checkbox: function( elem ) { + return elem.nodeName.toLowerCase() === "input" && "checkbox" === elem.type; + }, + + file: function( elem ) { + return elem.nodeName.toLowerCase() === "input" && "file" === elem.type; + }, + + password: function( elem ) { + return elem.nodeName.toLowerCase() === "input" && "password" === elem.type; + }, + + submit: function( elem ) { + var name = elem.nodeName.toLowerCase(); + return (name === "input" || name === "button") && "submit" === elem.type; + }, + + image: function( elem ) { + return elem.nodeName.toLowerCase() === "input" && "image" === elem.type; + }, + + reset: function( elem ) { + var name = elem.nodeName.toLowerCase(); + return (name === "input" || name === "button") && "reset" === elem.type; + }, + + button: function( elem ) { + var name = elem.nodeName.toLowerCase(); + return name === "input" && "button" === elem.type || name === "button"; + }, + + input: function( elem ) { + return (/input|select|textarea|button/i).test( elem.nodeName ); + }, + + focus: function( elem ) { + return elem === elem.ownerDocument.activeElement; + } + }, + setFilters: { + first: function( elem, i ) { + return i === 0; + }, + + last: function( elem, i, match, array ) { + return i === array.length - 1; + }, + + even: function( elem, i ) { + return i % 2 === 0; + }, + + odd: function( elem, i ) { + return i % 2 === 1; + }, + + lt: function( elem, i, match ) { + return i < match[3] - 0; + }, + + gt: function( elem, i, match ) { + return i > match[3] - 0; + }, + + nth: function( elem, i, match ) { + return match[3] - 0 === i; + }, + + eq: function( elem, i, match ) { + return match[3] - 0 === i; + } + }, + filter: { + PSEUDO: function( elem, match, i, array ) { + var name = match[1], + filter = Expr.filters[ name ]; + + if ( filter ) { + return filter( elem, i, match, array ); + + } else if ( name === "contains" ) { + return (elem.textContent || elem.innerText || Sizzle.getText([ elem ]) || "").indexOf(match[3]) >= 0; + + } else if ( name === "not" ) { + var not = match[3]; + + for ( var j = 0, l = not.length; j < l; j++ ) { + if ( not[j] === elem ) { + return false; + } + } + + return true; + + } else { + Sizzle.error( name ); + } + }, + + CHILD: function( elem, match ) { + var type = match[1], + node = elem; + + switch ( type ) { + case "only": + case "first": + while ( (node = node.previousSibling) ) { + if ( node.nodeType === 1 ) { + return false; + } + } + + if ( type === "first" ) { + return true; + } + + node = elem; + + case "last": + while ( (node = node.nextSibling) ) { + if ( node.nodeType === 1 ) { + return false; + } + } + + return true; + + case "nth": + var first = match[2], + last = match[3]; + + if ( first === 1 && last === 0 ) { + return true; + } + + var doneName = match[0], + parent = elem.parentNode; + + if ( parent && (parent.sizcache !== doneName || !elem.nodeIndex) ) { + var count = 0; + + for ( node = parent.firstChild; node; node = node.nextSibling ) { + if ( node.nodeType === 1 ) { + node.nodeIndex = ++count; + } + } + + parent.sizcache = doneName; + } + + var diff = elem.nodeIndex - last; + + if ( first === 0 ) { + return diff === 0; + + } else { + return ( diff % first === 0 && diff / first >= 0 ); + } + } + }, + + ID: function( elem, match ) { + return elem.nodeType === 1 && elem.getAttribute("id") === match; + }, + + TAG: function( elem, match ) { + return (match === "*" && elem.nodeType === 1) || elem.nodeName.toLowerCase() === match; + }, + + CLASS: function( elem, match ) { + return (" " + (elem.className || elem.getAttribute("class")) + " ") + .indexOf( match ) > -1; + }, + + ATTR: function( elem, match ) { + var name = match[1], + result = Expr.attrHandle[ name ] ? + Expr.attrHandle[ name ]( elem ) : + elem[ name ] != null ? + elem[ name ] : + elem.getAttribute( name ), + value = result + "", + type = match[2], + check = match[4]; + + return result == null ? + type === "!=" : + type === "=" ? + value === check : + type === "*=" ? + value.indexOf(check) >= 0 : + type === "~=" ? + (" " + value + " ").indexOf(check) >= 0 : + !check ? + value && result !== false : + type === "!=" ? + value !== check : + type === "^=" ? + value.indexOf(check) === 0 : + type === "$=" ? + value.substr(value.length - check.length) === check : + type === "|=" ? + value === check || value.substr(0, check.length + 1) === check + "-" : + false; + }, + + POS: function( elem, match, i, array ) { + var name = match[2], + filter = Expr.setFilters[ name ]; + + if ( filter ) { + return filter( elem, i, match, array ); + } + } + } +}; + +var origPOS = Expr.match.POS, + fescape = function(all, num){ + return "\\" + (num - 0 + 1); + }; + +for ( var type in Expr.match ) { + Expr.match[ type ] = new RegExp( Expr.match[ type ].source + (/(?![^\[]*\])(?![^\(]*\))/.source) ); + Expr.leftMatch[ type ] = new RegExp( /(^(?:.|\r|\n)*?)/.source + Expr.match[ type ].source.replace(/\\(\d+)/g, fescape) ); +} + +var makeArray = function( array, results ) { + array = Array.prototype.slice.call( array, 0 ); + + if ( results ) { + results.push.apply( results, array ); + return results; + } + + return array; +}; + +// Perform a simple check to determine if the browser is capable of +// converting a NodeList to an array using builtin methods. +// Also verifies that the returned array holds DOM nodes +// (which is not the case in the Blackberry browser) +try { + Array.prototype.slice.call( document.documentElement.childNodes, 0 )[0].nodeType; + +// Provide a fallback method if it does not work +} catch( e ) { + makeArray = function( array, results ) { + var i = 0, + ret = results || []; + + if ( toString.call(array) === "[object Array]" ) { + Array.prototype.push.apply( ret, array ); + + } else { + if ( typeof array.length === "number" ) { + for ( var l = array.length; i < l; i++ ) { + ret.push( array[i] ); + } + + } else { + for ( ; array[i]; i++ ) { + ret.push( array[i] ); + } + } + } + + return ret; + }; +} + +var sortOrder, siblingCheck; + +if ( document.documentElement.compareDocumentPosition ) { + sortOrder = function( a, b ) { + if ( a === b ) { + hasDuplicate = true; + return 0; + } + + if ( !a.compareDocumentPosition || !b.compareDocumentPosition ) { + return a.compareDocumentPosition ? -1 : 1; + } + + return a.compareDocumentPosition(b) & 4 ? -1 : 1; + }; + +} else { + sortOrder = function( a, b ) { + // The nodes are identical, we can exit early + if ( a === b ) { + hasDuplicate = true; + return 0; + + // Fallback to using sourceIndex (in IE) if it's available on both nodes + } else if ( a.sourceIndex && b.sourceIndex ) { + return a.sourceIndex - b.sourceIndex; + } + + var al, bl, + ap = [], + bp = [], + aup = a.parentNode, + bup = b.parentNode, + cur = aup; + + // If the nodes are siblings (or identical) we can do a quick check + if ( aup === bup ) { + return siblingCheck( a, b ); + + // If no parents were found then the nodes are disconnected + } else if ( !aup ) { + return -1; + + } else if ( !bup ) { + return 1; + } + + // Otherwise they're somewhere else in the tree so we need + // to build up a full list of the parentNodes for comparison + while ( cur ) { + ap.unshift( cur ); + cur = cur.parentNode; + } + + cur = bup; + + while ( cur ) { + bp.unshift( cur ); + cur = cur.parentNode; + } + + al = ap.length; + bl = bp.length; + + // Start walking down the tree looking for a discrepancy + for ( var i = 0; i < al && i < bl; i++ ) { + if ( ap[i] !== bp[i] ) { + return siblingCheck( ap[i], bp[i] ); + } + } + + // We ended someplace up the tree so do a sibling check + return i === al ? + siblingCheck( a, bp[i], -1 ) : + siblingCheck( ap[i], b, 1 ); + }; + + siblingCheck = function( a, b, ret ) { + if ( a === b ) { + return ret; + } + + var cur = a.nextSibling; + + while ( cur ) { + if ( cur === b ) { + return -1; + } + + cur = cur.nextSibling; + } + + return 1; + }; +} + +// Utility function for retreiving the text value of an array of DOM nodes +Sizzle.getText = function( elems ) { + var ret = "", elem; + + for ( var i = 0; elems[i]; i++ ) { + elem = elems[i]; + + // Get the text from text nodes and CDATA nodes + if ( elem.nodeType === 3 || elem.nodeType === 4 ) { + ret += elem.nodeValue; + + // Traverse everything else, except comment nodes + } else if ( elem.nodeType !== 8 ) { + ret += Sizzle.getText( elem.childNodes ); + } + } + + return ret; +}; + +// Check to see if the browser returns elements by name when +// querying by getElementById (and provide a workaround) +(function(){ + // We're going to inject a fake input element with a specified name + var form = document.createElement("div"), + id = "script" + (new Date()).getTime(), + root = document.documentElement; + + form.innerHTML = ""; + + // Inject it into the root element, check its status, and remove it quickly + root.insertBefore( form, root.firstChild ); + + // The workaround has to do additional checks after a getElementById + // Which slows things down for other browsers (hence the branching) + if ( document.getElementById( id ) ) { + Expr.find.ID = function( match, context, isXML ) { + if ( typeof context.getElementById !== "undefined" && !isXML ) { + var m = context.getElementById(match[1]); + + return m ? + m.id === match[1] || typeof m.getAttributeNode !== "undefined" && m.getAttributeNode("id").nodeValue === match[1] ? + [m] : + undefined : + []; + } + }; + + Expr.filter.ID = function( elem, match ) { + var node = typeof elem.getAttributeNode !== "undefined" && elem.getAttributeNode("id"); + + return elem.nodeType === 1 && node && node.nodeValue === match; + }; + } + + root.removeChild( form ); + + // release memory in IE + root = form = null; +})(); + +(function(){ + // Check to see if the browser returns only elements + // when doing getElementsByTagName("*") + + // Create a fake element + var div = document.createElement("div"); + div.appendChild( document.createComment("") ); + + // Make sure no comments are found + if ( div.getElementsByTagName("*").length > 0 ) { + Expr.find.TAG = function( match, context ) { + var results = context.getElementsByTagName( match[1] ); + + // Filter out possible comments + if ( match[1] === "*" ) { + var tmp = []; + + for ( var i = 0; results[i]; i++ ) { + if ( results[i].nodeType === 1 ) { + tmp.push( results[i] ); + } + } + + results = tmp; + } + + return results; + }; + } + + // Check to see if an attribute returns normalized href attributes + div.innerHTML = ""; + + if ( div.firstChild && typeof div.firstChild.getAttribute !== "undefined" && + div.firstChild.getAttribute("href") !== "#" ) { + + Expr.attrHandle.href = function( elem ) { + return elem.getAttribute( "href", 2 ); + }; + } + + // release memory in IE + div = null; +})(); + +if ( document.querySelectorAll ) { + (function(){ + var oldSizzle = Sizzle, + div = document.createElement("div"), + id = "__sizzle__"; + + div.innerHTML = "

    "; + + // Safari can't handle uppercase or unicode characters when + // in quirks mode. + if ( div.querySelectorAll && div.querySelectorAll(".TEST").length === 0 ) { + return; + } + + Sizzle = function( query, context, extra, seed ) { + context = context || document; + + // Only use querySelectorAll on non-XML documents + // (ID selectors don't work in non-HTML documents) + if ( !seed && !Sizzle.isXML(context) ) { + // See if we find a selector to speed up + var match = /^(\w+$)|^\.([\w\-]+$)|^#([\w\-]+$)/.exec( query ); + + if ( match && (context.nodeType === 1 || context.nodeType === 9) ) { + // Speed-up: Sizzle("TAG") + if ( match[1] ) { + return makeArray( context.getElementsByTagName( query ), extra ); + + // Speed-up: Sizzle(".CLASS") + } else if ( match[2] && Expr.find.CLASS && context.getElementsByClassName ) { + return makeArray( context.getElementsByClassName( match[2] ), extra ); + } + } + + if ( context.nodeType === 9 ) { + // Speed-up: Sizzle("body") + // The body element only exists once, optimize finding it + if ( query === "body" && context.body ) { + return makeArray( [ context.body ], extra ); + + // Speed-up: Sizzle("#ID") + } else if ( match && match[3] ) { + var elem = context.getElementById( match[3] ); + + // Check parentNode to catch when Blackberry 4.6 returns + // nodes that are no longer in the document #6963 + if ( elem && elem.parentNode ) { + // Handle the case where IE and Opera return items + // by name instead of ID + if ( elem.id === match[3] ) { + return makeArray( [ elem ], extra ); + } + + } else { + return makeArray( [], extra ); + } + } + + try { + return makeArray( context.querySelectorAll(query), extra ); + } catch(qsaError) {} + + // qSA works strangely on Element-rooted queries + // We can work around this by specifying an extra ID on the root + // and working up from there (Thanks to Andrew Dupont for the technique) + // IE 8 doesn't work on object elements + } else if ( context.nodeType === 1 && context.nodeName.toLowerCase() !== "object" ) { + var oldContext = context, + old = context.getAttribute( "id" ), + nid = old || id, + hasParent = context.parentNode, + relativeHierarchySelector = /^\s*[+~]/.test( query ); + + if ( !old ) { + context.setAttribute( "id", nid ); + } else { + nid = nid.replace( /'/g, "\\$&" ); + } + if ( relativeHierarchySelector && hasParent ) { + context = context.parentNode; + } + + try { + if ( !relativeHierarchySelector || hasParent ) { + return makeArray( context.querySelectorAll( "[id='" + nid + "'] " + query ), extra ); + } + + } catch(pseudoError) { + } finally { + if ( !old ) { + oldContext.removeAttribute( "id" ); + } + } + } + } + + return oldSizzle(query, context, extra, seed); + }; + + for ( var prop in oldSizzle ) { + Sizzle[ prop ] = oldSizzle[ prop ]; + } + + // release memory in IE + div = null; + })(); +} + +(function(){ + var html = document.documentElement, + matches = html.matchesSelector || html.mozMatchesSelector || html.webkitMatchesSelector || html.msMatchesSelector; + + if ( matches ) { + // Check to see if it's possible to do matchesSelector + // on a disconnected node (IE 9 fails this) + var disconnectedMatch = !matches.call( document.createElement( "div" ), "div" ), + pseudoWorks = false; + + try { + // This should fail with an exception + // Gecko does not error, returns false instead + matches.call( document.documentElement, "[test!='']:sizzle" ); + + } catch( pseudoError ) { + pseudoWorks = true; + } + + Sizzle.matchesSelector = function( node, expr ) { + // Make sure that attribute selectors are quoted + expr = expr.replace(/\=\s*([^'"\]]*)\s*\]/g, "='$1']"); + + if ( !Sizzle.isXML( node ) ) { + try { + if ( pseudoWorks || !Expr.match.PSEUDO.test( expr ) && !/!=/.test( expr ) ) { + var ret = matches.call( node, expr ); + + // IE 9's matchesSelector returns false on disconnected nodes + if ( ret || !disconnectedMatch || + // As well, disconnected nodes are said to be in a document + // fragment in IE 9, so check for that + node.document && node.document.nodeType !== 11 ) { + return ret; + } + } + } catch(e) {} + } + + return Sizzle(expr, null, null, [node]).length > 0; + }; + } +})(); + +(function(){ + var div = document.createElement("div"); + + div.innerHTML = "
    "; + + // Opera can't find a second classname (in 9.6) + // Also, make sure that getElementsByClassName actually exists + if ( !div.getElementsByClassName || div.getElementsByClassName("e").length === 0 ) { + return; + } + + // Safari caches class attributes, doesn't catch changes (in 3.2) + div.lastChild.className = "e"; + + if ( div.getElementsByClassName("e").length === 1 ) { + return; + } + + Expr.order.splice(1, 0, "CLASS"); + Expr.find.CLASS = function( match, context, isXML ) { + if ( typeof context.getElementsByClassName !== "undefined" && !isXML ) { + return context.getElementsByClassName(match[1]); + } + }; + + // release memory in IE + div = null; +})(); + +function dirNodeCheck( dir, cur, doneName, checkSet, nodeCheck, isXML ) { + for ( var i = 0, l = checkSet.length; i < l; i++ ) { + var elem = checkSet[i]; + + if ( elem ) { + var match = false; + + elem = elem[dir]; + + while ( elem ) { + if ( elem.sizcache === doneName ) { + match = checkSet[elem.sizset]; + break; + } + + if ( elem.nodeType === 1 && !isXML ){ + elem.sizcache = doneName; + elem.sizset = i; + } + + if ( elem.nodeName.toLowerCase() === cur ) { + match = elem; + break; + } + + elem = elem[dir]; + } + + checkSet[i] = match; + } + } +} + +function dirCheck( dir, cur, doneName, checkSet, nodeCheck, isXML ) { + for ( var i = 0, l = checkSet.length; i < l; i++ ) { + var elem = checkSet[i]; + + if ( elem ) { + var match = false; + + elem = elem[dir]; + + while ( elem ) { + if ( elem.sizcache === doneName ) { + match = checkSet[elem.sizset]; + break; + } + + if ( elem.nodeType === 1 ) { + if ( !isXML ) { + elem.sizcache = doneName; + elem.sizset = i; + } + + if ( typeof cur !== "string" ) { + if ( elem === cur ) { + match = true; + break; + } + + } else if ( Sizzle.filter( cur, [elem] ).length > 0 ) { + match = elem; + break; + } + } + + elem = elem[dir]; + } + + checkSet[i] = match; + } + } +} + +if ( document.documentElement.contains ) { + Sizzle.contains = function( a, b ) { + return a !== b && (a.contains ? a.contains(b) : true); + }; + +} else if ( document.documentElement.compareDocumentPosition ) { + Sizzle.contains = function( a, b ) { + return !!(a.compareDocumentPosition(b) & 16); + }; + +} else { + Sizzle.contains = function() { + return false; + }; +} + +Sizzle.isXML = function( elem ) { + // documentElement is verified for cases where it doesn't yet exist + // (such as loading iframes in IE - #4833) + var documentElement = (elem ? elem.ownerDocument || elem : 0).documentElement; + + return documentElement ? documentElement.nodeName !== "HTML" : false; +}; + +var posProcess = function( selector, context ) { + var match, + tmpSet = [], + later = "", + root = context.nodeType ? [context] : context; + + // Position selectors must be done after the filter + // And so must :not(positional) so we move all PSEUDOs to the end + while ( (match = Expr.match.PSEUDO.exec( selector )) ) { + later += match[0]; + selector = selector.replace( Expr.match.PSEUDO, "" ); + } + + selector = Expr.relative[selector] ? selector + "*" : selector; + + for ( var i = 0, l = root.length; i < l; i++ ) { + Sizzle( selector, root[i], tmpSet ); + } + + return Sizzle.filter( later, tmpSet ); +}; + +// EXPOSE +jQuery.find = Sizzle; +jQuery.expr = Sizzle.selectors; +jQuery.expr[":"] = jQuery.expr.filters; +jQuery.unique = Sizzle.uniqueSort; +jQuery.text = Sizzle.getText; +jQuery.isXMLDoc = Sizzle.isXML; +jQuery.contains = Sizzle.contains; + + +})(); + + +var runtil = /Until$/, + rparentsprev = /^(?:parents|prevUntil|prevAll)/, + // Note: This RegExp should be improved, or likely pulled from Sizzle + rmultiselector = /,/, + isSimple = /^.[^:#\[\.,]*$/, + slice = Array.prototype.slice, + POS = jQuery.expr.match.POS, + // methods guaranteed to produce a unique set when starting from a unique set + guaranteedUnique = { + children: true, + contents: true, + next: true, + prev: true + }; + +jQuery.fn.extend({ + find: function( selector ) { + var self = this, + i, l; + + if ( typeof selector !== "string" ) { + return jQuery( selector ).filter(function() { + for ( i = 0, l = self.length; i < l; i++ ) { + if ( jQuery.contains( self[ i ], this ) ) { + return true; + } + } + }); + } + + var ret = this.pushStack( "", "find", selector ), + length, n, r; + + for ( i = 0, l = this.length; i < l; i++ ) { + length = ret.length; + jQuery.find( selector, this[i], ret ); + + if ( i > 0 ) { + // Make sure that the results are unique + for ( n = length; n < ret.length; n++ ) { + for ( r = 0; r < length; r++ ) { + if ( ret[r] === ret[n] ) { + ret.splice(n--, 1); + break; + } + } + } + } + } + + return ret; + }, + + has: function( target ) { + var targets = jQuery( target ); + return this.filter(function() { + for ( var i = 0, l = targets.length; i < l; i++ ) { + if ( jQuery.contains( this, targets[i] ) ) { + return true; + } + } + }); + }, + + not: function( selector ) { + return this.pushStack( winnow(this, selector, false), "not", selector); + }, + + filter: function( selector ) { + return this.pushStack( winnow(this, selector, true), "filter", selector ); + }, + + is: function( selector ) { + return !!selector && ( typeof selector === "string" ? + jQuery.filter( selector, this ).length > 0 : + this.filter( selector ).length > 0 ); + }, + + closest: function( selectors, context ) { + var ret = [], i, l, cur = this[0]; + + // Array + if ( jQuery.isArray( selectors ) ) { + var match, selector, + matches = {}, + level = 1; + + if ( cur && selectors.length ) { + for ( i = 0, l = selectors.length; i < l; i++ ) { + selector = selectors[i]; + + if ( !matches[ selector ] ) { + matches[ selector ] = POS.test( selector ) ? + jQuery( selector, context || this.context ) : + selector; + } + } + + while ( cur && cur.ownerDocument && cur !== context ) { + for ( selector in matches ) { + match = matches[ selector ]; + + if ( match.jquery ? match.index( cur ) > -1 : jQuery( cur ).is( match ) ) { + ret.push({ selector: selector, elem: cur, level: level }); + } + } + + cur = cur.parentNode; + level++; + } + } + + return ret; + } + + // String + var pos = POS.test( selectors ) || typeof selectors !== "string" ? + jQuery( selectors, context || this.context ) : + 0; + + for ( i = 0, l = this.length; i < l; i++ ) { + cur = this[i]; + + while ( cur ) { + if ( pos ? pos.index(cur) > -1 : jQuery.find.matchesSelector(cur, selectors) ) { + ret.push( cur ); + break; + + } else { + cur = cur.parentNode; + if ( !cur || !cur.ownerDocument || cur === context || cur.nodeType === 11 ) { + break; + } + } + } + } + + ret = ret.length > 1 ? jQuery.unique( ret ) : ret; + + return this.pushStack( ret, "closest", selectors ); + }, + + // Determine the position of an element within + // the matched set of elements + index: function( elem ) { + + // No argument, return index in parent + if ( !elem ) { + return ( this[0] && this[0].parentNode ) ? this.prevAll().length : -1; + } + + // index in selector + if ( typeof elem === "string" ) { + return jQuery.inArray( this[0], jQuery( elem ) ); + } + + // Locate the position of the desired element + return jQuery.inArray( + // If it receives a jQuery object, the first element is used + elem.jquery ? elem[0] : elem, this ); + }, + + add: function( selector, context ) { + var set = typeof selector === "string" ? + jQuery( selector, context ) : + jQuery.makeArray( selector && selector.nodeType ? [ selector ] : selector ), + all = jQuery.merge( this.get(), set ); + + return this.pushStack( isDisconnected( set[0] ) || isDisconnected( all[0] ) ? + all : + jQuery.unique( all ) ); + }, + + andSelf: function() { + return this.add( this.prevObject ); + } +}); + +// A painfully simple check to see if an element is disconnected +// from a document (should be improved, where feasible). +function isDisconnected( node ) { + return !node || !node.parentNode || node.parentNode.nodeType === 11; +} + +jQuery.each({ + parent: function( elem ) { + var parent = elem.parentNode; + return parent && parent.nodeType !== 11 ? parent : null; + }, + parents: function( elem ) { + return jQuery.dir( elem, "parentNode" ); + }, + parentsUntil: function( elem, i, until ) { + return jQuery.dir( elem, "parentNode", until ); + }, + next: function( elem ) { + return jQuery.nth( elem, 2, "nextSibling" ); + }, + prev: function( elem ) { + return jQuery.nth( elem, 2, "previousSibling" ); + }, + nextAll: function( elem ) { + return jQuery.dir( elem, "nextSibling" ); + }, + prevAll: function( elem ) { + return jQuery.dir( elem, "previousSibling" ); + }, + nextUntil: function( elem, i, until ) { + return jQuery.dir( elem, "nextSibling", until ); + }, + prevUntil: function( elem, i, until ) { + return jQuery.dir( elem, "previousSibling", until ); + }, + siblings: function( elem ) { + return jQuery.sibling( elem.parentNode.firstChild, elem ); + }, + children: function( elem ) { + return jQuery.sibling( elem.firstChild ); + }, + contents: function( elem ) { + return jQuery.nodeName( elem, "iframe" ) ? + elem.contentDocument || elem.contentWindow.document : + jQuery.makeArray( elem.childNodes ); + } +}, function( name, fn ) { + jQuery.fn[ name ] = function( until, selector ) { + var ret = jQuery.map( this, fn, until ), + // The variable 'args' was introduced in + // https://github.com/jquery/jquery/commit/52a0238 + // to work around a bug in Chrome 10 (Dev) and should be removed when the bug is fixed. + // http://code.google.com/p/v8/issues/detail?id=1050 + args = slice.call(arguments); + + if ( !runtil.test( name ) ) { + selector = until; + } + + if ( selector && typeof selector === "string" ) { + ret = jQuery.filter( selector, ret ); + } + + ret = this.length > 1 && !guaranteedUnique[ name ] ? jQuery.unique( ret ) : ret; + + if ( (this.length > 1 || rmultiselector.test( selector )) && rparentsprev.test( name ) ) { + ret = ret.reverse(); + } + + return this.pushStack( ret, name, args.join(",") ); + }; +}); + +jQuery.extend({ + filter: function( expr, elems, not ) { + if ( not ) { + expr = ":not(" + expr + ")"; + } + + return elems.length === 1 ? + jQuery.find.matchesSelector(elems[0], expr) ? [ elems[0] ] : [] : + jQuery.find.matches(expr, elems); + }, + + dir: function( elem, dir, until ) { + var matched = [], + cur = elem[ dir ]; + + while ( cur && cur.nodeType !== 9 && (until === undefined || cur.nodeType !== 1 || !jQuery( cur ).is( until )) ) { + if ( cur.nodeType === 1 ) { + matched.push( cur ); + } + cur = cur[dir]; + } + return matched; + }, + + nth: function( cur, result, dir, elem ) { + result = result || 1; + var num = 0; + + for ( ; cur; cur = cur[dir] ) { + if ( cur.nodeType === 1 && ++num === result ) { + break; + } + } + + return cur; + }, + + sibling: function( n, elem ) { + var r = []; + + for ( ; n; n = n.nextSibling ) { + if ( n.nodeType === 1 && n !== elem ) { + r.push( n ); + } + } + + return r; + } +}); + +// Implement the identical functionality for filter and not +function winnow( elements, qualifier, keep ) { + + // Can't pass null or undefined to indexOf in Firefox 4 + // Set to 0 to skip string check + qualifier = qualifier || 0; + + if ( jQuery.isFunction( qualifier ) ) { + return jQuery.grep(elements, function( elem, i ) { + var retVal = !!qualifier.call( elem, i, elem ); + return retVal === keep; + }); + + } else if ( qualifier.nodeType ) { + return jQuery.grep(elements, function( elem, i ) { + return (elem === qualifier) === keep; + }); + + } else if ( typeof qualifier === "string" ) { + var filtered = jQuery.grep(elements, function( elem ) { + return elem.nodeType === 1; + }); + + if ( isSimple.test( qualifier ) ) { + return jQuery.filter(qualifier, filtered, !keep); + } else { + qualifier = jQuery.filter( qualifier, filtered ); + } + } + + return jQuery.grep(elements, function( elem, i ) { + return (jQuery.inArray( elem, qualifier ) >= 0) === keep; + }); +} + + + + +var rinlinejQuery = / jQuery\d+="(?:\d+|null)"/g, + rleadingWhitespace = /^\s+/, + rxhtmlTag = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/ig, + rtagName = /<([\w:]+)/, + rtbody = /", "" ], + legend: [ 1, "
    ", "
    " ], + thead: [ 1, "", "
    " ], + tr: [ 2, "", "
    " ], + td: [ 3, "", "
    " ], + col: [ 2, "", "
    " ], + area: [ 1, "", "" ], + _default: [ 0, "", "" ] + }; + +wrapMap.optgroup = wrapMap.option; +wrapMap.tbody = wrapMap.tfoot = wrapMap.colgroup = wrapMap.caption = wrapMap.thead; +wrapMap.th = wrapMap.td; + +// IE can't serialize and - - - + + + diff --git a/addons/web/static/lib/nivjs/test/test.js b/addons/web/static/lib/novajs/test/test.js similarity index 82% rename from addons/web/static/lib/nivjs/test/test.js rename to addons/web/static/lib/novajs/test/test.js index 244ba8d7f26..4ae3418212e 100644 --- a/addons/web/static/lib/nivjs/test/test.js +++ b/addons/web/static/lib/novajs/test/test.js @@ -2,9 +2,9 @@ module("Class"); test("base", function() { - ok(!!niv.Class, "Class does exist"); - ok(!!niv.Class.extend, "extend does exist"); - var Claz = niv.Class.extend({ + ok(!!nova.Class, "Class does exist"); + ok(!!nova.Class.extend, "extend does exist"); + var Claz = nova.Class.extend({ test: function() { return "ok"; } @@ -21,7 +21,7 @@ test("base", function() { module("DestroyableMixin"); test("base", function() { - var Claz = niv.Class.extend(_.extend({}, niv.DestroyableMixin, {})); + var Claz = nova.Class.extend(_.extend({}, nova.DestroyableMixin, {})); var x = new Claz(); equal(!!x.isDestroyed(), false); x.destroy(); @@ -31,7 +31,7 @@ test("base", function() { module("ParentedMixin"); test("base", function() { - var Claz = niv.Class.extend(_.extend({}, niv.ParentedMixin, {})); + var Claz = nova.Class.extend(_.extend({}, nova.ParentedMixin, {})); var x = new Claz(); var y = new Claz(); y.setParent(x); @@ -44,7 +44,7 @@ test("base", function() { module("Events"); test("base", function() { - var x = new niv.internal.Events(); + var x = new nova.internal.Events(); var tmp = 0; var fct = function() {tmp = 1;}; x.on("test", fct); @@ -60,7 +60,7 @@ test("base", function() { module("EventDispatcherMixin"); test("base", function() { - var Claz = niv.Class.extend(_.extend({}, niv.EventDispatcherMixin, {})); + var Claz = nova.Class.extend(_.extend({}, nova.EventDispatcherMixin, {})); var x = new Claz(); var y = new Claz(); var tmp = 0; @@ -83,7 +83,7 @@ test("base", function() { module("GetterSetterMixin"); test("base", function() { - var Claz = niv.Class.extend(_.extend({}, niv.GetterSetterMixin, {})); + var Claz = nova.Class.extend(_.extend({}, nova.GetterSetterMixin, {})); var x = new Claz(); var y = new Claz(); x.set({test: 1}); @@ -103,7 +103,7 @@ test("base", function() { module("Widget"); test("base", function() { - var Claz = niv.Widget.extend({ + var Claz = nova.Widget.extend({ render_element: function() { this.$element.attr("id", "testdiv"); this.$element.html("test"); diff --git a/addons/web/static/lib/novajs/test/underscore.js b/addons/web/static/lib/novajs/test/underscore.js new file mode 100644 index 00000000000..208d4cd890c --- /dev/null +++ b/addons/web/static/lib/novajs/test/underscore.js @@ -0,0 +1,999 @@ +// Underscore.js 1.3.1 +// (c) 2009-2012 Jeremy Ashkenas, DocumentCloud Inc. +// Underscore is freely distributable under the MIT license. +// Portions of Underscore are inspired or borrowed from Prototype, +// Oliver Steele's Functional, and John Resig's Micro-Templating. +// For all details and documentation: +// http://documentcloud.github.com/underscore + +(function() { + + // Baseline setup + // -------------- + + // Establish the root object, `window` in the browser, or `global` on the server. + var root = this; + + // Save the previous value of the `_` variable. + var previousUnderscore = root._; + + // Establish the object that gets returned to break out of a loop iteration. + var breaker = {}; + + // Save bytes in the minified (but not gzipped) version: + var ArrayProto = Array.prototype, ObjProto = Object.prototype, FuncProto = Function.prototype; + + // Create quick reference variables for speed access to core prototypes. + var slice = ArrayProto.slice, + unshift = ArrayProto.unshift, + toString = ObjProto.toString, + hasOwnProperty = ObjProto.hasOwnProperty; + + // All **ECMAScript 5** native function implementations that we hope to use + // are declared here. + var + nativeForEach = ArrayProto.forEach, + nativeMap = ArrayProto.map, + nativeReduce = ArrayProto.reduce, + nativeReduceRight = ArrayProto.reduceRight, + nativeFilter = ArrayProto.filter, + nativeEvery = ArrayProto.every, + nativeSome = ArrayProto.some, + nativeIndexOf = ArrayProto.indexOf, + nativeLastIndexOf = ArrayProto.lastIndexOf, + nativeIsArray = Array.isArray, + nativeKeys = Object.keys, + nativeBind = FuncProto.bind; + + // Create a safe reference to the Underscore object for use below. + var _ = function(obj) { return new wrapper(obj); }; + + // Export the Underscore object for **Node.js**, with + // backwards-compatibility for the old `require()` API. If we're in + // the browser, add `_` as a global object via a string identifier, + // for Closure Compiler "advanced" mode. + if (typeof exports !== 'undefined') { + if (typeof module !== 'undefined' && module.exports) { + exports = module.exports = _; + } + exports._ = _; + } else { + root['_'] = _; + } + + // Current version. + _.VERSION = '1.3.1'; + + // Collection Functions + // -------------------- + + // The cornerstone, an `each` implementation, aka `forEach`. + // Handles objects with the built-in `forEach`, arrays, and raw objects. + // Delegates to **ECMAScript 5**'s native `forEach` if available. + var each = _.each = _.forEach = function(obj, iterator, context) { + if (obj == null) return; + if (nativeForEach && obj.forEach === nativeForEach) { + obj.forEach(iterator, context); + } else if (obj.length === +obj.length) { + for (var i = 0, l = obj.length; i < l; i++) { + if (i in obj && iterator.call(context, obj[i], i, obj) === breaker) return; + } + } else { + for (var key in obj) { + if (_.has(obj, key)) { + if (iterator.call(context, obj[key], key, obj) === breaker) return; + } + } + } + }; + + // Return the results of applying the iterator to each element. + // Delegates to **ECMAScript 5**'s native `map` if available. + _.map = _.collect = function(obj, iterator, context) { + var results = []; + if (obj == null) return results; + if (nativeMap && obj.map === nativeMap) return obj.map(iterator, context); + each(obj, function(value, index, list) { + results[results.length] = iterator.call(context, value, index, list); + }); + if (obj.length === +obj.length) results.length = obj.length; + return results; + }; + + // **Reduce** builds up a single result from a list of values, aka `inject`, + // or `foldl`. Delegates to **ECMAScript 5**'s native `reduce` if available. + _.reduce = _.foldl = _.inject = function(obj, iterator, memo, context) { + var initial = arguments.length > 2; + if (obj == null) obj = []; + if (nativeReduce && obj.reduce === nativeReduce) { + if (context) iterator = _.bind(iterator, context); + return initial ? obj.reduce(iterator, memo) : obj.reduce(iterator); + } + each(obj, function(value, index, list) { + if (!initial) { + memo = value; + initial = true; + } else { + memo = iterator.call(context, memo, value, index, list); + } + }); + if (!initial) throw new TypeError('Reduce of empty array with no initial value'); + return memo; + }; + + // The right-associative version of reduce, also known as `foldr`. + // Delegates to **ECMAScript 5**'s native `reduceRight` if available. + _.reduceRight = _.foldr = function(obj, iterator, memo, context) { + var initial = arguments.length > 2; + if (obj == null) obj = []; + if (nativeReduceRight && obj.reduceRight === nativeReduceRight) { + if (context) iterator = _.bind(iterator, context); + return initial ? obj.reduceRight(iterator, memo) : obj.reduceRight(iterator); + } + var reversed = _.toArray(obj).reverse(); + if (context && !initial) iterator = _.bind(iterator, context); + return initial ? _.reduce(reversed, iterator, memo, context) : _.reduce(reversed, iterator); + }; + + // Return the first value which passes a truth test. Aliased as `detect`. + _.find = _.detect = function(obj, iterator, context) { + var result; + any(obj, function(value, index, list) { + if (iterator.call(context, value, index, list)) { + result = value; + return true; + } + }); + return result; + }; + + // Return all the elements that pass a truth test. + // Delegates to **ECMAScript 5**'s native `filter` if available. + // Aliased as `select`. + _.filter = _.select = function(obj, iterator, context) { + var results = []; + if (obj == null) return results; + if (nativeFilter && obj.filter === nativeFilter) return obj.filter(iterator, context); + each(obj, function(value, index, list) { + if (iterator.call(context, value, index, list)) results[results.length] = value; + }); + return results; + }; + + // Return all the elements for which a truth test fails. + _.reject = function(obj, iterator, context) { + var results = []; + if (obj == null) return results; + each(obj, function(value, index, list) { + if (!iterator.call(context, value, index, list)) results[results.length] = value; + }); + return results; + }; + + // Determine whether all of the elements match a truth test. + // Delegates to **ECMAScript 5**'s native `every` if available. + // Aliased as `all`. + _.every = _.all = function(obj, iterator, context) { + var result = true; + if (obj == null) return result; + if (nativeEvery && obj.every === nativeEvery) return obj.every(iterator, context); + each(obj, function(value, index, list) { + if (!(result = result && iterator.call(context, value, index, list))) return breaker; + }); + return result; + }; + + // Determine if at least one element in the object matches a truth test. + // Delegates to **ECMAScript 5**'s native `some` if available. + // Aliased as `any`. + var any = _.some = _.any = function(obj, iterator, context) { + iterator || (iterator = _.identity); + var result = false; + if (obj == null) return result; + if (nativeSome && obj.some === nativeSome) return obj.some(iterator, context); + each(obj, function(value, index, list) { + if (result || (result = iterator.call(context, value, index, list))) return breaker; + }); + return !!result; + }; + + // Determine if a given value is included in the array or object using `===`. + // Aliased as `contains`. + _.include = _.contains = function(obj, target) { + var found = false; + if (obj == null) return found; + if (nativeIndexOf && obj.indexOf === nativeIndexOf) return obj.indexOf(target) != -1; + found = any(obj, function(value) { + return value === target; + }); + return found; + }; + + // Invoke a method (with arguments) on every item in a collection. + _.invoke = function(obj, method) { + var args = slice.call(arguments, 2); + return _.map(obj, function(value) { + return (_.isFunction(method) ? method || value : value[method]).apply(value, args); + }); + }; + + // Convenience version of a common use case of `map`: fetching a property. + _.pluck = function(obj, key) { + return _.map(obj, function(value){ return value[key]; }); + }; + + // Return the maximum element or (element-based computation). + _.max = function(obj, iterator, context) { + if (!iterator && _.isArray(obj)) return Math.max.apply(Math, obj); + if (!iterator && _.isEmpty(obj)) return -Infinity; + var result = {computed : -Infinity}; + each(obj, function(value, index, list) { + var computed = iterator ? iterator.call(context, value, index, list) : value; + computed >= result.computed && (result = {value : value, computed : computed}); + }); + return result.value; + }; + + // Return the minimum element (or element-based computation). + _.min = function(obj, iterator, context) { + if (!iterator && _.isArray(obj)) return Math.min.apply(Math, obj); + if (!iterator && _.isEmpty(obj)) return Infinity; + var result = {computed : Infinity}; + each(obj, function(value, index, list) { + var computed = iterator ? iterator.call(context, value, index, list) : value; + computed < result.computed && (result = {value : value, computed : computed}); + }); + return result.value; + }; + + // Shuffle an array. + _.shuffle = function(obj) { + var shuffled = [], rand; + each(obj, function(value, index, list) { + if (index == 0) { + shuffled[0] = value; + } else { + rand = Math.floor(Math.random() * (index + 1)); + shuffled[index] = shuffled[rand]; + shuffled[rand] = value; + } + }); + return shuffled; + }; + + // Sort the object's values by a criterion produced by an iterator. + _.sortBy = function(obj, iterator, context) { + return _.pluck(_.map(obj, function(value, index, list) { + return { + value : value, + criteria : iterator.call(context, value, index, list) + }; + }).sort(function(left, right) { + var a = left.criteria, b = right.criteria; + return a < b ? -1 : a > b ? 1 : 0; + }), 'value'); + }; + + // Groups the object's values by a criterion. Pass either a string attribute + // to group by, or a function that returns the criterion. + _.groupBy = function(obj, val) { + var result = {}; + var iterator = _.isFunction(val) ? val : function(obj) { return obj[val]; }; + each(obj, function(value, index) { + var key = iterator(value, index); + (result[key] || (result[key] = [])).push(value); + }); + return result; + }; + + // Use a comparator function to figure out at what index an object should + // be inserted so as to maintain order. Uses binary search. + _.sortedIndex = function(array, obj, iterator) { + iterator || (iterator = _.identity); + var low = 0, high = array.length; + while (low < high) { + var mid = (low + high) >> 1; + iterator(array[mid]) < iterator(obj) ? low = mid + 1 : high = mid; + } + return low; + }; + + // Safely convert anything iterable into a real, live array. + _.toArray = function(iterable) { + if (!iterable) return []; + if (iterable.toArray) return iterable.toArray(); + if (_.isArray(iterable)) return slice.call(iterable); + if (_.isArguments(iterable)) return slice.call(iterable); + return _.values(iterable); + }; + + // Return the number of elements in an object. + _.size = function(obj) { + return _.toArray(obj).length; + }; + + // Array Functions + // --------------- + + // Get the first element of an array. Passing **n** will return the first N + // values in the array. Aliased as `head`. The **guard** check allows it to work + // with `_.map`. + _.first = _.head = function(array, n, guard) { + return (n != null) && !guard ? slice.call(array, 0, n) : array[0]; + }; + + // Returns everything but the last entry of the array. Especcialy useful on + // the arguments object. Passing **n** will return all the values in + // the array, excluding the last N. The **guard** check allows it to work with + // `_.map`. + _.initial = function(array, n, guard) { + return slice.call(array, 0, array.length - ((n == null) || guard ? 1 : n)); + }; + + // Get the last element of an array. Passing **n** will return the last N + // values in the array. The **guard** check allows it to work with `_.map`. + _.last = function(array, n, guard) { + if ((n != null) && !guard) { + return slice.call(array, Math.max(array.length - n, 0)); + } else { + return array[array.length - 1]; + } + }; + + // Returns everything but the first entry of the array. Aliased as `tail`. + // Especially useful on the arguments object. Passing an **index** will return + // the rest of the values in the array from that index onward. The **guard** + // check allows it to work with `_.map`. + _.rest = _.tail = function(array, index, guard) { + return slice.call(array, (index == null) || guard ? 1 : index); + }; + + // Trim out all falsy values from an array. + _.compact = function(array) { + return _.filter(array, function(value){ return !!value; }); + }; + + // Return a completely flattened version of an array. + _.flatten = function(array, shallow) { + return _.reduce(array, function(memo, value) { + if (_.isArray(value)) return memo.concat(shallow ? value : _.flatten(value)); + memo[memo.length] = value; + return memo; + }, []); + }; + + // Return a version of the array that does not contain the specified value(s). + _.without = function(array) { + return _.difference(array, slice.call(arguments, 1)); + }; + + // Produce a duplicate-free version of the array. If the array has already + // been sorted, you have the option of using a faster algorithm. + // Aliased as `unique`. + _.uniq = _.unique = function(array, isSorted, iterator) { + var initial = iterator ? _.map(array, iterator) : array; + var result = []; + _.reduce(initial, function(memo, el, i) { + if (0 == i || (isSorted === true ? _.last(memo) != el : !_.include(memo, el))) { + memo[memo.length] = el; + result[result.length] = array[i]; + } + return memo; + }, []); + return result; + }; + + // Produce an array that contains the union: each distinct element from all of + // the passed-in arrays. + _.union = function() { + return _.uniq(_.flatten(arguments, true)); + }; + + // Produce an array that contains every item shared between all the + // passed-in arrays. (Aliased as "intersect" for back-compat.) + _.intersection = _.intersect = function(array) { + var rest = slice.call(arguments, 1); + return _.filter(_.uniq(array), function(item) { + return _.every(rest, function(other) { + return _.indexOf(other, item) >= 0; + }); + }); + }; + + // Take the difference between one array and a number of other arrays. + // Only the elements present in just the first array will remain. + _.difference = function(array) { + var rest = _.flatten(slice.call(arguments, 1)); + return _.filter(array, function(value){ return !_.include(rest, value); }); + }; + + // Zip together multiple lists into a single array -- elements that share + // an index go together. + _.zip = function() { + var args = slice.call(arguments); + var length = _.max(_.pluck(args, 'length')); + var results = new Array(length); + for (var i = 0; i < length; i++) results[i] = _.pluck(args, "" + i); + return results; + }; + + // If the browser doesn't supply us with indexOf (I'm looking at you, **MSIE**), + // we need this function. Return the position of the first occurrence of an + // item in an array, or -1 if the item is not included in the array. + // Delegates to **ECMAScript 5**'s native `indexOf` if available. + // If the array is large and already in sort order, pass `true` + // for **isSorted** to use binary search. + _.indexOf = function(array, item, isSorted) { + if (array == null) return -1; + var i, l; + if (isSorted) { + i = _.sortedIndex(array, item); + return array[i] === item ? i : -1; + } + if (nativeIndexOf && array.indexOf === nativeIndexOf) return array.indexOf(item); + for (i = 0, l = array.length; i < l; i++) if (i in array && array[i] === item) return i; + return -1; + }; + + // Delegates to **ECMAScript 5**'s native `lastIndexOf` if available. + _.lastIndexOf = function(array, item) { + if (array == null) return -1; + if (nativeLastIndexOf && array.lastIndexOf === nativeLastIndexOf) return array.lastIndexOf(item); + var i = array.length; + while (i--) if (i in array && array[i] === item) return i; + return -1; + }; + + // Generate an integer Array containing an arithmetic progression. A port of + // the native Python `range()` function. See + // [the Python documentation](http://docs.python.org/library/functions.html#range). + _.range = function(start, stop, step) { + if (arguments.length <= 1) { + stop = start || 0; + start = 0; + } + step = arguments[2] || 1; + + var len = Math.max(Math.ceil((stop - start) / step), 0); + var idx = 0; + var range = new Array(len); + + while(idx < len) { + range[idx++] = start; + start += step; + } + + return range; + }; + + // Function (ahem) Functions + // ------------------ + + // Reusable constructor function for prototype setting. + var ctor = function(){}; + + // Create a function bound to a given object (assigning `this`, and arguments, + // optionally). Binding with arguments is also known as `curry`. + // Delegates to **ECMAScript 5**'s native `Function.bind` if available. + // We check for `func.bind` first, to fail fast when `func` is undefined. + _.bind = function bind(func, context) { + var bound, args; + if (func.bind === nativeBind && nativeBind) return nativeBind.apply(func, slice.call(arguments, 1)); + if (!_.isFunction(func)) throw new TypeError; + args = slice.call(arguments, 2); + return bound = function() { + if (!(this instanceof bound)) return func.apply(context, args.concat(slice.call(arguments))); + ctor.prototype = func.prototype; + var self = new ctor; + var result = func.apply(self, args.concat(slice.call(arguments))); + if (Object(result) === result) return result; + return self; + }; + }; + + // Bind all of an object's methods to that object. Useful for ensuring that + // all callbacks defined on an object belong to it. + _.bindAll = function(obj) { + var funcs = slice.call(arguments, 1); + if (funcs.length == 0) funcs = _.functions(obj); + each(funcs, function(f) { obj[f] = _.bind(obj[f], obj); }); + return obj; + }; + + // Memoize an expensive function by storing its results. + _.memoize = function(func, hasher) { + var memo = {}; + hasher || (hasher = _.identity); + return function() { + var key = hasher.apply(this, arguments); + return _.has(memo, key) ? memo[key] : (memo[key] = func.apply(this, arguments)); + }; + }; + + // Delays a function for the given number of milliseconds, and then calls + // it with the arguments supplied. + _.delay = function(func, wait) { + var args = slice.call(arguments, 2); + return setTimeout(function(){ return func.apply(func, args); }, wait); + }; + + // Defers a function, scheduling it to run after the current call stack has + // cleared. + _.defer = function(func) { + return _.delay.apply(_, [func, 1].concat(slice.call(arguments, 1))); + }; + + // Returns a function, that, when invoked, will only be triggered at most once + // during a given window of time. + _.throttle = function(func, wait) { + var context, args, timeout, throttling, more; + var whenDone = _.debounce(function(){ more = throttling = false; }, wait); + return function() { + context = this; args = arguments; + var later = function() { + timeout = null; + if (more) func.apply(context, args); + whenDone(); + }; + if (!timeout) timeout = setTimeout(later, wait); + if (throttling) { + more = true; + } else { + func.apply(context, args); + } + whenDone(); + throttling = true; + }; + }; + + // Returns a function, that, as long as it continues to be invoked, will not + // be triggered. The function will be called after it stops being called for + // N milliseconds. + _.debounce = function(func, wait) { + var timeout; + return function() { + var context = this, args = arguments; + var later = function() { + timeout = null; + func.apply(context, args); + }; + clearTimeout(timeout); + timeout = setTimeout(later, wait); + }; + }; + + // Returns a function that will be executed at most one time, no matter how + // often you call it. Useful for lazy initialization. + _.once = function(func) { + var ran = false, memo; + return function() { + if (ran) return memo; + ran = true; + return memo = func.apply(this, arguments); + }; + }; + + // Returns the first function passed as an argument to the second, + // allowing you to adjust arguments, run code before and after, and + // conditionally execute the original function. + _.wrap = function(func, wrapper) { + return function() { + var args = [func].concat(slice.call(arguments, 0)); + return wrapper.apply(this, args); + }; + }; + + // Returns a function that is the composition of a list of functions, each + // consuming the return value of the function that follows. + _.compose = function() { + var funcs = arguments; + return function() { + var args = arguments; + for (var i = funcs.length - 1; i >= 0; i--) { + args = [funcs[i].apply(this, args)]; + } + return args[0]; + }; + }; + + // Returns a function that will only be executed after being called N times. + _.after = function(times, func) { + if (times <= 0) return func(); + return function() { + if (--times < 1) { return func.apply(this, arguments); } + }; + }; + + // Object Functions + // ---------------- + + // Retrieve the names of an object's properties. + // Delegates to **ECMAScript 5**'s native `Object.keys` + _.keys = nativeKeys || function(obj) { + if (obj !== Object(obj)) throw new TypeError('Invalid object'); + var keys = []; + for (var key in obj) if (_.has(obj, key)) keys[keys.length] = key; + return keys; + }; + + // Retrieve the values of an object's properties. + _.values = function(obj) { + return _.map(obj, _.identity); + }; + + // Return a sorted list of the function names available on the object. + // Aliased as `methods` + _.functions = _.methods = function(obj) { + var names = []; + for (var key in obj) { + if (_.isFunction(obj[key])) names.push(key); + } + return names.sort(); + }; + + // Extend a given object with all the properties in passed-in object(s). + _.extend = function(obj) { + each(slice.call(arguments, 1), function(source) { + for (var prop in source) { + obj[prop] = source[prop]; + } + }); + return obj; + }; + + // Fill in a given object with default properties. + _.defaults = function(obj) { + each(slice.call(arguments, 1), function(source) { + for (var prop in source) { + if (obj[prop] == null) obj[prop] = source[prop]; + } + }); + return obj; + }; + + // Create a (shallow-cloned) duplicate of an object. + _.clone = function(obj) { + if (!_.isObject(obj)) return obj; + return _.isArray(obj) ? obj.slice() : _.extend({}, obj); + }; + + // Invokes interceptor with the obj, and then returns obj. + // The primary purpose of this method is to "tap into" a method chain, in + // order to perform operations on intermediate results within the chain. + _.tap = function(obj, interceptor) { + interceptor(obj); + return obj; + }; + + // Internal recursive comparison function. + function eq(a, b, stack) { + // Identical objects are equal. `0 === -0`, but they aren't identical. + // See the Harmony `egal` proposal: http://wiki.ecmascript.org/doku.php?id=harmony:egal. + if (a === b) return a !== 0 || 1 / a == 1 / b; + // A strict comparison is necessary because `null == undefined`. + if (a == null || b == null) return a === b; + // Unwrap any wrapped objects. + if (a._chain) a = a._wrapped; + if (b._chain) b = b._wrapped; + // Invoke a custom `isEqual` method if one is provided. + if (a.isEqual && _.isFunction(a.isEqual)) return a.isEqual(b); + if (b.isEqual && _.isFunction(b.isEqual)) return b.isEqual(a); + // Compare `[[Class]]` names. + var className = toString.call(a); + if (className != toString.call(b)) return false; + switch (className) { + // Strings, numbers, dates, and booleans are compared by value. + case '[object String]': + // Primitives and their corresponding object wrappers are equivalent; thus, `"5"` is + // equivalent to `new String("5")`. + return a == String(b); + case '[object Number]': + // `NaN`s are equivalent, but non-reflexive. An `egal` comparison is performed for + // other numeric values. + return a != +a ? b != +b : (a == 0 ? 1 / a == 1 / b : a == +b); + case '[object Date]': + case '[object Boolean]': + // Coerce dates and booleans to numeric primitive values. Dates are compared by their + // millisecond representations. Note that invalid dates with millisecond representations + // of `NaN` are not equivalent. + return +a == +b; + // RegExps are compared by their source patterns and flags. + case '[object RegExp]': + return a.source == b.source && + a.global == b.global && + a.multiline == b.multiline && + a.ignoreCase == b.ignoreCase; + } + if (typeof a != 'object' || typeof b != 'object') return false; + // Assume equality for cyclic structures. The algorithm for detecting cyclic + // structures is adapted from ES 5.1 section 15.12.3, abstract operation `JO`. + var length = stack.length; + while (length--) { + // Linear search. Performance is inversely proportional to the number of + // unique nested structures. + if (stack[length] == a) return true; + } + // Add the first object to the stack of traversed objects. + stack.push(a); + var size = 0, result = true; + // Recursively compare objects and arrays. + if (className == '[object Array]') { + // Compare array lengths to determine if a deep comparison is necessary. + size = a.length; + result = size == b.length; + if (result) { + // Deep compare the contents, ignoring non-numeric properties. + while (size--) { + // Ensure commutative equality for sparse arrays. + if (!(result = size in a == size in b && eq(a[size], b[size], stack))) break; + } + } + } else { + // Objects with different constructors are not equivalent. + if ('constructor' in a != 'constructor' in b || a.constructor != b.constructor) return false; + // Deep compare objects. + for (var key in a) { + if (_.has(a, key)) { + // Count the expected number of properties. + size++; + // Deep compare each member. + if (!(result = _.has(b, key) && eq(a[key], b[key], stack))) break; + } + } + // Ensure that both objects contain the same number of properties. + if (result) { + for (key in b) { + if (_.has(b, key) && !(size--)) break; + } + result = !size; + } + } + // Remove the first object from the stack of traversed objects. + stack.pop(); + return result; + } + + // Perform a deep comparison to check if two objects are equal. + _.isEqual = function(a, b) { + return eq(a, b, []); + }; + + // Is a given array, string, or object empty? + // An "empty" object has no enumerable own-properties. + _.isEmpty = function(obj) { + if (_.isArray(obj) || _.isString(obj)) return obj.length === 0; + for (var key in obj) if (_.has(obj, key)) return false; + return true; + }; + + // Is a given value a DOM element? + _.isElement = function(obj) { + return !!(obj && obj.nodeType == 1); + }; + + // Is a given value an array? + // Delegates to ECMA5's native Array.isArray + _.isArray = nativeIsArray || function(obj) { + return toString.call(obj) == '[object Array]'; + }; + + // Is a given variable an object? + _.isObject = function(obj) { + return obj === Object(obj); + }; + + // Is a given variable an arguments object? + _.isArguments = function(obj) { + return toString.call(obj) == '[object Arguments]'; + }; + if (!_.isArguments(arguments)) { + _.isArguments = function(obj) { + return !!(obj && _.has(obj, 'callee')); + }; + } + + // Is a given value a function? + _.isFunction = function(obj) { + return toString.call(obj) == '[object Function]'; + }; + + // Is a given value a string? + _.isString = function(obj) { + return toString.call(obj) == '[object String]'; + }; + + // Is a given value a number? + _.isNumber = function(obj) { + return toString.call(obj) == '[object Number]'; + }; + + // Is the given value `NaN`? + _.isNaN = function(obj) { + // `NaN` is the only value for which `===` is not reflexive. + return obj !== obj; + }; + + // Is a given value a boolean? + _.isBoolean = function(obj) { + return obj === true || obj === false || toString.call(obj) == '[object Boolean]'; + }; + + // Is a given value a date? + _.isDate = function(obj) { + return toString.call(obj) == '[object Date]'; + }; + + // Is the given value a regular expression? + _.isRegExp = function(obj) { + return toString.call(obj) == '[object RegExp]'; + }; + + // Is a given value equal to null? + _.isNull = function(obj) { + return obj === null; + }; + + // Is a given variable undefined? + _.isUndefined = function(obj) { + return obj === void 0; + }; + + // Has own property? + _.has = function(obj, key) { + return hasOwnProperty.call(obj, key); + }; + + // Utility Functions + // ----------------- + + // Run Underscore.js in *noConflict* mode, returning the `_` variable to its + // previous owner. Returns a reference to the Underscore object. + _.noConflict = function() { + root._ = previousUnderscore; + return this; + }; + + // Keep the identity function around for default iterators. + _.identity = function(value) { + return value; + }; + + // Run a function **n** times. + _.times = function (n, iterator, context) { + for (var i = 0; i < n; i++) iterator.call(context, i); + }; + + // Escape a string for HTML interpolation. + _.escape = function(string) { + return (''+string).replace(/&/g, '&').replace(//g, '>').replace(/"/g, '"').replace(/'/g, ''').replace(/\//g,'/'); + }; + + // Add your own custom functions to the Underscore object, ensuring that + // they're correctly added to the OOP wrapper as well. + _.mixin = function(obj) { + each(_.functions(obj), function(name){ + addToWrapper(name, _[name] = obj[name]); + }); + }; + + // Generate a unique integer id (unique within the entire client session). + // Useful for temporary DOM ids. + var idCounter = 0; + _.uniqueId = function(prefix) { + var id = idCounter++; + return prefix ? prefix + id : id; + }; + + // By default, Underscore uses ERB-style template delimiters, change the + // following template settings to use alternative delimiters. + _.templateSettings = { + evaluate : /<%([\s\S]+?)%>/g, + interpolate : /<%=([\s\S]+?)%>/g, + escape : /<%-([\s\S]+?)%>/g + }; + + // When customizing `templateSettings`, if you don't want to define an + // interpolation, evaluation or escaping regex, we need one that is + // guaranteed not to match. + var noMatch = /.^/; + + // Within an interpolation, evaluation, or escaping, remove HTML escaping + // that had been previously added. + var unescape = function(code) { + return code.replace(/\\\\/g, '\\').replace(/\\'/g, "'"); + }; + + // JavaScript micro-templating, similar to John Resig's implementation. + // Underscore templating handles arbitrary delimiters, preserves whitespace, + // and correctly escapes quotes within interpolated code. + _.template = function(str, data) { + var c = _.templateSettings; + var tmpl = 'var __p=[],print=function(){__p.push.apply(__p,arguments);};' + + 'with(obj||{}){__p.push(\'' + + str.replace(/\\/g, '\\\\') + .replace(/'/g, "\\'") + .replace(c.escape || noMatch, function(match, code) { + return "',_.escape(" + unescape(code) + "),'"; + }) + .replace(c.interpolate || noMatch, function(match, code) { + return "'," + unescape(code) + ",'"; + }) + .replace(c.evaluate || noMatch, function(match, code) { + return "');" + unescape(code).replace(/[\r\n\t]/g, ' ') + ";__p.push('"; + }) + .replace(/\r/g, '\\r') + .replace(/\n/g, '\\n') + .replace(/\t/g, '\\t') + + "');}return __p.join('');"; + var func = new Function('obj', '_', tmpl); + if (data) return func(data, _); + return function(data) { + return func.call(this, data, _); + }; + }; + + // Add a "chain" function, which will delegate to the wrapper. + _.chain = function(obj) { + return _(obj).chain(); + }; + + // The OOP Wrapper + // --------------- + + // If Underscore is called as a function, it returns a wrapped object that + // can be used OO-style. This wrapper holds altered versions of all the + // underscore functions. Wrapped objects may be chained. + var wrapper = function(obj) { this._wrapped = obj; }; + + // Expose `wrapper.prototype` as `_.prototype` + _.prototype = wrapper.prototype; + + // Helper function to continue chaining intermediate results. + var result = function(obj, chain) { + return chain ? _(obj).chain() : obj; + }; + + // A method to easily add functions to the OOP wrapper. + var addToWrapper = function(name, func) { + wrapper.prototype[name] = function() { + var args = slice.call(arguments); + unshift.call(args, this._wrapped); + return result(func.apply(_, args), this._chain); + }; + }; + + // Add all of the Underscore functions to the wrapper object. + _.mixin(_); + + // Add all mutator Array functions to the wrapper. + each(['pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift'], function(name) { + var method = ArrayProto[name]; + wrapper.prototype[name] = function() { + var wrapped = this._wrapped; + method.apply(wrapped, arguments); + var length = wrapped.length; + if ((name == 'shift' || name == 'splice') && length === 0) delete wrapped[0]; + return result(wrapped, this._chain); + }; + }); + + // Add all accessor Array functions to the wrapper. + each(['concat', 'join', 'slice'], function(name) { + var method = ArrayProto[name]; + wrapper.prototype[name] = function() { + return result(method.apply(this._wrapped, arguments), this._chain); + }; + }); + + // Start chaining a wrapped Underscore object. + wrapper.prototype.chain = function() { + this._chain = true; + return this; + }; + + // Extracts the result from a wrapped and chained object. + wrapper.prototype.value = function() { + return this._wrapped; + }; + +}).call(this); diff --git a/addons/web/static/src/js/core.js b/addons/web/static/src/js/core.js index e4d426ac4a0..bdc8059ff63 100644 --- a/addons/web/static/src/js/core.js +++ b/addons/web/static/src/js/core.js @@ -11,7 +11,7 @@ if (!console.debug) { openerp.web.core = function(openerp) { -openerp.web.Class = niv.Class; +openerp.web.Class = nova.Class; openerp.web.callback = function(obj, method) { var callback = function() { @@ -300,9 +300,9 @@ openerp.web.CallbackEnabledMixin = { } }; -openerp.web.CallbackEnabled = openerp.web.Class.extend(_.extend({}, niv.GetterSetterMixin, openerp.web.CallbackEnabledMixin, { +openerp.web.CallbackEnabled = openerp.web.Class.extend(_.extend({}, nova.GetterSetterMixin, openerp.web.CallbackEnabledMixin, { init: function() { - niv.GetterSetterMixin.init.call(this); + nova.GetterSetterMixin.init.call(this); openerp.web.CallbackEnabledMixin.init.call(this); } })); @@ -874,7 +874,7 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp. * * That will kill the widget in a clean way and erase its content from the dom. */ -openerp.web.Widget = niv.Widget.extend(_.extend({}, openerp.web.CallbackEnabledMixin, { +openerp.web.Widget = nova.Widget.extend(_.extend({}, openerp.web.CallbackEnabledMixin, { /** * The name of the QWeb template that will be used for rendering. Must be * redefined in subclasses or the default render() method can not be used. @@ -897,8 +897,8 @@ openerp.web.Widget = niv.Widget.extend(_.extend({}, openerp.web.CallbackEnabledM * for new components this argument should not be provided any more. */ init: function(parent) { - openerp.web.CallbackEnabledMixin.init.call(this); this._super(parent); + openerp.web.CallbackEnabledMixin.init.call(this); this.session = openerp.connection; }, /** From 72bce79c86fdbb5d3612e93462645d8c6bbdbc2d Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Mon, 27 Feb 2012 11:44:18 +0100 Subject: [PATCH 17/39] [imp] cosmetic improvements bzr revid: nicolas.vanhoren@openerp.com-20120227104418-70rfdvya0ni5aif8 --- addons/web/static/lib/novajs/src/nova.js | 42 ++++++++++++------------ 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/addons/web/static/lib/novajs/src/nova.js b/addons/web/static/lib/novajs/src/nova.js index 4a96092d635..da788462072 100644 --- a/addons/web/static/lib/novajs/src/nova.js +++ b/addons/web/static/lib/novajs/src/nova.js @@ -283,16 +283,16 @@ nova = (function() { __eventDispatcherMixin: true, init: function() { lib.ParentedMixin.init.call(this); - this.__events = new lib.internal.Events(); - this.__registeredEvents = []; + this.__edispatcherEvents = new lib.internal.Events(); + this.__edispatcherRegisteredEvents = []; }, bind: function(events, dest, func) { var self = this; events = events.split(/\s+/); _.each(events, function(eventName) { - self.__events.on(eventName, func, dest); + self.__edispatcherEvents.on(eventName, func, dest); if (dest && dest.__eventDispatcherMixin) { - dest.__registeredEvents.push({name: eventName, func: func, source: self}); + dest.__edispatcherRegisteredEvents.push({name: eventName, func: func, source: self}); } }); return this; @@ -301,9 +301,9 @@ nova = (function() { var self = this; events = events.split(/\s+/); _.each(events, function(eventName) { - self.__events.off(eventName, func, dest); + self.__edispatcherEvents.off(eventName, func, dest); if (dest && dest.__eventDispatcherMixin) { - dest.__registeredEvents = _.filter(dest.__registeredEvents, function(el) { + dest.__edispatcherRegisteredEvents = _.filter(dest.__edispatcherRegisteredEvents, function(el) { return !(el.name === eventName && el.func === func && el.source === self); }); } @@ -311,16 +311,16 @@ nova = (function() { return this; }, trigger: function(events) { - this.__events.trigger.apply(this.__events, arguments); + this.__edispatcherEvents.trigger.apply(this.__edispatcherEvents, arguments); return this; }, destroy: function() { var self = this; - _.each(this.__registeredEvents, function(event) { - event.source.__events.off(event.name, event.func, self); + _.each(this.__edispatcherRegisteredEvents, function(event) { + event.source.__edispatcherEvents.off(event.name, event.func, self); }); - this.__registeredEvents = []; - this.__events.off(); + this.__edispatcherRegisteredEvents = []; + this.__edispatcherEvents.off(); lib.ParentedMixin.destroy.call(this); } }); @@ -328,13 +328,13 @@ nova = (function() { lib.GetterSetterMixin = _.extend({}, lib.EventDispatcherMixin, { init: function() { lib.EventDispatcherMixin.init.call(this); - this.__internal_map = {}; + this.__getterSetterInternalMap = {}; }, set: function(map) { var self = this; _.each(map, function(val, key) { - var tmp = self.__internal_map[key]; - self.__internal_map[key] = val; + var tmp = self.__getterSetterInternalMap[key]; + self.__getterSetterInternalMap[key] = val; self.trigger("changed:" + key, { oldValue: tmp, newValue: val, @@ -343,7 +343,7 @@ nova = (function() { }); }, get: function(key) { - return this.__internal_map[key]; + return this.__getterSetterInternalMap[key]; } }); @@ -392,7 +392,7 @@ nova = (function() { */ appendTo: function(target) { var self = this; - return this._render_and_insert(function(t) { + return this.__renderAndInsert(function(t) { self.$element.appendTo(t); }, target); }, @@ -403,7 +403,7 @@ nova = (function() { */ prependTo: function(target) { var self = this; - return this._render_and_insert(function(t) { + return this.__renderAndInsert(function(t) { self.$element.prependTo(t); }, target); }, @@ -414,7 +414,7 @@ nova = (function() { */ insertAfter: function(target) { var self = this; - return this._render_and_insert(function(t) { + return this.__renderAndInsert(function(t) { self.$element.insertAfter(t); }, target); }, @@ -425,7 +425,7 @@ nova = (function() { */ insertBefore: function(target) { var self = this; - return this._render_and_insert(function(t) { + return this.__renderAndInsert(function(t) { self.$element.insertBefore(t); }, target); }, @@ -435,11 +435,11 @@ nova = (function() { * @param target A jQuery object or a Widget instance. */ replace: function(target) { - return this._render_and_insert(_.bind(function(t) { + return this.__renderAndInsert(_.bind(function(t) { this.$element.replaceAll(t); }, this), target); }, - _render_and_insert: function(insertion, target) { + __renderAndInsert: function(insertion, target) { this.render_element(); insertion(target); return this.start(); From c0232fb7480c69968988742cf3cea9da5f4bca74 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Mon, 27 Feb 2012 11:59:02 +0100 Subject: [PATCH 18/39] [imp] clarification bzr revid: nicolas.vanhoren@openerp.com-20120227105902-65c8b5q8ju6qqatq --- addons/web/static/lib/novajs/src/nova.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/web/static/lib/novajs/src/nova.js b/addons/web/static/lib/novajs/src/nova.js index da788462072..ea60d550ef1 100644 --- a/addons/web/static/lib/novajs/src/nova.js +++ b/addons/web/static/lib/novajs/src/nova.js @@ -28,7 +28,7 @@ nova = (function() { lib.internal = {}; /* - * Unmodified John Resig's inheritance + * (Almost) unmodified John Resig's inheritance */ /* * Simple JavaScript Inheritance By John Resig http://ejohn.org/ MIT From aca64bb558ebe2b617620eb62678107dccce971a Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Mon, 27 Feb 2012 13:49:58 +0100 Subject: [PATCH 19/39] [imp] removed useless function bzr revid: nicolas.vanhoren@openerp.com-20120227124958-ehlps91290hrwo9o --- addons/web/static/src/js/core.js | 25 ------------------------- 1 file changed, 25 deletions(-) diff --git a/addons/web/static/src/js/core.js b/addons/web/static/src/js/core.js index bdc8059ff63..6ff8f86dcc3 100644 --- a/addons/web/static/src/js/core.js +++ b/addons/web/static/src/js/core.js @@ -72,31 +72,6 @@ openerp.web.callback = function(obj, method) { }); }; -/** - * Generates an inherited class that replaces all the methods by null methods (methods - * that does nothing and always return undefined). - * - * @param {Class} claz - * @param {Object} add Additional functions to override. - * @return {Class} - */ -openerp.web.generate_null_object_class = function(claz, add) { - var newer = {}; - var copy_proto = function(prototype) { - for (var name in prototype) { - if(typeof prototype[name] == "function") { - newer[name] = function() {}; - } - } - if (prototype.prototype) - copy_proto(prototype.prototype); - }; - copy_proto(claz.prototype); - newer.init = openerp.web.Widget.prototype.init; - var tmpclass = claz.extend(newer); - return tmpclass.extend(add || {}); -}; - /** * web error for lookup failure * From db64573a8d1134b55f9f6f29fb3aba7b3f02e584 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Mon, 27 Feb 2012 17:27:04 +0100 Subject: [PATCH 20/39] [imp] cosmetic change bzr revid: nicolas.vanhoren@openerp.com-20120227162704-9f6piiywf7cz2rk8 --- addons/web/static/lib/novajs/src/nova.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/addons/web/static/lib/novajs/src/nova.js b/addons/web/static/lib/novajs/src/nova.js index ea60d550ef1..04bd4e1af4d 100644 --- a/addons/web/static/lib/novajs/src/nova.js +++ b/addons/web/static/lib/novajs/src/nova.js @@ -392,7 +392,7 @@ nova = (function() { */ appendTo: function(target) { var self = this; - return this.__renderAndInsert(function(t) { + return this.__widgetRenderAndInsert(function(t) { self.$element.appendTo(t); }, target); }, @@ -403,7 +403,7 @@ nova = (function() { */ prependTo: function(target) { var self = this; - return this.__renderAndInsert(function(t) { + return this.__widgetRenderAndInsert(function(t) { self.$element.prependTo(t); }, target); }, @@ -414,7 +414,7 @@ nova = (function() { */ insertAfter: function(target) { var self = this; - return this.__renderAndInsert(function(t) { + return this.__widgetRenderAndInsert(function(t) { self.$element.insertAfter(t); }, target); }, @@ -425,7 +425,7 @@ nova = (function() { */ insertBefore: function(target) { var self = this; - return this.__renderAndInsert(function(t) { + return this.__widgetRenderAndInsert(function(t) { self.$element.insertBefore(t); }, target); }, @@ -435,11 +435,11 @@ nova = (function() { * @param target A jQuery object or a Widget instance. */ replace: function(target) { - return this.__renderAndInsert(_.bind(function(t) { + return this.__widgetRenderAndInsert(_.bind(function(t) { this.$element.replaceAll(t); }, this), target); }, - __renderAndInsert: function(insertion, target) { + __widgetRenderAndInsert: function(insertion, target) { this.render_element(); insertion(target); return this.start(); From e7f72af654dbfa59ed8fc853911a1e7381a2227e Mon Sep 17 00:00:00 2001 From: Antony Lesuisse Date: Wed, 29 Feb 2012 10:53:45 +0100 Subject: [PATCH 21/39] [IMP] menu load action bzr revid: al@openerp.com-20120229095345-ll5rbc3h4m7f29as --- addons/web/controllers/main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/web/controllers/main.py b/addons/web/controllers/main.py index 623b297233b..8e3dbfd344c 100644 --- a/addons/web/controllers/main.py +++ b/addons/web/controllers/main.py @@ -832,13 +832,13 @@ class Menu(openerpweb.Controller): context = req.session.eval_context(req.context) Menus = req.session.model('ir.ui.menu') - menu_roots = Menus.read(self.do_get_user_roots(req), ['name', 'sequence', 'parent_id'], context) + menu_roots = Menus.read(self.do_get_user_roots(req), ['name', 'sequence', 'parent_id', 'action'], context) menu_root = {'id': False, 'name': 'root', 'parent_id': [-1, ''], 'children' : menu_roots} # menus are loaded fully unlike a regular tree view, cause there are a # limited number of items (752 when all 6.1 addons are installed) menu_ids = Menus.search([], 0, False, False, context) - menu_items = Menus.read(menu_ids, ['name', 'sequence', 'parent_id'], context) + menu_items = Menus.read(menu_ids, ['name', 'sequence', 'parent_id', 'action'], context) # adds roots at the end of the sequence, so that they will overwrite # equivalent menu items from full menu read when put into id:item # mapping, resulting in children being correctly set on the roots. From 63edbe735946bb62db534f2253f69f2e63cd859b Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Wed, 29 Feb 2012 11:23:21 +0100 Subject: [PATCH 22/39] [imp] removed some comments bzr revid: nicolas.vanhoren@openerp.com-20120229102321-b61kqie9t3y6cyky --- addons/web/static/lib/novajs/src/nova.js | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/addons/web/static/lib/novajs/src/nova.js b/addons/web/static/lib/novajs/src/nova.js index 04bd4e1af4d..1c8bd397eb7 100644 --- a/addons/web/static/lib/novajs/src/nova.js +++ b/addons/web/static/lib/novajs/src/nova.js @@ -190,17 +190,11 @@ nova = (function() { // http://backbonejs.org lib.internal.Events = lib.Class.extend({ - // Bind an event, specified by a string name, `ev`, to a `callback` - // function. Passing `"all"` will bind the callback to all events fired. on : function(events, callback, context) { var ev; events = events.split(/\s+/); var calls = this._callbacks || (this._callbacks = {}); while (ev = events.shift()) { - // Create an immutable callback list, allowing traversal during - // modification. The tail is an empty object that will always be - // used - // as the next node. var list = calls[ev] || (calls[ev] = {}); var tail = list.tail || (list.tail = list.next = {}); tail.callback = callback; @@ -210,11 +204,6 @@ nova = (function() { return this; }, - // Remove one or many callbacks. If `context` is null, removes all - // callbacks - // with that function. If `callback` is null, removes all callbacks for - // the - // event. If `ev` is null, removes all bound callbacks for all events. off : function(events, callback, context) { var ev, calls, node; if (!events) { @@ -226,8 +215,6 @@ nova = (function() { delete calls[ev]; if (!callback || !node) continue; - // Create a new list, omitting the indicated event/context - // pairs. while ((node = node.next) && node.next) { if (node.callback === callback && (!context || node.context === context)) @@ -239,11 +226,6 @@ nova = (function() { return this; }, - // Trigger an event, firing all bound callbacks. Callbacks are passed - // the - // same arguments as `trigger` is, apart from the event name. - // Listening for `"all"` passes the true event name as the first - // argument. trigger : function(events) { var event, node, calls, tail, args, all, rest; if (!(calls = this._callbacks)) @@ -265,7 +247,6 @@ nova = (function() { tail : node.tail }); } - // Traverse each list, stopping when the saved tail is reached. rest = Array.prototype.slice.call(arguments, 1); while (node = events.pop()) { tail = node.tail; From 6dcc45a0bb50435eaf2c64e0fbc8eca4b99bedf3 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Wed, 29 Feb 2012 11:28:16 +0100 Subject: [PATCH 23/39] [imp] changed get and set bzr revid: nicolas.vanhoren@openerp.com-20120229102816-8wdpo4ybeq5zrsh7 --- addons/web/static/lib/novajs/src/nova.js | 6 +++--- addons/web/static/lib/novajs/test/test.js | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/addons/web/static/lib/novajs/src/nova.js b/addons/web/static/lib/novajs/src/nova.js index 1c8bd397eb7..c90a1ca2800 100644 --- a/addons/web/static/lib/novajs/src/nova.js +++ b/addons/web/static/lib/novajs/src/nova.js @@ -316,12 +316,12 @@ nova = (function() { _.each(map, function(val, key) { var tmp = self.__getterSetterInternalMap[key]; self.__getterSetterInternalMap[key] = val; - self.trigger("changed:" + key, { + self.trigger("change:" + key, self, { oldValue: tmp, - newValue: val, - source: self + newValue: val }); }); + self.trigger("change", self); }, get: function(key) { return this.__getterSetterInternalMap[key]; diff --git a/addons/web/static/lib/novajs/test/test.js b/addons/web/static/lib/novajs/test/test.js index 4ae3418212e..363f2794fb9 100644 --- a/addons/web/static/lib/novajs/test/test.js +++ b/addons/web/static/lib/novajs/test/test.js @@ -89,12 +89,12 @@ test("base", function() { x.set({test: 1}); equal(x.get("test"), 1); var tmp = 0; - x.bind("changed:test", y, function(arg) { + x.bind("change:test", y, function(model, options) { tmp = 1; - equal(arg.oldValue, 1); - equal(arg.newValue, 2); + equal(options.oldValue, 1); + equal(options.newValue, 2); equal(x.get("test"), 2); - equal(arg.source, x); + equal(model, x); }); x.set({test: 2}); equal(tmp, 1); From ff248a97cf89155b3c9bfd3a2f9dedb3229f9eb6 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Wed, 29 Feb 2012 12:02:28 +0100 Subject: [PATCH 24/39] [imp] modified on and off bzr revid: nicolas.vanhoren@openerp.com-20120229110228-15fi6jyj8z51rtmr --- addons/web/static/lib/novajs/src/nova.js | 4 ++-- addons/web/static/lib/novajs/test/test.js | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/addons/web/static/lib/novajs/src/nova.js b/addons/web/static/lib/novajs/src/nova.js index c90a1ca2800..c03c23067a3 100644 --- a/addons/web/static/lib/novajs/src/nova.js +++ b/addons/web/static/lib/novajs/src/nova.js @@ -267,7 +267,7 @@ nova = (function() { this.__edispatcherEvents = new lib.internal.Events(); this.__edispatcherRegisteredEvents = []; }, - bind: function(events, dest, func) { + on: function(events, dest, func) { var self = this; events = events.split(/\s+/); _.each(events, function(eventName) { @@ -278,7 +278,7 @@ nova = (function() { }); return this; }, - unbind: function(events, dest, func) { + off: function(events, dest, func) { var self = this; events = events.split(/\s+/); _.each(events, function(eventName) { diff --git a/addons/web/static/lib/novajs/test/test.js b/addons/web/static/lib/novajs/test/test.js index 363f2794fb9..924d085c9ac 100644 --- a/addons/web/static/lib/novajs/test/test.js +++ b/addons/web/static/lib/novajs/test/test.js @@ -65,16 +65,16 @@ test("base", function() { var y = new Claz(); var tmp = 0; var fct = function() {tmp = 1;}; - x.bind("test", y, fct); + x.on("test", y, fct); equal(tmp, 0); x.trigger("test"); equal(tmp, 1); tmp = 0; - x.unbind("test", y, fct); + x.off("test", y, fct); x.trigger("test"); equal(tmp, 0); tmp = 0; - x.bind("test", y, fct); + x.on("test", y, fct); y.destroy(); x.trigger("test"); equal(tmp, 0); @@ -89,7 +89,7 @@ test("base", function() { x.set({test: 1}); equal(x.get("test"), 1); var tmp = 0; - x.bind("change:test", y, function(model, options) { + x.on("change:test", y, function(model, options) { tmp = 1; equal(options.oldValue, 1); equal(options.newValue, 2); From 2da29835334266a278e030411d1a3539fc7d11e2 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Wed, 29 Feb 2012 12:04:28 +0100 Subject: [PATCH 25/39] [imp] renammed tag_name bzr revid: nicolas.vanhoren@openerp.com-20120229110428-es0fof2fxxa5qzd5 --- addons/web/static/lib/novajs/src/nova.js | 4 ++-- addons/web/static/src/js/core.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/addons/web/static/lib/novajs/src/nova.js b/addons/web/static/lib/novajs/src/nova.js index c03c23067a3..a299dad23d3 100644 --- a/addons/web/static/lib/novajs/src/nova.js +++ b/addons/web/static/lib/novajs/src/nova.js @@ -333,7 +333,7 @@ nova = (function() { * Tag name when creating a default $element. * @type string */ - tag_name: 'div', + tagName: 'div', /** * Constructs the widget and sets its parent if a parent is given. * @@ -350,7 +350,7 @@ nova = (function() { */ init: function(parent) { lib.GetterSetterMixin.init.call(this); - this.$element = $(document.createElement(this.tag_name)); + this.$element = $(document.createElement(this.tagName)); this.setParent(parent); }, diff --git a/addons/web/static/src/js/core.js b/addons/web/static/src/js/core.js index 93e2b06c1f6..bbfac551c5d 100644 --- a/addons/web/static/src/js/core.js +++ b/addons/web/static/src/js/core.js @@ -937,7 +937,7 @@ openerp.web.OldWidget = openerp.web.Widget.extend({ this.element_id = element_id; this.element_id = this.element_id || _.uniqueId('widget-'); var tmp = document.getElementById(this.element_id); - this.$element = tmp ? $(tmp) : $(document.createElement(this.tag_name)); + this.$element = tmp ? $(tmp) : $(document.createElement(this.tagName)); }, render_element: function() { var rendered = this.render(); From 7eb12aee74633e4f240b0373eae476788c14ecba Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Wed, 29 Feb 2012 12:07:44 +0100 Subject: [PATCH 26/39] [imp] renammed render_element bzr revid: nicolas.vanhoren@openerp.com-20120229110744-0m55gqlme6s225jv --- addons/web/static/lib/novajs/src/nova.js | 4 ++-- addons/web/static/lib/novajs/test/test.js | 2 +- addons/web/static/src/js/chrome.js | 2 +- addons/web/static/src/js/core.js | 4 ++-- addons/web/static/src/js/view_form.js | 22 +++++++++---------- .../web_dashboard/static/src/js/dashboard.js | 4 ++-- 6 files changed, 19 insertions(+), 19 deletions(-) diff --git a/addons/web/static/lib/novajs/src/nova.js b/addons/web/static/lib/novajs/src/nova.js index a299dad23d3..2a593611165 100644 --- a/addons/web/static/lib/novajs/src/nova.js +++ b/addons/web/static/lib/novajs/src/nova.js @@ -421,14 +421,14 @@ nova = (function() { }, this), target); }, __widgetRenderAndInsert: function(insertion, target) { - this.render_element(); + this.renderElement(); insertion(target); return this.start(); }, /** * This is the method to implement to render the Widget. */ - render_element: function() {}, + renderElement: function() {}, /** * Method called after rendering. Mostly used to bind actions, perform asynchronous * calls, etc... diff --git a/addons/web/static/lib/novajs/test/test.js b/addons/web/static/lib/novajs/test/test.js index 924d085c9ac..60ef8b966e6 100644 --- a/addons/web/static/lib/novajs/test/test.js +++ b/addons/web/static/lib/novajs/test/test.js @@ -104,7 +104,7 @@ module("Widget"); test("base", function() { var Claz = nova.Widget.extend({ - render_element: function() { + renderElement: function() { this.$element.attr("id", "testdiv"); this.$element.html("test"); } diff --git a/addons/web/static/src/js/chrome.js b/addons/web/static/src/js/chrome.js index de3275f3230..c019d59e7e1 100644 --- a/addons/web/static/src/js/chrome.js +++ b/addons/web/static/src/js/chrome.js @@ -864,7 +864,7 @@ openerp.web.Menu = openerp.web.Widget.extend(/** @lends openerp.web.Menu# */{ }, on_loaded: function(data) { this.data = data; - this.render_element(); + this.renderElement(); if (!this.$secondary_menu && this.getParent()) { // TODO: create Widget openerp.web.SubMenu this.$secondary_menu = this.getParent().$element.find('.oe_secondary_menu'); diff --git a/addons/web/static/src/js/core.js b/addons/web/static/src/js/core.js index bbfac551c5d..fe2ca1beb4f 100644 --- a/addons/web/static/src/js/core.js +++ b/addons/web/static/src/js/core.js @@ -881,7 +881,7 @@ openerp.web.Widget = nova.Widget.extend(_.extend({}, openerp.web.CallbackEnabled * `this.template` must be defined. The context given to QWeb contains the "widget" * key that references `this`. */ - render_element: function() { + renderElement: function() { var rendered = null; if (this.template) rendered = openerp.web.qweb.render(this.template, {widget: this}); @@ -939,7 +939,7 @@ openerp.web.OldWidget = openerp.web.Widget.extend({ var tmp = document.getElementById(this.element_id); this.$element = tmp ? $(tmp) : $(document.createElement(this.tagName)); }, - render_element: function() { + renderElement: function() { var rendered = this.render(); if (rendered) { var elem = $(rendered); diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index 17b9849cd42..78626f69d8a 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -936,7 +936,7 @@ openerp.web.form.Widget = openerp.web.OldWidget.extend(/** @lends openerp.web.fo update_dom: function() { this.$element.toggle(!this.invisible); }, - render_element: function() { + renderElement: function() { this.$element.html(QWeb.render(this.form_template, { "widget": this })); }, do_attach_tooltip: function(widget, trigger, options) { @@ -1030,13 +1030,13 @@ openerp.web.form.WidgetFrame = openerp.web.form.Widget.extend({ } this.set_row_cells_with(this.table[this.table.length - 1]); }, - render_element: function() { + renderElement: function() { this._super(); var self = this; _.each(this.table, function(row) { _.each(row, function(td) { td.$element = self.$element.find('.' + td.element_class); - td.render_element(); + td.renderElement(); }); }); }, @@ -1140,12 +1140,12 @@ openerp.web.form.WidgetNotebook = openerp.web.form.Widget.extend({ } } }, - render_element: function() { + renderElement: function() { this._super(); var self = this; _.each(this.pages, function(page) { page.$element = self.$element.find('.' + page.element_class); - page.render_element(); + page.renderElement(); }); }, start: function() { @@ -1335,7 +1335,7 @@ openerp.web.form.WidgetLabel = openerp.web.form.Widget.extend({ this.nowrap = true; } }, - render_element: function() { + renderElement: function() { var rendered; if (this['for'] && this.type !== 'label') { rendered = QWeb.render(this.form_template, {widget: this['for']}); @@ -2819,7 +2819,7 @@ openerp.web.form.SelectCreatePopup = openerp.web.OldWidget.extend(/** @lends ope }, read_function: null}); this.initial_ids = this.options.initial_ids; this.created_elements = []; - this.render_element(); + this.renderElement(); openerp.web.form.dialog(this.$element, { close: function() { self.check_exit(); @@ -3028,7 +3028,7 @@ openerp.web.form.FormOpenPopup = openerp.web.OldWidget.extend(/** @lends openerp this.row_id = row_id; this.context = context || {}; this.options = _.defaults(options || {}, {"auto_write": true}); - this.render_element(); + this.renderElement(); openerp.web.dialog(this.$element, { title: options.title || '', modal: true, @@ -3150,10 +3150,10 @@ openerp.web.form.FieldReference = openerp.web.form.Field.extend({ start: function() { this._super(); this.selection.$element = $(".oe_form_view_reference_selection", this.$element); - this.selection.render_element(); + this.selection.renderElement(); this.selection.start(); this.m2o.$element = $(".oe_form_view_reference_m2o", this.$element); - this.m2o.render_element(); + this.m2o.renderElement(); this.m2o.start(); }, is_valid: function() { @@ -3400,7 +3400,7 @@ openerp.web.form.FieldStatus = openerp.web.form.Field.extend({ }); openerp.web.form.WidgetHtml = openerp.web.form.Widget.extend({ - render_element: function () { + renderElement: function () { var $root = $('
    '); this.render_children(this, $root); var rendered = $root.html(); diff --git a/addons/web_dashboard/static/src/js/dashboard.js b/addons/web_dashboard/static/src/js/dashboard.js index 793ad651b81..afe64e6284e 100644 --- a/addons/web_dashboard/static/src/js/dashboard.js +++ b/addons/web_dashboard/static/src/js/dashboard.js @@ -225,7 +225,7 @@ openerp.web.form.DashBoard = openerp.web.form.Widget.extend({ }); } }, - render_element: function() { + renderElement: function() { // We should start with three columns available for (var i = this.node.children.length; i < 3; i++) { this.node.children.push({ @@ -245,7 +245,7 @@ openerp.web.form.DashBoard = openerp.web.form.Widget.extend({ } }); openerp.web.form.DashBoardLegacy = openerp.web.form.DashBoard.extend({ - render_element: function() { + renderElement: function() { if (this.node.tag == 'hpaned') { this.node.attrs.style = '2-1'; } else if (this.node.tag == 'vpaned') { From e762aec5a159cf472e87c8dc4271d6c6eae413b6 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Wed, 29 Feb 2012 12:54:56 +0100 Subject: [PATCH 27/39] [ADD] forgotten py.js license bzr revid: xmo@openerp.com-20120229115456-5rp0iuv3sftujq6b --- addons/web/static/lib/py.js/LICENSE | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 addons/web/static/lib/py.js/LICENSE diff --git a/addons/web/static/lib/py.js/LICENSE b/addons/web/static/lib/py.js/LICENSE new file mode 100644 index 00000000000..01733ddac98 --- /dev/null +++ b/addons/web/static/lib/py.js/LICENSE @@ -0,0 +1,13 @@ + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + Version 2, December 2004 + + Copyright (C) 2012 + + Everyone is permitted to copy and distribute verbatim or modified + copies of this license document, and changing it is allowed as long + as the name is changed. + + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. You just DO WHAT THE FUCK YOU WANT TO. From e543b9a8fbebac5127326cbec009c061aa92e3df Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Wed, 29 Feb 2012 13:34:50 +0100 Subject: [PATCH 28/39] [imp] adaptation to .js due to changes in web bzr revid: nicolas.vanhoren@openerp.com-20120229123450-mn8zpku48uqlryeh --- addons/point_of_sale/static/src/js/pos.js | 58 +++++++++++------------ 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/addons/point_of_sale/static/src/js/pos.js b/addons/point_of_sale/static/src/js/pos.js index c713389ac71..1885604d42c 100644 --- a/addons/point_of_sale/static/src/js/pos.js +++ b/addons/point_of_sale/static/src/js/pos.js @@ -681,7 +681,7 @@ openerp.point_of_sale = function(db) { }, this)); return (this.shop.get('selectedOrder')).addPaymentLine(cashRegister); }, - render_element: function() { + renderElement: function() { this.$element.empty(); return (this.shop.get('cashRegisters')).each(_.bind( function(cashRegister) { var button = new PaymentButtonWidget(); @@ -692,7 +692,7 @@ openerp.point_of_sale = function(db) { }); var PaymentButtonWidget = db.web.OldWidget.extend({ template_fct: qweb_template('pos-payment-button-template'), - render_element: function() { + renderElement: function() { this.$element.html(this.template_fct({ id: this.model.get('id'), name: (this.model.get('journal_id'))[1] @@ -735,7 +735,7 @@ openerp.point_of_sale = function(db) { Shopping carts. */ var OrderlineWidget = db.web.OldWidget.extend({ - tag_name: 'tr', + tagName: 'tr', template_fct: qweb_template('pos-orderline-template'), init: function(parent, options) { this._super(parent); @@ -755,12 +755,12 @@ openerp.point_of_sale = function(db) { clickHandler: function() { this.select(); }, - render_element: function() { + renderElement: function() { this.$element.html(this.template_fct(this.model.toJSON())); this.select(); }, refresh: function() { - this.render_element(); + this.renderElement(); var heights = _.map(this.$element.prevAll(), function(el) {return $(el).outerHeight();}); heights.push($('#current-order thead').outerHeight()); var position = _.reduce(heights, function(memo, num){ return memo + num; }, 0); @@ -805,12 +805,12 @@ openerp.point_of_sale = function(db) { changeSelectedOrder: function() { this.currentOrderLines.unbind(); this.bindOrderLineEvents(); - this.render_element(); + this.renderElement(); }, bindOrderLineEvents: function() { this.currentOrderLines = (this.shop.get('selectedOrder')).get('orderLines'); this.currentOrderLines.bind('add', this.addLine, this); - this.currentOrderLines.bind('remove', this.render_element, this); + this.currentOrderLines.bind('remove', this.renderElement, this); }, addLine: function(newLine) { var line = new OrderlineWidget(null, { @@ -832,7 +832,7 @@ openerp.point_of_sale = function(db) { this.numpadState.reset(); this.updateSummary(); }, - render_element: function() { + renderElement: function() { this.$element.empty(); this.currentOrderLines.each(_.bind( function(orderLine) { var line = new OrderlineWidget(null, { @@ -863,7 +863,7 @@ openerp.point_of_sale = function(db) { this.$element.find(".oe-pos-categories-list a").click(_.bind(this.changeCategory, this)); }, template_fct: qweb_template('pos-category-template'), - render_element: function() { + renderElement: function() { var self = this; var c; this.$element.html(this.template_fct({ @@ -894,7 +894,7 @@ openerp.point_of_sale = function(db) { on_change_category: function(id) {}, }); var ProductWidget = db.web.OldWidget.extend({ - tag_name:'li', + tagName:'li', template_fct: qweb_template('pos-product-template'), init: function(parent, options) { this._super(parent); @@ -909,7 +909,7 @@ openerp.point_of_sale = function(db) { event.preventDefault(); return (this.shop.get('selectedOrder')).addProduct(this.model); }, - render_element: function() { + renderElement: function() { this.$element.addClass("product"); this.$element.html(this.template_fct(this.model.toJSON())); return this; @@ -920,9 +920,9 @@ openerp.point_of_sale = function(db) { this._super(parent); this.model = options.model; this.shop = options.shop; - this.shop.get('products').bind('reset', this.render_element, this); + this.shop.get('products').bind('reset', this.renderElement, this); }, - render_element: function() { + renderElement: function() { this.$element.empty(); (this.shop.get('products')).each(_.bind( function(product) { var p = new ProductWidget(null, { @@ -938,7 +938,7 @@ openerp.point_of_sale = function(db) { "Payment" step. */ var PaymentlineWidget = db.web.OldWidget.extend({ - tag_name: 'tr', + tagName: 'tr', template_fct: qweb_template('pos-paymentline-template'), init: function(parent, options) { this._super(parent); @@ -958,9 +958,9 @@ openerp.point_of_sale = function(db) { }, changedAmount: function() { if (this.amount !== this.model.get('amount')) - this.render_element(); + this.renderElement(); }, - render_element: function() { + renderElement: function() { this.amount = this.model.get('amount'); this.$element.html(this.template_fct({ name: (this.model.get('journal_id'))[1], @@ -1004,7 +1004,7 @@ openerp.point_of_sale = function(db) { bindPaymentLineEvents: function() { this.currentPaymentLines = (this.shop.get('selectedOrder')).get('paymentLines'); this.currentPaymentLines.bind('add', this.addPaymentLine, this); - this.currentPaymentLines.bind('remove', this.render_element, this); + this.currentPaymentLines.bind('remove', this.renderElement, this); this.currentPaymentLines.bind('all', this.updatePaymentSummary, this); }, bindOrderLineEvents: function() { @@ -1016,7 +1016,7 @@ openerp.point_of_sale = function(db) { this.bindPaymentLineEvents(); this.currentOrderLines.unbind(); this.bindOrderLineEvents(); - this.render_element(); + this.renderElement(); }, addPaymentLine: function(newPaymentLine) { var x = new PaymentlineWidget(null, { @@ -1025,7 +1025,7 @@ openerp.point_of_sale = function(db) { x.on_delete.add(_.bind(this.deleteLine, this, x)); x.appendTo(this.paymentLineList()); }, - render_element: function() { + renderElement: function() { this.paymentLineList().empty(); this.currentPaymentLines.each(_.bind( function(paymentLine) { this.addPaymentLine(paymentLine); @@ -1079,7 +1079,7 @@ openerp.point_of_sale = function(db) { this.shop.bind('change:selectedOrder', this.changeSelectedOrder, this); this.changeSelectedOrder(); }, - render_element: function() { + renderElement: function() { this.$element.html(qweb_template('pos-receipt-view')); $('button#pos-finish-order', this.$element).click(_.bind(this.finishOrder, this)); $('button#print-the-ticket', this.$element).click(_.bind(this.print, this)); @@ -1109,7 +1109,7 @@ openerp.point_of_sale = function(db) { }, }); var OrderButtonWidget = db.web.OldWidget.extend({ - tag_name: 'li', + tagName: 'li', template_fct: qweb_template('pos-order-selector-button-template'), init: function(parent, options) { this._super(parent); @@ -1142,7 +1142,7 @@ openerp.point_of_sale = function(db) { closeOrder: function(event) { this.order.destroy(); }, - render_element: function() { + renderElement: function() { this.$element.html(this.template_fct({widget:this})); this.$element.addClass('order-selector-button'); } @@ -1161,13 +1161,13 @@ openerp.point_of_sale = function(db) { shop: this.shop }); this.productListView.$element = $("#products-screen-ol"); - this.productListView.render_element(); + this.productListView.renderElement(); this.productListView.start(); this.paypadView = new PaypadWidget(null, { shop: this.shop }); this.paypadView.$element = $('#paypad'); - this.paypadView.render_element(); + this.paypadView.renderElement(); this.paypadView.start(); this.numpadView = new NumpadWidget(null); this.numpadView.$element = $('#numpad'); @@ -1181,7 +1181,7 @@ openerp.point_of_sale = function(db) { shop: this.shop }); this.paymentView.$element = $('#payment-screen'); - this.paymentView.render_element(); + this.paymentView.renderElement(); this.paymentView.start(); this.receiptView = new ReceiptWidget(null, { shop: this.shop, @@ -1251,7 +1251,7 @@ openerp.point_of_sale = function(db) { c = pos.categories[id]; this.categoryView.ancestors = c.ancestors; this.categoryView.children = c.children; - this.categoryView.render_element(); + this.categoryView.renderElement(); this.categoryView.start(); products = pos.store.get('product.product').filter( function(p) { var _ref; @@ -1288,13 +1288,13 @@ openerp.point_of_sale = function(db) { this._super.apply(this, arguments); this.nbr_pending = 0; }, - render_element: function() { + renderElement: function() { this._super.apply(this, arguments); $('.oe_pos_synch-notification-button', this.$element).click(this.on_synch); }, on_change_nbr_pending: function(nbr_pending) { this.nbr_pending = nbr_pending; - this.render_element(); + this.renderElement(); }, on_synch: function() {} }); @@ -1312,7 +1312,7 @@ openerp.point_of_sale = function(db) { start: function() { var self = this; return pos.ready.then(_.bind(function() { - this.render_element(); + this.renderElement(); this.synch_notification = new db.point_of_sale.SynchNotification(this); this.synch_notification.replace($('.oe_pos_synch-notification', this.$element)); this.synch_notification.on_synch.add(_.bind(pos.flush, pos)); From 2f2c246fac6bcef23687e7623e8addc9b92a8998 Mon Sep 17 00:00:00 2001 From: Fabien Meghazi Date: Wed, 29 Feb 2012 14:02:35 +0100 Subject: [PATCH 29/39] [IMP] Improve menus. Works when client is reloaded bzr revid: fme@openerp.com-20120229130235-bx8ptrz4xah1aqct --- addons/web/static/src/js/chrome.js | 28 ++++++++++++++++------------ addons/web/static/src/js/views.js | 3 +++ addons/web/static/src/xml/base.xml | 8 ++++---- 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/addons/web/static/src/js/chrome.js b/addons/web/static/src/js/chrome.js index ae3a7143d9d..1589ede75c1 100644 --- a/addons/web/static/src/js/chrome.js +++ b/addons/web/static/src/js/chrome.js @@ -674,6 +674,10 @@ openerp.web.Menu = openerp.web.Widget.extend(/** @lends openerp.web.Menu# */{ * @param parent */ template: 'Menu', + init: function() { + this._super.apply(this, arguments); + this.has_been_loaded = $.Deferred(); + }, do_reload: function() { var self = this; return this.rpc("/web/menu/load", {}, this.on_loaded).then(function () { @@ -693,12 +697,13 @@ openerp.web.Menu = openerp.web.Widget.extend(/** @lends openerp.web.Menu# */{ this.$secondary_menus.html(QWeb.render("Menu.secondary", { widget : this })); // Hide second level submenus this.$secondary_menus.find('.oe_menu_toggler').siblings('.oe_secondary_submenu').hide(); + this.has_been_loaded.resolve(); }, /** * Opens a given menu by id, as if a user had browsed to that menu by hand * except does not trigger any event on the way * - * @param {Number} menu_id database id of the terminal menu to select + * @param {Number} id database id of the terminal menu to select */ open_menu: function (id) { var $clicked_menu, $sub_menu, $main_menu; @@ -731,6 +736,12 @@ openerp.web.Menu = openerp.web.Widget.extend(/** @lends openerp.web.Menu# */{ } } }, + open_action: function (id) { + var menu_id, $menu = this.$element.add(this.$secondary_menus).find('a[data-action-id=' + id + ']'); + if (menu_id = $menu.data('menu')) { + this.open_menu(menu_id); + } + }, on_menu_click: function(ev, id) { id = id || 0; var $clicked_menu, manual = false; @@ -751,7 +762,10 @@ openerp.web.Menu = openerp.web.Widget.extend(/** @lends openerp.web.Menu# */{ this.open_menu(id); this.current_menu = id; this.session.active_id = id; - this.rpc('/web/menu/action', {'menu_id': id}, this.on_menu_action_loaded); + var action_id = $clicked_menu.data('action-id'); + if (action_id) { + this.on_action(action_id); + } } if (ev) { ev.stopPropagation(); @@ -766,16 +780,6 @@ openerp.web.Menu = openerp.web.Widget.extend(/** @lends openerp.web.Menu# */{ } $sub_menu.show(); }, - on_menu_action_loaded: function(data) { - var self = this; - if (data.action.length) { - var action = data.action[0][2]; - action.from_menu = true; - self.on_action(action); - } else { - self.on_action({type: 'null_action'}); - } - }, on_action: function(action) { } }); diff --git a/addons/web/static/src/js/views.js b/addons/web/static/src/js/views.js index 08886ddfbe3..82f6d63b9f1 100644 --- a/addons/web/static/src/js/views.js +++ b/addons/web/static/src/js/views.js @@ -65,6 +65,9 @@ session.web.ActionManager = session.web.OldWidget.extend({ if (run_action) { this.null_action(); action_loaded = this.do_action(state.action_id); + session.webclient.menu.has_been_loaded.then(function() { + session.webclient.menu.open_action(state.action_id); + }); } } else if (state.model && state.id) { // TODO handle context & domain ? diff --git a/addons/web/static/src/xml/base.xml b/addons/web/static/src/xml/base.xml index d2d30c5d580..d1dbf9845c9 100644 --- a/addons/web/static/src/xml/base.xml +++ b/addons/web/static/src/xml/base.xml @@ -327,9 +327,7 @@ @@ -359,7 +357,9 @@ + t-att-data-menu="menu.id" + t-att-data-action-model="menu.action ? menu.action.split(',')[0] : ''" + t-att-data-action-id="menu.action ? menu.action.split(',')[1] : ''"> From aacfe84d5d9aade37c48157bdc81100ae3595965 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Wed, 29 Feb 2012 14:18:26 +0100 Subject: [PATCH 30/39] [fix] small problem in client actions bzr revid: nicolas.vanhoren@openerp.com-20120229131826-uofegm4lmsn83r06 --- addons/web/static/src/js/views.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/web/static/src/js/views.js b/addons/web/static/src/js/views.js index 82f6d63b9f1..503ec360013 100644 --- a/addons/web/static/src/js/views.js +++ b/addons/web/static/src/js/views.js @@ -183,7 +183,7 @@ session.web.ActionManager = session.web.OldWidget.extend({ this.content_stop(); this.dialog_stop(); var ClientWidget = session.web.client_actions.get_object(action.tag); - (this.client_widget = new ClientWidget(this, action.params)).appendTo(this); + (this.client_widget = new ClientWidget(this, action.params)).appendTo(this.$element); }, ir_actions_report_xml: function(action, on_closed) { var self = this; From c7809cafe795e2e29f5e1605691028f2c0159860 Mon Sep 17 00:00:00 2001 From: Fabien Meghazi Date: Wed, 29 Feb 2012 15:15:27 +0100 Subject: [PATCH 31/39] [IMP] Renamed DropDownMenu to UserMenu bzr revid: fme@openerp.com-20120229141527-tuhkt0isveefy2kp --- addons/web/static/src/css/base.css | 16 ++++++++-------- addons/web/static/src/css/base.sass | 4 ++-- addons/web/static/src/js/chrome.js | 20 ++++++++++---------- addons/web/static/src/xml/base.xml | 8 ++++---- 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/addons/web/static/src/css/base.css b/addons/web/static/src/css/base.css index c36e8c61a2b..ccfc4568513 100644 --- a/addons/web/static/src/css/base.css +++ b/addons/web/static/src/css/base.css @@ -231,19 +231,19 @@ border-right: 4px solid transparent; border-top: 4px solid #4c4c4c; } -.openerp2 .oe_dropdown_menu { +.openerp2 .oe_user_menu { float: right; padding: 0; margin: 0; } -.openerp2 .oe_dropdown_menu li { +.openerp2 .oe_user_menu li { list-style-type: none; float: left; } -.openerp2 .oe_dropdown_menu .oe_dropdown { +.openerp2 .oe_user_menu .oe_dropdown { position: relative; } -.openerp2 .oe_dropdown_menu .oe_dropdown_toggle:after { +.openerp2 .oe_user_menu .oe_dropdown_toggle:after { width: 0; height: 0; display: inline-block; @@ -260,7 +260,7 @@ -moz-opacity: 0.5; opacity: 0.5; } -.openerp2 .oe_dropdown_menu .oe_dropdown_options { +.openerp2 .oe_user_menu .oe_dropdown_options { float: left; background: #333333; background: rgba(37, 37, 37, 0.9); @@ -288,12 +288,12 @@ -moz-background-clip: padding-box; background-clip: padding-box; } -.openerp2 .oe_dropdown_menu .oe_dropdown_options li { +.openerp2 .oe_user_menu .oe_dropdown_options li { float: none; display: block; background-color: none; } -.openerp2 .oe_dropdown_menu .oe_dropdown_options li a { +.openerp2 .oe_user_menu .oe_dropdown_options li a { display: block; padding: 4px 15px; clear: both; @@ -301,7 +301,7 @@ line-height: 18px; color: #eeeeee; } -.openerp2 .oe_dropdown_menu .oe_dropdown_options li a:hover { +.openerp2 .oe_user_menu .oe_dropdown_options li a:hover { background: #292929; background: -moz-linear-gradient(#292929, #191919); background: -webkit-gradient(linear, left top, left bottom, from(#292929), to(#191919)); diff --git a/addons/web/static/src/css/base.sass b/addons/web/static/src/css/base.sass index f62841896bd..10c6a1ad038 100644 --- a/addons/web/static/src/css/base.sass +++ b/addons/web/static/src/css/base.sass @@ -242,8 +242,8 @@ $colour4: #8a89ba border-top: 4px solid #4c4c4c // }}} - // DropDown Menu {{{ - .oe_dropdown_menu + // UserMenu {{{ + .oe_user_menu float: right padding: 0 margin: 0 diff --git a/addons/web/static/src/js/chrome.js b/addons/web/static/src/js/chrome.js index 1589ede75c1..4b958f5caf0 100644 --- a/addons/web/static/src/js/chrome.js +++ b/addons/web/static/src/js/chrome.js @@ -784,10 +784,10 @@ openerp.web.Menu = openerp.web.Widget.extend(/** @lends openerp.web.Menu# */{ } }); -openerp.web.DropDownMenu = openerp.web.Widget.extend(/** @lends openerp.web.DropDownMenu# */{ - template: "DropDownMenu", +openerp.web.UserMenu = openerp.web.Widget.extend(/** @lends openerp.web.UserMenu# */{ + template: "UserMenu", /** - * @constructs openerp.web.DropDownMenu + * @constructs openerp.web.UserMenu * @extends openerp.web.Widget * * @param parent @@ -876,7 +876,7 @@ openerp.web.DropDownMenu = openerp.web.Widget.extend(/** @lends openerp.web.Dro $(sc.binding).bind({ 'add': function (e, attrs) { shortcuts_ds.create(attrs, function (out) { - var shortcut = QWeb.render('DropDownMenu.shortcut', { + var shortcut = QWeb.render('UserMenu.shortcut', { shortcuts : [{ name : attrs.name, id : out.result, @@ -904,7 +904,7 @@ openerp.web.DropDownMenu = openerp.web.Widget.extend(/** @lends openerp.web.Dro sc.splice(0, sc.length); sc.push.apply(sc, shortcuts); - $(QWeb.render('DropDownMenu.shortcut', {'shortcuts': shortcuts})) + $(QWeb.render('UserMenu.shortcut', {'shortcuts': shortcuts})) .appendTo(self.$element.find('.oe_dropdown_options')); }); }, @@ -1004,7 +1004,7 @@ openerp.web.WebClient = openerp.web.Widget.extend(/** @lends openerp.web.WebClie this.session.on_session_valid.add(function() { self.show_application(); - self.dropdown_menu.do_update(); + self.user_menu.do_update(); self.menu.do_reload(); if(self.action_manager) self.action_manager.destroy(); @@ -1034,10 +1034,10 @@ openerp.web.WebClient = openerp.web.Widget.extend(/** @lends openerp.web.WebClie self.menu = new openerp.web.Menu(self); self.menu.replace(this.$element.find('.oe_menu_placeholder')); self.menu.on_action.add(this.proxy('on_menu_action')); - self.dropdown_menu = new openerp.web.DropDownMenu(self); - self.dropdown_menu.replace(this.$element.find('.oe_dropdown_menu_placeholder')); - self.dropdown_menu.on_menu_logout.add(this.proxy('on_logout')); - self.dropdown_menu.on_action.add(this.proxy('on_menu_action')); + self.user_menu = new openerp.web.UserMenu(self); + self.user_menu.replace(this.$element.find('.oe_user_menu_placeholder')); + self.user_menu.on_menu_logout.add(this.proxy('on_logout')); + self.user_menu.on_action.add(this.proxy('on_menu_action')); }, show_common: function() { var self = this; diff --git a/addons/web/static/src/xml/base.xml b/addons/web/static/src/xml/base.xml index d1dbf9845c9..7b5643ec8f9 100644 --- a/addons/web/static/src/xml/base.xml +++ b/addons/web/static/src/xml/base.xml @@ -21,7 +21,7 @@
    -
    +
    @@ -364,8 +364,8 @@ - -
      + + - +
    • From 71c94be053fe84cdde22da8e7bf016d825665151 Mon Sep 17 00:00:00 2001 From: Fabien Meghazi Date: Wed, 29 Feb 2012 16:55:26 +0100 Subject: [PATCH 32/39] [ADD] Added systray zone in webclient bzr revid: fme@openerp.com-20120229155526-14gpto9k1qtcl1m8 --- addons/web/static/src/css/base.css | 3 +++ addons/web/static/src/css/base.sass | 2 ++ addons/web/static/src/xml/base.xml | 1 + 3 files changed, 6 insertions(+) diff --git a/addons/web/static/src/css/base.css b/addons/web/static/src/css/base.css index ccfc4568513..fa4ceae540a 100644 --- a/addons/web/static/src/css/base.css +++ b/addons/web/static/src/css/base.css @@ -34,6 +34,9 @@ background: -webkit-gradient(linear, left top, left bottom, from(#646060), to(#262626)); background: -webkit-linear-gradient(#646060, #262626); } +.openerp2 .oe_topbar .oe_systray { + float: right; +} .openerp2 .oe_topbar .oe_topbar_item li { float: left; } diff --git a/addons/web/static/src/css/base.sass b/addons/web/static/src/css/base.sass index 10c6a1ad038..19fed7c1fe5 100644 --- a/addons/web/static/src/css/base.sass +++ b/addons/web/static/src/css/base.sass @@ -83,6 +83,8 @@ $colour4: #8a89ba border-bottom: solid 1px black @include vertical-gradient(#646060, #262626) + .oe_systray + float: right .oe_topbar_item li float: left diff --git a/addons/web/static/src/xml/base.xml b/addons/web/static/src/xml/base.xml index 7b5643ec8f9..08887e5b837 100644 --- a/addons/web/static/src/xml/base.xml +++ b/addons/web/static/src/xml/base.xml @@ -22,6 +22,7 @@
      +
      From f32e1dacbb8fb2c927d39cce7533239b4a938d19 Mon Sep 17 00:00:00 2001 From: Fabien Meghazi Date: Wed, 29 Feb 2012 17:22:47 +0100 Subject: [PATCH 33/39] [ADD] Add menuClicked event to Menu bzr revid: fme@openerp.com-20120229162247-m765betv577y4a2i --- addons/web/static/src/js/chrome.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/addons/web/static/src/js/chrome.js b/addons/web/static/src/js/chrome.js index 4b958f5caf0..58820efd15c 100644 --- a/addons/web/static/src/js/chrome.js +++ b/addons/web/static/src/js/chrome.js @@ -758,6 +758,8 @@ openerp.web.Menu = openerp.web.Widget.extend(/** @lends openerp.web.Menu# */{ id = $clicked_menu.data('menu'); } + this.trigger('menuClicked', id, $clicked_menu); + if (id) { this.open_menu(id); this.current_menu = id; From 0f6fea75bf5949ed5a0d0e162dbea667450ac364 Mon Sep 17 00:00:00 2001 From: Fabien Meghazi Date: Wed, 29 Feb 2012 17:31:49 +0100 Subject: [PATCH 34/39] [FIX] Fixed broken web addon due to webclient's new layout bzr revid: fme@openerp.com-20120229163149-unq4fqjlrkrxiv8r --- addons/web_uservoice/__openerp__.py | 1 - .../static/src/css/uservoice.css | 7 ---- .../static/src/js/web_uservoice.js | 34 +++++++------------ .../static/src/xml/web_uservoice.xml | 6 ++-- 4 files changed, 16 insertions(+), 32 deletions(-) delete mode 100644 addons/web_uservoice/static/src/css/uservoice.css diff --git a/addons/web_uservoice/__openerp__.py b/addons/web_uservoice/__openerp__.py index 971401dc3c9..8385b97ccaf 100644 --- a/addons/web_uservoice/__openerp__.py +++ b/addons/web_uservoice/__openerp__.py @@ -38,7 +38,6 @@ Invite OpenERP user feedback, powered by uservoice. 'certificate': '0040452504963885', 'js': ['static/src/js/web_uservoice.js'], - 'css': ['static/src/css/uservoice.css'], 'qweb' : [ "static/src/xml/*.xml", ], diff --git a/addons/web_uservoice/static/src/css/uservoice.css b/addons/web_uservoice/static/src/css/uservoice.css deleted file mode 100644 index 665ccee7f6e..00000000000 --- a/addons/web_uservoice/static/src/css/uservoice.css +++ /dev/null @@ -1,7 +0,0 @@ -div.header_corner div.feedback a { - /*color: #9a0404;*/ -} -div.header_corner div.feedback img { - vertical-align: middle; - margin-right: 0.5em; -} diff --git a/addons/web_uservoice/static/src/js/web_uservoice.js b/addons/web_uservoice/static/src/js/web_uservoice.js index 4871fb80c9d..3daa91beb82 100644 --- a/addons/web_uservoice/static/src/js/web_uservoice.js +++ b/addons/web_uservoice/static/src/js/web_uservoice.js @@ -1,8 +1,7 @@ - openerp.web_uservoice = function(instance) { -instance.web_uservoice.UserVoice = instance.web.OldWidget.extend({ - template: 'Header-UserVoice', +instance.web_uservoice.UserVoice = instance.web.Widget.extend({ + template: 'Systray.UserVoice', default_forum: '77459', init: function() { @@ -16,7 +15,12 @@ instance.web_uservoice.UserVoice = instance.web.OldWidget.extend({ showTab: false }; - instance.webclient.menu.do_menu_click.add_first(this.do_menu_click); + instance.webclient.menu.on('menuClicked', this, function(id, $clicked_menu) { + var root = $clicked_menu.parents('div.oe_menu').length === 1; + if (id && root) { + this.uservoiceOptions.forum = this.uservoiceForums[id] || this.default_forum; + } + }); }, start: function() { @@ -45,27 +49,16 @@ instance.web_uservoice.UserVoice = instance.web.OldWidget.extend({ self.uservoiceForums[menu.id] = forum_mapping[menu.name.toLowerCase()] || self.default_forum; }); }); - + this.$element.find('a').click(function(e) { e.preventDefault(); UserVoice.Popin.show(self.uservoiceOptions); return false; - }); - }, - - - do_menu_click: function($clicked_menu, manual) { - var id = $clicked_menu.attr('data-menu'), - root = $clicked_menu.parents('div.menu').length === 1; - if (id && root) { - this.uservoiceOptions.forum = this.uservoiceForums[id] || this.default_forum; - } - }, - + }).tipsy(); + } }); - -instance.web.Header.include({ +instance.web.UserMenu.include({ do_update: function() { var self = this; this._super(); @@ -74,12 +67,11 @@ instance.web.Header.include({ self.uservoice.destroy(); } self.uservoice = new instance.web_uservoice.UserVoice(self); - self.uservoice.prependTo(self.$element.find('div.header_corner')); + self.uservoice.appendTo(instance.webclient.$element.find('.oe_systray')); }); } }); - if (instance.webclient) { $(function() { var src = ("https:" == document.location.protocol ? "https://" : "http://") + "cdn.uservoice.com/javascripts/widgets/tab.js"; diff --git a/addons/web_uservoice/static/src/xml/web_uservoice.xml b/addons/web_uservoice/static/src/xml/web_uservoice.xml index e37ed2c17d3..3e8862474c2 100644 --- a/addons/web_uservoice/static/src/xml/web_uservoice.xml +++ b/addons/web_uservoice/static/src/xml/web_uservoice.xml @@ -2,7 +2,7 @@ - - - + +
      +
      From f48d255e1c23d29fe667cf3ea4a1ce3e16434f78 Mon Sep 17 00:00:00 2001 From: Fabien Meghazi Date: Wed, 29 Feb 2012 18:51:35 +0100 Subject: [PATCH 35/39] [ADD] Add styling to Systray bzr revid: fme@openerp.com-20120229175135-op7lllco1nzdr2z1 --- addons/web/static/src/css/base.css | 4 ++++ addons/web/static/src/css/base.sass | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/addons/web/static/src/css/base.css b/addons/web/static/src/css/base.css index fa4ceae540a..b81dea89050 100644 --- a/addons/web/static/src/css/base.css +++ b/addons/web/static/src/css/base.css @@ -37,6 +37,10 @@ .openerp2 .oe_topbar .oe_systray { float: right; } +.openerp2 .oe_topbar .oe_systray > div { + float: left; + padding: 0 4px 0 4px; +} .openerp2 .oe_topbar .oe_topbar_item li { float: left; } diff --git a/addons/web/static/src/css/base.sass b/addons/web/static/src/css/base.sass index 19fed7c1fe5..cfb8178de12 100644 --- a/addons/web/static/src/css/base.sass +++ b/addons/web/static/src/css/base.sass @@ -85,6 +85,10 @@ $colour4: #8a89ba .oe_systray float: right + .oe_systray > div + float: left + padding: 0 4px 0 4px + .oe_topbar_item li float: left From 00216e0e2dd392c6e26f778916ed513ee27aaed1 Mon Sep 17 00:00:00 2001 From: Fabien Meghazi Date: Wed, 29 Feb 2012 18:53:58 +0100 Subject: [PATCH 36/39] [FIX] web_livechat: Fixed broken addon due to webclient's layout change lp bug: https://launchpad.net/bugs/942468 fixed bzr revid: fme@openerp.com-20120229175358-f5phyhwn7wy3q6m6 --- addons/web_livechat/publisher_warranty.py | 4 -- .../static/src/js/web_livechat.js | 47 +++++++++---------- .../static/src/xml/web_livechat.xml | 8 ++-- 3 files changed, 27 insertions(+), 32 deletions(-) diff --git a/addons/web_livechat/publisher_warranty.py b/addons/web_livechat/publisher_warranty.py index a3b59811ff8..0328e4181a7 100644 --- a/addons/web_livechat/publisher_warranty.py +++ b/addons/web_livechat/publisher_warranty.py @@ -42,10 +42,6 @@ class publisher_warranty_contract(osv.osv): domain = [('state', '=', 'valid'), ('check_support', '=', True)] return self.search_count(cr, uid, domain) != 0 - @cache(skiparg=3) - def get_default_livechat_text(self, cr, uid): - return 'Support' - publisher_warranty_contract() diff --git a/addons/web_livechat/static/src/js/web_livechat.js b/addons/web_livechat/static/src/js/web_livechat.js index 4ddc93e3e6e..cf88f8fd25f 100644 --- a/addons/web_livechat/static/src/js/web_livechat.js +++ b/addons/web_livechat/static/src/js/web_livechat.js @@ -22,8 +22,8 @@ var __lc_buttons = []; openerp.web_livechat = function (openerp) { -openerp.web_livechat.Livechat = openerp.web.OldWidget.extend({ - template: 'Header-LiveChat', +openerp.web_livechat.Livechat = openerp.web.Widget.extend({ + template: 'Systray.LiveChat', start: function() { this._super(); @@ -31,26 +31,28 @@ openerp.web_livechat.Livechat = openerp.web.OldWidget.extend({ return; var self = this; var pwc = new openerp.web.Model("publisher_warranty.contract"); - return pwc.get_func('get_default_livechat_text')().then(function(text) { - self.$element.html(text); - pwc.get_func('is_livechat_enable')().then(function(res) { - if(res) { - self.$element.click(self.do_load_livechat); - } else { - self.$element.click(self.do_open_url); - } - }) + pwc.get_func('is_livechat_enable')().then(function(res) { + if(res) { + self.$element.click(self.do_load_livechat); + } else { + self.$element.click(self.do_open_url); + } + }); + this.$element.on('hover', '.oe_systray_livechat img', function() { + $(this).tipsy(); }); }, do_open_url: function(evt) { - evt.preventDefault(); + evt.preventDefault(); openerp.webclient.action_manager.do_action({type: 'ir.actions.act.url', url: 'http://www.openerp.com/support-or-publisher-warranty-contract', target: 'new'}); }, do_load_livechat: function(evt) { - evt.preventDefault(); var self = this; + if (evt) { + evt.preventDefault(); + } this.$element.unbind('click', this.do_load_livechat); @@ -58,9 +60,8 @@ openerp.web_livechat.Livechat = openerp.web.OldWidget.extend({ this.$element.attr('id', lc_id); var pwc = new openerp.web.Model("publisher_warranty.contract"); - + pwc.get_func('is_livechat_enable')().then(function(res) { - console.log('res', res); if(!res) { return; } @@ -74,39 +75,35 @@ openerp.web_livechat.Livechat = openerp.web.OldWidget.extend({ skill: '2', type: 'text', labels: { - online: 'Support', - offline: 'Support', + online: '', + offline: '', } }); }); } }); - -openerp.web.Header.include({ +openerp.web.UserMenu.include({ do_update: function() { var self = this; - this._super(); + this._super.apply(this, arguments); this.update_promise.then(function() { if (self.livechat) { self.livechat.destroy(); } self.livechat = new openerp.web_livechat.Livechat(self); - self.livechat.prependTo(self.$element.find('div.header_corner')); + self.livechat.appendTo(openerp.webclient.$element.find('.oe_systray')); }); } }); - - - if (openerp.webclient) { // tracking code from LiveChat var license = '1035052', params = '', lang = 'en', skill = '0'; - __lc_load = function (p) { + __lc_load = function (p) { if (typeof __lc_loaded != 'function') if (p) { var d = document, diff --git a/addons/web_livechat/static/src/xml/web_livechat.xml b/addons/web_livechat/static/src/xml/web_livechat.xml index b5e2db515b0..75221b0ab35 100644 --- a/addons/web_livechat/static/src/xml/web_livechat.xml +++ b/addons/web_livechat/static/src/xml/web_livechat.xml @@ -2,7 +2,9 @@ - -
      -
      + +
      + +
      +
      From e71848cee408b729538d7dc076e4c655ffdbb736 Mon Sep 17 00:00:00 2001 From: Launchpad Translations on behalf of openerp <> Date: Thu, 1 Mar 2012 04:46:46 +0000 Subject: [PATCH 37/39] Launchpad automatic translations update. bzr revid: launchpad_translations_on_behalf_of_openerp-20120301044646-9uirmxfvvb6dr69i --- addons/fetchmail_hr_recruitment/i18n/pt.po | 32 ++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 addons/fetchmail_hr_recruitment/i18n/pt.po diff --git a/addons/fetchmail_hr_recruitment/i18n/pt.po b/addons/fetchmail_hr_recruitment/i18n/pt.po new file mode 100644 index 00000000000..c1256badb11 --- /dev/null +++ b/addons/fetchmail_hr_recruitment/i18n/pt.po @@ -0,0 +1,32 @@ +# Portuguese translation for openobject-addons +# Copyright (c) 2012 Rosetta Contributors and Canonical Ltd 2012 +# This file is distributed under the same license as the openobject-addons package. +# FIRST AUTHOR , 2012. +# +msgid "" +msgstr "" +"Project-Id-Version: openobject-addons\n" +"Report-Msgid-Bugs-To: FULL NAME \n" +"POT-Creation-Date: 2012-02-08 00:36+0000\n" +"PO-Revision-Date: 2012-02-29 22:48+0000\n" +"Last-Translator: FULL NAME \n" +"Language-Team: Portuguese \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Launchpad-Export-Date: 2012-03-01 04:46+0000\n" +"X-Generator: Launchpad (build 14874)\n" + +#. module: fetchmail_hr_recruitment +#: model:ir.actions.act_window,help:fetchmail_hr_recruitment.action_link_applicant_to_email_account +msgid "" +"You can synchronize the job email account (e.g. job@yourcompany.com) with " +"OpenERP so that new applicants are created automatically in OpenERP for the " +"followup of the recruitment process. Attachments are automatically stored in " +"the DMS of OpenERP so that you get an indexation of all the CVs received." +msgstr "" + +#. module: fetchmail_hr_recruitment +#: model:ir.actions.act_window,name:fetchmail_hr_recruitment.action_link_applicant_to_email_account +msgid "Create Applicants from Email Account" +msgstr "" From bedb2d9596010f226c81c65b831795d7e1536acc Mon Sep 17 00:00:00 2001 From: Fabien Meghazi Date: Thu, 1 Mar 2012 10:58:07 +0100 Subject: [PATCH 38/39] [IMP] Added Systray tooltips bzr revid: fme@openerp.com-20120301095807-w8xi6b36adf1ky1z --- addons/web/static/src/js/chrome.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/addons/web/static/src/js/chrome.js b/addons/web/static/src/js/chrome.js index 58820efd15c..3b0e30382aa 100644 --- a/addons/web/static/src/js/chrome.js +++ b/addons/web/static/src/js/chrome.js @@ -1019,6 +1019,9 @@ openerp.web.WebClient = openerp.web.Widget.extend(/** @lends openerp.web.WebClie document.title = version_label; } }); + this.$element.on('mouseenter', '.oe_systray > div:not([data-tipsy=true])', function() { + $(this).attr('data-tipsy', 'true').tipsy().trigger('mouseenter'); + }); }, show_login: function() { var self = this; From e1ef7c7d88c830024376307cb165b01105fb1b60 Mon Sep 17 00:00:00 2001 From: Fabien Meghazi Date: Thu, 1 Mar 2012 11:00:07 +0100 Subject: [PATCH 39/39] [IMP] web addons: Use webclient's Systray tooltips bzr revid: fme@openerp.com-20120301100007-wobb5a8h87x2q47g --- addons/web_livechat/static/src/js/web_livechat.js | 7 ++----- addons/web_livechat/static/src/xml/web_livechat.xml | 4 ++-- addons/web_uservoice/static/src/xml/web_uservoice.xml | 2 +- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/addons/web_livechat/static/src/js/web_livechat.js b/addons/web_livechat/static/src/js/web_livechat.js index cf88f8fd25f..540af94310f 100644 --- a/addons/web_livechat/static/src/js/web_livechat.js +++ b/addons/web_livechat/static/src/js/web_livechat.js @@ -38,9 +38,6 @@ openerp.web_livechat.Livechat = openerp.web.Widget.extend({ self.$element.click(self.do_open_url); } }); - this.$element.on('hover', '.oe_systray_livechat img', function() { - $(this).tipsy(); - }); }, do_open_url: function(evt) { @@ -75,8 +72,8 @@ openerp.web_livechat.Livechat = openerp.web.Widget.extend({ skill: '2', type: 'text', labels: { - online: '', - offline: '', + online: '', + offline: '', } }); }); diff --git a/addons/web_livechat/static/src/xml/web_livechat.xml b/addons/web_livechat/static/src/xml/web_livechat.xml index 75221b0ab35..0f1bf073bc2 100644 --- a/addons/web_livechat/static/src/xml/web_livechat.xml +++ b/addons/web_livechat/static/src/xml/web_livechat.xml @@ -3,8 +3,8 @@ --> -
      - +
      +
      diff --git a/addons/web_uservoice/static/src/xml/web_uservoice.xml b/addons/web_uservoice/static/src/xml/web_uservoice.xml index 3e8862474c2..f9b7040ec64 100644 --- a/addons/web_uservoice/static/src/xml/web_uservoice.xml +++ b/addons/web_uservoice/static/src/xml/web_uservoice.xml @@ -3,6 +3,6 @@ --> -
      +