diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index d6dc4705..00000000 --- a/.gitattributes +++ /dev/null @@ -1,2 +0,0 @@ -* eol=lf -*.jar binary diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 6cd54797..00000000 --- a/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -src/selector.js -dist -.settings -*~ -*.diff -*.patch -/*.html -.DS_Store diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 19c60418..00000000 --- a/.gitmodules +++ /dev/null @@ -1,6 +0,0 @@ -[submodule "src/sizzle"] - path = src/sizzle - url = git://github.com/jquery/sizzle.git -[submodule "test/qunit"] - path = test/qunit - url = git://github.com/jquery/qunit.git diff --git a/ChangeLog.txt b/ChangeLog.txt new file mode 100644 index 00000000..6d834c19 --- /dev/null +++ b/ChangeLog.txt @@ -0,0 +1,98 @@ +== jQuery ChangeLog == + +== 1.2.2 == + +* show is now element aware (uses default display type instead of just forcing block) +* New special events api: jQuery.events.special +* ready is now a real event and can be bound, unbound and triggered. +* mouseenter and mouseleave now work on all supported browsers +* The hover helper method now uses the mouseenter and mouseleave events +* New offset test suite test/offset.html (requires your pop-up blocker to be disabled) +* Refactored the width and height methods (fixes lots of bugs) +* Fixed event memory leaks in IE (html, remove, empty also no longer leak memory) +* Fixed window/document width/height values +* Fixed event.pageX and event.pageY in IE + +== 1.2 == + +=== 1.1.3 === +* Always create an ActiveXObject when it is available instead of the XMLHttpRequest, even in IE7 +* Removed XMLHttpRequest shadowing, may break code that relies on existence of that function for browser checking +* ... + +=== 1.1.2 === + +* Event handlers (like element.onclick) are now removed when no more functions are bound to the event. +* Fixed DOM Manipulations for form elements. +* Fixed jQuery.isFunction to return false on nodes. +* Fixed jQuery.className.has, escaping regex characters in className (for metadata) +* Fixed an issue in IE where an event on a cloned element is fired during a .clone() inside of an event handler. +* Fixed IE ID selectors selecting by the name attribute. +* Change: Events are now internally stored in elem.$events rather than elem.events (due to a nasty bug relating to DOM 0 expandos). +* .attr('href') is now consistent in all browsers. +* @href is now consistent in all browsers. +* Fixed the slideDown flickering bug. +* Having a \r endline in $("...") caused a never-ending loop. +* Fixed IE6 AJAX memory leak +* Fixed bug in pushStack, reporting an element at [0] in a jQuery object with length 0 + +=== 1.1.1 === + +* Setting the numerical value of a css property failed, for example: .css("opacity",0.5) (also occurred with zIndex, fontWeight) +* Calling $(..., jqobj) with a context of a jQuery object failed. +* Accessing a property on an element that doesn't exist caused an error, for example: $("#foobar").attr("id") +* Calling .load() without a callback caused an error. +* You couldn't cancel an event that was triggered using .trigger() or .click() (for example). +* .add()ing a single DOM element to a jQuery object was broken. +* Passing in undefined values to a $.post() caused weird errors to occur. +* Accessing child nodes within an xml document didn't work properly. +* jQuery.isFunction() was unable to reliably determine a function, in a cross-browser way. +* Triggering a .click() failed in IE. +* Triggered click handlers were executed twice in most browsers. +* A newline passed into $(...) caused Firefox to go into a never-ending loop. +* Calling $.post() without any data caused an error. +* Calling a descendant selector after a child selector caused strange results, for example: $("ul > li ul") +* Triggered events did not occur if an event handler was not bound for that event. + +== 1.1 == + +* Massive speed-ups (4x-10x) in the selector engine. +* You can now unbind event handlers from within themselves +* Added new .one( "type", fn ) method +* text(String) now escapes HTML +* Added attr(String,Function) to calculate the value +* Performming .click(), .blur(), .focus(), .submit() will actually trigger the browsers default action for those events. +* Added global settings for AJAX (in addition to timeout), use $.ajaxSetup() to modify them +* Implemented a better error handling for ajax requests. Exceptions caused by dropping connections are now handled, too. +* Improved event fixing (Opera provides event.srcElement, must ignore it if target is available; only create pageX if clientX is available) +* Fixed nth-child selectors to start on the right number +* jQuery is no longer destructive. Doing var a = $("a"); a.find("span"); does not change the original "a" variable. +* Fixed synchronous requests +* Fixed ID with context selectors (eg. div #id doesn't ignore "div" anymore) +* Fixed docs for html(): Now mentions that is not available for XML documents +* Improved AJAX docs (eg. more examples for $.ajax) +* Documented filter(Function), a very powerful approach for custom filtering +* Improved docs for FX module, merging method descriptions and marking optional arguments +* Improved docs for append, prepend, before and after, merging the three pairs into one +* Improved show/hide animations to show only hidden and hide only visible elements +* Removed .oneEvent() and .unEvent() helper methods. +* Removed all CSS helper methods. +* Removed most attribute helper methods. +* Removed the (undocumented) .find( "selector", fn ) for all destructive methods. +* $.get, $.getIfModified, $.post, $.getScript and $.getJSON now all pass through the XMLHttpRequest as returned by $.ajax + +== 1.0.4 == + +* Tons of bug fixes +* Extensions to $.ajax: $.ajax accepts additonal options: beforeSend, async and processData; returns XMLHttpRequest to allow manual aborting of requests, see docs for details +* AJAX module: the public $.ajax API is now used internally (for $.get/$.post etc.); loading scripts works now much more reliable on all browers except Safari +* New global ajax handler: ajaxSend - called before an ajax request is sent +* Extensions to global ajax handlers: ajaxSend, ajaxSuccess, ajaxError and ajaxComplete get XMLHttpRequest and settings passed as arguments +* Extensions to event handling: pageX and pageY are available x-browser (IE does not provide native pageX/Y) +* Improved docs: $(String) method has now two seperate descriptions, one for selecting elements, one for creating (html on-the-fly) +* FX module: Most inline stlyes added by animations are now removed when the animation is complete, eg. height style when animating height (exception: display styles) +* Added note to attr(String, Object) about issues with setting the name property on input elements +* Seperated internal stuff from get() into set() +* Merged the two API examples for each() into one more precise example +* Improved docs for $.browser and added docs for $.boxModel +* Docs for the jQuery constructor $() were improved: There is now $(String expression[, Object context]) and $(String html) diff --git a/MIT-LICENSE.txt b/MIT-LICENSE.txt index 53270463..d4215f0e 100644 --- a/MIT-LICENSE.txt +++ b/MIT-LICENSE.txt @@ -1,4 +1,4 @@ -Copyright (c) 2011 John Resig, http://jquery.com/ +Copyright (c) 2008 John Resig, http://jquery.com/ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/Makefile b/Makefile index 06cee5de..3ca4c3b5 100644 --- a/Makefile +++ b/Makefile @@ -1,120 +1,166 @@ SRC_DIR = src -TEST_DIR = test BUILD_DIR = build PREFIX = . +DOCS_DIR = ${PREFIX}/docs +TEST_DIR = ${PREFIX}/test DIST_DIR = ${PREFIX}/dist - -JS_ENGINE ?= `which node nodejs` -COMPILER = ${JS_ENGINE} ${BUILD_DIR}/uglify.js --unsafe -POST_COMPILER = ${JS_ENGINE} ${BUILD_DIR}/post-compile.js +SPEED_DIR = ${PREFIX}/speed +PLUG_DIR = ../plugins BASE_FILES = ${SRC_DIR}/core.js\ - ${SRC_DIR}/deferred.js\ - ${SRC_DIR}/support.js\ - ${SRC_DIR}/data.js\ - ${SRC_DIR}/queue.js\ - ${SRC_DIR}/attributes.js\ - ${SRC_DIR}/event.js\ ${SRC_DIR}/selector.js\ - ${SRC_DIR}/traversing.js\ - ${SRC_DIR}/manipulation.js\ - ${SRC_DIR}/css.js\ + ${SRC_DIR}/event.js\ ${SRC_DIR}/ajax.js\ - ${SRC_DIR}/ajax/jsonp.js\ - ${SRC_DIR}/ajax/script.js\ - ${SRC_DIR}/ajax/xhr.js\ - ${SRC_DIR}/effects.js\ - ${SRC_DIR}/offset.js\ - ${SRC_DIR}/dimensions.js + ${SRC_DIR}/fx.js\ + ${SRC_DIR}/offset.js + +PLUGINS = ${PLUG_DIR}/button/*\ + ${PLUG_DIR}/center/*\ + ${PLUG_DIR}/cookie/*\ + ${PLUG_DIR}/dimensions/*\ + ${PLUG_DIR}/metadata/*\ + ${PLUG_DIR}/form/*\ + ${PLUG_DIR}/greybox/greybox.js\ + ${PLUG_DIR}/interface/*\ + ${PLUG_DIR}/pager/*\ + ${PLUG_DIR}/tablesorter/*\ + ${PLUG_DIR}/tabs/*\ + ${PLUG_DIR}/tooltip/jquery.tooltip.js\ + ${PLUG_DIR}/accordion/jquery.accordion.js MODULES = ${SRC_DIR}/intro.js\ ${BASE_FILES}\ ${SRC_DIR}/outro.js +MODULES_WITH_PLUGINS = ${SRC_DIR}/intro.js\ + ${BASE_FILES}\ + ${PLUGINS}\ + ${SRC_DIR}/outro.js + JQ = ${DIST_DIR}/jquery.js +JQ_LITE = ${DIST_DIR}/jquery.lite.js JQ_MIN = ${DIST_DIR}/jquery.min.js +JQ_PACK = ${DIST_DIR}/jquery.pack.js -SIZZLE_DIR = ${SRC_DIR}/sizzle +JQ_VER = `cat version.txt` +VER = sed s/@VERSION/${JQ_VER}/ -JQ_VER = $(shell cat version.txt) -VER = sed "s/@VERSION/${JQ_VER}/" +JAR = java -jar ${BUILD_DIR}/js.jar -DATE=$(shell git log -1 --pretty=format:%ad) - -all: update_submodules core - -core: jquery min lint +all: jquery lite min pack speed @@echo "jQuery build complete." ${DIST_DIR}: @@mkdir -p ${DIST_DIR} -jquery: ${JQ} +jquery: ${DIST_DIR} ${JQ} -${JQ}: ${MODULES} | ${DIST_DIR} +${JQ}: ${MODULES} @@echo "Building" ${JQ} - @@cat ${MODULES} | \ - sed 's/.function..jQuery...{//' | \ - sed 's/}...jQuery..;//' | \ - sed 's/@DATE/'"${DATE}"'/' | \ - ${VER} > ${JQ}; + @@mkdir -p ${DIST_DIR} + @@cat ${MODULES} | ${VER} > ${JQ}; -${SRC_DIR}/selector.js: ${SIZZLE_DIR}/sizzle.js - @@echo "Building selector code from Sizzle" - @@sed '/EXPOSE/r src/sizzle-jquery.js' ${SIZZLE_DIR}/sizzle.js | grep -v window.Sizzle > ${SRC_DIR}/selector.js + @@echo ${JQ} "Built" + @@echo -lint: jquery - @@if test ! -z ${JS_ENGINE}; then \ - echo "Checking jQuery against JSLint..."; \ - ${JS_ENGINE} build/jslint-check.js; \ - else \ - echo "You must have NodeJS installed in order to test jQuery against JSLint."; \ - fi +with_plugins: ${MODULES_WITH_PLUGINS} + @@echo "Building" ${JQ} -min: jquery ${JQ_MIN} + @@mkdir -p ${DIST_DIR} + @@cat ${MODULES_WITH_PLUGINS} | ${VER} > ${JQ}; + + @@echo ${JQ} "Built" + @@echo + +lite: ${JQ_LITE} + +${JQ_LITE}: ${JQ} + @@echo "Building" ${JQ_LITE} + + @@cp ${JQ} ${JQ_LITE} + + @@echo ${JQ_LITE} "Built" + @@echo + +pack: ${JQ_PACK} + +${JQ_PACK}: ${JQ} + @@echo "Building" ${JQ_PACK} + + @@echo " - Compressing using Packer" + @@${JAR} ${BUILD_DIR}/build/pack.js ${JQ} ${JQ_PACK} + + @@echo ${JQ_PACK} "Built" + @@echo + +min: ${JQ_MIN} ${JQ_MIN}: ${JQ} - @@if test ! -z ${JS_ENGINE}; then \ - echo "Minifying jQuery" ${JQ_MIN}; \ - ${COMPILER} ${JQ} > ${JQ_MIN}.tmp; \ - ${POST_COMPILER} ${JQ_MIN}.tmp > ${JQ_MIN}; \ - rm -f ${JQ_MIN}.tmp; \ - else \ - echo "You must have NodeJS installed in order to minify jQuery."; \ - fi - + @@echo "Building" ${JQ_MIN} + + @@echo " - Compressing using Minifier" + @@${JAR} ${BUILD_DIR}/build/min.js ${JQ} ${JQ_MIN} + + @@echo ${JQ_MIN} "Built" + @@echo + +test: ${JQ} + @@echo "Building Test Suite" + @@echo "Test Suite Built" + @@echo + +runtest: ${JQ} test + @@echo "Running Automated Test Suite" + @@${JAR} ${BUILD_DIR}/runtest/test.js + + @@echo "Test Suite Finished" + @@echo + +docs: ${JQ} + @@echo "Building Documentation" + + @@echo " - Making Documentation Directory:" ${DOCS_DIR} + @@mkdir -p ${DOCS_DIR} + @@mkdir -p ${DOCS_DIR}/data + + @@echo " - Copying over htaccess file." + @@cp -fR ${BUILD_DIR}/docs/.htaccess ${DOCS_DIR} + + @@echo " - Copying over script files." + @@cp -fR ${BUILD_DIR}/docs/js ${DOCS_DIR}/js + + @@echo " - Copying over style files." + @@cp -fR ${BUILD_DIR}/docs/style ${DOCS_DIR}/style + + @@echo " - Extracting ScriptDoc from" ${JQ} + @@${JAR} ${BUILD_DIR}/docs/docs.js ${JQ} ${DOCS_DIR} + + @@echo "Documentation Built" + @@echo + +speed: ${JQ} + @@echo "Building Speed Test Suite" + + @@echo " - Making Speed Test Suite Directory:" ${SPEED_DIR} + @@mkdir -p ${SPEED_DIR} + + @@echo " - Copying over script files." + @@cp -f ${BUILD_DIR}/speed/index.html ${SPEED_DIR} + @@cp -f ${BUILD_DIR}/speed/benchmarker.css ${SPEED_DIR} + @@cp -f ${BUILD_DIR}/speed/benchmarker.js ${SPEED_DIR} + @@cp -f ${BUILD_DIR}/speed/jquery-basis.js ${SPEED_DIR} + + @@echo "Speed Test Suite Built" + @@echo clean: @@echo "Removing Distribution directory:" ${DIST_DIR} @@rm -rf ${DIST_DIR} - @@echo "Removing built copy of Sizzle" - @@rm -f src/selector.js + @@echo "Removing Documentation directory:" ${DOCS_DIR} + @@rm -rf ${DOCS_DIR} -distclean: clean - @@echo "Removing submodules" - @@rm -rf test/qunit src/sizzle - -# change pointers for submodules and update them to what is specified in jQuery -# --merge doesn't work when doing an initial clone, thus test if we have non-existing -# submodules, then do an real update -update_submodules: - @@if [ -d .git ]; then \ - if git submodule status | grep -q -E '^-'; then \ - git submodule update --init --recursive; \ - else \ - git submodule update --init --recursive --merge; \ - fi; \ - fi; - -# update the submodules to the latest at the most logical branch -pull_submodules: - @@git submodule foreach "git pull \$$(git config remote.origin.url)" - @@git submodule summary - -pull: pull_submodules - @@git pull ${REMOTE} ${BRANCH} - -.PHONY: all jquery lint min clean distclean update_submodules pull_submodules pull core + @@echo "Removing Speed Test Suite directory:" ${SPEED_DIR} + @@rm -rf ${SPEED_DIR} diff --git a/README b/README new file mode 100644 index 00000000..cb936483 --- /dev/null +++ b/README @@ -0,0 +1,67 @@ + +-------------------------------- +jQuery - New Wave Javascript +http://jquery.com/ +-------------------------------- + +What you need to build your own jQuery: + - Make sure that you have Java installed. + + If not, go to this page and download "Java Runtime Environment (JRE) 5.0" + http://java.sun.com/javase/downloads/index.jsp + + - You now have two options for building jQuery, if you have access to + common UNIX commands (like 'make', 'mkdir', 'rm', 'cat', and 'echo') + then simply type 'make' to build all the components. + + - The other option is if you have Ant installed (or are on Windows and + don't have access to make). You can download Ant from here: + http://ant.apache.org/bindownload.cgi + + If you do have Ant, everytime (in this README) that I say 'make', do + 'ant' instead - it works identically (for all intents and purposes). + +How to build your own jQuery: + +In the main directory of the distribution (the one that this file is in), type +the following to make all versions of jQuery, the documentation, and the test suite: + make + +Here are each of the individual items that are buildable from the Makefile. + +make jquery + The standard, uncompressed, jQuery code. + Makes: ./dist/jquery.js + +make lite + jQuery without all the additional inline documentation and test cases. + Makes: ./dist/jquery.lite.js + +make pack + A compressed version of jQuery (made with Packer). + Makes: ./dist/jquery.pack.js + +make docs + Builds a complete copy of the documentation, based upon the jQuery source. + Makes ./docs/ + Open this file in your browser: + ./docs/index.xml + +make test + Builds a complete copy of the test suite, based upon the jQuery source. + Makes ./test/ + Open this file in your browser: + ./test/index.html + +Finally, you can remove all the built files using the command: + make clean + +Additionally, if you want to install jQuery to a location that is not this +directory, you can specify the PREFIX directory, for example: + make PREFIX=/home/john/test/ +OR + make PREFIX=~/www/ docs + +If you have any questions, please feel free to ask them on the jQuery +mailing list, which can be found here: + http://jquery.com/discuss/ diff --git a/README.md b/README.md deleted file mode 100644 index a54a02df..00000000 --- a/README.md +++ /dev/null @@ -1,147 +0,0 @@ -[jQuery](http://jquery.com/) - New Wave JavaScript -================================================== - -What you need to build your own jQuery --------------------------------------- - -In order to build jQuery, you need to have GNU make 3.8 or later, Node.js 0.2 or later, and git 1.7 or later. -(Earlier versions might work OK, but are not tested.) - -Windows users have two options: - -1. Install [msysgit](https://code.google.com/p/msysgit/) (Full installer for official Git), - [GNU make for Windows](http://gnuwin32.sourceforge.net/packages/make.htm), and a - [binary version of Node.js](http://node-js.prcn.co.cc/). Make sure all three packages are installed to the same - location (by default, this is C:\Program Files\Git). -2. Install [Cygwin](http://cygwin.com/) (make sure you install the git, make, and which packages), then either follow - the [Node.js build instructions](https://github.com/ry/node/wiki/Building-node.js-on-Cygwin-%28Windows%29) or install - the [binary version of Node.js](http://node-js.prcn.co.cc/). - -Mac OS users should install Xcode (comes on your Mac OS install DVD, or downloadable from -[Apple's Xcode site](http://developer.apple.com/technologies/xcode.html)) and -[http://mxcl.github.com/homebrew/](Homebrew). Once Homebrew is installed, run `brew install git` to install git, -and `brew install node` to install Node.js. - -Linux/BSD users should use their appropriate package managers to install make, git, and node, or build from source -if you swing that way. Easy-peasy. - - -How to build your own jQuery ----------------------------- - -First, clone a copy of the main jQuery git repo by running `git clone git://github.com/jquery/jquery.git`. - -Then, to get a complete, minified, jslinted version of jQuery, simply `cd` to the `jquery` directory and type -`make`. If you don't have Node installed and/or want to make a basic, uncompressed, unlinted version of jQuery, use -`make jquery` instead of `make`. - -The built version of jQuery will be put in the `dist/` subdirectory. - -To remove all built files, run `make clean`. - - -Building to a different directory ---------------------------------- - -If you want to build jQuery to a directory that is different from the default location, you can specify the PREFIX -directory: `make PREFIX=/home/jquery/test/ [command]` - -With this example, the output files would end up in `/home/jquery/test/dist/`. - - -Troubleshooting ---------------- - -Sometimes, the various git repositories get into an inconsistent state where builds don't complete properly -(usually this results in the jquery.js or jquery.min.js being 0 bytes). If this happens, run `make clean`, then -run `make` again. - -Git for dummies ---------------- - -As the source code is handled by the version control system Git, it's useful to know some features used. - -### Submodules ### - -The repository uses submodules, which normally are handled directly by the Makefile, but sometimes you want to -be able to work with them manually. - -Following are the steps to manually get the submodules: - -1. `git clone https://github.com/jquery/jquery.git` -2. `git submodule init` -3. `git submodule update` - -Or: - -1. `git clone https://github.com/jquery/jquery.git` -2. `git submodule update --init` - -Or: - -1. `git clone --recursive https://github.com/jquery/jquery.git` - -If you want to work inside a submodule, it is possible, but first you need to checkout a branch: - -1. `cd src/sizzle` -2. `git checkout master` - -After you've committed your changes to the submodule, you'll update the jquery project to point to the new commit, -but remember to push the submodule changes before pushing the new jquery commit: - -1. `cd src/sizzle` -2. `git push origin master` -3. `cd ..` -4. `git add src/sizzle` -5. `git commit` - -The makefile has some targets to simplify submodule handling: - -#### `make update_submodules` #### - -checks out the commit pointed to by jquery, but merges your local changes, if any. This target is executed -when you are doing a normal `make`. - -#### `make pull_submodules` #### - -updates the content of the submodules to what is probably the latest upstream code. - -#### `make pull` #### - -make a `make pull_submodules` and after that a `git pull`. if you have no remote tracking in your master branch, you can -execute this command as `make pull REMOTE=origin BRANCH=master` instead. - -### cleaning ### - -If you want to purge your working directory back to the status of upstream, following commands can be used (remember everything you've worked on is gone after these): - -1. `git reset --hard upstream/master` -2. `git clean -fdx` - -### rebasing ### - -For feature/topic branches, you should always used the `--rebase` flag to `git pull`, or if you are usually handling many temporary "to be in a github pull request" branches, run following to automate this: - -* `git config branch.autosetuprebase local` (see `man git-config` for more information) - -### handling merge conflicts ### - -If you're getting merge conflicts when merging, instead of editing the conflicted files manually, you can use the feature -`git mergetool`. Even though the default tool `xxdiff` looks awful/old, it's rather useful. - -Following are some commands that can be used there: - -* `Ctrl + Alt + M` - automerge as much as possible -* `b` - jump to next merge conflict -* `s` - change the order of the conflicted lines -* `u` - undo an merge -* `left mouse button` - mark a block to be the winner -* `middle mouse button` - mark a line to be the winner -* `Ctrl + S` - save -* `Ctrl + Q` - quit - -Questions? ----------- - -If you have any questions, please feel free to ask on the -[Developing jQuery Core forum](http://forum.jquery.com/developing-jquery-core) or in #jquery on irc.freenode.net. diff --git a/build.xml b/build.xml new file mode 100644 index 00000000..ddc23bfa --- /dev/null +++ b/build.xml @@ -0,0 +1,88 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/build/build/build.js b/build/build/build.js new file mode 100644 index 00000000..8c622ec4 --- /dev/null +++ b/build/build/build.js @@ -0,0 +1,5 @@ +load("build/js/ParseMaster.js", "build/js/pack.js", "build/js/writeFile.js"); + +var out = readFile( arguments[0] ); + +writeFile( arguments[1], pack( out, 62, true, false ) ); diff --git a/build/build/min.js b/build/build/min.js new file mode 100644 index 00000000..5707d4af --- /dev/null +++ b/build/build/min.js @@ -0,0 +1,11 @@ +load("build/js/jsmin.js", "build/js/writeFile.js"); + +// arguments +var inFile = arguments[0]; +var outFile = arguments[1] || inFile.replace(/\.js$/, ".min.js"); + +var script = readFile(inFile); +var header = script.match(/\/\*(.|\n)*?\*\//)[0]; +var minifiedScript = jsmin('', script, 3); + +writeFile( outFile, header + minifiedScript ); diff --git a/build/build/pack.js b/build/build/pack.js new file mode 100644 index 00000000..f3873920 --- /dev/null +++ b/build/build/pack.js @@ -0,0 +1,19 @@ +load("build/js/writeFile.js"); +load("build/js/base2.js"); +load("build/js/Packer.js"); +load("build/js/Words.js"); + +// arguments +var inFile = arguments[0]; +var outFile = arguments[1] || inFile.replace(/\.js$/, ".pack.js"); + +// options +var base62 = true; +var shrink = true; + +var script = readFile(inFile); +var header = script.match(/\/\*(.|\n)*?\*\//)[0]; +var packer = new Packer; +var packedScript = packer.pack(script, base62, shrink); + +writeFile(outFile, header + "\n" + packedScript); diff --git a/build/build/version.js b/build/build/version.js new file mode 100644 index 00000000..f586c77c --- /dev/null +++ b/build/build/version.js @@ -0,0 +1,4 @@ +load("build/js/writeFile.js"); + +var file = arguments[0]; +writeFile(file, readFile(file).replace(new RegExp("@VERSION", "g"), readFile("version.txt").replace( /^\s+|\s+$/g, "" ))); diff --git a/build/js.jar b/build/js.jar new file mode 100644 index 00000000..a76cc7c6 Binary files /dev/null and b/build/js.jar differ diff --git a/build/js/Packer.js b/build/js/Packer.js new file mode 100644 index 00000000..88c47d0f --- /dev/null +++ b/build/js/Packer.js @@ -0,0 +1,209 @@ +/* + Packer version 3.0 (beta 8) - copyright 2004-2007, Dean Edwards + http://www.opensource.org/licenses/mit-license +*/ + +eval(base2.namespace); + +var IGNORE = RegGrp.IGNORE; +var REMOVE = ""; +var SPACE = " "; +var WORDS = /\w+/g; + +var Packer = Base.extend({ + minify: function(script) { + script = script.replace(Packer.CONTINUE, ""); + script = Packer.data.exec(script); + script = Packer.whitespace.exec(script); + script = Packer.clean.exec(script); + return script; + }, + + pack: function(script, base62, shrink) { + script = this.minify(script + "\n"); + if (shrink) script = this._shrinkVariables(script); + if (base62) script = this._base62Encode(script); + return script; + }, + + _base62Encode: function(script) { + var words = new Words(script); + var encode = function(word) { + return words.fetch(word).encoded; + }; + + /* build the packed script */ + + var p = this._escape(script.replace(WORDS, encode)); + var a = Math.min(Math.max(words.count(), 2), 62); + var c = words.count(); + var k = words; + var e = Packer["ENCODE" + (a > 10 ? a > 36 ? 62 : 36 : 10)]; + var r = a > 10 ? "e(c)" : "c"; + + // the whole thing + return format(Packer.UNPACK, p,a,c,k,e,r); + }, + + _escape: function(script) { + // single quotes wrap the final string so escape them + // also escape new lines required by conditional comments + return script.replace(/([\\'])/g, "\\$1").replace(/[\r\n]+/g, "\\n"); + }, + + _shrinkVariables: function(script) { + // Windows Scripting Host cannot do regexp.test() on global regexps. + var global = function(regexp) { + // This function creates a global version of the passed regexp. + return new RegExp(regexp.source, "g"); + }; + + var data = []; // encoded strings and regular expressions + var REGEXP = /^[^'"]\//; + var store = function(string) { + var replacement = "#" + data.length; + if (REGEXP.test(string)) { + replacement = string.charAt(0) + replacement; + string = string.slice(1); + } + data.push(string); + return replacement; + }; + + // Base52 encoding (a-Z) + var encode52 = function(c) { + return (c < 52 ? '' : arguments.callee(parseInt(c / 52))) + + ((c = c % 52) > 25 ? String.fromCharCode(c + 39) : String.fromCharCode(c + 97)); + }; + + // identify blocks, particularly identify function blocks (which define scope) + var BLOCK = /(function\s*[\w$]*\s*\(\s*([^\)]*)\s*\)\s*)?(\{([^{}]*)\})/; + var VAR_ = /var\s+/g; + var VAR_NAME = /var\s+[\w$]+/g; + var COMMA = /\s*,\s*/; + var blocks = []; // store program blocks (anything between braces {}) + // encoder for program blocks + var encode = function(block, func, args) { + if (func) { // the block is a function block + + // decode the function block (THIS IS THE IMPORTANT BIT) + // We are retrieving all sub-blocks and will re-parse them in light + // of newly shrunk variables + block = decode(block); + + // create the list of variable and argument names + var vars = match(block, VAR_NAME).join(",").replace(VAR_, ""); + var ids = Array2.combine(args.split(COMMA).concat(vars.split(COMMA))); + + // process each identifier + var count = 0, shortId; + forEach (ids, function(id) { + id = trim(id); + if (id && id.length > 1) { // > 1 char + id = rescape(id); + // find the next free short name (check everything in the current scope) + do shortId = encode52(count++); + while (new RegExp("[^\\w$.]" + shortId + "[^\\w$:]").test(block)); + // replace the long name with the short name + var reg = new RegExp("([^\\w$.])" + id + "([^\\w$:])"); + while (reg.test(block)) block = block.replace(global(reg), "$1" + shortId + "$2"); + var reg = new RegExp("([^{,])" + id + ":", "g"); + block = block.replace(reg, "$1" + shortId + ":"); + } + }); + } + var replacement = "~" + blocks.length + "~"; + blocks.push(block); + return replacement; + }; + + // decoder for program blocks + var ENCODED = /~(\d+)~/; + var decode = function(script) { + while (ENCODED.test(script)) { + script = script.replace(global(ENCODED), function(match, index) { + return blocks[index]; + }); + } + return script; + }; + + // encode strings and regular expressions + script = Packer.data.exec(script, store); + + // remove closures (this is for base2 namespaces only) + script = script.replace(/new function\(_\)\s*\{/g, "{;#;"); + + // encode blocks, as we encode we replace variable and argument names + while (BLOCK.test(script)) { + script = script.replace(global(BLOCK), encode); + } + + // put the blocks back + script = decode(script); + + // put back the closure (for base2 namespaces only) + script = script.replace(/\{;#;/g, "new function(_){"); + + // put strings and regular expressions back + script = script.replace(/#(\d+)/g, function(match, index) { + return data[index]; + }); + + return script; + } +}, { + CONTINUE: /\\\r?\n/g, + + ENCODE10: "String", + ENCODE36: "function(c){return c.toString(a)}", + ENCODE62: "function(c){return(c35?String.fromCharCode(c+29):c.toString(36))}", + + UNPACK: "eval(function(p,a,c,k,e,r){e=%5;if(!''.replace(/^/,String)){while(c--)r[%6]=k[c]" + + "||%6;k=[function(e){return r[e]}];e=function(){return'\\\\w+'};c=1};while(c--)if(k[c])p=p." + + "replace(new RegExp('\\\\b'+e(c)+'\\\\b','g'),k[c]);return p}('%1',%2,%3,'%4'.split('|'),0,{}))", + + init: function() { + this.data = reduce(this.data, function(data, replacement, expression) { + data.store(this.javascript.exec(expression), replacement); + return data; + }, new RegGrp, this); + this.clean = this.data.union(this.clean); + this.whitespace = this.data.union(this.whitespace); + }, + + clean: { + "\\(\\s*;\\s*;\\s*\\)": "(;;)", // for (;;) loops + "throw[^};]+[};]": IGNORE, // a safari 1.3 bug + ";+\\s*([};])": "$1" + }, + + data: { + // strings + "STRING1": IGNORE, + 'STRING2': IGNORE, + "CONDITIONAL": IGNORE, // conditional comments + "(COMMENT1)\\n\\s*(REGEXP)?": "\n$3", + "(COMMENT2)\\s*(REGEXP)?": " $3", + "([\\[(\\^=,{}:;&|!*?])\\s*(REGEXP)": "$1$2" + }, + + javascript: new RegGrp({ + COMMENT1: /(\/\/|;;;)[^\n]*/.source, + COMMENT2: /\/\*[^*]*\*+([^\/][^*]*\*+)*\//.source, + CONDITIONAL: /\/\*@|@\*\/|\/\/@[^\n]*\n/.source, + REGEXP: /\/(\\[\/\\]|[^*\/])(\\.|[^\/\n\\])*\/[gim]*/.source, + STRING1: /'(\\.|[^'\\])*'/.source, + STRING2: /"(\\.|[^"\\])*"/.source + }), + + whitespace: { + "(\\d)\\s+(\\.\\s*[a-z\\$_\\[(])": "$1 $2", // http://dean.edwards.name/weblog/2007/04/packer3/#comment84066 + "([+-])\\s+([+-])": "$1 $2", // c = a++ +b; + "\\b\\s+\\$\\s+\\b": " $ ", // var $ in + "\\$\\s+\\b": "$ ", // object$ in + "\\b\\s+\\$": " $", // return $object + "\\b\\s+\\b": SPACE, + "\\s+": REMOVE + } +}); diff --git a/build/js/ParseMaster.js b/build/js/ParseMaster.js new file mode 100644 index 00000000..915a8b5d --- /dev/null +++ b/build/js/ParseMaster.js @@ -0,0 +1,106 @@ +/* + ParseMaster, version 1.0.2 (2005-08-19) + Copyright 2005, Dean Edwards + License: http://creativecommons.org/licenses/LGPL/2.1/ +*/ + +/* a multi-pattern parser */ + +// KNOWN BUG: erroneous behavior when using escapeChar with a replacement value that is a function + +function ParseMaster() { + // constants + var $EXPRESSION = 0, $REPLACEMENT = 1, $LENGTH = 2; + // used to determine nesting levels + var $GROUPS = /\(/g, $SUB_REPLACE = /\$\d/, $INDEXED = /^\$\d+$/, + $TRIM = /(['"])\1\+(.*)\+\1\1$/, $$ESCAPE = /\\./g, $QUOTE = /'/, + $$DELETED = /\x01[^\x01]*\x01/g; + var self = this; + // public + this.add = function($expression, $replacement) { + if (!$replacement) $replacement = ""; + // count the number of sub-expressions + // - add one because each pattern is itself a sub-expression + var $length = (_internalEscape(String($expression)).match($GROUPS) || "").length + 1; + // does the pattern deal with sub-expressions? + if ($SUB_REPLACE.test($replacement)) { + // a simple lookup? (e.g. "$2") + if ($INDEXED.test($replacement)) { + // store the index (used for fast retrieval of matched strings) + $replacement = parseInt($replacement.slice(1)) - 1; + } else { // a complicated lookup (e.g. "Hello $2 $1") + // build a function to do the lookup + var i = $length; + var $quote = $QUOTE.test(_internalEscape($replacement)) ? '"' : "'"; + while (i) $replacement = $replacement.split("$" + i--).join($quote + "+a[o+" + i + "]+" + $quote); + $replacement = new Function("a,o", "return" + $quote + $replacement.replace($TRIM, "$1") + $quote); + } + } + // pass the modified arguments + _add($expression || "/^$/", $replacement, $length); + }; + // execute the global replacement + this.exec = function($string) { + _escaped.length = 0; + return _unescape(_escape($string, this.escapeChar).replace( + new RegExp(_patterns, this.ignoreCase ? "gi" : "g"), _replacement), this.escapeChar).replace($$DELETED, ""); + }; + // clear the patterns collection so that this object may be re-used + this.reset = function() { + _patterns.length = 0; + }; + + // private + var _escaped = []; // escaped characters + var _patterns = []; // patterns stored by index + var _toString = function(){return "(" + String(this[$EXPRESSION]).slice(1, -1) + ")"}; + _patterns.toString = function(){return this.join("|")}; + // create and add a new pattern to the patterns collection + function _add() { + arguments.toString = _toString; + // store the pattern - as an arguments object (i think this is quicker..?) + _patterns[_patterns.length] = arguments; + } + // this is the global replace function (it's quite complicated) + function _replacement() { + if (!arguments[0]) return ""; + var i = 1, j = 0, $pattern; + // loop through the patterns + while ($pattern = _patterns[j++]) { + // do we have a result? + if (arguments[i]) { + var $replacement = $pattern[$REPLACEMENT]; + switch (typeof $replacement) { + case "function": return $replacement(arguments, i); + case "number": return arguments[$replacement + i]; + } + var $delete = (arguments[i].indexOf(self.escapeChar) == -1) ? "" : + "\x01" + arguments[i] + "\x01"; + return $delete + $replacement; + // skip over references to sub-expressions + } else i += $pattern[$LENGTH]; + } + }; + // encode escaped characters + function _escape($string, $escapeChar) { + return $escapeChar ? $string.replace(new RegExp("\\" + $escapeChar + "(.)", "g"), function($match, $char) { + _escaped[_escaped.length] = $char; + return $escapeChar; + }) : $string; + }; + // decode escaped characters + function _unescape($string, $escapeChar) { + var i = 0; + return $escapeChar ? $string.replace(new RegExp("\\" + $escapeChar, "g"), function() { + return $escapeChar + (_escaped[i++] || ""); + }) : $string; + }; + function _internalEscape($string) { + return $string.replace($$ESCAPE, ""); + }; +}; +ParseMaster.prototype = { + constructor: ParseMaster, + ignoreCase: false, + escapeChar: "" +}; diff --git a/build/js/Words.js b/build/js/Words.js new file mode 100644 index 00000000..264d42fa --- /dev/null +++ b/build/js/Words.js @@ -0,0 +1,62 @@ + +var Words = Collection.extend({ + constructor: function(script) { + this.base(); + forEach (script.match(WORDS), this.add, this); + this.encode(); + }, + + add: function(word) { + if (!this.exists(word)) this.base(word); + word = this.fetch(word); + word.count++; + return word; + }, + + encode: function() { + // sort by frequency + this.sort(function(word1, word2) { + return word2.count - word1.count; + }); + + eval("var a=62,e=" + Packer.ENCODE62); + var encode = e; + var encoded = new Collection; // a dictionary of base62 -> base10 + var count = this.count(); + for (var i = 0; i < count; i++) { + encoded.store(encode(i), i); + } + + var empty = function() {return ""}; + var index = 0; + forEach (this, function(word) { + if (encoded.exists(word)) { + word.index = encoded.fetch(word); + word.toString = empty; + } else { + while (this.exists(encode(index))) index++; + word.index = index++; + } + word.encoded = encode(word.index); + }, this); + + // sort by encoding + this.sort(function(word1, word2) { + return word1.index - word2.index; + }); + }, + + toString: function() { + return this.values().join("|"); + } +}, { + Item: { + constructor: function(word) { + this.toString = function() {return word}; + }, + + count: 0, + encoded: "", + index: -1 + } +}); diff --git a/build/js/base2.js b/build/js/base2.js new file mode 100644 index 00000000..87eb37b6 --- /dev/null +++ b/build/js/base2.js @@ -0,0 +1,978 @@ +// timestamp: Tue, 01 May 2007 19:13:00 +/* + base2.js - copyright 2007, Dean Edwards + http://www.opensource.org/licenses/mit-license +*/ + +var base2 = {}; + +// You know, writing a javascript library is awfully time consuming. + +new function(_) { //////////////////// BEGIN: CLOSURE //////////////////// + +// ========================================================================= +// base2/Base.js +// ========================================================================= + +// version 1.1 + +var Base = function() { + // call this method from any other method to invoke that method's ancestor +}; + +Base.prototype = { + extend: function(source) { + if (arguments.length > 1) { // extending with a name/value pair + var ancestor = this[source]; + var value = arguments[1]; + if (typeof value == "function" && ancestor && /\bbase\b/.test(value)) { + var method = value; + value = function() { // override + var previous = this.base; + this.base = ancestor; + var returnValue = method.apply(this, arguments); + this.base = previous; + return returnValue; + }; + value.method = method; + value.ancestor = ancestor; + } + this[source] = value; + } else if (source) { // extending with an object literal + var extend = Base.prototype.extend; + if (Base._prototyping) { + var key, i = 0, members = ["constructor", "toString", "valueOf"]; + while (key = members[i++]) if (source[key] != Object.prototype[key]) { + extend.call(this, key, source[key]); + } + } else if (typeof this != "function") { + // if the object has a customised extend() method then use it + extend = this.extend || extend; + } + // copy each of the source object's properties to this object + for (key in source) if (!Object.prototype[key]) { + extend.call(this, key, source[key]); + } + } + return this; + }, + + base: Base +}; + +Base.extend = function(_instance, _static) { // subclass + var extend = Base.prototype.extend; + + // build the prototype + Base._prototyping = true; + var proto = new this; + extend.call(proto, _instance); + delete Base._prototyping; + + // create the wrapper for the constructor function + var constructor = proto.constructor; + var klass = proto.constructor = function() { + if (!Base._prototyping) { + if (this._constructing || this.constructor == klass) { // instantiation + this._constructing = true; + constructor.apply(this, arguments); + delete this._constructing; + } else { // casting + var object = arguments[0]; + if (object != null) { + (object.extend || extend).call(object, proto); + } + return object; + } + } + }; + + // build the class interface + for (var i in Base) klass[i] = this[i]; + klass.ancestor = this; + klass.base = Base.base; + klass.prototype = proto; + klass.toString = this.toString; + extend.call(klass, _static); + // class initialisation + if (typeof klass.init == "function") klass.init(); + return klass; +}; + +// initialise +Base = Base.extend({ + constructor: function() { + this.extend(arguments[0]); + } +}, { + ancestor: Object, + base: Base, + + implement: function(_interface) { + if (typeof _interface == "function") { + // if it's a function, call it + _interface(this.prototype); + } else { + // add the interface using the extend() method + this.prototype.extend(_interface); + } + return this; + } +}); + +// ========================================================================= +// lang/main.js +// ========================================================================= + +var Legacy = typeof $Legacy == "undefined" ? {} : $Legacy; + +var K = function(k) {return k}; + +var assert = function(condition, message, Err) { + if (!condition) { + throw new (Err || Error)(message || "Assertion failed."); + } +}; + +var assertType = function(object, type, message) { + if (type) { + var condition = typeof type == "function" ? instanceOf(object, type) : typeof object == type; + assert(condition, message || "Invalid type.", TypeError); + } +}; + +var copy = function(object) { + var fn = new Function; + fn.prototype = object; + return new fn; +}; + +var format = function(string) { + // replace %n with arguments[n] + // e.g. format("%1 %2%3 %2a %1%3", "she", "se", "lls"); + // ==> "she sells sea shells" + // only supports nine replacements: %1 - %9 + var args = arguments; + return String(string).replace(/%([1-9])/g, function(match, index) { + return index < args.length ? args[index] : match; + }); +}; + +var $instanceOf = Legacy.instanceOf || new Function("o,k", "return o instanceof k"); +var instanceOf = function(object, klass) { + assertType(klass, "function", "Invalid 'instanceOf' operand."); + if ($instanceOf(object, klass)) return true; + // handle exceptions where the target object originates from another frame + // this is handy for JSON parsing (amongst other things) + if (object != null) switch (klass) { + case Object: + return true; + case Number: + case Boolean: + case Function: + case String: + return typeof object == typeof klass.prototype.valueOf(); + case Array: + // this is the only troublesome one + return !!(object.join && object.splice && !arguments.callee(object, Function)); + case Date: + return !!object.getTimezoneOffset; + case RegExp: + return String(object.constructor.prototype) == String(new RegExp); + } + return false; +}; + +var match = function(string, expression) { + // same as String.match() except that this function will return an empty + // array if there is no match + return String(string).match(expression) || []; +}; + +var RESCAPE = /([\/()[\]{}|*+-.,^$?\\])/g; +var rescape = function(string) { + // make a string safe for creating a RegExp + return String(string).replace(RESCAPE, "\\$1"); +}; + +var $slice = Array.prototype.slice; +var slice = function(object) { + // slice an array-like object + return $slice.apply(object, $slice.call(arguments, 1)); +}; + +var TRIM = /^\s+|\s+$/g; +var trim = function(string) { + return String(string).replace(TRIM, ""); +}; + +// ========================================================================= +// lang/extend.js +// ========================================================================= + +var base = function(object, args) { + // invoke the base method with all supplied arguments + return object.base.apply(object, args); +}; + +var extend = function(object) { + assert(object != Object.prototype, "Object.prototype is verboten!"); + return Base.prototype.extend.apply(object, slice(arguments, 1)); +}; + +// ========================================================================= +// lang/assignID.js +// ========================================================================= + +var $ID = 1; +var assignID = function(object) { + // assign a unique id + if (!object.base2ID) object.base2ID = "b2_" + $ID++; + return object.base2ID; +}; + +// ========================================================================= +// lang/forEach.js +// ========================================================================= + +if (typeof StopIteration == "undefined") { + StopIteration = new Error("StopIteration"); +} + +var forEach = function(object, block, context) { + if (object == null) return; + if (typeof object == "function") { + // functions are a special case + var fn = Function; + } else if (typeof object.forEach == "function" && object.forEach != arguments.callee) { + // the object implements a custom forEach method + object.forEach(block, context); + return; + } else if (typeof object.length == "number") { + // the object is array-like + forEach.Array(object, block, context); + return; + } + forEach.Function(fn || Object, object, block, context); +}; + +// these are the two core enumeration methods. all other forEach methods +// eventually call one of these two. + +forEach.Array = function(array, block, context) { + var i, length = array.length; // preserve + if (typeof array == "string") { + for (i = 0; i < length; i++) { + block.call(context, array.charAt(i), i, array); + } + } else { + for (i = 0; i < length; i++) { + block.call(context, array[i], i, array); + } + } +}; + +forEach.Function = Legacy.forEach || function(fn, object, block, context) { + // enumerate an object and compare its keys with fn's prototype + for (var key in object) { + if (fn.prototype[key] === undefined) { + block.call(context, object[key], key, object); + } + } +}; + +// ========================================================================= +// base2/Base/forEach.js +// ========================================================================= + +Base.forEach = function(object, block, context) { + forEach.Function(this, object, block, context); +}; + +// ========================================================================= +// base2/../Function.js +// ========================================================================= + +// some browsers don't define this + +Function.prototype.prototype = {}; + + +// ========================================================================= +// base2/../String.js +// ========================================================================= + +// fix String.replace (Safari/IE5.0) + +if ("".replace(/^/, String)) { + extend(String.prototype, "replace", function(expression, replacement) { + if (typeof replacement == "function") { // Safari doesn't like functions + if (instanceOf(expression, RegExp)) { + var regexp = expression; + var global = regexp.global; + if (global == null) global = /(g|gi)$/.test(regexp); + // we have to convert global RexpExps for exec() to work consistently + if (global) regexp = new RegExp(regexp.source); // non-global + } else { + regexp = new RegExp(rescape(expression)); + } + var match, string = this, result = ""; + while (string && (match = regexp.exec(string))) { + result += string.slice(0, match.index) + replacement.apply(this, match); + string = string.slice(match.index + match[0].length); + if (!global) break; + } + return result + string; + } else { + return base(this, arguments); + } + }); +} + +// ========================================================================= +// base2/Abstract.js +// ========================================================================= + +var Abstract = Base.extend({ + constructor: function() { + throw new TypeError("Class cannot be instantiated."); + } +}); + +// ========================================================================= +// base2/Module.js +// ========================================================================= + +// based on ruby's Module class and Mozilla's Array generics: +// http://www.ruby-doc.org/core/classes/Module.html +// http://developer.mozilla.org/en/docs/New_in_JavaScript_1.6#Array_and_String_generics + +// A Module is used as the basis for creating interfaces that can be +// applied to other classes. *All* properties and methods are static. +// When a module is used as a mixin, methods defined on what would normally be +// the instance interface become instance methods of the target object. + +// Modules cannot be instantiated. Static properties and methods are inherited. + +var Module = Abstract.extend(null, { + extend: function(_interface, _static) { + // extend a module to create a new module + var module = this.base(); + // inherit static methods + forEach (this, function(property, name) { + if (!Module[name] && name != "init") { + extend(module, name, property); + } + }); + // implement module (instance AND static) methods + module.implement(_interface); + // implement static properties and methods + extend(module, _static); + // Make the submarine noises Larry! + if (typeof module.init == "function") module.init(); + return module; + }, + + implement: function(_interface) { + // implement an interface on BOTH the instance and static interfaces + var module = this; + if (typeof _interface == "function") { + module.base(_interface); + forEach (_interface, function(property, name) { + if (!Module[name] && name != "init") { + extend(module, name, property); + } + }); + } else { + // create the instance interface + Base.forEach (extend({}, _interface), function(property, name) { + // instance methods call the equivalent static method + if (typeof property == "function") { + property = function() { + base; // force inheritance + return module[name].apply(module, [this].concat(slice(arguments))); + }; + } + if (!Module[name]) extend(this, name, property); + }, module.prototype); + // add the static interface + extend(module, _interface); + } + return module; + } +}); + + +// ========================================================================= +// base2/Enumerable.js +// ========================================================================= + +var Enumerable = Module.extend({ + every: function(object, test, context) { + var result = true; + try { + this.forEach (object, function(value, key) { + result = test.call(context, value, key, object); + if (!result) throw StopIteration; + }); + } catch (error) { + if (error != StopIteration) throw error; + } + return !!result; // cast to boolean + }, + + filter: function(object, test, context) { + return this.reduce(object, function(result, value, key) { + if (test.call(context, value, key, object)) { + result[result.length] = value; + } + return result; + }, new Array2); + }, + + invoke: function(object, method) { + // apply a method to each item in the enumerated object + var args = slice(arguments, 2); + return this.map(object, (typeof method == "function") ? function(item) { + if (item != null) return method.apply(item, args); + } : function(item) { + if (item != null) return item[method].apply(item, args); + }); + }, + + map: function(object, block, context) { + var result = new Array2; + this.forEach (object, function(value, key) { + result[result.length] = block.call(context, value, key, object); + }); + return result; + }, + + pluck: function(object, key) { + return this.map(object, function(item) { + if (item != null) return item[key]; + }); + }, + + reduce: function(object, block, result, context) { + this.forEach (object, function(value, key) { + result = block.call(context, result, value, key, object); + }); + return result; + }, + + some: function(object, test, context) { + return !this.every(object, function(value, key) { + return !test.call(context, value, key, object); + }); + } +}, { + forEach: forEach +}); + +// ========================================================================= +// base2/Array2.js +// ========================================================================= + +// The IArray module implements all Array methods. +// This module is not public but its methods are accessible through the Array2 object (below). + +var IArray = Module.extend({ + combine: function(keys, values) { + // combine two arrays to make a hash + if (!values) values = keys; + return this.reduce(keys, function(object, key, index) { + object[key] = values[index]; + return object; + }, {}); + }, + + copy: function(array) { + return this.concat(array); + }, + + contains: function(array, item) { + return this.indexOf(array, item) != -1; + }, + + forEach: forEach.Array, + + indexOf: function(array, item, fromIndex) { + var length = array.length; + if (fromIndex == null) { + fromIndex = 0; + } else if (fromIndex < 0) { + fromIndex = Math.max(0, length + fromIndex); + } + for (var i = fromIndex; i < length; i++) { + if (array[i] === item) return i; + } + return -1; + }, + + insertAt: function(array, item, index) { + this.splice(array, index, 0, item); + return item; + }, + + insertBefore: function(array, item, before) { + var index = this.indexOf(array, before); + if (index == -1) this.push(array, item); + else this.splice(array, index, 0, item); + return item; + }, + + lastIndexOf: function(array, item, fromIndex) { + var length = array.length; + if (fromIndex == null) { + fromIndex = length - 1; + } else if (from < 0) { + fromIndex = Math.max(0, length + fromIndex); + } + for (var i = fromIndex; i >= 0; i--) { + if (array[i] === item) return i; + } + return -1; + }, + + remove: function(array, item) { + var index = this.indexOf(array, item); + if (index != -1) this.removeAt(array, index); + return item; + }, + + removeAt: function(array, index) { + var item = array[index]; + this.splice(array, index, 1); + return item; + } +}); + +IArray.prototype.forEach = function(block, context) { + forEach.Array(this, block, context); +}; + +IArray.implement(Enumerable); + +forEach ("concat,join,pop,push,reverse,shift,slice,sort,splice,unshift".split(","), function(name) { + IArray[name] = function(array) { + return Array.prototype[name].apply(array, slice(arguments, 1)); + }; +}); + +// create a faux constructor that augments the built-in Array object +var Array2 = function() { + return IArray(this.constructor == IArray ? Array.apply(null, arguments) : arguments[0]); +}; +// expose IArray.prototype so that it can be extended +Array2.prototype = IArray.prototype; + +forEach (IArray, function(method, name, proto) { + if (Array[name]) { + IArray[name] = Array[name]; + delete IArray.prototype[name]; + } + Array2[name] = IArray[name]; +}); + +// ========================================================================= +// base2/Hash.js +// ========================================================================= + +var HASH = "#" + Number(new Date); +var KEYS = HASH + "keys"; +var VALUES = HASH + "values"; + +var Hash = Base.extend({ + constructor: function(values) { + this[KEYS] = new Array2; + this[VALUES] = {}; + this.merge(values); + }, + + copy: function() { + var copy = new this.constructor(this); + Base.forEach (this, function(property, name) { + if (typeof property != "function" && name.charAt(0) != "#") { + copy[name] = property; + } + }); + return copy; + }, + + // ancient browsers throw an error when we use "in" as an operator + // so we must create the function dynamically + exists: Legacy.exists || new Function("k", format("return('%1'+k)in this['%2']", HASH, VALUES)), + + fetch: function(key) { + return this[VALUES][HASH + key]; + }, + + forEach: function(block, context) { + forEach (this[KEYS], function(key) { + block.call(context, this.fetch(key), key, this); + }, this); + }, + + keys: function(index, length) { + var keys = this[KEYS] || new Array2; + switch (arguments.length) { + case 0: return keys.copy(); + case 1: return keys[index]; + default: return keys.slice(index, length); + } + }, + + merge: function(values) { + forEach (arguments, function(values) { + forEach (values, function(value, key) { + this.store(key, value); + }, this); + }, this); + return this; + }, + + remove: function(key) { + var value = this.fetch(key); + this[KEYS].remove(String(key)); + delete this[VALUES][HASH + key]; + return value; + }, + + store: function(key, value) { + if (arguments.length == 1) value = key; + // only store the key for a new entry + if (!this.exists(key)) { + this[KEYS].push(String(key)); + } + // create the new entry (or overwrite the old entry) + this[VALUES][HASH + key] = value; + return value; + }, + + toString: function() { + return String(this[KEYS]); + }, + + union: function(values) { + return this.merge.apply(this.copy(), arguments); + }, + + values: function(index, length) { + var values = this.map(K); + switch (arguments.length) { + case 0: return values; + case 1: return values[index]; + default: return values.slice(index, length); + } + } +}); + +Hash.implement(Enumerable); + +// ========================================================================= +// base2/Collection.js +// ========================================================================= + +// A Hash that is more array-like (accessible by index). + +// Collection classes have a special (optional) property: Item +// The Item property points to a constructor function. +// Members of the collection must be an instance of Item. +// e.g. +// var Dates = Collection.extend(); // create a collection class +// Dates.Item = Date; // only JavaScript Date objects allowed as members +// var appointments = new Dates(); // instantiate the class +// appointments.add(appointmentId, new Date); // add a date +// appointments.add(appointmentId, "tomorrow"); // ERROR! + +// The static create() method is responsible for all construction of collection items. +// Instance methods that add new items (add, store, insertAt, replaceAt) pass *all* of their arguments +// to the static create() method. If you want to modify the way collection items are +// created then you only need to override this method for custom collections. + +var Collection = Hash.extend({ + add: function(key, item) { + // Duplicates not allowed using add(). + // - but you can still overwrite entries using store() + assert(!this.exists(key), "Duplicate key."); + return this.store.apply(this, arguments); + }, + + count: function() { + return this[KEYS].length; + }, + + indexOf: function(key) { + return this[KEYS].indexOf(String(key)); + }, + + insertAt: function(index, key, item) { + assert(!this.exists(key), "Duplicate key."); + this[KEYS].insertAt(index, String(key)); + return this.store.apply(this, slice(arguments, 1)); + }, + + item: function(index) { + return this.fetch(this[KEYS][index]); + }, + + removeAt: function(index) { + return this.remove(this[KEYS][index]); + }, + + reverse: function() { + this[KEYS].reverse(); + return this; + }, + + sort: function(compare) { + if (compare) { + var self = this; + this[KEYS].sort(function(key1, key2) { + return compare(self.fetch(key1), self.fetch(key2), key1, key2); + }); + } else this[KEYS].sort(); + return this; + }, + + store: function(key, item) { + if (arguments.length == 1) item = key; + item = this.constructor.create.apply(this.constructor, arguments); + return this.base(key, item); + }, + + storeAt: function(index, item) { + //-dean: get rid of this? + assert(index < this.count(), "Index out of bounds."); + arguments[0] = this[KEYS][index]; + return this.store.apply(this, arguments); + } +}, { + Item: null, // if specified, all members of the Collection must be instances of Item + + create: function(key, item) { + if (this.Item && !instanceOf(item, this.Item)) { + item = new this.Item(key, item); + } + return item; + }, + + extend: function(_instance, _static) { + var klass = this.base(_instance); + klass.create = this.create; + extend(klass, _static); + if (!klass.Item) { + klass.Item = this.Item; + } else if (typeof klass.Item != "function") { + klass.Item = (this.Item || Base).extend(klass.Item); + } + if (typeof klass.init == "function") klass.init(); + return klass; + } +}); + +// ========================================================================= +// base2/RegGrp.js +// ========================================================================= + +var RegGrp = Collection.extend({ + constructor: function(values, flags) { + this.base(values); + if (typeof flags == "string") { + this.global = /g/.test(flags); + this.ignoreCase = /i/.test(flags); + } + }, + + global: true, // global is the default setting + ignoreCase: false, + + exec: function(string, replacement) { + if (arguments.length == 1) { + var keys = this[KEYS]; + var values = this[VALUES]; + replacement = function(match) { + if (!match) return ""; + var offset = 1, i = 0; + // loop through the values + while (match = values[HASH + keys[i++]]) { + // do we have a result? + if (arguments[offset]) { + var replacement = match.replacement; + switch (typeof replacement) { + case "function": + return replacement.apply(null, slice(arguments, offset)); + case "number": + return arguments[offset + replacement]; + default: + return replacement; + } + // no? then skip over references to sub-expressions + } else offset += match.length + 1; + } + }; + } + var flags = (this.global ? "g" : "") + (this.ignoreCase ? "i" : ""); + return String(string).replace(new RegExp(this, flags), replacement); + }, + + test: function(string) { + return this.exec(string) != string; + }, + + toString: function() { + var length = 0; + return "(" + this.map(function(item) { + // fix back references + var expression = String(item).replace(/\\(\d+)/g, function($, index) { + return "\\" + (1 + Number(index) + length); + }); + length += item.length + 1; + return expression; + }).join(")|(") + ")"; + } +}, { + IGNORE: "$0", + + init: function() { + forEach ("add,exists,fetch,remove,store".split(","), function(name) { + extend(this, name, function(expression) { + if (instanceOf(expression, RegExp)) { + expression = expression.source; + } + return base(this, arguments); + }); + }, this.prototype); + } +}); + +// ========================================================================= +// base2/RegGrp/Item.js +// ========================================================================= + +RegGrp.Item = Base.extend({ + constructor: function(expression, replacement) { + var ESCAPE = /\\./g; + var STRING = /(['"])\1\+(.*)\+\1\1$/; + + expression = instanceOf(expression, RegExp) ? expression.source : String(expression); + + if (typeof replacement == "number") replacement = String(replacement); + else if (replacement == null) replacement = ""; + + // count the number of sub-expressions + // - add one because each pattern is itself a sub-expression + this.length = match(expression.replace(ESCAPE, "").replace(/\[[^\]]+\]/g, ""), /\(/g).length; + + // does the pattern use sub-expressions? + if (typeof replacement == "string" && /\$(\d+)/.test(replacement)) { + // a simple lookup? (e.g. "$2") + if (/^\$\d+$/.test(replacement)) { + // store the index (used for fast retrieval of matched strings) + replacement = parseInt(replacement.slice(1)); + } else { // a complicated lookup (e.g. "Hello $2 $1") + // build a function to do the lookup + var i = this.length + 1; + var Q = /'/.test(replacement.replace(ESCAPE, "")) ? '"' : "'"; + replacement = replacement.replace(/\n/g, "\\n").replace(/\r/g, "\\r").replace(/\$(\d+)/g, Q + + "+(arguments[$1]||" + Q+Q + ")+" + Q); + replacement = new Function("return " + Q + replacement.replace(STRING, "$1") + Q); + } + } + this.replacement = replacement; + this.toString = function() { + return expression || ""; + }; + }, + + length: 0, + replacement: "" +}); + +// ========================================================================= +// base2/Namespace.js +// ========================================================================= + +var Namespace = Base.extend({ + constructor: function(_private, _public) { + this.extend(_public); + this.toString = function() { + return format("[base2.%1]", this.name); + }; + + // initialise + if (typeof this.init == "function") this.init(); + + if (this.name != "base2") { + this.namespace = format("var %1=base2.%1;", this.name); + } + + var namespace = "var base=" + base + ";"; + var imports = ("base2,lang," + this.imports).split(","); + _private.imports = Enumerable.reduce(imports, function(namespace, name) { + if (base2[name]) namespace += base2[name].namespace; + return namespace; + }, namespace); + + var namespace = format("base2.%1=%1;", this.name); + var exports = this.exports.split(","); + _private.exports = Enumerable.reduce(exports, function(namespace, name) { + if (name) { + this.namespace += format("var %2=%1.%2;", this.name, name); + namespace += format("if(!%1.%2)%1.%2=%2;base2.%2=%1.%2;", this.name, name); + } + return namespace; + }, namespace, this); + + if (this.name != "base2") { + base2.namespace += format("var %1=base2.%1;", this.name); + } + }, + + exports: "", + imports: "", + namespace: "", + name: "" +}); + +base2 = new Namespace(this, { + name: "base2", + version: "0.8 (alpha)", + exports: "Base,Abstract,Module,Enumerable,Array2,Hash,Collection,RegGrp,Namespace" +}); + +base2.toString = function() { + return "[base2]"; +}; + +eval(this.exports); + +// ========================================================================= +// base2/lang/namespace.js +// ========================================================================= + +var lang = new Namespace(this, { + name: "lang", + version: base2.version, + exports: "K,assert,assertType,assignID,copy,instanceOf,extend,format,forEach,match,rescape,slice,trim", + + init: function() { + this.extend = extend; + // add the Enumerable methods to the lang object + forEach (Enumerable.prototype, function(method, name) { + if (!Module[name]) { + this[name] = function() { + return Enumerable[name].apply(Enumerable, arguments); + }; + this.exports += "," + name; + } + }, this); + } +}); + +eval(this.exports); + +base2.namespace += lang.namespace; + +}; //////////////////// END: CLOSURE ///////////////////////////////////// diff --git a/build/js/jsmin.js b/build/js/jsmin.js new file mode 100644 index 00000000..3e1ff070 --- /dev/null +++ b/build/js/jsmin.js @@ -0,0 +1,316 @@ +/* jsmin.js - 2006-08-31 +Author: Franck Marcia +This work is an adaptation of jsminc.c published by Douglas Crockford. +Permission is hereby granted to use the Javascript version under the same +conditions as the jsmin.c on which it is based. + +jsmin.c +2006-05-04 + +Copyright (c) 2002 Douglas Crockford (www.crockford.com) + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +The Software shall be used for Good, not Evil. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +Update: + add level: + 1: minimal, keep linefeeds if single + 2: normal, the standard algorithm + 3: agressive, remove any linefeed and doesn't take care of potential + missing semicolons (can be regressive) + store stats + jsmin.oldSize + jsmin.newSize +*/ + +String.prototype.has = function(c) { + return this.indexOf(c) > -1; +}; + +function jsmin(comment, input, level) { + + if (input === undefined) { + input = comment; + comment = ''; + level = 2; + } else if (level === undefined || level < 1 || level > 3) { + level = 2; + } + + if (comment.length > 0) { + comment += '\n'; + } + + var a = '', + b = '', + EOF = -1, + LETTERS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz', + DIGITS = '0123456789', + ALNUM = LETTERS + DIGITS + '_$\\', + theLookahead = EOF; + + + /* isAlphanum -- return true if the character is a letter, digit, underscore, + dollar sign, or non-ASCII character. + */ + + function isAlphanum(c) { + return c != EOF && (ALNUM.has(c) || c.charCodeAt(0) > 126); + } + + + /* get -- return the next character. Watch out for lookahead. If the + character is a control character, translate it to a space or + linefeed. + */ + + function get() { + + var c = theLookahead; + if (get.i == get.l) { + return EOF; + } + theLookahead = EOF; + if (c == EOF) { + c = input.charAt(get.i); + ++get.i; + } + if (c >= ' ' || c == '\n') { + return c; + } + if (c == '\r') { + return '\n'; + } + return ' '; + } + + get.i = 0; + get.l = input.length; + + + /* peek -- get the next character without getting it. + */ + + function peek() { + theLookahead = get(); + return theLookahead; + } + + + /* next -- get the next character, excluding comments. peek() is used to see + if a '/' is followed by a '/' or '*'. + */ + + function next() { + + var c = get(); + if (c == '/') { + switch (peek()) { + case '/': + for (;;) { + c = get(); + if (c <= '\n') { + return c; + } + } + break; + case '*': + get(); + for (;;) { + switch (get()) { + case '*': + if (peek() == '/') { + get(); + return ' '; + } + break; + case EOF: + throw 'Error: Unterminated comment.'; + } + } + break; + default: + return c; + } + } + return c; + } + + + /* action -- do something! What you do is determined by the argument: + 1 Output A. Copy B to A. Get the next B. + 2 Copy B to A. Get the next B. (Delete A). + 3 Get the next B. (Delete B). + action treats a string as a single character. Wow! + action recognizes a regular expression if it is preceded by ( or , or =. + */ + + function action(d) { + + var r = []; + + if (d == 1) { + r.push(a); + } + + if (d < 3) { + a = b; + if (a == '\'' || a == '"') { + for (;;) { + r.push(a); + a = get(); + if (a == b) { + break; + } + if (a <= '\n') { + throw 'Error: unterminated string literal: ' + a; + } + if (a == '\\') { + r.push(a); + a = get(); + } + } + } + } + + b = next(); + + if (b == '/' && '(,=:[!&|'.has(a)) { + r.push(a); + r.push(b); + for (;;) { + a = get(); + if (a == '/') { + break; + } else if (a =='\\') { + r.push(a); + a = get(); + } else if (a <= '\n') { + throw 'Error: unterminated Regular Expression literal'; + } + r.push(a); + } + b = next(); + } + + return r.join(''); + } + + + /* m -- Copy the input to the output, deleting the characters which are + insignificant to JavaScript. Comments will be removed. Tabs will be + replaced with spaces. Carriage returns will be replaced with + linefeeds. + Most spaces and linefeeds will be removed. + */ + + function m() { + + var r = []; + a = '\n'; + + r.push(action(3)); + + while (a != EOF) { + switch (a) { + case ' ': + if (isAlphanum(b)) { + r.push(action(1)); + } else { + r.push(action(2)); + } + break; + case '\n': + switch (b) { + case '{': + case '[': + case '(': + case '+': + case '-': + r.push(action(1)); + break; + case ' ': + r.push(action(3)); + break; + default: + if (isAlphanum(b)) { + r.push(action(1)); + } else { + if (level == 1 && b != '\n') { + r.push(action(1)); + } else { + r.push(action(2)); + } + } + } + break; + default: + switch (b) { + case ' ': + if (isAlphanum(a)) { + r.push(action(1)); + break; + } + r.push(action(3)); + break; + case '\n': + if (level == 1 && a != '\n') { + r.push(action(1)); + } else { + switch (a) { + case '}': + case ']': + case ')': + case '+': + case '-': + case '"': + case '\'': + if (level == 3) { + r.push(action(3)); + } else { + r.push(action(1)); + } + break; + default: + if (isAlphanum(a)) { + r.push(action(1)); + } else { + r.push(action(3)); + } + } + } + break; + default: + r.push(action(1)); + break; + } + } + } + + return r.join(''); + } + + jsmin.oldSize = input.length; + var r = m(input); + jsmin.newSize = r.length; + + return comment + r; + +} diff --git a/build/js/json.js b/build/js/json.js new file mode 100644 index 00000000..d59ca0c9 --- /dev/null +++ b/build/js/json.js @@ -0,0 +1,117 @@ +/* + json.js + 2006-04-28 + + This file adds these methods to JavaScript: + + object.toJSONString() + + This method produces a JSON text from an object. The + object must not contain any cyclical references. + + array.toJSONString() + + This method produces a JSON text from an array. The + array must not contain any cyclical references. + + string.parseJSON() + + This method parses a JSON text to produce an object or + array. It will return false if there is an error. +*/ +(function () { + var m = { + '\b': '\\b', + '\t': '\\t', + '\n': '\\n', + '\f': '\\f', + '\r': '\\r', + '"' : '\\"', + '\\': '\\\\' + }, + s = { + array: function (x) { + var a = ['['], b, f, i, l = x.length, v; + for (i = 0; i < l; i += 1) { + v = x[i]; + f = s[typeof v]; + if (f) { + v = f(v); + if (typeof v == 'string') { + if (b) { + a[a.length] = ','; + } + a[a.length] = v; + b = true; + } + } + } + a[a.length] = ']'; + return a.join(''); + }, + 'boolean': function (x) { + return String(x); + }, + 'null': function (x) { + return "null"; + }, + number: function (x) { + return isFinite(x) ? String(x) : 'null'; + }, + object: function (x) { + if (x) { + if (x instanceof Array) { + return s.array(x); + } + var a = ['{'], b, f, i, v; + for (i in x) { + v = x[i]; + f = s[typeof v]; + if (f) { + v = f(v); + if (typeof v == 'string') { + if (b) { + a[a.length] = ','; + } + a.push(s.string(i), ':', v); + b = true; + } + } + } + a[a.length] = '}'; + return a.join(''); + } + return 'null'; + }, + string: function (x) { + if (/["\\\x00-\x1f]/.test(x)) { + x = x.replace(/([\x00-\x1f\\"])/g, function(a, b) { + var c = m[b]; + if (c) { + return c; + } + c = b.charCodeAt(); + return '\\u00' + + Math.floor(c / 16).toString(16) + + (c % 16).toString(16); + }); + } + return '"' + x + '"'; + } + }; + + Object.toJSON = function(obj) { + return s.object(obj); + }; +})(); + +String.prototype.parseJSON = function () { + try { + return !(/[^,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]/.test( + this.replace(/"(\\.|[^"\\])*"/g, ''))) && + eval('(' + this + ')'); + } catch (e) { + return false; + } +}; + diff --git a/build/js/pack.js b/build/js/pack.js new file mode 100644 index 00000000..56bfdd1a --- /dev/null +++ b/build/js/pack.js @@ -0,0 +1,316 @@ +/* + packer, version 2.0.2 (2005-08-19) + Copyright 2004-2005, Dean Edwards + License: http://creativecommons.org/licenses/LGPL/2.1/ +*/ + +function pack(_script, _encoding, _fastDecode, _specialChars) { + // constants + var $IGNORE = "$1"; + + // validate parameters + _script += "\n"; + _encoding = Math.min(parseInt(_encoding), 95); + + // apply all parsing routines + function _pack($script) { + var i, $parse; + for (i = 0; ($parse = _parsers[i]); i++) { + $script = $parse($script); + } + return $script; + }; + + // unpacking function - this is the boot strap function + // data extracted from this packing routine is passed to + // this function when decoded in the target + var _unpack = function($packed, $ascii, $count, $keywords, $encode, $decode) { + while ($count--) + if ($keywords[$count]) + $packed = $packed.replace(new RegExp('\\b' + $encode($count) + '\\b', 'g'), $keywords[$count]); + return $packed; + }; + + // code-snippet inserted into the unpacker to speed up decoding + var _decode = function() { + // does the browser support String.replace where the + // replacement value is a function? + if (!''.replace(/^/, String)) { + // decode all the values we need + while ($count--) $decode[$encode($count)] = $keywords[$count] || $encode($count); + // global replacement function + $keywords = [function($encoded){return $decode[$encoded]}]; + // generic match + $encode = function(){return'\\w+'}; + // reset the loop counter - we are now doing a global replace + $count = 1; + } + }; + + // keep a list of parsing functions, they'll be executed all at once + var _parsers = []; + function _addParser($parser) { + _parsers[_parsers.length] = $parser; + }; + + // zero encoding - just removal of white space and comments + function _basicCompression($script) { + var $parser = new ParseMaster; + // make safe + $parser.escapeChar = "\\"; + // protect strings + $parser.add(/'[^'\n\r]*'/, $IGNORE); + $parser.add(/"[^"\n\r]*"/, $IGNORE); + // remove comments + $parser.add(/\/\/[^\n\r]*[\n\r]/, " "); + $parser.add(/\/\*[^*]*\*+([^\/][^*]*\*+)*\//, " "); + // protect regular expressions + $parser.add(/\s+(\/[^\/\n\r\*][^\/\n\r]*\/g?i?)/, "$2"); // IGNORE + $parser.add(/[^\w\x24\/'"*)\?:]\/[^\/\n\r\*][^\/\n\r]*\/g?i?/, $IGNORE); + // remove: ;;; doSomething(); + if (_specialChars) $parser.add(/;;;[^\n\r]+[\n\r]/); + // remove redundant semi-colons + $parser.add(/\(;;\)/, $IGNORE); // protect for (;;) loops + $parser.add(/;+\s*([};])/, "$2"); + // apply the above + $script = $parser.exec($script); + + // remove white-space + $parser.add(/(\b|\x24)\s+(\b|\x24)/, "$2 $3"); + $parser.add(/([+\-])\s+([+\-])/, "$2 $3"); + $parser.add(/\s+/, ""); + // done + return $parser.exec($script); + }; + + function _encodeSpecialChars($script) { + var $parser = new ParseMaster; + // replace: $name -> n, $$name -> na + $parser.add(/((\x24+)([a-zA-Z$_]+))(\d*)/, function($match, $offset) { + var $length = $match[$offset + 2].length; + var $start = $length - Math.max($length - $match[$offset + 3].length, 0); + return $match[$offset + 1].substr($start, $length) + $match[$offset + 4]; + }); + // replace: _name -> _0, double-underscore (__name) is ignored + var $regexp = /\b_[A-Za-z\d]\w*/; + // build the word list + var $keywords = _analyze($script, _globalize($regexp), _encodePrivate); + // quick ref + var $encoded = $keywords.$encoded; + $parser.add($regexp, function($match, $offset) { + return $encoded[$match[$offset]]; + }); + return $parser.exec($script); + }; + + function _encodeKeywords($script) { + // escape high-ascii values already in the script (i.e. in strings) + if (_encoding > 62) $script = _escape95($script); + // create the parser + var $parser = new ParseMaster; + var $encode = _getEncoder(_encoding); + // for high-ascii, don't encode single character low-ascii + var $regexp = (_encoding > 62) ? /\w\w+/ : /\w+/; + // build the word list + $keywords = _analyze($script, _globalize($regexp), $encode); + var $encoded = $keywords.$encoded; + // encode + $parser.add($regexp, function($match, $offset) { + return $encoded[$match[$offset]]; + }); + // if encoded, wrap the script in a decoding function + return $script && _bootStrap($parser.exec($script), $keywords); + }; + + function _analyze($script, $regexp, $encode) { + // analyse + // retreive all words in the script + var $all = $script.match($regexp); + var $$sorted = []; // list of words sorted by frequency + var $$encoded = {}; // dictionary of word->encoding + var $$protected = {}; // instances of "protected" words + if ($all) { + var $unsorted = []; // same list, not sorted + var $protected = {}; // "protected" words (dictionary of word->"word") + var $values = {}; // dictionary of charCode->encoding (eg. 256->ff) + var $count = {}; // word->count + var i = $all.length, j = 0, $word; + // count the occurrences - used for sorting later + do { + $word = "$" + $all[--i]; + if (!$count[$word]) { + $count[$word] = 0; + $unsorted[j] = $word; + // make a dictionary of all of the protected words in this script + // these are words that might be mistaken for encoding + $protected["$" + ($values[j] = $encode(j))] = j++; + } + // increment the word counter + $count[$word]++; + } while (i); + // prepare to sort the word list, first we must protect + // words that are also used as codes. we assign them a code + // equivalent to the word itself. + // e.g. if "do" falls within our encoding range + // then we store keywords["do"] = "do"; + // this avoids problems when decoding + i = $unsorted.length; + do { + $word = $unsorted[--i]; + if ($protected[$word] != null) { + $$sorted[$protected[$word]] = $word.slice(1); + $$protected[$protected[$word]] = true; + $count[$word] = 0; + } + } while (i); + // sort the words by frequency + $unsorted.sort(function($match1, $match2) { + return $count[$match2] - $count[$match1]; + }); + j = 0; + // because there are "protected" words in the list + // we must add the sorted words around them + do { + if ($$sorted[i] == null) $$sorted[i] = $unsorted[j++].slice(1); + $$encoded[$$sorted[i]] = $values[i]; + } while (++i < $unsorted.length); + } + return {$sorted: $$sorted, $encoded: $$encoded, $protected: $$protected}; + }; + + // build the boot function used for loading and decoding + function _bootStrap($packed, $keywords) { + var $ENCODE = _safeRegExp("$encode\\($count\\)", "g"); + + // $packed: the packed script + $packed = "'" + _escape($packed) + "'"; + + // $ascii: base for encoding + var $ascii = Math.min($keywords.$sorted.length, _encoding) || 1; + + // $count: number of words contained in the script + var $count = $keywords.$sorted.length; + + // $keywords: list of words contained in the script + for (var i in $keywords.$protected) $keywords.$sorted[i] = ""; + // convert from a string to an array + $keywords = "'" + $keywords.$sorted.join("|") + "'.split('|')"; + + // $encode: encoding function (used for decoding the script) + var $encode = _encoding > 62 ? _encode95 : _getEncoder($ascii); + $encode = String($encode).replace(/_encoding/g, "$ascii").replace(/arguments\.callee/g, "$encode"); + var $inline = "$count" + ($ascii > 10 ? ".toString($ascii)" : ""); + + // $decode: code snippet to speed up decoding + if (_fastDecode) { + // create the decoder + var $decode = _getFunctionBody(_decode); + if (_encoding > 62) $decode = $decode.replace(/\\\\w/g, "[\\xa1-\\xff]"); + // perform the encoding inline for lower ascii values + else if ($ascii < 36) $decode = $decode.replace($ENCODE, $inline); + // special case: when $count==0 there are no keywords. I want to keep + // the basic shape of the unpacking funcion so i'll frig the code... + if (!$count) $decode = $decode.replace(_safeRegExp("($count)\\s*=\\s*1"), "$1=0"); + } + + // boot function + var $unpack = String(_unpack); + if (_fastDecode) { + // insert the decoder + $unpack = $unpack.replace(/\{/, "{" + $decode + ";"); + } + $unpack = $unpack.replace(/"/g, "'"); + if (_encoding > 62) { // high-ascii + // get rid of the word-boundaries for regexp matches + $unpack = $unpack.replace(/'\\\\b'\s*\+|\+\s*'\\\\b'/g, ""); + } + if ($ascii > 36 || _encoding > 62 || _fastDecode) { + // insert the encode function + $unpack = $unpack.replace(/\{/, "{$encode=" + $encode + ";"); + } else { + // perform the encoding inline + $unpack = $unpack.replace($ENCODE, $inline); + } + // pack the boot function too + $unpack = pack($unpack, 0, false, true); + + // arguments + var $params = [$packed, $ascii, $count, $keywords]; + if (_fastDecode) { + // insert placeholders for the decoder + $params = $params.concat(0, "{}"); + } + + // the whole thing + return "eval(" + $unpack + "(" + $params + "))\n"; + }; + + // mmm.. ..which one do i need ?? + function _getEncoder($ascii) { + return $ascii > 10 ? $ascii > 36 ? $ascii > 62 ? _encode95 : _encode62 : _encode36 : _encode10; + }; + + // zero encoding + // characters: 0123456789 + var _encode10 = function($charCode) { + return $charCode; + }; + + // inherent base36 support + // characters: 0123456789abcdefghijklmnopqrstuvwxyz + var _encode36 = function($charCode) { + return $charCode.toString(36); + }; + + // hitch a ride on base36 and add the upper case alpha characters + // characters: 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ + var _encode62 = function($charCode) { + return ($charCode < _encoding ? '' : arguments.callee(parseInt($charCode / _encoding))) + + (($charCode = $charCode % _encoding) > 35 ? String.fromCharCode($charCode + 29) : $charCode.toString(36)); + }; + + // use high-ascii values + var _encode95 = function($charCode) { + return ($charCode < _encoding ? '' : arguments.callee($charCode / _encoding)) + + String.fromCharCode($charCode % _encoding + 161); + }; + + // special _chars + var _encodePrivate = function($charCode) { + return "_" + $charCode; + }; + + // protect characters used by the parser + function _escape($script) { + return $script.replace(/([\\'])/g, "\\$1"); + }; + + // protect high-ascii characters already in the script + function _escape95($script) { + return $script.replace(/[\xa1-\xff]/g, function($match) { + return "\\x" + $match.charCodeAt(0).toString(16); + }); + }; + + function _safeRegExp($string, $flags) { + return new RegExp($string.replace(/\$/g, "\\$"), $flags); + }; + + // extract the body of a function + function _getFunctionBody($function) { + with (String($function)) return slice(indexOf("{") + 1, lastIndexOf("}")); + }; + + // set the global flag on a RegExp (you have to create a new one) + function _globalize($regexp) { + return new RegExp(String($regexp).slice(1, -1), "g"); + }; + + // build the parsing routine + _addParser(_basicCompression); + if (_specialChars) _addParser(_encodeSpecialChars); + if (_encoding) _addParser(_encodeKeywords); + + // go! + return _pack(_script); +}; diff --git a/build/js/parse.js b/build/js/parse.js new file mode 100644 index 00000000..211fe6ce --- /dev/null +++ b/build/js/parse.js @@ -0,0 +1,105 @@ +function parse( f ) { + var c = [], bm, m; + var blockMatch = /\/\*\*\s*((.|\n)*?)\s*\*\//g; + var paramMatch = /\@(\S+) *((.|\n)*?)(?=\n\@|!!!)/m; + + while ( bm = blockMatch.exec(f) ) { + block = bm[1].replace(/^\s*\* ?/mg,"") + "!!!"; + var ret = { params: [], examples: [], tests: [], options: [] }; + + while ( m = paramMatch.exec( block ) ) { + block = block.replace( paramMatch, "" ); + + var n = m[1]; + var v = m[2] + .replace(/\s*$/g,"") + .replace(/^\s*/g,"") + .replace(/&/g, "&") + .replace(//g, ">") + //.replace(/\n/g, "
") + /*.replace(/(\s\s+)/g, function(a){ + var ret = ""; + for ( var i = 0; i < a.length; i++ ) + ret += " "; + return ret; + })*/ || 1; + + if ( n == 'param' || n == 'option' ) { + var args = v.split(/\s+/); + v = args.slice( 2, args.length ); + v = { type: args[0], name: args[1], desc: v.join(' ') }; + n = n + "s"; + } else if ( n == 'example' ) { + v = { code: v }; + n = "examples"; + } else if ( n == 'test' ) { + n = "tests"; + } + + if ( n == 'desc' || n == 'before' || n == 'after' || n == 'result' ) { + ret.examples[ ret.examples.length - 1 ][ n ] = v; + } else { + if ( ret[ n ] ) { + if ( ret[ n ].constructor == Array ) { + ret[ n ].push( v ); + } else { + ret[ n ] = [ ret[ n ], v ]; + } + } else { + ret[ n ] = v; + } + } + } + + ret.desc = block.replace(/\s*!!!$/,"") + .replace(//g, ">"); + //.replace(/\n\n/g, "

") + //.replace(/\n/g, " "); + + var m = /^((.|\n)*?(\.|$))/.exec( ret.desc ); + if ( m ) ret['short'] = m[1]; + + if ( ret.name ) c.push( ret ); + } + + return c; +} + +function categorize( json ) { + var obj = { cat: [], method: [] }; + + for ( var i = 0; i < json.length; i++ ) { + if ( !json[i].cat ) json[i].cat = ""; + + var cat = json[i].cat.split("/"); + + var pos = obj; + for ( var j = 0; j < cat.length; j++ ) { + var c = cat[j]; + var curCat = null; + + // Locate current category + for ( var n = 0; n < pos.cat.length; n++ ) + if ( pos.cat[n].value == c ) + curCat = pos.cat[n]; + + // Create current category + if ( !curCat ) { + curCat = { value: c, cat: [], method: [] }; + pos.cat.push( curCat ) + } + + // If we're at the end, add the method + if ( j == cat.length - 1 ) + curCat.method.push( json[i] ); + + // Otherwise, traverse deeper + else + pos = curCat; + } + } + + return obj; +} diff --git a/build/js/writeFile.js b/build/js/writeFile.js new file mode 100644 index 00000000..43b1eb24 --- /dev/null +++ b/build/js/writeFile.js @@ -0,0 +1,19 @@ +importPackage(java.io); + +function writeFile( file, stream ) { + var buffer = new PrintWriter( new FileWriter( file ) ); + buffer.print( stream ); + buffer.close(); +} + +function read( file ) { + var jq = new File(file); + var reader = new BufferedReader(new FileReader(jq)); + var line = null; + var buffer = new java.lang.StringBuffer(jq.length()); + while( (line = reader.readLine()) != null) { + buffer.append(line); + buffer.append("\n"); + } + return buffer.toString(); +} \ No newline at end of file diff --git a/build/js/xml.js b/build/js/xml.js new file mode 100644 index 00000000..1d50558e --- /dev/null +++ b/build/js/xml.js @@ -0,0 +1,25 @@ +Object.toXML = function( obj, tag ) { + if ( obj.constructor == Array ) { + var ret = ""; + for ( var i = 0; i < obj.length; i++ ) + ret += Object.toXML( obj[i], tag ); + return ret; + } else if ( obj.constructor == Object ) { + var tag = tag || "tmp"; + var p = "", child = ""; + + for ( var i in obj ) + if ( ( obj[i].constructor != String && obj[i].constructor != Number ) || /\n" + child + "\n" : "/>\n" ); + } else if ( obj.constructor == String || obj.constructor == Number ) { + return "<" + tag + ">" + obj + "\n"; + } + + return ""; +}; + +Object.toXML.force = {}; diff --git a/build/jslint-check.js b/build/jslint-check.js deleted file mode 100644 index 72d67018..00000000 --- a/build/jslint-check.js +++ /dev/null @@ -1,36 +0,0 @@ -var JSLINT = require("./lib/jslint").JSLINT, - print = require("sys").print, - src = require("fs").readFileSync("dist/jquery.js", "utf8"); - -JSLINT(src, { evil: true, forin: true, maxerr: 100 }); - -// All of the following are known issues that we think are 'ok' -// (in contradiction with JSLint) more information here: -// http://docs.jquery.com/JQuery_Core_Style_Guidelines -var ok = { - "Expected an identifier and instead saw 'undefined' (a reserved word).": true, - "Use '===' to compare with 'null'.": true, - "Use '!==' to compare with 'null'.": true, - "Expected an assignment or function call and instead saw an expression.": true, - "Expected a 'break' statement before 'case'.": true, - "'e' is already defined.": true -}; - -var e = JSLINT.errors, found = 0, w; - -for ( var i = 0; i < e.length; i++ ) { - w = e[i]; - - if ( !ok[ w.reason ] ) { - found++; - print( "\n" + w.evidence + "\n" ); - print( " Problem at line " + w.line + " character " + w.character + ": " + w.reason ); - } -} - -if ( found > 0 ) { - print( "\n" + found + " Error(s) found.\n" ); - -} else { - print( "JSLint check passed.\n" ); -} diff --git a/build/lib/jslint.js b/build/lib/jslint.js deleted file mode 100644 index f563292b..00000000 --- a/build/lib/jslint.js +++ /dev/null @@ -1,5504 +0,0 @@ -// jslint.js -// 2010-02-20 - -/* -Copyright (c) 2002 Douglas Crockford (www.JSLint.com) - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -of the Software, and to permit persons to whom the Software is furnished to do -so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -The Software shall be used for Good, not Evil. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ - -/* - JSLINT is a global function. It takes two parameters. - - var myResult = JSLINT(source, option); - - The first parameter is either a string or an array of strings. If it is a - string, it will be split on '\n' or '\r'. If it is an array of strings, it - is assumed that each string represents one line. The source can be a - JavaScript text, or HTML text, or a Konfabulator text. - - The second parameter is an optional object of options which control the - operation of JSLINT. Most of the options are booleans: They are all are - optional and have a default value of false. - - If it checks out, JSLINT returns true. Otherwise, it returns false. - - If false, you can inspect JSLINT.errors to find out the problems. - JSLINT.errors is an array of objects containing these members: - - { - line : The line (relative to 0) at which the lint was found - character : The character (relative to 0) at which the lint was found - reason : The problem - evidence : The text line in which the problem occurred - raw : The raw message before the details were inserted - a : The first detail - b : The second detail - c : The third detail - d : The fourth detail - } - - If a fatal error was found, a null will be the last element of the - JSLINT.errors array. - - You can request a Function Report, which shows all of the functions - and the parameters and vars that they use. This can be used to find - implied global variables and other problems. The report is in HTML and - can be inserted in an HTML . - - var myReport = JSLINT.report(limited); - - If limited is true, then the report will be limited to only errors. - - You can request a data structure which contains JSLint's results. - - var myData = JSLINT.data(); - - It returns a structure with this form: - - { - errors: [ - { - line: NUMBER, - character: NUMBER, - reason: STRING, - evidence: STRING - } - ], - functions: [ - name: STRING, - line: NUMBER, - last: NUMBER, - param: [ - STRING - ], - closure: [ - STRING - ], - var: [ - STRING - ], - exception: [ - STRING - ], - outer: [ - STRING - ], - unused: [ - STRING - ], - global: [ - STRING - ], - label: [ - STRING - ] - ], - globals: [ - STRING - ], - member: { - STRING: NUMBER - }, - unuseds: [ - { - name: STRING, - line: NUMBER - } - ], - implieds: [ - { - name: STRING, - line: NUMBER - } - ], - urls: [ - STRING - ], - json: BOOLEAN - } - - Empty arrays will not be included. - -*/ - -/*jslint - evil: true, nomen: false, onevar: false, regexp: false, strict: true -*/ - -/*members "\b", "\t", "\n", "\f", "\r", "!=", "!==", "\"", "%", - "(begin)", "(breakage)", "(context)", "(error)", "(global)", - "(identifier)", "(last)", "(line)", "(loopage)", "(name)", "(onevar)", - "(params)", "(scope)", "(verb)", "*", "+", "++", "-", "--", "\/", - "<", "<=", "==", "===", ">", ">=", ADSAFE, Array, Boolean, - COM, Canvas, CustomAnimation, Date, Debug, E, Error, EvalError, - FadeAnimation, Flash, FormField, Frame, Function, HotKey, Image, JSON, - LN10, LN2, LOG10E, LOG2E, MAX_VALUE, MIN_VALUE, Math, MenuItem, - MoveAnimation, NEGATIVE_INFINITY, Number, Object, Option, PI, - POSITIVE_INFINITY, Point, RangeError, Rectangle, ReferenceError, RegExp, - ResizeAnimation, RotateAnimation, SQRT1_2, SQRT2, ScrollBar, String, - Style, SyntaxError, System, Text, TextArea, Timer, TypeError, URIError, - URL, Web, Window, XMLDOM, XMLHttpRequest, "\\", a, abbr, acronym, - addEventListener, address, adsafe, alert, aliceblue, animator, - antiquewhite, appleScript, applet, apply, approved, aqua, aquamarine, - area, arguments, arity, autocomplete, azure, b, background, - "background-attachment", "background-color", "background-image", - "background-position", "background-repeat", base, bdo, beep, beige, big, - bisque, bitwise, black, blanchedalmond, block, blockquote, blue, - blueviolet, blur, body, border, "border-bottom", "border-bottom-color", - "border-bottom-style", "border-bottom-width", "border-collapse", - "border-color", "border-left", "border-left-color", "border-left-style", - "border-left-width", "border-right", "border-right-color", - "border-right-style", "border-right-width", "border-spacing", - "border-style", "border-top", "border-top-color", "border-top-style", - "border-top-width", "border-width", bottom, br, brown, browser, - burlywood, button, bytesToUIString, c, cadetblue, call, callee, caller, - canvas, cap, caption, "caption-side", cases, center, charAt, charCodeAt, - character, chartreuse, chocolate, chooseColor, chooseFile, chooseFolder, - cite, clear, clearInterval, clearTimeout, clip, close, closeWidget, - closed, closure, cm, code, col, colgroup, color, comment, condition, - confirm, console, constructor, content, convertPathToHFS, - convertPathToPlatform, coral, cornflowerblue, cornsilk, - "counter-increment", "counter-reset", create, crimson, css, cursor, - cyan, d, darkblue, darkcyan, darkgoldenrod, darkgray, darkgreen, - darkkhaki, darkmagenta, darkolivegreen, darkorange, darkorchid, darkred, - darksalmon, darkseagreen, darkslateblue, darkslategray, darkturquoise, - darkviolet, data, dd, debug, decodeURI, decodeURIComponent, deeppink, - deepskyblue, defaultStatus, defineClass, del, deserialize, devel, dfn, - dimension, dimgray, dir, direction, display, div, dl, document, - dodgerblue, dt, edition, else, em, embed, empty, "empty-cells", - encodeURI, encodeURIComponent, entityify, eqeqeq, errors, escape, eval, - event, evidence, evil, ex, exception, exec, exps, fieldset, filesystem, - firebrick, first, float, floor, floralwhite, focus, focusWidget, font, - "font-face", "font-family", "font-size", "font-size-adjust", - "font-stretch", "font-style", "font-variant", "font-weight", - forestgreen, forin, form, fragment, frame, frames, frameset, from, - fromCharCode, fuchsia, fud, funct, function, functions, g, gainsboro, - gc, getComputedStyle, ghostwhite, global, globals, gold, goldenrod, - gray, green, greenyellow, h1, h2, h3, h4, h5, h6, hasOwnProperty, head, - height, help, history, honeydew, hotpink, hr, html, i, iTunes, id, - identifier, iframe, img, immed, implieds, in, include, indent, indexOf, - indianred, indigo, init, input, ins, isAlpha, isApplicationRunning, - isDigit, isFinite, isNaN, ivory, join, jslint, json, kbd, khaki, - konfabulatorVersion, label, labelled, lang, last, lavender, - lavenderblush, lawngreen, laxbreak, lbp, led, left, legend, - lemonchiffon, length, "letter-spacing", li, lib, lightblue, lightcoral, - lightcyan, lightgoldenrodyellow, lightgreen, lightpink, lightsalmon, - lightseagreen, lightskyblue, lightslategray, lightsteelblue, - lightyellow, lime, limegreen, line, "line-height", linen, link, - "list-style", "list-style-image", "list-style-position", - "list-style-type", load, loadClass, location, log, m, magenta, map, - margin, "margin-bottom", "margin-left", "margin-right", "margin-top", - "marker-offset", maroon, match, "max-height", "max-width", maxerr, maxlen, - md5, media, mediumaquamarine, mediumblue, mediumorchid, mediumpurple, - mediumseagreen, mediumslateblue, mediumspringgreen, mediumturquoise, - mediumvioletred, member, menu, message, meta, midnightblue, - "min-height", "min-width", mintcream, mistyrose, mm, moccasin, moveBy, - moveTo, name, navajowhite, navigator, navy, new, newcap, noframes, - nomen, noscript, nud, object, ol, oldlace, olive, olivedrab, on, - onbeforeunload, onblur, onerror, onevar, onfocus, onload, onresize, - onunload, opacity, open, openURL, opener, opera, optgroup, option, - orange, orangered, orchid, outer, outline, "outline-color", - "outline-style", "outline-width", overflow, "overflow-x", "overflow-y", - p, padding, "padding-bottom", "padding-left", "padding-right", - "padding-top", page, "page-break-after", "page-break-before", - palegoldenrod, palegreen, paleturquoise, palevioletred, papayawhip, - param, parent, parseFloat, parseInt, passfail, pc, peachpuff, peru, - pink, play, plum, plusplus, pop, popupMenu, position, powderblue, pre, - predef, preferenceGroups, preferences, print, prompt, prototype, pt, - purple, push, px, q, quit, quotes, random, range, raw, reach, readFile, - readUrl, reason, red, regexp, reloadWidget, removeEventListener, - replace, report, reserved, resizeBy, resizeTo, resolvePath, - resumeUpdates, rhino, right, rosybrown, royalblue, runCommand, - runCommandInBg, saddlebrown, safe, salmon, samp, sandybrown, saveAs, - savePreferences, screen, script, scroll, scrollBy, scrollTo, seagreen, - seal, search, seashell, select, serialize, setInterval, setTimeout, - shift, showWidgetPreferences, sidebar, sienna, silver, skyblue, - slateblue, slategray, sleep, slice, small, snow, sort, span, spawn, - speak, split, springgreen, src, status, steelblue, strict, strong, - style, styleproperty, sub, substr, sup, supplant, suppressUpdates, sync, - system, table, "table-layout", tan, tbody, td, teal, tellWidget, test, - "text-align", "text-decoration", "text-indent", "text-shadow", - "text-transform", textarea, tfoot, th, thead, thistle, title, - toLowerCase, toString, toUpperCase, toint32, token, tomato, top, tr, tt, - turquoise, type, u, ul, undef, unescape, "unicode-bidi", unused, - unwatch, updateNow, urls, value, valueOf, var, version, - "vertical-align", violet, visibility, watch, wheat, white, - "white-space", whitesmoke, widget, width, "word-spacing", "word-wrap", - yahooCheckLogin, yahooLogin, yahooLogout, yellow, yellowgreen, - "z-index" -*/ - - -// We build the application inside a function so that we produce only a single -// global variable. The function will be invoked, its return value is the JSLINT -// application itself. - -"use strict"; - -var JSLINT = (function () { - var adsafe_id, // The widget's ADsafe id. - adsafe_may, // The widget may load approved scripts. - adsafe_went, // ADSAFE.go has been called. - anonname, // The guessed name for anonymous functions. - approved, // ADsafe approved urls. - - atrule = { - media : true, - 'font-face': true, - page : true - }, - -// These are operators that should not be used with the ! operator. - - bang = { - '<': true, - '<=': true, - '==': true, - '===': true, - '!==': true, - '!=': true, - '>': true, - '>=': true, - '+': true, - '-': true, - '*': true, - '/': true, - '%': true - }, - -// These are members that should not be permitted in the safe subset. - - banned = { // the member names that ADsafe prohibits. - 'arguments' : true, - callee : true, - caller : true, - constructor : true, - 'eval' : true, - prototype : true, - unwatch : true, - valueOf : true, - watch : true - }, - - -// These are the JSLint boolean options. - - boolOptions = { - adsafe : true, // if ADsafe should be enforced - bitwise : true, // if bitwise operators should not be allowed - browser : true, // if the standard browser globals should be predefined - cap : true, // if upper case HTML should be allowed - css : true, // if CSS workarounds should be tolerated - debug : true, // if debugger statements should be allowed - devel : true, // if logging should be allowed (console, alert, etc.) - eqeqeq : true, // if === should be required - evil : true, // if eval should be allowed - forin : true, // if for in statements must filter - fragment : true, // if HTML fragments should be allowed - immed : true, // if immediate invocations must be wrapped in parens - laxbreak : true, // if line breaks should not be checked - newcap : true, // if constructor names must be capitalized - nomen : true, // if names should be checked - on : true, // if HTML event handlers should be allowed - onevar : true, // if only one var statement per function should be allowed - passfail : true, // if the scan should stop on first error - plusplus : true, // if increment/decrement should not be allowed - regexp : true, // if the . should not be allowed in regexp literals - rhino : true, // if the Rhino environment globals should be predefined - undef : true, // if variables should be declared before used - safe : true, // if use of some browser features should be restricted - sidebar : true, // if the System object should be predefined - strict : true, // require the "use strict"; pragma - sub : true, // if all forms of subscript notation are tolerated - white : true, // if strict whitespace rules apply - widget : true // if the Yahoo Widgets globals should be predefined - }, - -// browser contains a set of global names which are commonly provided by a -// web browser environment. - - browser = { - addEventListener: false, - blur : false, - clearInterval : false, - clearTimeout : false, - close : false, - closed : false, - defaultStatus : false, - document : false, - event : false, - focus : false, - frames : false, - getComputedStyle: false, - history : false, - Image : false, - length : false, - location : false, - moveBy : false, - moveTo : false, - name : false, - navigator : false, - onbeforeunload : true, - onblur : true, - onerror : true, - onfocus : true, - onload : true, - onresize : true, - onunload : true, - open : false, - opener : false, - Option : false, - parent : false, - print : false, - removeEventListener: false, - resizeBy : false, - resizeTo : false, - screen : false, - scroll : false, - scrollBy : false, - scrollTo : false, - setInterval : false, - setTimeout : false, - status : false, - top : false, - XMLHttpRequest : false - }, - - cssAttributeData, - cssAny, - - cssColorData = { - "aliceblue" : true, - "antiquewhite" : true, - "aqua" : true, - "aquamarine" : true, - "azure" : true, - "beige" : true, - "bisque" : true, - "black" : true, - "blanchedalmond" : true, - "blue" : true, - "blueviolet" : true, - "brown" : true, - "burlywood" : true, - "cadetblue" : true, - "chartreuse" : true, - "chocolate" : true, - "coral" : true, - "cornflowerblue" : true, - "cornsilk" : true, - "crimson" : true, - "cyan" : true, - "darkblue" : true, - "darkcyan" : true, - "darkgoldenrod" : true, - "darkgray" : true, - "darkgreen" : true, - "darkkhaki" : true, - "darkmagenta" : true, - "darkolivegreen" : true, - "darkorange" : true, - "darkorchid" : true, - "darkred" : true, - "darksalmon" : true, - "darkseagreen" : true, - "darkslateblue" : true, - "darkslategray" : true, - "darkturquoise" : true, - "darkviolet" : true, - "deeppink" : true, - "deepskyblue" : true, - "dimgray" : true, - "dodgerblue" : true, - "firebrick" : true, - "floralwhite" : true, - "forestgreen" : true, - "fuchsia" : true, - "gainsboro" : true, - "ghostwhite" : true, - "gold" : true, - "goldenrod" : true, - "gray" : true, - "green" : true, - "greenyellow" : true, - "honeydew" : true, - "hotpink" : true, - "indianred" : true, - "indigo" : true, - "ivory" : true, - "khaki" : true, - "lavender" : true, - "lavenderblush" : true, - "lawngreen" : true, - "lemonchiffon" : true, - "lightblue" : true, - "lightcoral" : true, - "lightcyan" : true, - "lightgoldenrodyellow" : true, - "lightgreen" : true, - "lightpink" : true, - "lightsalmon" : true, - "lightseagreen" : true, - "lightskyblue" : true, - "lightslategray" : true, - "lightsteelblue" : true, - "lightyellow" : true, - "lime" : true, - "limegreen" : true, - "linen" : true, - "magenta" : true, - "maroon" : true, - "mediumaquamarine" : true, - "mediumblue" : true, - "mediumorchid" : true, - "mediumpurple" : true, - "mediumseagreen" : true, - "mediumslateblue" : true, - "mediumspringgreen" : true, - "mediumturquoise" : true, - "mediumvioletred" : true, - "midnightblue" : true, - "mintcream" : true, - "mistyrose" : true, - "moccasin" : true, - "navajowhite" : true, - "navy" : true, - "oldlace" : true, - "olive" : true, - "olivedrab" : true, - "orange" : true, - "orangered" : true, - "orchid" : true, - "palegoldenrod" : true, - "palegreen" : true, - "paleturquoise" : true, - "palevioletred" : true, - "papayawhip" : true, - "peachpuff" : true, - "peru" : true, - "pink" : true, - "plum" : true, - "powderblue" : true, - "purple" : true, - "red" : true, - "rosybrown" : true, - "royalblue" : true, - "saddlebrown" : true, - "salmon" : true, - "sandybrown" : true, - "seagreen" : true, - "seashell" : true, - "sienna" : true, - "silver" : true, - "skyblue" : true, - "slateblue" : true, - "slategray" : true, - "snow" : true, - "springgreen" : true, - "steelblue" : true, - "tan" : true, - "teal" : true, - "thistle" : true, - "tomato" : true, - "turquoise" : true, - "violet" : true, - "wheat" : true, - "white" : true, - "whitesmoke" : true, - "yellow" : true, - "yellowgreen" : true - }, - - cssBorderStyle, - cssBreak, - - cssLengthData = { - '%': true, - 'cm': true, - 'em': true, - 'ex': true, - 'in': true, - 'mm': true, - 'pc': true, - 'pt': true, - 'px': true - }, - - cssOverflow, - - devel = { - alert : false, - confirm : false, - console : false, - Debug : false, - opera : false, - prompt : false - }, - - escapes = { - '\b': '\\b', - '\t': '\\t', - '\n': '\\n', - '\f': '\\f', - '\r': '\\r', - '"' : '\\"', - '/' : '\\/', - '\\': '\\\\' - }, - - funct, // The current function - - functionicity = [ - 'closure', 'exception', 'global', 'label', - 'outer', 'unused', 'var' - ], - - functions, // All of the functions - - global, // The global scope - htmltag = { - a: {}, - abbr: {}, - acronym: {}, - address: {}, - applet: {}, - area: {empty: true, parent: ' map '}, - b: {}, - base: {empty: true, parent: ' head '}, - bdo: {}, - big: {}, - blockquote: {}, - body: {parent: ' html noframes '}, - br: {empty: true}, - button: {}, - canvas: {parent: ' body p div th td '}, - caption: {parent: ' table '}, - center: {}, - cite: {}, - code: {}, - col: {empty: true, parent: ' table colgroup '}, - colgroup: {parent: ' table '}, - dd: {parent: ' dl '}, - del: {}, - dfn: {}, - dir: {}, - div: {}, - dl: {}, - dt: {parent: ' dl '}, - em: {}, - embed: {}, - fieldset: {}, - font: {}, - form: {}, - frame: {empty: true, parent: ' frameset '}, - frameset: {parent: ' html frameset '}, - h1: {}, - h2: {}, - h3: {}, - h4: {}, - h5: {}, - h6: {}, - head: {parent: ' html '}, - html: {parent: '*'}, - hr: {empty: true}, - i: {}, - iframe: {}, - img: {empty: true}, - input: {empty: true}, - ins: {}, - kbd: {}, - label: {}, - legend: {parent: ' fieldset '}, - li: {parent: ' dir menu ol ul '}, - link: {empty: true, parent: ' head '}, - map: {}, - menu: {}, - meta: {empty: true, parent: ' head noframes noscript '}, - noframes: {parent: ' html body '}, - noscript: {parent: ' body head noframes '}, - object: {}, - ol: {}, - optgroup: {parent: ' select '}, - option: {parent: ' optgroup select '}, - p: {}, - param: {empty: true, parent: ' applet object '}, - pre: {}, - q: {}, - samp: {}, - script: {empty: true, parent: ' body div frame head iframe p pre span '}, - select: {}, - small: {}, - span: {}, - strong: {}, - style: {parent: ' head ', empty: true}, - sub: {}, - sup: {}, - table: {}, - tbody: {parent: ' table '}, - td: {parent: ' tr '}, - textarea: {}, - tfoot: {parent: ' table '}, - th: {parent: ' tr '}, - thead: {parent: ' table '}, - title: {parent: ' head '}, - tr: {parent: ' table tbody thead tfoot '}, - tt: {}, - u: {}, - ul: {}, - 'var': {} - }, - - ids, // HTML ids - implied, // Implied globals - inblock, - indent, - jsonmode, - lines, - lookahead, - member, - membersOnly, - nexttoken, - noreach, - option, - predefined, // Global variables defined by option - prereg, - prevtoken, - - rhino = { - defineClass : false, - deserialize : false, - gc : false, - help : false, - load : false, - loadClass : false, - print : false, - quit : false, - readFile : false, - readUrl : false, - runCommand : false, - seal : false, - serialize : false, - spawn : false, - sync : false, - toint32 : false, - version : false - }, - - scope, // The current scope - - sidebar = { - System : false - }, - - src, - stack, - -// standard contains the global names that are provided by the -// ECMAScript standard. - - standard = { - Array : false, - Boolean : false, - Date : false, - decodeURI : false, - decodeURIComponent : false, - encodeURI : false, - encodeURIComponent : false, - Error : false, - 'eval' : false, - EvalError : false, - Function : false, - hasOwnProperty : false, - isFinite : false, - isNaN : false, - JSON : false, - Math : false, - Number : false, - Object : false, - parseInt : false, - parseFloat : false, - RangeError : false, - ReferenceError : false, - RegExp : false, - String : false, - SyntaxError : false, - TypeError : false, - URIError : false - }, - - standard_member = { - E : true, - LN2 : true, - LN10 : true, - LOG2E : true, - LOG10E : true, - PI : true, - SQRT1_2 : true, - SQRT2 : true, - MAX_VALUE : true, - MIN_VALUE : true, - NEGATIVE_INFINITY : true, - POSITIVE_INFINITY : true - }, - - strict_mode, - syntax = {}, - tab, - token, - urls, - warnings, - -// widget contains the global names which are provided to a Yahoo -// (fna Konfabulator) widget. - - widget = { - alert : true, - animator : true, - appleScript : true, - beep : true, - bytesToUIString : true, - Canvas : true, - chooseColor : true, - chooseFile : true, - chooseFolder : true, - closeWidget : true, - COM : true, - convertPathToHFS : true, - convertPathToPlatform : true, - CustomAnimation : true, - escape : true, - FadeAnimation : true, - filesystem : true, - Flash : true, - focusWidget : true, - form : true, - FormField : true, - Frame : true, - HotKey : true, - Image : true, - include : true, - isApplicationRunning : true, - iTunes : true, - konfabulatorVersion : true, - log : true, - md5 : true, - MenuItem : true, - MoveAnimation : true, - openURL : true, - play : true, - Point : true, - popupMenu : true, - preferenceGroups : true, - preferences : true, - print : true, - prompt : true, - random : true, - Rectangle : true, - reloadWidget : true, - ResizeAnimation : true, - resolvePath : true, - resumeUpdates : true, - RotateAnimation : true, - runCommand : true, - runCommandInBg : true, - saveAs : true, - savePreferences : true, - screen : true, - ScrollBar : true, - showWidgetPreferences : true, - sleep : true, - speak : true, - Style : true, - suppressUpdates : true, - system : true, - tellWidget : true, - Text : true, - TextArea : true, - Timer : true, - unescape : true, - updateNow : true, - URL : true, - Web : true, - widget : true, - Window : true, - XMLDOM : true, - XMLHttpRequest : true, - yahooCheckLogin : true, - yahooLogin : true, - yahooLogout : true - }, - -// xmode is used to adapt to the exceptions in html parsing. -// It can have these states: -// false .js script file -// html -// outer -// script -// style -// scriptstring -// styleproperty - - xmode, - xquote, - -// unsafe comment or string - ax = /@cc|<\/?|script|\]*s\]|<\s*!|</i, -// unsafe characters that are silently deleted by one or more browsers - cx = /[\u0000-\u001f\u007f-\u009f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/, -// token - tx = /^\s*([(){}\[.,:;'"~\?\]#@]|==?=?|\/(\*(jslint|members?|global)?|=|\/)?|\*[\/=]?|\+[+=]?|-[\-=]?|%=?|&[&=]?|\|[|=]?|>>?>?=?|<([\/=!]|\!(\[|--)?|<=?)?|\^=?|\!=?=?|[a-zA-Z_$][a-zA-Z0-9_$]*|[0-9]+([xX][0-9a-fA-F]+|\.[0-9]*)?([eE][+\-]?[0-9]+)?)/, -// html token -//////// hx = /^\s*(['"=>\/&#]|<(?:\/|\!(?:--)?)?|[a-zA-Z][a-zA-Z0-9_\-]*|[0-9]+|--|.)/, - hx = /^\s*(['"=>\/&#]|<(?:\/|\!(?:--)?)?|[a-zA-Z][a-zA-Z0-9_\-]*|[0-9]+|--)/, -// characters in strings that need escapement - nx = /[\u0000-\u001f&<"\/\\\u007f-\u009f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/, - nxg = /[\u0000-\u001f&<"\/\\\u007f-\u009f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, -// outer html token - ox = /[>&]|<[\/!]?|--/, -// star slash - lx = /\*\/|\/\*/, -// identifier - ix = /^([a-zA-Z_$][a-zA-Z0-9_$]*)$/, -// javascript url - jx = /^(?:javascript|jscript|ecmascript|vbscript|mocha|livescript)\s*:/i, -// url badness - ux = /&|\+|\u00AD|\.\.|\/\*|%[^;]|base64|url|expression|data|mailto/i, -// style - sx = /^\s*([{:#%.=,>+\[\]@()"';]|\*=?|\$=|\|=|\^=|~=|[a-zA-Z_][a-zA-Z0-9_\-]*|[0-9]+|<\/|\/\*)/, - ssx = /^\s*([@#!"'};:\-%.=,+\[\]()*_]|[a-zA-Z][a-zA-Z0-9._\-]*|\/\*?|\d+(?:\.\d+)?|<\/)/, -// attributes characters - qx = /[^a-zA-Z0-9-_\/ ]/, -// query characters for ids - dx = /[\[\]\/\\"'*<>.&:(){}+=#]/, - - rx = { - outer: hx, - html: hx, - style: sx, - styleproperty: ssx - }; - - function F() {} - - if (typeof Object.create !== 'function') { - Object.create = function (o) { - F.prototype = o; - return new F(); - }; - } - - - function is_own(object, name) { - return Object.prototype.hasOwnProperty.call(object, name); - } - - - function combine(t, o) { - var n; - for (n in o) { - if (is_own(o, n)) { - t[n] = o[n]; - } - } - } - - String.prototype.entityify = function () { - return this. - replace(/&/g, '&'). - replace(//g, '>'); - }; - - String.prototype.isAlpha = function () { - return (this >= 'a' && this <= 'z\uffff') || - (this >= 'A' && this <= 'Z\uffff'); - }; - - - String.prototype.isDigit = function () { - return (this >= '0' && this <= '9'); - }; - - - String.prototype.supplant = function (o) { - return this.replace(/\{([^{}]*)\}/g, function (a, b) { - var r = o[b]; - return typeof r === 'string' || typeof r === 'number' ? r : a; - }); - }; - - String.prototype.name = function () { - -// If the string looks like an identifier, then we can return it as is. -// If the string contains no control characters, no quote characters, and no -// backslash characters, then we can simply slap some quotes around it. -// Otherwise we must also replace the offending characters with safe -// sequences. - - if (ix.test(this)) { - return this; - } - if (nx.test(this)) { - return '"' + this.replace(nxg, function (a) { - var c = escapes[a]; - if (c) { - return c; - } - return '\\u' + ('0000' + a.charCodeAt().toString(16)).slice(-4); - }) + '"'; - } - return '"' + this + '"'; - }; - - - function assume() { - if (!option.safe) { - if (option.rhino) { - combine(predefined, rhino); - } - if (option.devel) { - combine(predefined, devel); - } - if (option.browser || option.sidebar) { - combine(predefined, browser); - } - if (option.sidebar) { - combine(predefined, sidebar); - } - if (option.widget) { - combine(predefined, widget); - } - } - } - - -// Produce an error warning. - - function quit(m, l, ch) { - throw { - name: 'JSLintError', - line: l, - character: ch, - message: m + " (" + Math.floor((l / lines.length) * 100) + - "% scanned)." - }; - } - - function warning(m, t, a, b, c, d) { - var ch, l, w; - t = t || nexttoken; - if (t.id === '(end)') { // `~ - t = token; - } - l = t.line || 0; - ch = t.from || 0; - w = { - id: '(error)', - raw: m, - evidence: lines[l - 1] || '', - line: l, - character: ch, - a: a, - b: b, - c: c, - d: d - }; - w.reason = m.supplant(w); - JSLINT.errors.push(w); - if (option.passfail) { - quit('Stopping. ', l, ch); - } - warnings += 1; - if (warnings >= option.maxerr) { - quit("Too many errors.", l, ch); - } - return w; - } - - function warningAt(m, l, ch, a, b, c, d) { - return warning(m, { - line: l, - from: ch - }, a, b, c, d); - } - - function error(m, t, a, b, c, d) { - var w = warning(m, t, a, b, c, d); - quit("Stopping, unable to continue.", w.line, w.character); - } - - function errorAt(m, l, ch, a, b, c, d) { - return error(m, { - line: l, - from: ch - }, a, b, c, d); - } - - - -// lexical analysis - - var lex = (function lex() { - var character, from, line, s; - -// Private lex methods - - function nextLine() { - var at; - if (line >= lines.length) { - return false; - } - character = 1; - s = lines[line]; - line += 1; - at = s.search(/ \t/); - if (at >= 0) { - warningAt("Mixed spaces and tabs.", line, at + 1); - } - s = s.replace(/\t/g, tab); - at = s.search(cx); - if (at >= 0) { - warningAt("Unsafe character.", line, at); - } - if (option.maxlen && option.maxlen < s.length) { - warningAt("Line too long.", line, s.length); - } - return true; - } - -// Produce a token object. The token inherits from a syntax symbol. - - function it(type, value) { - var i, t; - if (type === '(color)') { - t = {type: type}; - } else if (type === '(punctuator)' || - (type === '(identifier)' && is_own(syntax, value))) { - t = syntax[value] || syntax['(error)']; - } else { - t = syntax[type]; - } - t = Object.create(t); - if (type === '(string)' || type === '(range)') { - if (jx.test(value)) { - warningAt("Script URL.", line, from); - } - } - if (type === '(identifier)') { - t.identifier = true; - if (value === '__iterator__' || value === '__proto__') { - errorAt("Reserved name '{a}'.", - line, from, value); - } else if (option.nomen && - (value.charAt(0) === '_' || - value.charAt(value.length - 1) === '_')) { - warningAt("Unexpected {a} in '{b}'.", line, from, - "dangling '_'", value); - } - } - t.value = value; - t.line = line; - t.character = character; - t.from = from; - i = t.id; - if (i !== '(endline)') { - prereg = i && - (('(,=:[!&|?{};'.indexOf(i.charAt(i.length - 1)) >= 0) || - i === 'return'); - } - return t; - } - -// Public lex methods - - return { - init: function (source) { - if (typeof source === 'string') { - lines = source. - replace(/\r\n/g, '\n'). - replace(/\r/g, '\n'). - split('\n'); - } else { - lines = source; - } - line = 0; - nextLine(); - from = 1; - }, - - range: function (begin, end) { - var c, value = ''; - from = character; - if (s.charAt(0) !== begin) { - errorAt("Expected '{a}' and instead saw '{b}'.", - line, character, begin, s.charAt(0)); - } - for (;;) { - s = s.slice(1); - character += 1; - c = s.charAt(0); - switch (c) { - case '': - errorAt("Missing '{a}'.", line, character, c); - break; - case end: - s = s.slice(1); - character += 1; - return it('(range)', value); - case xquote: - case '\\': - warningAt("Unexpected '{a}'.", line, character, c); - } - value += c; - } - - }, - -// token -- this is called by advance to get the next token. - - token: function () { - var b, c, captures, d, depth, high, i, l, low, q, t; - - function match(x) { - var r = x.exec(s), r1; - if (r) { - l = r[0].length; - r1 = r[1]; - c = r1.charAt(0); - s = s.substr(l); - from = character + l - r1.length; - character += l; - return r1; - } - } - - function string(x) { - var c, j, r = ''; - - if (jsonmode && x !== '"') { - warningAt("Strings must use doublequote.", - line, character); - } - - if (xquote === x || (xmode === 'scriptstring' && !xquote)) { - return it('(punctuator)', x); - } - - function esc(n) { - var i = parseInt(s.substr(j + 1, n), 16); - j += n; - if (i >= 32 && i <= 126 && - i !== 34 && i !== 92 && i !== 39) { - warningAt("Unnecessary escapement.", line, character); - } - character += n; - c = String.fromCharCode(i); - } - j = 0; - for (;;) { - while (j >= s.length) { - j = 0; - if (xmode !== 'html' || !nextLine()) { - errorAt("Unclosed string.", line, from); - } - } - c = s.charAt(j); - if (c === x) { - character += 1; - s = s.substr(j + 1); - return it('(string)', r, x); - } - if (c < ' ') { - if (c === '\n' || c === '\r') { - break; - } - warningAt("Control character in string: {a}.", - line, character + j, s.slice(0, j)); - } else if (c === xquote) { - warningAt("Bad HTML string", line, character + j); - } else if (c === '<') { - if (option.safe && xmode === 'html') { - warningAt("ADsafe string violation.", - line, character + j); - } else if (s.charAt(j + 1) === '/' && (xmode || option.safe)) { - warningAt("Expected '<\\/' and instead saw ' 0) { - character += 1; - s = s.slice(i); - break; - } else { - if (!nextLine()) { - return it('(end)', ''); - } - } - } -// t = match(rx[xmode] || tx); -// if (!t) { -// if (xmode === 'html') { -// return it('(error)', s.charAt(0)); -// } else { -// t = ''; -// c = ''; -// while (s && s < '!') { -// s = s.substr(1); -// } -// if (s) { -// errorAt("Unexpected '{a}'.", -// line, character, s.substr(0, 1)); -// } -// } - t = match(rx[xmode] || tx); - if (!t) { - t = ''; - c = ''; - while (s && s < '!') { - s = s.substr(1); - } - if (s) { - if (xmode === 'html') { - return it('(error)', s.charAt(0)); - } else { - errorAt("Unexpected '{a}'.", - line, character, s.substr(0, 1)); - } - } - } else { - - // identifier - - if (c.isAlpha() || c === '_' || c === '$') { - return it('(identifier)', t); - } - - // number - - if (c.isDigit()) { - if (xmode !== 'style' && !isFinite(Number(t))) { - warningAt("Bad number '{a}'.", - line, character, t); - } - if (xmode !== 'style' && - xmode !== 'styleproperty' && - s.substr(0, 1).isAlpha()) { - warningAt("Missing space after '{a}'.", - line, character, t); - } - if (c === '0') { - d = t.substr(1, 1); - if (d.isDigit()) { - if (token.id !== '.' && xmode !== 'styleproperty') { - warningAt("Don't use extra leading zeros '{a}'.", - line, character, t); - } - } else if (jsonmode && (d === 'x' || d === 'X')) { - warningAt("Avoid 0x-. '{a}'.", - line, character, t); - } - } - if (t.substr(t.length - 1) === '.') { - warningAt( - "A trailing decimal point can be confused with a dot '{a}'.", - line, character, t); - } - return it('(number)', t); - } - switch (t) { - - // string - - case '"': - case "'": - return string(t); - - // // comment - - case '//': - if (src || (xmode && xmode !== 'script')) { - warningAt("Unexpected comment.", line, character); - } else if (xmode === 'script' && /<\s*\//i.test(s)) { - warningAt("Unexpected <\/ in comment.", line, character); - } else if ((option.safe || xmode === 'script') && ax.test(s)) { - warningAt("Dangerous comment.", line, character); - } - s = ''; - token.comment = true; - break; - - // /* comment - - case '/*': - if (src || (xmode && xmode !== 'script' && xmode !== 'style' && xmode !== 'styleproperty')) { - warningAt("Unexpected comment.", line, character); - } - if (option.safe && ax.test(s)) { - warningAt("ADsafe comment violation.", line, character); - } - for (;;) { - i = s.search(lx); - if (i >= 0) { - break; - } - if (!nextLine()) { - errorAt("Unclosed comment.", line, character); - } else { - if (option.safe && ax.test(s)) { - warningAt("ADsafe comment violation.", line, character); - } - } - } - character += i + 2; - if (s.substr(i, 1) === '/') { - errorAt("Nested comment.", line, character); - } - s = s.substr(i + 2); - token.comment = true; - break; - - // /*members /*jslint /*global - - case '/*members': - case '/*member': - case '/*jslint': - case '/*global': - case '*/': - return { - value: t, - type: 'special', - line: line, - character: character, - from: from - }; - - case '': - break; - // / - case '/': - if (token.id === '/=') { - errorAt( -"A regular expression literal can be confused with '/='.", line, from); - } - if (prereg) { - depth = 0; - captures = 0; - l = 0; - for (;;) { - b = true; - c = s.charAt(l); - l += 1; - switch (c) { - case '': - errorAt("Unclosed regular expression.", line, from); - return; - case '/': - if (depth > 0) { - warningAt("Unescaped '{a}'.", line, from + l, '/'); - } - c = s.substr(0, l - 1); - q = { - g: true, - i: true, - m: true - }; - while (q[s.charAt(l)] === true) { - q[s.charAt(l)] = false; - l += 1; - } - character += l; - s = s.substr(l); - q = s.charAt(0); - if (q === '/' || q === '*') { - errorAt("Confusing regular expression.", line, from); - } - return it('(regexp)', c); - case '\\': - c = s.charAt(l); - if (c < ' ') { - warningAt("Unexpected control character in regular expression.", line, from + l); - } else if (c === '<') { - warningAt("Unexpected escaped character '{a}' in regular expression.", line, from + l, c); - } - l += 1; - break; - case '(': - depth += 1; - b = false; - if (s.charAt(l) === '?') { - l += 1; - switch (s.charAt(l)) { - case ':': - case '=': - case '!': - l += 1; - break; - default: - warningAt("Expected '{a}' and instead saw '{b}'.", line, from + l, ':', s.charAt(l)); - } - } else { - captures += 1; - } - break; - case '|': - b = false; - break; - case ')': - if (depth === 0) { - warningAt("Unescaped '{a}'.", line, from + l, ')'); - } else { - depth -= 1; - } - break; - case ' ': - q = 1; - while (s.charAt(l) === ' ') { - l += 1; - q += 1; - } - if (q > 1) { - warningAt("Spaces are hard to count. Use {{a}}.", line, from + l, q); - } - break; - case '[': - c = s.charAt(l); - if (c === '^') { - l += 1; - if (option.regexp) { - warningAt("Insecure '{a}'.", line, from + l, c); - } - } - q = false; - if (c === ']') { - warningAt("Empty class.", line, from + l - 1); - q = true; - } - klass: do { - c = s.charAt(l); - l += 1; - switch (c) { - case '[': - case '^': - warningAt("Unescaped '{a}'.", line, from + l, c); - q = true; - break; - case '-': - if (q) { - q = false; - } else { - warningAt("Unescaped '{a}'.", line, from + l, '-'); - q = true; - } - break; - case ']': - if (!q) { - warningAt("Unescaped '{a}'.", line, from + l - 1, '-'); - } - break klass; - case '\\': - c = s.charAt(l); - if (c < ' ') { - warningAt("Unexpected control character in regular expression.", line, from + l); - } else if (c === '<') { - warningAt("Unexpected escaped character '{a}' in regular expression.", line, from + l, c); - } - l += 1; - q = true; - break; - case '/': - warningAt("Unescaped '{a}'.", line, from + l - 1, '/'); - q = true; - break; - case '<': - if (xmode === 'script') { - c = s.charAt(l); - if (c === '!' || c === '/') { - warningAt("HTML confusion in regular expression '<{a}'.", line, from + l, c); - } - } - q = true; - break; - default: - q = true; - } - } while (c); - break; - case '.': - if (option.regexp) { - warningAt("Insecure '{a}'.", line, from + l, c); - } - break; - case ']': - case '?': - case '{': - case '}': - case '+': - case '*': - warningAt("Unescaped '{a}'.", line, from + l, c); - break; - case '<': - if (xmode === 'script') { - c = s.charAt(l); - if (c === '!' || c === '/') { - warningAt("HTML confusion in regular expression '<{a}'.", line, from + l, c); - } - } - } - if (b) { - switch (s.charAt(l)) { - case '?': - case '+': - case '*': - l += 1; - if (s.charAt(l) === '?') { - l += 1; - } - break; - case '{': - l += 1; - c = s.charAt(l); - if (c < '0' || c > '9') { - warningAt("Expected a number and instead saw '{a}'.", line, from + l, c); - } - l += 1; - low = +c; - for (;;) { - c = s.charAt(l); - if (c < '0' || c > '9') { - break; - } - l += 1; - low = +c + (low * 10); - } - high = low; - if (c === ',') { - l += 1; - high = Infinity; - c = s.charAt(l); - if (c >= '0' && c <= '9') { - l += 1; - high = +c; - for (;;) { - c = s.charAt(l); - if (c < '0' || c > '9') { - break; - } - l += 1; - high = +c + (high * 10); - } - } - } - if (s.charAt(l) !== '}') { - warningAt("Expected '{a}' and instead saw '{b}'.", line, from + l, '}', c); - } else { - l += 1; - } - if (s.charAt(l) === '?') { - l += 1; - } - if (low > high) { - warningAt("'{a}' should not be greater than '{b}'.", line, from + l, low, high); - } - } - } - } - c = s.substr(0, l - 1); - character += l; - s = s.substr(l); - return it('(regexp)', c); - } - return it('(punctuator)', t); - - // punctuator - - case '.", line, character); - } - character += 3; - s = s.slice(i + 3); - break; - case '#': - if (xmode === 'html' || xmode === 'styleproperty') { - for (;;) { - c = s.charAt(0); - if ((c < '0' || c > '9') && - (c < 'a' || c > 'f') && - (c < 'A' || c > 'F')) { - break; - } - character += 1; - s = s.substr(1); - t += c; - } - if (t.length !== 4 && t.length !== 7) { - warningAt("Bad hex color '{a}'.", line, - from + l, t); - } - return it('(color)', t); - } - return it('(punctuator)', t); - default: - if (xmode === 'outer' && c === '&') { - character += 1; - s = s.substr(1); - for (;;) { - c = s.charAt(0); - character += 1; - s = s.substr(1); - if (c === ';') { - break; - } - if (!((c >= '0' && c <= '9') || - (c >= 'a' && c <= 'z') || - c === '#')) { - errorAt("Bad entity", line, from + l, - character); - } - } - break; - } - return it('(punctuator)', t); - } - } - } - } - }; - }()); - - - function addlabel(t, type) { - - if (option.safe && funct['(global)'] && typeof predefined[t] !== 'boolean') { - warning('ADsafe global: ' + t + '.', token); - } else if (t === 'hasOwnProperty') { - warning("'hasOwnProperty' is a really bad name."); - } - -// Define t in the current function in the current scope. - - if (is_own(funct, t) && !funct['(global)']) { - warning(funct[t] === true ? - "'{a}' was used before it was defined." : - "'{a}' is already defined.", - nexttoken, t); - } - funct[t] = type; - if (funct['(global)']) { - global[t] = funct; - if (is_own(implied, t)) { - warning("'{a}' was used before it was defined.", nexttoken, t); - delete implied[t]; - } - } else { - scope[t] = funct; - } - } - - - function doOption() { - var b, obj, filter, o = nexttoken.value, t, v; - switch (o) { - case '*/': - error("Unbegun comment."); - break; - case '/*members': - case '/*member': - o = '/*members'; - if (!membersOnly) { - membersOnly = {}; - } - obj = membersOnly; - break; - case '/*jslint': - if (option.safe) { - warning("ADsafe restriction."); - } - obj = option; - filter = boolOptions; - break; - case '/*global': - if (option.safe) { - warning("ADsafe restriction."); - } - obj = predefined; - break; - default: - } - t = lex.token(); -loop: for (;;) { - for (;;) { - if (t.type === 'special' && t.value === '*/') { - break loop; - } - if (t.id !== '(endline)' && t.id !== ',') { - break; - } - t = lex.token(); - } - if (t.type !== '(string)' && t.type !== '(identifier)' && - o !== '/*members') { - error("Bad option.", t); - } - v = lex.token(); - if (v.id === ':') { - v = lex.token(); - if (obj === membersOnly) { - error("Expected '{a}' and instead saw '{b}'.", - t, '*/', ':'); - } - if (t.value === 'indent' && o === '/*jslint') { - b = +v.value; - if (typeof b !== 'number' || !isFinite(b) || b <= 0 || - Math.floor(b) !== b) { - error("Expected a small integer and instead saw '{a}'.", - v, v.value); - } - obj.white = true; - obj.indent = b; - } else if (t.value === 'maxerr' && o === '/*jslint') { - b = +v.value; - if (typeof b !== 'number' || !isFinite(b) || b <= 0 || - Math.floor(b) !== b) { - error("Expected a small integer and instead saw '{a}'.", - v, v.value); - } - obj.maxerr = b; - } else if (t.value === 'maxlen' && o === '/*jslint') { - b = +v.value; - if (typeof b !== 'number' || !isFinite(b) || b <= 0 || - Math.floor(b) !== b) { - error("Expected a small integer and instead saw '{a}'.", - v, v.value); - } - obj.maxlen = b; - } else if (v.value === 'true') { - obj[t.value] = true; - } else if (v.value === 'false') { - obj[t.value] = false; - } else { - error("Bad option value.", v); - } - t = lex.token(); - } else { - if (o === '/*jslint') { - error("Missing option value.", t); - } - obj[t.value] = false; - t = v; - } - } - if (filter) { - assume(); - } - } - - -// We need a peek function. If it has an argument, it peeks that much farther -// ahead. It is used to distinguish -// for ( var i in ... -// from -// for ( var i = ... - - function peek(p) { - var i = p || 0, j = 0, t; - - while (j <= i) { - t = lookahead[j]; - if (!t) { - t = lookahead[j] = lex.token(); - } - j += 1; - } - return t; - } - - - -// Produce the next token. It looks for programming errors. - - function advance(id, t) { - switch (token.id) { - case '(number)': - if (nexttoken.id === '.') { - warning( -"A dot following a number can be confused with a decimal point.", token); - } - break; - case '-': - if (nexttoken.id === '-' || nexttoken.id === '--') { - warning("Confusing minusses."); - } - break; - case '+': - if (nexttoken.id === '+' || nexttoken.id === '++') { - warning("Confusing plusses."); - } - break; - } - if (token.type === '(string)' || token.identifier) { - anonname = token.value; - } - - if (id && nexttoken.id !== id) { - if (t) { - if (nexttoken.id === '(end)') { - warning("Unmatched '{a}'.", t, t.id); - } else { - warning("Expected '{a}' to match '{b}' from line {c} and instead saw '{d}'.", - nexttoken, id, t.id, t.line, nexttoken.value); - } - } else if (nexttoken.type !== '(identifier)' || - nexttoken.value !== id) { - warning("Expected '{a}' and instead saw '{b}'.", - nexttoken, id, nexttoken.value); - } - } - prevtoken = token; - token = nexttoken; - for (;;) { - nexttoken = lookahead.shift() || lex.token(); - if (nexttoken.id === '(end)' || nexttoken.id === '(error)') { - return; - } - if (nexttoken.type === 'special') { - doOption(); - } else { - if (nexttoken.id !== '(endline)') { - break; - } - } - } - } - - -// This is the heart of JSLINT, the Pratt parser. In addition to parsing, it -// is looking for ad hoc lint patterns. We add to Pratt's model .fud, which is -// like nud except that it is only used on the first token of a statement. -// Having .fud makes it much easier to define JavaScript. I retained Pratt's -// nomenclature. - -// .nud Null denotation -// .fud First null denotation -// .led Left denotation -// lbp Left binding power -// rbp Right binding power - -// They are key to the parsing method called Top Down Operator Precedence. - - function parse(rbp, initial) { - var left; - if (nexttoken.id === '(end)') { - error("Unexpected early end of program.", token); - } - advance(); - if (option.safe && typeof predefined[token.value] === 'boolean' && - (nexttoken.id !== '(' && nexttoken.id !== '.')) { - warning('ADsafe violation.', token); - } - if (initial) { - anonname = 'anonymous'; - funct['(verb)'] = token.value; - } - if (initial === true && token.fud) { - left = token.fud(); - } else { - if (token.nud) { - left = token.nud(); - } else { - if (nexttoken.type === '(number)' && token.id === '.') { - warning( -"A leading decimal point can be confused with a dot: '.{a}'.", - token, nexttoken.value); - advance(); - return token; - } else { - error("Expected an identifier and instead saw '{a}'.", - token, token.id); - } - } - while (rbp < nexttoken.lbp) { - advance(); - if (token.led) { - left = token.led(left); - } else { - error("Expected an operator and instead saw '{a}'.", - token, token.id); - } - } - } - return left; - } - - -// Functions for conformance of style. - - function adjacent(left, right) { - left = left || token; - right = right || nexttoken; - if (option.white || xmode === 'styleproperty' || xmode === 'style') { - if (left.character !== right.from && left.line === right.line) { - warning("Unexpected space after '{a}'.", right, left.value); - } - } - } - - function nospace(left, right) { - left = left || token; - right = right || nexttoken; - if (option.white && !left.comment) { - if (left.line === right.line) { - adjacent(left, right); - } - } - } - - - function nonadjacent(left, right) { - if (option.white) { - left = left || token; - right = right || nexttoken; - if (left.line === right.line && left.character === right.from) { - warning("Missing space after '{a}'.", - nexttoken, left.value); - } - } - } - - function nobreaknonadjacent(left, right) { - left = left || token; - right = right || nexttoken; - if (!option.laxbreak && left.line !== right.line) { - warning("Bad line breaking before '{a}'.", right, right.id); - } else if (option.white) { - left = left || token; - right = right || nexttoken; - if (left.character === right.from) { - warning("Missing space after '{a}'.", - nexttoken, left.value); - } - } - } - - function indentation(bias) { - var i; - if (option.white && nexttoken.id !== '(end)') { - i = indent + (bias || 0); - if (nexttoken.from !== i) { - warning("Expected '{a}' to have an indentation at {b} instead at {c}.", - nexttoken, nexttoken.value, i, nexttoken.from); - } - } - } - - function nolinebreak(t) { - t = t || token; - if (t.line !== nexttoken.line) { - warning("Line breaking error '{a}'.", t, t.value); - } - } - - - function comma() { - if (token.line !== nexttoken.line) { - if (!option.laxbreak) { - warning("Bad line breaking before '{a}'.", token, nexttoken.id); - } - } else if (token.character !== nexttoken.from && option.white) { - warning("Unexpected space after '{a}'.", nexttoken, token.value); - } - advance(','); - nonadjacent(token, nexttoken); - } - - -// Functional constructors for making the symbols that will be inherited by -// tokens. - - function symbol(s, p) { - var x = syntax[s]; - if (!x || typeof x !== 'object') { - syntax[s] = x = { - id: s, - lbp: p, - value: s - }; - } - return x; - } - - - function delim(s) { - return symbol(s, 0); - } - - - function stmt(s, f) { - var x = delim(s); - x.identifier = x.reserved = true; - x.fud = f; - return x; - } - - - function blockstmt(s, f) { - var x = stmt(s, f); - x.block = true; - return x; - } - - - function reserveName(x) { - var c = x.id.charAt(0); - if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) { - x.identifier = x.reserved = true; - } - return x; - } - - - function prefix(s, f) { - var x = symbol(s, 150); - reserveName(x); - x.nud = (typeof f === 'function') ? f : function () { - this.right = parse(150); - this.arity = 'unary'; - if (this.id === '++' || this.id === '--') { - if (option.plusplus) { - warning("Unexpected use of '{a}'.", this, this.id); - } else if ((!this.right.identifier || this.right.reserved) && - this.right.id !== '.' && this.right.id !== '[') { - warning("Bad operand.", this); - } - } - return this; - }; - return x; - } - - - function type(s, f) { - var x = delim(s); - x.type = s; - x.nud = f; - return x; - } - - - function reserve(s, f) { - var x = type(s, f); - x.identifier = x.reserved = true; - return x; - } - - - function reservevar(s, v) { - return reserve(s, function () { - if (this.id === 'this' || this.id === 'arguments') { - if (strict_mode && funct['(global)']) { - warning("Strict violation.", this); - } else if (option.safe) { - warning("ADsafe violation.", this); - } - } - return this; - }); - } - - - function infix(s, f, p, w) { - var x = symbol(s, p); - reserveName(x); - x.led = function (left) { - if (!w) { - nobreaknonadjacent(prevtoken, token); - nonadjacent(token, nexttoken); - } - if (typeof f === 'function') { - return f(left, this); - } else { - this.left = left; - this.right = parse(p); - return this; - } - }; - return x; - } - - - function relation(s, f) { - var x = symbol(s, 100); - x.led = function (left) { - nobreaknonadjacent(prevtoken, token); - nonadjacent(token, nexttoken); - var right = parse(100); - if ((left && left.id === 'NaN') || (right && right.id === 'NaN')) { - warning("Use the isNaN function to compare with NaN.", this); - } else if (f) { - f.apply(this, [left, right]); - } - if (left.id === '!') { - warning("Confusing use of '{a}'.", left, '!'); - } - if (right.id === '!') { - warning("Confusing use of '{a}'.", left, '!'); - } - this.left = left; - this.right = right; - return this; - }; - return x; - } - - - function isPoorRelation(node) { - return node && - ((node.type === '(number)' && +node.value === 0) || - (node.type === '(string)' && node.value === ' ') || - node.type === 'true' || - node.type === 'false' || - node.type === 'undefined' || - node.type === 'null'); - } - - - function assignop(s, f) { - symbol(s, 20).exps = true; - return infix(s, function (left, that) { - var l; - that.left = left; - if (predefined[left.value] === false && - scope[left.value]['(global)'] === true) { - warning('Read only.', left); - } - if (option.safe) { - l = left; - do { - if (typeof predefined[l.value] === 'boolean') { - warning('ADsafe violation.', l); - } - l = l.left; - } while (l); - } - if (left) { - if (left.id === '.' || left.id === '[') { - if (!left.left || left.left.value === 'arguments') { - warning('Bad assignment.', that); - } - that.right = parse(19); - return that; - } else if (left.identifier && !left.reserved) { - if (funct[left.value] === 'exception') { - warning("Do not assign to the exception parameter.", left); - } - that.right = parse(19); - return that; - } - if (left === syntax['function']) { - warning( -"Expected an identifier in an assignment and instead saw a function invocation.", - token); - } - } - error("Bad assignment.", that); - }, 20); - } - - function bitwise(s, f, p) { - var x = symbol(s, p); - reserveName(x); - x.led = (typeof f === 'function') ? f : function (left) { - if (option.bitwise) { - warning("Unexpected use of '{a}'.", this, this.id); - } - this.left = left; - this.right = parse(p); - return this; - }; - return x; - } - - function bitwiseassignop(s) { - symbol(s, 20).exps = true; - return infix(s, function (left, that) { - if (option.bitwise) { - warning("Unexpected use of '{a}'.", that, that.id); - } - nonadjacent(prevtoken, token); - nonadjacent(token, nexttoken); - if (left) { - if (left.id === '.' || left.id === '[' || - (left.identifier && !left.reserved)) { - parse(19); - return that; - } - if (left === syntax['function']) { - warning( -"Expected an identifier in an assignment, and instead saw a function invocation.", - token); - } - return that; - } - error("Bad assignment.", that); - }, 20); - } - - - function suffix(s, f) { - var x = symbol(s, 150); - x.led = function (left) { - if (option.plusplus) { - warning("Unexpected use of '{a}'.", this, this.id); - } else if ((!left.identifier || left.reserved) && left.id !== '.' && left.id !== '[') { - warning("Bad operand.", this); - } - this.left = left; - return this; - }; - return x; - } - - - function optionalidentifier() { - if (nexttoken.reserved) { - warning("Expected an identifier and instead saw '{a}' (a reserved word).", - nexttoken, nexttoken.id); - } - if (nexttoken.identifier) { - advance(); - return token.value; - } - } - - - function identifier() { - var i = optionalidentifier(); - if (i) { - return i; - } - if (token.id === 'function' && nexttoken.id === '(') { - warning("Missing name in function statement."); - } else { - error("Expected an identifier and instead saw '{a}'.", - nexttoken, nexttoken.value); - } - } - - function reachable(s) { - var i = 0, t; - if (nexttoken.id !== ';' || noreach) { - return; - } - for (;;) { - t = peek(i); - if (t.reach) { - return; - } - if (t.id !== '(endline)') { - if (t.id === 'function') { - warning( -"Inner functions should be listed at the top of the outer function.", t); - break; - } - warning("Unreachable '{a}' after '{b}'.", t, t.value, s); - break; - } - i += 1; - } - } - - - function statement(noindent) { - var i = indent, r, s = scope, t = nexttoken; - -// We don't like the empty statement. - - if (t.id === ';') { - warning("Unnecessary semicolon.", t); - advance(';'); - return; - } - -// Is this a labelled statement? - - if (t.identifier && !t.reserved && peek().id === ':') { - advance(); - advance(':'); - scope = Object.create(s); - addlabel(t.value, 'label'); - if (!nexttoken.labelled) { - warning("Label '{a}' on {b} statement.", - nexttoken, t.value, nexttoken.value); - } - if (jx.test(t.value + ':')) { - warning("Label '{a}' looks like a javascript url.", - t, t.value); - } - nexttoken.label = t.value; - t = nexttoken; - } - -// Parse the statement. - - if (!noindent) { - indentation(); - } - r = parse(0, true); - -// Look for the final semicolon. - - if (!t.block) { - if (!r || !r.exps) { - warning( -"Expected an assignment or function call and instead saw an expression.", - token); - } else if (r.id === '(' && r.left.id === 'new') { - warning("Do not use 'new' for side effects."); - } - if (nexttoken.id !== ';') { - warningAt("Missing semicolon.", token.line, - token.from + token.value.length); - } else { - adjacent(token, nexttoken); - advance(';'); - nonadjacent(token, nexttoken); - } - } - -// Restore the indentation. - - indent = i; - scope = s; - return r; - } - - - function use_strict() { - if (nexttoken.value === 'use strict') { - advance(); - advance(';'); - strict_mode = true; - return true; - } else { - return false; - } - } - - - function statements(begin) { - var a = [], f, p; - if (begin && !use_strict() && option.strict) { - warning('Missing "use strict" statement.', nexttoken); - } - if (option.adsafe) { - switch (begin) { - case 'script': - if (!adsafe_may) { - if (nexttoken.value !== 'ADSAFE' || - peek(0).id !== '.' || - (peek(1).value !== 'id' && - peek(1).value !== 'go')) { - error('ADsafe violation: Missing ADSAFE.id or ADSAFE.go.', - nexttoken); - } - } - if (nexttoken.value === 'ADSAFE' && - peek(0).id === '.' && - peek(1).value === 'id') { - if (adsafe_may) { - error('ADsafe violation.', nexttoken); - } - advance('ADSAFE'); - advance('.'); - advance('id'); - advance('('); - if (nexttoken.value !== adsafe_id) { - error('ADsafe violation: id does not match.', nexttoken); - } - advance('(string)'); - advance(')'); - advance(';'); - adsafe_may = true; - } - break; - case 'lib': - if (nexttoken.value === 'ADSAFE') { - advance('ADSAFE'); - advance('.'); - advance('lib'); - advance('('); - advance('(string)'); - comma(); - f = parse(0); - if (f.id !== 'function') { - error('The second argument to lib must be a function.', f); - } - p = f.funct['(params)']; - p = p && p.join(', '); - if (p && p !== 'lib') { - error("Expected '{a}' and instead saw '{b}'.", - f, '(lib)', '(' + p + ')'); - } - advance(')'); - advance(';'); - return a; - } else { - error("ADsafe lib violation."); - } - } - } - while (!nexttoken.reach && nexttoken.id !== '(end)') { - if (nexttoken.id === ';') { - warning("Unnecessary semicolon."); - advance(';'); - } else { - a.push(statement()); - } - } - return a; - } - - - function block(f) { - var a, b = inblock, old_indent = indent, s = scope, t; - inblock = f; - scope = Object.create(scope); - nonadjacent(token, nexttoken); - t = nexttoken; - if (nexttoken.id === '{') { - advance('{'); - if (nexttoken.id !== '}' || token.line !== nexttoken.line) { - indent += option.indent; - while (!f && nexttoken.from > indent) { - indent += option.indent; - } - if (!f) { - use_strict(); - } - a = statements(); - indent -= option.indent; - indentation(); - } - advance('}', t); - indent = old_indent; - } else { - warning("Expected '{a}' and instead saw '{b}'.", - nexttoken, '{', nexttoken.value); - noreach = true; - a = [statement()]; - noreach = false; - } - funct['(verb)'] = null; - scope = s; - inblock = b; - return a; - } - - -// An identity function, used by string and number tokens. - - function idValue() { - return this; - } - - - function countMember(m) { - if (membersOnly && typeof membersOnly[m] !== 'boolean') { - warning("Unexpected /*member '{a}'.", token, m); - } - if (typeof member[m] === 'number') { - member[m] += 1; - } else { - member[m] = 1; - } - } - - - function note_implied(token) { - var name = token.value, line = token.line, a = implied[name]; - if (typeof a === 'function') { - a = false; - } - if (!a) { - a = [line]; - implied[name] = a; - } else if (a[a.length - 1] !== line) { - a.push(line); - } - } - -// CSS parsing. - - - function cssName() { - if (nexttoken.identifier) { - advance(); - return true; - } - } - - function cssNumber() { - if (nexttoken.id === '-') { - advance('-'); - adjacent(); - nolinebreak(); - } - if (nexttoken.type === '(number)') { - advance('(number)'); - return true; - } - } - - function cssString() { - if (nexttoken.type === '(string)') { - advance(); - return true; - } - } - - function cssColor() { - var i, number, value; - if (nexttoken.identifier) { - value = nexttoken.value; - if (value === 'rgb' || value === 'rgba') { - advance(); - advance('('); - for (i = 0; i < 3; i += 1) { - if (i) { - advance(','); - } - number = nexttoken.value; - if (nexttoken.type !== '(number)' || number < 0) { - warning("Expected a positive number and instead saw '{a}'", - nexttoken, number); - advance(); - } else { - advance(); - if (nexttoken.id === '%') { - advance('%'); - if (number > 100) { - warning("Expected a percentage and instead saw '{a}'", - token, number); - } - } else { - if (number > 255) { - warning("Expected a small number and instead saw '{a}'", - token, number); - } - } - } - } - if (value === 'rgba') { - advance(','); - number = +nexttoken.value; - if (nexttoken.type !== '(number)' || number < 0 || number > 1) { - warning("Expected a number between 0 and 1 and instead saw '{a}'", - nexttoken, number); - } - advance(); - if (nexttoken.id === '%') { - warning("Unexpected '%'."); - advance('%'); - } - } - advance(')'); - return true; - } else if (cssColorData[nexttoken.value] === true) { - advance(); - return true; - } - } else if (nexttoken.type === '(color)') { - advance(); - return true; - } - return false; - } - - function cssLength() { - if (nexttoken.id === '-') { - advance('-'); - adjacent(); - nolinebreak(); - } - if (nexttoken.type === '(number)') { - advance(); - if (nexttoken.type !== '(string)' && - cssLengthData[nexttoken.value] === true) { - adjacent(); - advance(); - } else if (+token.value !== 0) { - warning("Expected a linear unit and instead saw '{a}'.", - nexttoken, nexttoken.value); - } - return true; - } - return false; - } - - function cssLineHeight() { - if (nexttoken.id === '-') { - advance('-'); - adjacent(); - } - if (nexttoken.type === '(number)') { - advance(); - if (nexttoken.type !== '(string)' && - cssLengthData[nexttoken.value] === true) { - adjacent(); - advance(); - } - return true; - } - return false; - } - - function cssWidth() { - if (nexttoken.identifier) { - switch (nexttoken.value) { - case 'thin': - case 'medium': - case 'thick': - advance(); - return true; - } - } else { - return cssLength(); - } - } - - function cssMargin() { - if (nexttoken.identifier) { - if (nexttoken.value === 'auto') { - advance(); - return true; - } - } else { - return cssLength(); - } - } - - function cssAttr() { - if (nexttoken.identifier && nexttoken.value === 'attr') { - advance(); - advance('('); - if (!nexttoken.identifier) { - warning("Expected a name and instead saw '{a}'.", - nexttoken, nexttoken.value); - } - advance(); - advance(')'); - return true; - } - return false; - } - - function cssCommaList() { - while (nexttoken.id !== ';') { - if (!cssName() && !cssString()) { - warning("Expected a name and instead saw '{a}'.", - nexttoken, nexttoken.value); - } - if (nexttoken.id !== ',') { - return true; - } - comma(); - } - } - - function cssCounter() { - if (nexttoken.identifier && nexttoken.value === 'counter') { - advance(); - advance('('); - if (!nexttoken.identifier) { - } - advance(); - if (nexttoken.id === ',') { - comma(); - if (nexttoken.type !== '(string)') { - warning("Expected a string and instead saw '{a}'.", - nexttoken, nexttoken.value); - } - advance(); - } - advance(')'); - return true; - } - if (nexttoken.identifier && nexttoken.value === 'counters') { - advance(); - advance('('); - if (!nexttoken.identifier) { - warning("Expected a name and instead saw '{a}'.", - nexttoken, nexttoken.value); - } - advance(); - if (nexttoken.id === ',') { - comma(); - if (nexttoken.type !== '(string)') { - warning("Expected a string and instead saw '{a}'.", - nexttoken, nexttoken.value); - } - advance(); - } - if (nexttoken.id === ',') { - comma(); - if (nexttoken.type !== '(string)') { - warning("Expected a string and instead saw '{a}'.", - nexttoken, nexttoken.value); - } - advance(); - } - advance(')'); - return true; - } - return false; - } - - - function cssShape() { - var i; - if (nexttoken.identifier && nexttoken.value === 'rect') { - advance(); - advance('('); - for (i = 0; i < 4; i += 1) { - if (!cssLength()) { - warning("Expected a number and instead saw '{a}'.", - nexttoken, nexttoken.value); - break; - } - } - advance(')'); - return true; - } - return false; - } - - function cssUrl() { - var c, url; - if (nexttoken.identifier && nexttoken.value === 'url') { - nexttoken = lex.range('(', ')'); - url = nexttoken.value; - c = url.charAt(0); - if (c === '"' || c === '\'') { - if (url.slice(-1) !== c) { - warning("Bad url string."); - } else { - url = url.slice(1, -1); - if (url.indexOf(c) >= 0) { - warning("Bad url string."); - } - } - } - if (!url) { - warning("Missing url."); - } - advance(); - if (option.safe && ux.test(url)) { - error("ADsafe URL violation."); - } - urls.push(url); - return true; - } - return false; - } - - cssAny = [cssUrl, function () { - for (;;) { - if (nexttoken.identifier) { - switch (nexttoken.value.toLowerCase()) { - case 'url': - cssUrl(); - break; - case 'expression': - warning("Unexpected expression '{a}'.", - nexttoken, nexttoken.value); - advance(); - break; - default: - advance(); - } - } else { - if (nexttoken.id === ';' || nexttoken.id === '!' || - nexttoken.id === '(end)' || nexttoken.id === '}') { - return true; - } - advance(); - } - } - }]; - - cssBorderStyle = [ - 'none', 'hidden', 'dotted', 'dashed', 'solid', 'double', 'ridge', - 'inset', 'outset' - ]; - - cssBreak = [ - 'auto', 'always', 'avoid', 'left', 'right' - ]; - - cssOverflow = [ - 'auto', 'hidden', 'scroll', 'visible' - ]; - - cssAttributeData = { - background: [ - true, 'background-attachment', 'background-color', - 'background-image', 'background-position', 'background-repeat' - ], - 'background-attachment': ['scroll', 'fixed'], - 'background-color': ['transparent', cssColor], - 'background-image': ['none', cssUrl], - 'background-position': [ - 2, [cssLength, 'top', 'bottom', 'left', 'right', 'center'] - ], - 'background-repeat': [ - 'repeat', 'repeat-x', 'repeat-y', 'no-repeat' - ], - 'border': [true, 'border-color', 'border-style', 'border-width'], - 'border-bottom': [ - true, 'border-bottom-color', 'border-bottom-style', - 'border-bottom-width' - ], - 'border-bottom-color': cssColor, - 'border-bottom-style': cssBorderStyle, - 'border-bottom-width': cssWidth, - 'border-collapse': ['collapse', 'separate'], - 'border-color': ['transparent', 4, cssColor], - 'border-left': [ - true, 'border-left-color', 'border-left-style', 'border-left-width' - ], - 'border-left-color': cssColor, - 'border-left-style': cssBorderStyle, - 'border-left-width': cssWidth, - 'border-right': [ - true, 'border-right-color', 'border-right-style', - 'border-right-width' - ], - 'border-right-color': cssColor, - 'border-right-style': cssBorderStyle, - 'border-right-width': cssWidth, - 'border-spacing': [2, cssLength], - 'border-style': [4, cssBorderStyle], - 'border-top': [ - true, 'border-top-color', 'border-top-style', 'border-top-width' - ], - 'border-top-color': cssColor, - 'border-top-style': cssBorderStyle, - 'border-top-width': cssWidth, - 'border-width': [4, cssWidth], - bottom: [cssLength, 'auto'], - 'caption-side' : ['bottom', 'left', 'right', 'top'], - clear: ['both', 'left', 'none', 'right'], - clip: [cssShape, 'auto'], - color: cssColor, - content: [ - 'open-quote', 'close-quote', 'no-open-quote', 'no-close-quote', - cssString, cssUrl, cssCounter, cssAttr - ], - 'counter-increment': [ - cssName, 'none' - ], - 'counter-reset': [ - cssName, 'none' - ], - cursor: [ - cssUrl, 'auto', 'crosshair', 'default', 'e-resize', 'help', 'move', - 'n-resize', 'ne-resize', 'nw-resize', 'pointer', 's-resize', - 'se-resize', 'sw-resize', 'w-resize', 'text', 'wait' - ], - direction: ['ltr', 'rtl'], - display: [ - 'block', 'compact', 'inline', 'inline-block', 'inline-table', - 'list-item', 'marker', 'none', 'run-in', 'table', 'table-caption', - 'table-cell', 'table-column', 'table-column-group', - 'table-footer-group', 'table-header-group', 'table-row', - 'table-row-group' - ], - 'empty-cells': ['show', 'hide'], - 'float': ['left', 'none', 'right'], - font: [ - 'caption', 'icon', 'menu', 'message-box', 'small-caption', - 'status-bar', true, 'font-size', 'font-style', 'font-weight', - 'font-family' - ], - 'font-family': cssCommaList, - 'font-size': [ - 'xx-small', 'x-small', 'small', 'medium', 'large', 'x-large', - 'xx-large', 'larger', 'smaller', cssLength - ], - 'font-size-adjust': ['none', cssNumber], - 'font-stretch': [ - 'normal', 'wider', 'narrower', 'ultra-condensed', - 'extra-condensed', 'condensed', 'semi-condensed', - 'semi-expanded', 'expanded', 'extra-expanded' - ], - 'font-style': [ - 'normal', 'italic', 'oblique' - ], - 'font-variant': [ - 'normal', 'small-caps' - ], - 'font-weight': [ - 'normal', 'bold', 'bolder', 'lighter', cssNumber - ], - height: [cssLength, 'auto'], - left: [cssLength, 'auto'], - 'letter-spacing': ['normal', cssLength], - 'line-height': ['normal', cssLineHeight], - 'list-style': [ - true, 'list-style-image', 'list-style-position', 'list-style-type' - ], - 'list-style-image': ['none', cssUrl], - 'list-style-position': ['inside', 'outside'], - 'list-style-type': [ - 'circle', 'disc', 'square', 'decimal', 'decimal-leading-zero', - 'lower-roman', 'upper-roman', 'lower-greek', 'lower-alpha', - 'lower-latin', 'upper-alpha', 'upper-latin', 'hebrew', 'katakana', - 'hiragana-iroha', 'katakana-oroha', 'none' - ], - margin: [4, cssMargin], - 'margin-bottom': cssMargin, - 'margin-left': cssMargin, - 'margin-right': cssMargin, - 'margin-top': cssMargin, - 'marker-offset': [cssLength, 'auto'], - 'max-height': [cssLength, 'none'], - 'max-width': [cssLength, 'none'], - 'min-height': cssLength, - 'min-width': cssLength, - opacity: cssNumber, - outline: [true, 'outline-color', 'outline-style', 'outline-width'], - 'outline-color': ['invert', cssColor], - 'outline-style': [ - 'dashed', 'dotted', 'double', 'groove', 'inset', 'none', - 'outset', 'ridge', 'solid' - ], - 'outline-width': cssWidth, - overflow: cssOverflow, - 'overflow-x': cssOverflow, - 'overflow-y': cssOverflow, - padding: [4, cssLength], - 'padding-bottom': cssLength, - 'padding-left': cssLength, - 'padding-right': cssLength, - 'padding-top': cssLength, - 'page-break-after': cssBreak, - 'page-break-before': cssBreak, - position: ['absolute', 'fixed', 'relative', 'static'], - quotes: [8, cssString], - right: [cssLength, 'auto'], - 'table-layout': ['auto', 'fixed'], - 'text-align': ['center', 'justify', 'left', 'right'], - 'text-decoration': [ - 'none', 'underline', 'overline', 'line-through', 'blink' - ], - 'text-indent': cssLength, - 'text-shadow': ['none', 4, [cssColor, cssLength]], - 'text-transform': ['capitalize', 'uppercase', 'lowercase', 'none'], - top: [cssLength, 'auto'], - 'unicode-bidi': ['normal', 'embed', 'bidi-override'], - 'vertical-align': [ - 'baseline', 'bottom', 'sub', 'super', 'top', 'text-top', 'middle', - 'text-bottom', cssLength - ], - visibility: ['visible', 'hidden', 'collapse'], - 'white-space': [ - 'normal', 'nowrap', 'pre', 'pre-line', 'pre-wrap', 'inherit' - ], - width: [cssLength, 'auto'], - 'word-spacing': ['normal', cssLength], - 'word-wrap': ['break-word', 'normal'], - 'z-index': ['auto', cssNumber] - }; - - function styleAttribute() { - var v; - while (nexttoken.id === '*' || nexttoken.id === '#' || - nexttoken.value === '_') { - if (!option.css) { - warning("Unexpected '{a}'.", nexttoken, nexttoken.value); - } - advance(); - } - if (nexttoken.id === '-') { - if (!option.css) { - warning("Unexpected '{a}'.", nexttoken, nexttoken.value); - } - advance('-'); - if (!nexttoken.identifier) { - warning( -"Expected a non-standard style attribute and instead saw '{a}'.", - nexttoken, nexttoken.value); - } - advance(); - return cssAny; - } else { - if (!nexttoken.identifier) { - warning("Excepted a style attribute, and instead saw '{a}'.", - nexttoken, nexttoken.value); - } else { - if (is_own(cssAttributeData, nexttoken.value)) { - v = cssAttributeData[nexttoken.value]; - } else { - v = cssAny; - if (!option.css) { - warning("Unrecognized style attribute '{a}'.", - nexttoken, nexttoken.value); - } - } - } - advance(); - return v; - } - } - - function styleValue(v) { - var i = 0, - n, - once, - match, - round, - start = 0, - vi; - switch (typeof v) { - case 'function': - return v(); - case 'string': - if (nexttoken.identifier && nexttoken.value === v) { - advance(); - return true; - } - return false; - } - for (;;) { - if (i >= v.length) { - return false; - } - vi = v[i]; - i += 1; - if (vi === true) { - break; - } else if (typeof vi === 'number') { - n = vi; - vi = v[i]; - i += 1; - } else { - n = 1; - } - match = false; - while (n > 0) { - if (styleValue(vi)) { - match = true; - n -= 1; - } else { - break; - } - } - if (match) { - return true; - } - } - start = i; - once = []; - for (;;) { - round = false; - for (i = start; i < v.length; i += 1) { - if (!once[i]) { - if (styleValue(cssAttributeData[v[i]])) { - match = true; - round = true; - once[i] = true; - break; - } - } - } - if (!round) { - return match; - } - } - } - - function styleChild() { - if (nexttoken.id === '(number)') { - advance(); - if (nexttoken.value === 'n' && nexttoken.identifier) { - adjacent(); - advance(); - if (nexttoken.id === '+') { - adjacent(); - advance('+'); - adjacent(); - advance('(number)'); - } - } - return; - } else { - switch (nexttoken.value) { - case 'odd': - case 'even': - if (nexttoken.identifier) { - advance(); - return; - } - } - } - warning("Unexpected token '{a}'.", nexttoken, nexttoken.value); - } - - function substyle() { - var v; - for (;;) { - if (nexttoken.id === '}' || nexttoken.id === '(end)' || - xquote && nexttoken.id === xquote) { - return; - } - while (nexttoken.id === ';') { - warning("Misplaced ';'."); - advance(';'); - } - v = styleAttribute(); - advance(':'); - if (nexttoken.identifier && nexttoken.value === 'inherit') { - advance(); - } else { - if (!styleValue(v)) { - warning("Unexpected token '{a}'.", nexttoken, - nexttoken.value); - advance(); - } - } - if (nexttoken.id === '!') { - advance('!'); - adjacent(); - if (nexttoken.identifier && nexttoken.value === 'important') { - advance(); - } else { - warning("Expected '{a}' and instead saw '{b}'.", - nexttoken, 'important', nexttoken.value); - } - } - if (nexttoken.id === '}' || nexttoken.id === xquote) { - warning("Missing '{a}'.", nexttoken, ';'); - } else { - advance(';'); - } - } - } - - function styleSelector() { - if (nexttoken.identifier) { - if (!is_own(htmltag, nexttoken.value)) { - warning("Expected a tagName, and instead saw {a}.", - nexttoken, nexttoken.value); - } - advance(); - } else { - switch (nexttoken.id) { - case '>': - case '+': - advance(); - styleSelector(); - break; - case ':': - advance(':'); - switch (nexttoken.value) { - case 'active': - case 'after': - case 'before': - case 'checked': - case 'disabled': - case 'empty': - case 'enabled': - case 'first-child': - case 'first-letter': - case 'first-line': - case 'first-of-type': - case 'focus': - case 'hover': - case 'last-of-type': - case 'link': - case 'only-of-type': - case 'root': - case 'target': - case 'visited': - advance(); - break; - case 'lang': - advance(); - advance('('); - if (!nexttoken.identifier) { - warning("Expected a lang code, and instead saw :{a}.", - nexttoken, nexttoken.value); - } - advance(')'); - break; - case 'nth-child': - case 'nth-last-child': - case 'nth-last-of-type': - case 'nth-of-type': - advance(); - advance('('); - styleChild(); - advance(')'); - break; - case 'not': - advance(); - advance('('); - if (nexttoken.id === ':' && peek(0).value === 'not') { - warning("Nested not."); - } - styleSelector(); - advance(')'); - break; - default: - warning("Expected a pseudo, and instead saw :{a}.", - nexttoken, nexttoken.value); - } - break; - case '#': - advance('#'); - if (!nexttoken.identifier) { - warning("Expected an id, and instead saw #{a}.", - nexttoken, nexttoken.value); - } - advance(); - break; - case '*': - advance('*'); - break; - case '.': - advance('.'); - if (!nexttoken.identifier) { - warning("Expected a class, and instead saw #.{a}.", - nexttoken, nexttoken.value); - } - advance(); - break; - case '[': - advance('['); - if (!nexttoken.identifier) { - warning("Expected an attribute, and instead saw [{a}].", - nexttoken, nexttoken.value); - } - advance(); - if (nexttoken.id === '=' || nexttoken.value === '~=' || - nexttoken.value === '$=' || - nexttoken.value === '|=' || - nexttoken.id === '*=' || - nexttoken.id === '^=') { - advance(); - if (nexttoken.type !== '(string)') { - warning("Expected a string, and instead saw {a}.", - nexttoken, nexttoken.value); - } - advance(); - } - advance(']'); - break; - default: - error("Expected a CSS selector, and instead saw {a}.", - nexttoken, nexttoken.value); - } - } - } - - function stylePattern() { - var name; - if (nexttoken.id === '{') { - warning("Expected a style pattern, and instead saw '{a}'.", nexttoken, - nexttoken.id); - } else if (nexttoken.id === '@') { - advance('@'); - name = nexttoken.value; - if (nexttoken.identifier && atrule[name] === true) { - advance(); - return name; - } - warning("Expected an at-rule, and instead saw @{a}.", nexttoken, name); - } - for (;;) { - styleSelector(); - if (nexttoken.id === ' fragments and .js files.", token); - } - if (option.fragment) { - if (n !== 'div') { - error("ADsafe violation: Wrap the widget in a div.", token); - } - } else { - error("Use the fragment option.", token); - } - } - option.browser = true; - assume(); - } - - function doAttribute(n, a, v) { - var u, x; - if (a === 'id') { - u = typeof v === 'string' ? v.toUpperCase() : ''; - if (ids[u] === true) { - warning("Duplicate id='{a}'.", nexttoken, v); - } - if (!/^[A-Za-z][A-Za-z0-9._:\-]*$/.test(v)) { - warning("Bad id: '{a}'.", nexttoken, v); - } else if (option.adsafe) { - if (adsafe_id) { - if (v.slice(0, adsafe_id.length) !== adsafe_id) { - warning("ADsafe violation: An id must have a '{a}' prefix", - nexttoken, adsafe_id); - } else if (!/^[A-Z]+_[A-Z]+$/.test(v)) { - warning("ADSAFE violation: bad id."); - } - } else { - adsafe_id = v; - if (!/^[A-Z]+_$/.test(v)) { - warning("ADSAFE violation: bad id."); - } - } - } - x = v.search(dx); - if (x >= 0) { - warning("Unexpected character '{a}' in {b}.", token, v.charAt(x), a); - } - ids[u] = true; - } else if (a === 'class' || a === 'type' || a === 'name') { - x = v.search(qx); - if (x >= 0) { - warning("Unexpected character '{a}' in {b}.", token, v.charAt(x), a); - } - ids[u] = true; - } else if (a === 'href' || a === 'background' || - a === 'content' || a === 'data' || - a.indexOf('src') >= 0 || a.indexOf('url') >= 0) { - if (option.safe && ux.test(v)) { - error("ADsafe URL violation."); - } - urls.push(v); - } else if (a === 'for') { - if (option.adsafe) { - if (adsafe_id) { - if (v.slice(0, adsafe_id.length) !== adsafe_id) { - warning("ADsafe violation: An id must have a '{a}' prefix", - nexttoken, adsafe_id); - } else if (!/^[A-Z]+_[A-Z]+$/.test(v)) { - warning("ADSAFE violation: bad id."); - } - } else { - warning("ADSAFE violation: bad id."); - } - } - } else if (a === 'name') { - if (option.adsafe && v.indexOf('_') >= 0) { - warning("ADsafe name violation."); - } - } - } - - function doTag(n, a) { - var i, t = htmltag[n], x; - src = false; - if (!t) { - error("Unrecognized tag '<{a}>'.", - nexttoken, - n === n.toLowerCase() ? n : - n + ' (capitalization error)'); - } - if (stack.length > 0) { - if (n === 'html') { - error("Too many tags.", token); - } - x = t.parent; - if (x) { - if (x.indexOf(' ' + stack[stack.length - 1].name + ' ') < 0) { - error("A '<{a}>' must be within '<{b}>'.", - token, n, x); - } - } else if (!option.adsafe && !option.fragment) { - i = stack.length; - do { - if (i <= 0) { - error("A '<{a}>' must be within '<{b}>'.", - token, n, 'body'); - } - i -= 1; - } while (stack[i].name !== 'body'); - } - } - switch (n) { - case 'div': - if (option.adsafe && stack.length === 1 && !adsafe_id) { - warning("ADSAFE violation: missing ID_."); - } - break; - case 'script': - xmode = 'script'; - advance('>'); - indent = nexttoken.from; - if (a.lang) { - warning("lang is deprecated.", token); - } - if (option.adsafe && stack.length !== 1) { - warning("ADsafe script placement violation.", token); - } - if (a.src) { - if (option.adsafe && (!adsafe_may || !approved[a.src])) { - warning("ADsafe unapproved script source.", token); - } - if (a.type) { - warning("type is unnecessary.", token); - } - } else { - if (adsafe_went) { - error("ADsafe script violation.", token); - } - statements('script'); - } - xmode = 'html'; - advance(''); - styles(); - xmode = 'html'; - advance(''; - } - - function html() { - var a, attributes, e, n, q, t, v, w = option.white, wmode; - xmode = 'html'; - xquote = ''; - stack = null; - for (;;) { - switch (nexttoken.value) { - case '<': - xmode = 'html'; - advance('<'); - attributes = {}; - t = nexttoken; - if (!t.identifier) { - warning("Bad identifier {a}.", t, t.value); - } - n = t.value; - if (option.cap) { - n = n.toLowerCase(); - } - t.name = n; - advance(); - if (!stack) { - stack = []; - doBegin(n); - } - v = htmltag[n]; - if (typeof v !== 'object') { - error("Unrecognized tag '<{a}>'.", t, n); - } - e = v.empty; - t.type = n; - for (;;) { - if (nexttoken.id === '/') { - advance('/'); - if (nexttoken.id !== '>') { - warning("Expected '{a}' and instead saw '{b}'.", - nexttoken, '>', nexttoken.value); - } - break; - } - if (nexttoken.id && nexttoken.id.substr(0, 1) === '>') { - break; - } - if (!nexttoken.identifier) { - if (nexttoken.id === '(end)' || nexttoken.id === '(error)') { - error("Missing '>'.", nexttoken); - } - warning("Bad identifier."); - } - option.white = true; - nonadjacent(token, nexttoken); - a = nexttoken.value; - option.white = w; - advance(); - if (!option.cap && a !== a.toLowerCase()) { - warning("Attribute '{a}' not all lower case.", nexttoken, a); - } - a = a.toLowerCase(); - xquote = ''; - if (is_own(attributes, a)) { - warning("Attribute '{a}' repeated.", nexttoken, a); - } - if (a.slice(0, 2) === 'on') { - if (!option.on) { - warning("Avoid HTML event handlers."); - } - xmode = 'scriptstring'; - advance('='); - q = nexttoken.id; - if (q !== '"' && q !== "'") { - error("Missing quote."); - } - xquote = q; - wmode = option.white; - option.white = false; - advance(q); - statements('on'); - option.white = wmode; - if (nexttoken.id !== q) { - error("Missing close quote on script attribute."); - } - xmode = 'html'; - xquote = ''; - advance(q); - v = false; - } else if (a === 'style') { - xmode = 'scriptstring'; - advance('='); - q = nexttoken.id; - if (q !== '"' && q !== "'") { - error("Missing quote."); - } - xmode = 'styleproperty'; - xquote = q; - advance(q); - substyle(); - xmode = 'html'; - xquote = ''; - advance(q); - v = false; - } else { - if (nexttoken.id === '=') { - advance('='); - v = nexttoken.value; - if (!nexttoken.identifier && - nexttoken.id !== '"' && - nexttoken.id !== '\'' && - nexttoken.type !== '(string)' && - nexttoken.type !== '(number)' && - nexttoken.type !== '(color)') { - warning("Expected an attribute value and instead saw '{a}'.", token, a); - } - advance(); - } else { - v = true; - } - } - attributes[a] = v; - doAttribute(n, a, v); - } - doTag(n, attributes); - if (!e) { - stack.push(t); - } - xmode = 'outer'; - advance('>'); - break; - case '') { - error("Missing '{a}'.", nexttoken, '>'); - } - xmode = 'outer'; - advance('>'); - break; - case '' || nexttoken.id === '(end)') { - break; - } - if (nexttoken.value.indexOf('--') >= 0) { - warning("Unexpected --."); - } - if (nexttoken.value.indexOf('<') >= 0) { - warning("Unexpected <."); - } - if (nexttoken.value.indexOf('>') >= 0) { - warning("Unexpected >."); - } - } - xmode = 'outer'; - advance('>'); - break; - case '(end)': - return; - default: - if (nexttoken.id === '(end)') { - error("Missing '{a}'.", nexttoken, - ''); - } else { - advance(); - } - } - if (stack && stack.length === 0 && (option.adsafe || - !option.fragment || nexttoken.id === '(end)')) { - break; - } - } - if (nexttoken.id !== '(end)') { - error("Unexpected material after the end."); - } - } - - -// Build the syntax table by declaring the syntactic elements of the language. - - type('(number)', idValue); - type('(string)', idValue); - - syntax['(identifier)'] = { - type: '(identifier)', - lbp: 0, - identifier: true, - nud: function () { - var v = this.value, - s = scope[v], - f; - if (typeof s === 'function') { - s = undefined; - } else if (typeof s === 'boolean') { - f = funct; - funct = functions[0]; - addlabel(v, 'var'); - s = funct; - funct = f; - } - -// The name is in scope and defined in the current function. - - if (funct === s) { - -// Change 'unused' to 'var', and reject labels. - - switch (funct[v]) { - case 'unused': - funct[v] = 'var'; - break; - case 'label': - warning("'{a}' is a statement label.", token, v); - break; - } - -// The name is not defined in the function. If we are in the global scope, -// then we have an undefined variable. - - } else if (funct['(global)']) { - if (option.undef && predefined[v] !== 'boolean') { - warning("'{a}' is not defined.", token, v); - } - note_implied(token); - -// If the name is already defined in the current -// function, but not as outer, then there is a scope error. - - } else { - switch (funct[v]) { - case 'closure': - case 'function': - case 'var': - case 'unused': - warning("'{a}' used out of scope.", token, v); - break; - case 'label': - warning("'{a}' is a statement label.", token, v); - break; - case 'outer': - case 'global': - break; - default: - -// If the name is defined in an outer function, make an outer entry, and if -// it was unused, make it var. - - if (s === true) { - funct[v] = true; - } else if (s === null) { - warning("'{a}' is not allowed.", token, v); - note_implied(token); - } else if (typeof s !== 'object') { - if (option.undef) { - warning("'{a}' is not defined.", token, v); - } else { - funct[v] = true; - } - note_implied(token); - } else { - switch (s[v]) { - case 'function': - case 'var': - case 'unused': - s[v] = 'closure'; - funct[v] = s['(global)'] ? 'global' : 'outer'; - break; - case 'closure': - case 'parameter': - funct[v] = s['(global)'] ? 'global' : 'outer'; - break; - case 'label': - warning("'{a}' is a statement label.", token, v); - } - } - } - } - return this; - }, - led: function () { - error("Expected an operator and instead saw '{a}'.", - nexttoken, nexttoken.value); - } - }; - - type('(regexp)', function () { - return this; - }); - - delim('(endline)'); - delim('(begin)'); - delim('(end)').reach = true; - delim(''); - delim('(error)').reach = true; - delim('}').reach = true; - delim(')'); - delim(']'); - delim('"').reach = true; - delim("'").reach = true; - delim(';'); - delim(':').reach = true; - delim(','); - delim('#'); - delim('@'); - reserve('else'); - reserve('case').reach = true; - reserve('catch'); - reserve('default').reach = true; - reserve('finally'); - reservevar('arguments'); - reservevar('eval'); - reservevar('false'); - reservevar('Infinity'); - reservevar('NaN'); - reservevar('null'); - reservevar('this'); - reservevar('true'); - reservevar('undefined'); - assignop('=', 'assign', 20); - assignop('+=', 'assignadd', 20); - assignop('-=', 'assignsub', 20); - assignop('*=', 'assignmult', 20); - assignop('/=', 'assigndiv', 20).nud = function () { - error("A regular expression literal can be confused with '/='."); - }; - assignop('%=', 'assignmod', 20); - bitwiseassignop('&=', 'assignbitand', 20); - bitwiseassignop('|=', 'assignbitor', 20); - bitwiseassignop('^=', 'assignbitxor', 20); - bitwiseassignop('<<=', 'assignshiftleft', 20); - bitwiseassignop('>>=', 'assignshiftright', 20); - bitwiseassignop('>>>=', 'assignshiftrightunsigned', 20); - infix('?', function (left, that) { - that.left = left; - that.right = parse(10); - advance(':'); - that['else'] = parse(10); - return that; - }, 30); - - infix('||', 'or', 40); - infix('&&', 'and', 50); - bitwise('|', 'bitor', 70); - bitwise('^', 'bitxor', 80); - bitwise('&', 'bitand', 90); - relation('==', function (left, right) { - if (option.eqeqeq) { - warning("Expected '{a}' and instead saw '{b}'.", - this, '===', '=='); - } else if (isPoorRelation(left)) { - warning("Use '{a}' to compare with '{b}'.", - this, '===', left.value); - } else if (isPoorRelation(right)) { - warning("Use '{a}' to compare with '{b}'.", - this, '===', right.value); - } - return this; - }); - relation('==='); - relation('!=', function (left, right) { - if (option.eqeqeq) { - warning("Expected '{a}' and instead saw '{b}'.", - this, '!==', '!='); - } else if (isPoorRelation(left)) { - warning("Use '{a}' to compare with '{b}'.", - this, '!==', left.value); - } else if (isPoorRelation(right)) { - warning("Use '{a}' to compare with '{b}'.", - this, '!==', right.value); - } - return this; - }); - relation('!=='); - relation('<'); - relation('>'); - relation('<='); - relation('>='); - bitwise('<<', 'shiftleft', 120); - bitwise('>>', 'shiftright', 120); - bitwise('>>>', 'shiftrightunsigned', 120); - infix('in', 'in', 120); - infix('instanceof', 'instanceof', 120); - infix('+', function (left, that) { - var right = parse(130); - if (left && right && left.id === '(string)' && right.id === '(string)') { - left.value += right.value; - left.character = right.character; - if (jx.test(left.value)) { - warning("JavaScript URL.", left); - } - return left; - } - that.left = left; - that.right = right; - return that; - }, 130); - prefix('+', 'num'); - infix('-', 'sub', 130); - prefix('-', 'neg'); - infix('*', 'mult', 140); - infix('/', 'div', 140); - infix('%', 'mod', 140); - - suffix('++', 'postinc'); - prefix('++', 'preinc'); - syntax['++'].exps = true; - - suffix('--', 'postdec'); - prefix('--', 'predec'); - syntax['--'].exps = true; - prefix('delete', function () { - var p = parse(0); - if (!p || (p.id !== '.' && p.id !== '[')) { - warning("Expected '{a}' and instead saw '{b}'.", - nexttoken, '.', nexttoken.value); - } - this.first = p; - return this; - }).exps = true; - - - prefix('~', function () { - if (option.bitwise) { - warning("Unexpected '{a}'.", this, '~'); - } - parse(150); - return this; - }); - prefix('!', function () { - this.right = parse(150); - this.arity = 'unary'; - if (bang[this.right.id] === true) { - warning("Confusing use of '{a}'.", this, '!'); - } - return this; - }); - prefix('typeof', 'typeof'); - prefix('new', function () { - var c = parse(155), i; - if (c && c.id !== 'function') { - if (c.identifier) { - c['new'] = true; - switch (c.value) { - case 'Object': - warning("Use the object literal notation {}.", token); - break; - case 'Array': - if (nexttoken.id !== '(') { - warning("Use the array literal notation [].", token); - } else { - advance('('); - if (nexttoken.id === ')') { - warning("Use the array literal notation [].", token); - } else { - i = parse(0); - c.dimension = i; - if ((i.id === '(number)' && /[.+\-Ee]/.test(i.value)) || - (i.id === '-' && !i.right) || - i.id === '(string)' || i.id === '[' || - i.id === '{' || i.id === 'true' || - i.id === 'false' || - i.id === 'null' || i.id === 'undefined' || - i.id === 'Infinity') { - warning("Use the array literal notation [].", token); - } - if (nexttoken.id !== ')') { - error("Use the array literal notation [].", token); - } - } - advance(')'); - } - this.first = c; - return this; - case 'Number': - case 'String': - case 'Boolean': - case 'Math': - case 'JSON': - warning("Do not use {a} as a constructor.", token, c.value); - break; - case 'Function': - if (!option.evil) { - warning("The Function constructor is eval."); - } - break; - case 'Date': - case 'RegExp': - break; - default: - if (c.id !== 'function') { - i = c.value.substr(0, 1); - if (option.newcap && (i < 'A' || i > 'Z')) { - warning( - "A constructor name should start with an uppercase letter.", - token); - } - } - } - } else { - if (c.id !== '.' && c.id !== '[' && c.id !== '(') { - warning("Bad constructor.", token); - } - } - } else { - warning("Weird construction. Delete 'new'.", this); - } - adjacent(token, nexttoken); - if (nexttoken.id !== '(') { - warning("Missing '()' invoking a constructor."); - } - this.first = c; - return this; - }); - syntax['new'].exps = true; - - infix('.', function (left, that) { - adjacent(prevtoken, token); - var m = identifier(); - if (typeof m === 'string') { - countMember(m); - } - that.left = left; - that.right = m; - if (!option.evil && left && left.value === 'document' && - (m === 'write' || m === 'writeln')) { - warning("document.write can be a form of eval.", left); - } else if (option.adsafe) { - if (left && left.value === 'ADSAFE') { - if (m === 'id' || m === 'lib') { - warning("ADsafe violation.", that); - } else if (m === 'go') { - if (xmode !== 'script') { - warning("ADsafe violation.", that); - } else if (adsafe_went || nexttoken.id !== '(' || - peek(0).id !== '(string)' || - peek(0).value !== adsafe_id || - peek(1).id !== ',') { - error("ADsafe violation: go.", that); - } - adsafe_went = true; - adsafe_may = false; - } - } - } - if (!option.evil && (m === 'eval' || m === 'execScript')) { - warning('eval is evil.'); - } else if (option.safe) { - for (;;) { - if (banned[m] === true) { - warning("ADsafe restricted word '{a}'.", token, m); - } - if (typeof predefined[left.value] !== 'boolean' || - nexttoken.id === '(') { - break; - } - if (standard_member[m] === true) { - if (nexttoken.id === '.') { - warning("ADsafe violation.", that); - } - break; - } - if (nexttoken.id !== '.') { - warning("ADsafe violation.", that); - break; - } - advance('.'); - token.left = that; - token.right = m; - that = token; - m = identifier(); - if (typeof m === 'string') { - countMember(m); - } - } - } - return that; - }, 160, true); - - infix('(', function (left, that) { - adjacent(prevtoken, token); - nospace(); - var n = 0, - p = []; - if (left) { - if (left.type === '(identifier)') { - if (left.value.match(/^[A-Z]([A-Z0-9_$]*[a-z][A-Za-z0-9_$]*)?$/)) { - if (left.value !== 'Number' && left.value !== 'String' && - left.value !== 'Boolean' && - left.value !== 'Date') { - if (left.value === 'Math') { - warning("Math is not a function.", left); - } else if (option.newcap) { - warning( -"Missing 'new' prefix when invoking a constructor.", left); - } - } - } - } else if (left.id === '.') { - if (option.safe && left.left.value === 'Math' && - left.right === 'random') { - warning("ADsafe violation.", left); - } - } - } - if (nexttoken.id !== ')') { - for (;;) { - p[p.length] = parse(10); - n += 1; - if (nexttoken.id !== ',') { - break; - } - comma(); - } - } - advance(')'); - if (option.immed && left.id === 'function' && nexttoken.id !== ')') { - warning("Wrap the entire immediate function invocation in parens.", - that); - } - nospace(prevtoken, token); - if (typeof left === 'object') { - if (left.value === 'parseInt' && n === 1) { - warning("Missing radix parameter.", left); - } - if (!option.evil) { - if (left.value === 'eval' || left.value === 'Function' || - left.value === 'execScript') { - warning("eval is evil.", left); - } else if (p[0] && p[0].id === '(string)' && - (left.value === 'setTimeout' || - left.value === 'setInterval')) { - warning( - "Implied eval is evil. Pass a function instead of a string.", left); - } - } - if (!left.identifier && left.id !== '.' && left.id !== '[' && - left.id !== '(' && left.id !== '&&' && left.id !== '||' && - left.id !== '?') { - warning("Bad invocation.", left); - } - } - that.left = left; - return that; - }, 155, true).exps = true; - - prefix('(', function () { - nospace(); - var v = parse(0); - advance(')', this); - nospace(prevtoken, token); - if (option.immed && v.id === 'function') { - if (nexttoken.id === '(') { - warning( -"Move the invocation into the parens that contain the function.", nexttoken); - } else { - warning( -"Do not wrap function literals in parens unless they are to be immediately invoked.", - this); - } - } - return v; - }); - - infix('[', function (left, that) { - nospace(); - var e = parse(0), s; - if (e && e.type === '(string)') { - if (option.safe && banned[e.value] === true) { - warning("ADsafe restricted word '{a}'.", that, e.value); - } else if (!option.evil && - (e.value === 'eval' || e.value === 'execScript')) { - warning("eval is evil.", that); - } else if (option.safe && - (e.value.charAt(0) === '_' || e.value.charAt(0) === '-')) { - warning("ADsafe restricted subscript '{a}'.", that, e.value); - } - countMember(e.value); - if (!option.sub && ix.test(e.value)) { - s = syntax[e.value]; - if (!s || !s.reserved) { - warning("['{a}'] is better written in dot notation.", - e, e.value); - } - } - } else if (!e || e.type !== '(number)' || e.value < 0) { - if (option.safe) { - warning('ADsafe subscripting.'); - } - } - advance(']', that); - nospace(prevtoken, token); - that.left = left; - that.right = e; - return that; - }, 160, true); - - prefix('[', function () { - var b = token.line !== nexttoken.line; - this.first = []; - if (b) { - indent += option.indent; - if (nexttoken.from === indent + option.indent) { - indent += option.indent; - } - } - while (nexttoken.id !== '(end)') { - while (nexttoken.id === ',') { - warning("Extra comma."); - advance(','); - } - if (nexttoken.id === ']') { - break; - } - if (b && token.line !== nexttoken.line) { - indentation(); - } - this.first.push(parse(10)); - if (nexttoken.id === ',') { - comma(); - if (nexttoken.id === ']') { - warning("Extra comma.", token); - break; - } - } else { - break; - } - } - if (b) { - indent -= option.indent; - indentation(); - } - advance(']', this); - return this; - }, 160); - - (function (x) { - x.nud = function () { - var b, i, s, seen = {}; - b = token.line !== nexttoken.line; - if (b) { - indent += option.indent; - if (nexttoken.from === indent + option.indent) { - indent += option.indent; - } - } - for (;;) { - if (nexttoken.id === '}') { - break; - } - if (b) { - indentation(); - } - i = optionalidentifier(true); - if (!i) { - if (nexttoken.id === '(string)') { - i = nexttoken.value; - if (ix.test(i)) { - s = syntax[i]; - } - advance(); - } else if (nexttoken.id === '(number)') { - i = nexttoken.value.toString(); - advance(); - } else { - error("Expected '{a}' and instead saw '{b}'.", - nexttoken, '}', nexttoken.value); - } - } - if (seen[i] === true) { - warning("Duplicate member '{a}'.", nexttoken, i); - } - seen[i] = true; - countMember(i); - advance(':'); - nonadjacent(token, nexttoken); - parse(10); - if (nexttoken.id === ',') { - comma(); - if (nexttoken.id === ',' || nexttoken.id === '}') { - warning("Extra comma.", token); - } - } else { - break; - } - } - if (b) { - indent -= option.indent; - indentation(); - } - advance('}', this); - return this; - }; - x.fud = function () { - error("Expected to see a statement and instead saw a block.", token); - }; - }(delim('{'))); - - - function varstatement(prefix) { - -// JavaScript does not have block scope. It only has function scope. So, -// declaring a variable in a block can have unexpected consequences. - - var id, name, value; - - if (funct['(onevar)'] && option.onevar) { - warning("Too many var statements."); - } else if (!funct['(global)']) { - funct['(onevar)'] = true; - } - this.first = []; - for (;;) { - nonadjacent(token, nexttoken); - id = identifier(); - if (funct['(global)'] && predefined[id] === false) { - warning("Redefinition of '{a}'.", token, id); - } - addlabel(id, 'unused'); - if (prefix) { - break; - } - name = token; - this.first.push(token); - if (nexttoken.id === '=') { - nonadjacent(token, nexttoken); - advance('='); - nonadjacent(token, nexttoken); - if (nexttoken.id === 'undefined') { - warning("It is not necessary to initialize '{a}' to 'undefined'.", token, id); - } - if (peek(0).id === '=' && nexttoken.identifier) { - error("Variable {a} was not declared correctly.", - nexttoken, nexttoken.value); - } - value = parse(0); - name.first = value; - } - if (nexttoken.id !== ',') { - break; - } - comma(); - } - return this; - } - - - stmt('var', varstatement).exps = true; - - - function functionparams() { - var i, t = nexttoken, p = []; - advance('('); - nospace(); - if (nexttoken.id === ')') { - advance(')'); - nospace(prevtoken, token); - return; - } - for (;;) { - i = identifier(); - p.push(i); - addlabel(i, 'parameter'); - if (nexttoken.id === ',') { - comma(); - } else { - advance(')', t); - nospace(prevtoken, token); - return p; - } - } - } - - function doFunction(i) { - var s = scope; - scope = Object.create(s); - funct = { - '(name)' : i || '"' + anonname + '"', - '(line)' : nexttoken.line, - '(context)' : funct, - '(breakage)': 0, - '(loopage)' : 0, - '(scope)' : scope - }; - token.funct = funct; - functions.push(funct); - if (i) { - addlabel(i, 'function'); - } - funct['(params)'] = functionparams(); - - block(false); - scope = s; - funct['(last)'] = token.line; - funct = funct['(context)']; - } - - - blockstmt('function', function () { - if (inblock) { - warning( -"Function statements cannot be placed in blocks. Use a function expression or move the statement to the top of the outer function.", token); - - } - var i = identifier(); - adjacent(token, nexttoken); - addlabel(i, 'unused'); - doFunction(i); - if (nexttoken.id === '(' && nexttoken.line === token.line) { - error( -"Function statements are not invocable. Wrap the whole function invocation in parens."); - } - return this; - }); - - prefix('function', function () { - var i = optionalidentifier(); - if (i) { - adjacent(token, nexttoken); - } else { - nonadjacent(token, nexttoken); - } - doFunction(i); - if (funct['(loopage)']) { - warning("Don't make functions within a loop."); - } - return this; - }); - - blockstmt('if', function () { - var t = nexttoken; - advance('('); - nonadjacent(this, t); - nospace(); - parse(20); - if (nexttoken.id === '=') { - warning("Expected a conditional expression and instead saw an assignment."); - advance('='); - parse(20); - } - advance(')', t); - nospace(prevtoken, token); - block(true); - if (nexttoken.id === 'else') { - nonadjacent(token, nexttoken); - advance('else'); - if (nexttoken.id === 'if' || nexttoken.id === 'switch') { - statement(true); - } else { - block(true); - } - } - return this; - }); - - blockstmt('try', function () { - var b, e, s; - if (option.adsafe) { - warning("ADsafe try violation.", this); - } - block(false); - if (nexttoken.id === 'catch') { - advance('catch'); - nonadjacent(token, nexttoken); - advance('('); - s = scope; - scope = Object.create(s); - e = nexttoken.value; - if (nexttoken.type !== '(identifier)') { - warning("Expected an identifier and instead saw '{a}'.", - nexttoken, e); - } else { - addlabel(e, 'exception'); - } - advance(); - advance(')'); - block(false); - b = true; - scope = s; - } - if (nexttoken.id === 'finally') { - advance('finally'); - block(false); - return; - } else if (!b) { - error("Expected '{a}' and instead saw '{b}'.", - nexttoken, 'catch', nexttoken.value); - } - return this; - }); - - blockstmt('while', function () { - var t = nexttoken; - funct['(breakage)'] += 1; - funct['(loopage)'] += 1; - advance('('); - nonadjacent(this, t); - nospace(); - parse(20); - if (nexttoken.id === '=') { - warning("Expected a conditional expression and instead saw an assignment."); - advance('='); - parse(20); - } - advance(')', t); - nospace(prevtoken, token); - block(true); - funct['(breakage)'] -= 1; - funct['(loopage)'] -= 1; - return this; - }).labelled = true; - - reserve('with'); - - blockstmt('switch', function () { - var t = nexttoken, - g = false; - funct['(breakage)'] += 1; - advance('('); - nonadjacent(this, t); - nospace(); - this.condition = parse(20); - advance(')', t); - nospace(prevtoken, token); - nonadjacent(token, nexttoken); - t = nexttoken; - advance('{'); - nonadjacent(token, nexttoken); - indent += option.indent; - this.cases = []; - for (;;) { - switch (nexttoken.id) { - case 'case': - switch (funct['(verb)']) { - case 'break': - case 'case': - case 'continue': - case 'return': - case 'switch': - case 'throw': - break; - default: - warning( - "Expected a 'break' statement before 'case'.", - token); - } - indentation(-option.indent); - advance('case'); - this.cases.push(parse(20)); - g = true; - advance(':'); - funct['(verb)'] = 'case'; - break; - case 'default': - switch (funct['(verb)']) { - case 'break': - case 'continue': - case 'return': - case 'throw': - break; - default: - warning( - "Expected a 'break' statement before 'default'.", - token); - } - indentation(-option.indent); - advance('default'); - g = true; - advance(':'); - break; - case '}': - indent -= option.indent; - indentation(); - advance('}', t); - if (this.cases.length === 1 || this.condition.id === 'true' || - this.condition.id === 'false') { - warning("This 'switch' should be an 'if'.", this); - } - funct['(breakage)'] -= 1; - funct['(verb)'] = undefined; - return; - case '(end)': - error("Missing '{a}'.", nexttoken, '}'); - return; - default: - if (g) { - switch (token.id) { - case ',': - error("Each value should have its own case label."); - return; - case ':': - statements(); - break; - default: - error("Missing ':' on a case clause.", token); - } - } else { - error("Expected '{a}' and instead saw '{b}'.", - nexttoken, 'case', nexttoken.value); - } - } - } - }).labelled = true; - - stmt('debugger', function () { - if (!option.debug) { - warning("All 'debugger' statements should be removed."); - } - return this; - }).exps = true; - - (function () { - var x = stmt('do', function () { - funct['(breakage)'] += 1; - funct['(loopage)'] += 1; - this.first = block(true); - advance('while'); - var t = nexttoken; - nonadjacent(token, t); - advance('('); - nospace(); - parse(20); - if (nexttoken.id === '=') { - warning("Expected a conditional expression and instead saw an assignment."); - advance('='); - parse(20); - } - advance(')', t); - nospace(prevtoken, token); - funct['(breakage)'] -= 1; - funct['(loopage)'] -= 1; - return this; - }); - x.labelled = true; - x.exps = true; - }()); - - blockstmt('for', function () { - var f = option.forin, s, t = nexttoken; - funct['(breakage)'] += 1; - funct['(loopage)'] += 1; - advance('('); - nonadjacent(this, t); - nospace(); - if (peek(nexttoken.id === 'var' ? 1 : 0).id === 'in') { - if (nexttoken.id === 'var') { - advance('var'); - varstatement(true); - } else { - switch (funct[nexttoken.value]) { - case 'unused': - funct[nexttoken.value] = 'var'; - break; - case 'var': - break; - default: - warning("Bad for in variable '{a}'.", - nexttoken, nexttoken.value); - } - advance(); - } - advance('in'); - parse(20); - advance(')', t); - s = block(true); - if (!f && (s.length > 1 || typeof s[0] !== 'object' || - s[0].value !== 'if')) { - warning("The body of a for in should be wrapped in an if statement to filter unwanted properties from the prototype.", this); - } - funct['(breakage)'] -= 1; - funct['(loopage)'] -= 1; - return this; - } else { - if (nexttoken.id !== ';') { - if (nexttoken.id === 'var') { - advance('var'); - varstatement(); - } else { - for (;;) { - parse(0, 'for'); - if (nexttoken.id !== ',') { - break; - } - comma(); - } - } - } - nolinebreak(token); - advance(';'); - if (nexttoken.id !== ';') { - parse(20); - if (nexttoken.id === '=') { - warning("Expected a conditional expression and instead saw an assignment."); - advance('='); - parse(20); - } - } - nolinebreak(token); - advance(';'); - if (nexttoken.id === ';') { - error("Expected '{a}' and instead saw '{b}'.", - nexttoken, ')', ';'); - } - if (nexttoken.id !== ')') { - for (;;) { - parse(0, 'for'); - if (nexttoken.id !== ',') { - break; - } - comma(); - } - } - advance(')', t); - nospace(prevtoken, token); - block(true); - funct['(breakage)'] -= 1; - funct['(loopage)'] -= 1; - return this; - } - }).labelled = true; - - - stmt('break', function () { - var v = nexttoken.value; - if (funct['(breakage)'] === 0) { - warning("Unexpected '{a}'.", nexttoken, this.value); - } - nolinebreak(this); - if (nexttoken.id !== ';') { - if (token.line === nexttoken.line) { - if (funct[v] !== 'label') { - warning("'{a}' is not a statement label.", nexttoken, v); - } else if (scope[v] !== funct) { - warning("'{a}' is out of scope.", nexttoken, v); - } - this.first = nexttoken; - advance(); - } - } - reachable('break'); - return this; - }).exps = true; - - - stmt('continue', function () { - var v = nexttoken.value; - if (funct['(breakage)'] === 0) { - warning("Unexpected '{a}'.", nexttoken, this.value); - } - nolinebreak(this); - if (nexttoken.id !== ';') { - if (token.line === nexttoken.line) { - if (funct[v] !== 'label') { - warning("'{a}' is not a statement label.", nexttoken, v); - } else if (scope[v] !== funct) { - warning("'{a}' is out of scope.", nexttoken, v); - } - this.first = nexttoken; - advance(); - } - } else if (!funct['(loopage)']) { - warning("Unexpected '{a}'.", nexttoken, this.value); - } - reachable('continue'); - return this; - }).exps = true; - - - stmt('return', function () { - nolinebreak(this); - if (nexttoken.id === '(regexp)') { - warning("Wrap the /regexp/ literal in parens to disambiguate the slash operator."); - } - if (nexttoken.id !== ';' && !nexttoken.reach) { - nonadjacent(token, nexttoken); - this.first = parse(20); - } - reachable('return'); - return this; - }).exps = true; - - - stmt('throw', function () { - nolinebreak(this); - nonadjacent(token, nexttoken); - this.first = parse(20); - reachable('throw'); - return this; - }).exps = true; - - reserve('void'); - -// Superfluous reserved words - - reserve('class'); - reserve('const'); - reserve('enum'); - reserve('export'); - reserve('extends'); - reserve('import'); - reserve('super'); - - reserve('let'); - reserve('yield'); - reserve('implements'); - reserve('interface'); - reserve('package'); - reserve('private'); - reserve('protected'); - reserve('public'); - reserve('static'); - - function jsonValue() { - - function jsonObject() { - var o = {}, t = nexttoken; - advance('{'); - if (nexttoken.id !== '}') { - for (;;) { - if (nexttoken.id === '(end)') { - error("Missing '}' to match '{' from line {a}.", - nexttoken, t.line); - } else if (nexttoken.id === '}') { - warning("Unexpected comma.", token); - break; - } else if (nexttoken.id === ',') { - error("Unexpected comma.", nexttoken); - } else if (nexttoken.id !== '(string)') { - warning("Expected a string and instead saw {a}.", - nexttoken, nexttoken.value); - } - if (o[nexttoken.value] === true) { - warning("Duplicate key '{a}'.", - nexttoken, nexttoken.value); - } else if (nexttoken.value === '__proto__') { - warning("Stupid key '{a}'.", - nexttoken, nexttoken.value); - } else { - o[nexttoken.value] = true; - } - advance(); - advance(':'); - jsonValue(); - if (nexttoken.id !== ',') { - break; - } - advance(','); - } - } - advance('}'); - } - - function jsonArray() { - var t = nexttoken; - advance('['); - if (nexttoken.id !== ']') { - for (;;) { - if (nexttoken.id === '(end)') { - error("Missing ']' to match '[' from line {a}.", - nexttoken, t.line); - } else if (nexttoken.id === ']') { - warning("Unexpected comma.", token); - break; - } else if (nexttoken.id === ',') { - error("Unexpected comma.", nexttoken); - } - jsonValue(); - if (nexttoken.id !== ',') { - break; - } - advance(','); - } - } - advance(']'); - } - - switch (nexttoken.id) { - case '{': - jsonObject(); - break; - case '[': - jsonArray(); - break; - case 'true': - case 'false': - case 'null': - case '(number)': - case '(string)': - advance(); - break; - case '-': - advance('-'); - if (token.character !== nexttoken.from) { - warning("Unexpected space after '-'.", token); - } - adjacent(token, nexttoken); - advance('(number)'); - break; - default: - error("Expected a JSON value.", nexttoken); - } - } - - -// The actual JSLINT function itself. - - var itself = function (s, o) { - var a, i; - JSLINT.errors = []; - predefined = Object.create(standard); - if (o) { - a = o.predef; - if (a instanceof Array) { - for (i = 0; i < a.length; i += 1) { - predefined[a[i]] = true; - } - } - if (o.adsafe) { - o.safe = true; - } - if (o.safe) { - o.browser = false; - o.css = false; - o.debug = false; - o.devel = false; - o.eqeqeq = true; - o.evil = false; - o.forin = false; - o.nomen = true; - o.on = false; - o.rhino = false; - o.safe = true; - o.sidebar = false; - o.strict = true; - o.sub = false; - o.undef = true; - o.widget = false; - predefined.Date = null; - predefined['eval'] = null; - predefined.Function = null; - predefined.Object = null; - predefined.ADSAFE = false; - predefined.lib = false; - } - option = o; - } else { - option = {}; - } - option.indent = option.indent || 4; - option.maxerr = option.maxerr || 50; - adsafe_id = ''; - adsafe_may = false; - adsafe_went = false; - approved = {}; - if (option.approved) { - for (i = 0; i < option.approved.length; i += 1) { - approved[option.approved[i]] = option.approved[i]; - } - } else { - approved.test = 'test'; - } - tab = ''; - for (i = 0; i < option.indent; i += 1) { - tab += ' '; - } - indent = 1; - global = Object.create(predefined); - scope = global; - funct = { - '(global)': true, - '(name)': '(global)', - '(scope)': scope, - '(breakage)': 0, - '(loopage)': 0 - }; - functions = [funct]; - ids = {}; - urls = []; - src = false; - xmode = false; - stack = null; - member = {}; - membersOnly = null; - implied = {}; - inblock = false; - lookahead = []; - jsonmode = false; - warnings = 0; - lex.init(s); - prereg = true; - strict_mode = false; - - prevtoken = token = nexttoken = syntax['(begin)']; - assume(); - - try { - advance(); - if (nexttoken.value.charAt(0) === '<') { - html(); - if (option.adsafe && !adsafe_went) { - warning("ADsafe violation: Missing ADSAFE.go.", this); - } - } else { - switch (nexttoken.id) { - case '{': - case '[': - option.laxbreak = true; - jsonmode = true; - jsonValue(); - break; - case '@': - case '*': - case '#': - case '.': - case ':': - xmode = 'style'; - advance(); - if (token.id !== '@' || !nexttoken.identifier || - nexttoken.value !== 'charset' || token.line !== 1 || - token.from !== 1) { - error('A css file should begin with @charset "UTF-8";'); - } - advance(); - if (nexttoken.type !== '(string)' && - nexttoken.value !== 'UTF-8') { - error('A css file should begin with @charset "UTF-8";'); - } - advance(); - advance(';'); - styles(); - break; - - default: - if (option.adsafe && option.fragment) { - error("Expected '{a}' and instead saw '{b}'.", - nexttoken, '
', nexttoken.value); - } - statements('lib'); - } - } - advance('(end)'); - } catch (e) { - if (e) { - JSLINT.errors.push({ - reason : e.message, - line : e.line || nexttoken.line, - character : e.character || nexttoken.from - }, null); - } - } - return JSLINT.errors.length === 0; - }; - - function is_array(o) { - return Object.prototype.toString.apply(o) === '[object Array]'; - } - - function to_array(o) { - var a = [], k; - for (k in o) { - if (is_own(o, k)) { - a.push(k); - } - } - return a; - } - -// Data summary. - - itself.data = function () { - - var data = {functions: []}, fu, globals, implieds = [], f, i, j, - members = [], n, unused = [], v; - if (itself.errors.length) { - data.errors = itself.errors; - } - - if (jsonmode) { - data.json = true; - } - - for (n in implied) { - if (is_own(implied, n)) { - implieds.push({ - name: n, - line: implied[n] - }); - } - } - if (implieds.length > 0) { - data.implieds = implieds; - } - - if (urls.length > 0) { - data.urls = urls; - } - - globals = to_array(scope); - if (globals.length > 0) { - data.globals = globals; - } - - for (i = 1; i < functions.length; i += 1) { - f = functions[i]; - fu = {}; - for (j = 0; j < functionicity.length; j += 1) { - fu[functionicity[j]] = []; - } - for (n in f) { - if (is_own(f, n) && n.charAt(0) !== '(') { - v = f[n]; - if (is_array(fu[v])) { - fu[v].push(n); - if (v === 'unused') { - unused.push({ - name: n, - line: f['(line)'], - 'function': f['(name)'] - }); - } - } - } - } - for (j = 0; j < functionicity.length; j += 1) { - if (fu[functionicity[j]].length === 0) { - delete fu[functionicity[j]]; - } - } - fu.name = f['(name)']; - fu.param = f['(params)']; - fu.line = f['(line)']; - fu.last = f['(last)']; - data.functions.push(fu); - } - - if (unused.length > 0) { - data.unused = unused; - } - - members = []; - for (n in member) { - if (typeof member[n] === 'number') { - data.member = member; - break; - } - } - - return data; - }; - - itself.report = function (option) { - var data = itself.data(); - - var a = [], c, e, err, f, i, k, l, m = '', n, o = [], s; - - function detail(h, array) { - var b, i, singularity; - if (array) { - o.push('
' + h + ' '); - array = array.sort(); - for (i = 0; i < array.length; i += 1) { - if (array[i] !== singularity) { - singularity = array[i]; - o.push((b ? ', ' : '') + singularity); - b = true; - } - } - o.push('
'); - } - } - - - if (data.errors || data.implieds || data.unused) { - err = true; - o.push('
Error:'); - if (data.errors) { - for (i = 0; i < data.errors.length; i += 1) { - c = data.errors[i]; - if (c) { - e = c.evidence || ''; - o.push('

Problem' + (isFinite(c.line) ? ' at line ' + - c.line + ' character ' + c.character : '') + - ': ' + c.reason.entityify() + - '

' + - (e && (e.length > 80 ? e.slice(0, 77) + '...' : - e).entityify()) + '

'); - } - } - } - - if (data.implieds) { - s = []; - for (i = 0; i < data.implieds.length; i += 1) { - s[i] = '' + data.implieds[i].name + ' ' + - data.implieds[i].line + ''; - } - o.push('

Implied global: ' + s.join(', ') + '

'); - } - - if (data.unused) { - s = []; - for (i = 0; i < data.unused.length; i += 1) { - s[i] = '' + data.unused[i].name + ' ' + - data.unused[i].line + ' ' + - data.unused[i]['function'] + ''; - } - o.push('

Unused variable: ' + s.join(', ') + '

'); - } - if (data.json) { - o.push('

JSON: bad.

'); - } - o.push('
'); - } - - if (!option) { - - o.push('
'); - - if (data.urls) { - detail("URLs
", data.urls, '
'); - } - - if (xmode === 'style') { - o.push('

CSS.

'); - } else if (data.json && !err) { - o.push('

JSON: good.

'); - } else if (data.globals) { - o.push('
Global ' + - data.globals.sort().join(', ') + '
'); - } else { - o.push('
No new global variables introduced.
'); - } - - for (i = 0; i < data.functions.length; i += 1) { - f = data.functions[i]; - - o.push('
' + f.line + '-' + - f.last + ' ' + (f.name || '') + '(' + - (f.param ? f.param.join(', ') : '') + ')
'); - detail('Unused', f.unused); - detail('Closure', f.closure); - detail('Variable', f['var']); - detail('Exception', f.exception); - detail('Outer', f.outer); - detail('Global', f.global); - detail('Label', f.label); - } - - if (data.member) { - a = to_array(data.member); - if (a.length) { - a = a.sort(); - m = '
/*members ';
-                    l = 10;
-                    for (i = 0; i < a.length; i += 1) {
-                        k = a[i];
-                        n = k.name();
-                        if (l + n.length > 72) {
-                            o.push(m + '
'); - m = ' '; - l = 1; - } - l += n.length + 2; - if (data.member[k] === 1) { - n = '' + n + ''; - } - if (i < a.length - 1) { - n += ', '; - } - m += n; - } - o.push(m + '
*/
'); - } - o.push('
'); - } - } - return o.join(''); - }; - itself.jslint = itself; - - itself.edition = '2010-02-20'; - - if (typeof exports !== "undefined") { - exports.JSLINT = itself; - } - - return itself; - -}()); diff --git a/build/lib/parse-js.js b/build/lib/parse-js.js deleted file mode 100644 index 8edecb73..00000000 --- a/build/lib/parse-js.js +++ /dev/null @@ -1,1315 +0,0 @@ -/*********************************************************************** - - A JavaScript tokenizer / parser / beautifier / compressor. - - This version is suitable for Node.js. With minimal changes (the - exports stuff) it should work on any JS platform. - - This file contains the tokenizer/parser. It is a port to JavaScript - of parse-js [1], a JavaScript parser library written in Common Lisp - by Marijn Haverbeke. Thank you Marijn! - - [1] http://marijn.haverbeke.nl/parse-js/ - - Exported functions: - - - tokenizer(code) -- returns a function. Call the returned - function to fetch the next token. - - - parse(code) -- returns an AST of the given JavaScript code. - - -------------------------------- (C) --------------------------------- - - Author: Mihai Bazon - - http://mihai.bazon.net/blog - - Distributed under the BSD license: - - Copyright 2010 (c) Mihai Bazon - Based on parse-js (http://marijn.haverbeke.nl/parse-js/). - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - * Redistributions of source code must retain the above - copyright notice, this list of conditions and the following - disclaimer. - - * 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 HOLDER “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 HOLDER 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. - - ***********************************************************************/ - -/* -----[ Tokenizer (constants) ]----- */ - -var KEYWORDS = array_to_hash([ - "break", - "case", - "catch", - "const", - "continue", - "default", - "delete", - "do", - "else", - "finally", - "for", - "function", - "if", - "in", - "instanceof", - "new", - "return", - "switch", - "throw", - "try", - "typeof", - "var", - "void", - "while", - "with" -]); - -var RESERVED_WORDS = array_to_hash([ - "abstract", - "boolean", - "byte", - "char", - "class", - "debugger", - "double", - "enum", - "export", - "extends", - "final", - "float", - "goto", - "implements", - "import", - "int", - "interface", - "long", - "native", - "package", - "private", - "protected", - "public", - "short", - "static", - "super", - "synchronized", - "throws", - "transient", - "volatile" -]); - -var KEYWORDS_BEFORE_EXPRESSION = array_to_hash([ - "return", - "new", - "delete", - "throw", - "else", - "case" -]); - -var KEYWORDS_ATOM = array_to_hash([ - "false", - "null", - "true", - "undefined" -]); - -var OPERATOR_CHARS = array_to_hash(characters("+-*&%=<>!?|~^")); - -var RE_HEX_NUMBER = /^0x[0-9a-f]+$/i; -var RE_OCT_NUMBER = /^0[0-7]+$/; -var RE_DEC_NUMBER = /^\d*\.?\d*(?:e[+-]?\d*(?:\d\.?|\.?\d)\d*)?$/i; - -var OPERATORS = array_to_hash([ - "in", - "instanceof", - "typeof", - "new", - "void", - "delete", - "++", - "--", - "+", - "-", - "!", - "~", - "&", - "|", - "^", - "*", - "/", - "%", - ">>", - "<<", - ">>>", - "<", - ">", - "<=", - ">=", - "==", - "===", - "!=", - "!==", - "?", - "=", - "+=", - "-=", - "/=", - "*=", - "%=", - ">>=", - "<<=", - ">>>=", - "|=", - "^=", - "&=", - "&&", - "||" -]); - -var WHITESPACE_CHARS = array_to_hash(characters(" \n\r\t\u200b")); - -var PUNC_BEFORE_EXPRESSION = array_to_hash(characters("[{}(,.;:")); - -var PUNC_CHARS = array_to_hash(characters("[]{}(),;:")); - -var REGEXP_MODIFIERS = array_to_hash(characters("gmsiy")); - -/* -----[ Tokenizer ]----- */ - -// regexps adapted from http://xregexp.com/plugins/#unicode -var UNICODE = { - letter: new RegExp("[\\u0041-\\u005A\\u0061-\\u007A\\u00AA\\u00B5\\u00BA\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02C1\\u02C6-\\u02D1\\u02E0-\\u02E4\\u02EC\\u02EE\\u0370-\\u0374\\u0376\\u0377\\u037A-\\u037D\\u0386\\u0388-\\u038A\\u038C\\u038E-\\u03A1\\u03A3-\\u03F5\\u03F7-\\u0481\\u048A-\\u0523\\u0531-\\u0556\\u0559\\u0561-\\u0587\\u05D0-\\u05EA\\u05F0-\\u05F2\\u0621-\\u064A\\u066E\\u066F\\u0671-\\u06D3\\u06D5\\u06E5\\u06E6\\u06EE\\u06EF\\u06FA-\\u06FC\\u06FF\\u0710\\u0712-\\u072F\\u074D-\\u07A5\\u07B1\\u07CA-\\u07EA\\u07F4\\u07F5\\u07FA\\u0904-\\u0939\\u093D\\u0950\\u0958-\\u0961\\u0971\\u0972\\u097B-\\u097F\\u0985-\\u098C\\u098F\\u0990\\u0993-\\u09A8\\u09AA-\\u09B0\\u09B2\\u09B6-\\u09B9\\u09BD\\u09CE\\u09DC\\u09DD\\u09DF-\\u09E1\\u09F0\\u09F1\\u0A05-\\u0A0A\\u0A0F\\u0A10\\u0A13-\\u0A28\\u0A2A-\\u0A30\\u0A32\\u0A33\\u0A35\\u0A36\\u0A38\\u0A39\\u0A59-\\u0A5C\\u0A5E\\u0A72-\\u0A74\\u0A85-\\u0A8D\\u0A8F-\\u0A91\\u0A93-\\u0AA8\\u0AAA-\\u0AB0\\u0AB2\\u0AB3\\u0AB5-\\u0AB9\\u0ABD\\u0AD0\\u0AE0\\u0AE1\\u0B05-\\u0B0C\\u0B0F\\u0B10\\u0B13-\\u0B28\\u0B2A-\\u0B30\\u0B32\\u0B33\\u0B35-\\u0B39\\u0B3D\\u0B5C\\u0B5D\\u0B5F-\\u0B61\\u0B71\\u0B83\\u0B85-\\u0B8A\\u0B8E-\\u0B90\\u0B92-\\u0B95\\u0B99\\u0B9A\\u0B9C\\u0B9E\\u0B9F\\u0BA3\\u0BA4\\u0BA8-\\u0BAA\\u0BAE-\\u0BB9\\u0BD0\\u0C05-\\u0C0C\\u0C0E-\\u0C10\\u0C12-\\u0C28\\u0C2A-\\u0C33\\u0C35-\\u0C39\\u0C3D\\u0C58\\u0C59\\u0C60\\u0C61\\u0C85-\\u0C8C\\u0C8E-\\u0C90\\u0C92-\\u0CA8\\u0CAA-\\u0CB3\\u0CB5-\\u0CB9\\u0CBD\\u0CDE\\u0CE0\\u0CE1\\u0D05-\\u0D0C\\u0D0E-\\u0D10\\u0D12-\\u0D28\\u0D2A-\\u0D39\\u0D3D\\u0D60\\u0D61\\u0D7A-\\u0D7F\\u0D85-\\u0D96\\u0D9A-\\u0DB1\\u0DB3-\\u0DBB\\u0DBD\\u0DC0-\\u0DC6\\u0E01-\\u0E30\\u0E32\\u0E33\\u0E40-\\u0E46\\u0E81\\u0E82\\u0E84\\u0E87\\u0E88\\u0E8A\\u0E8D\\u0E94-\\u0E97\\u0E99-\\u0E9F\\u0EA1-\\u0EA3\\u0EA5\\u0EA7\\u0EAA\\u0EAB\\u0EAD-\\u0EB0\\u0EB2\\u0EB3\\u0EBD\\u0EC0-\\u0EC4\\u0EC6\\u0EDC\\u0EDD\\u0F00\\u0F40-\\u0F47\\u0F49-\\u0F6C\\u0F88-\\u0F8B\\u1000-\\u102A\\u103F\\u1050-\\u1055\\u105A-\\u105D\\u1061\\u1065\\u1066\\u106E-\\u1070\\u1075-\\u1081\\u108E\\u10A0-\\u10C5\\u10D0-\\u10FA\\u10FC\\u1100-\\u1159\\u115F-\\u11A2\\u11A8-\\u11F9\\u1200-\\u1248\\u124A-\\u124D\\u1250-\\u1256\\u1258\\u125A-\\u125D\\u1260-\\u1288\\u128A-\\u128D\\u1290-\\u12B0\\u12B2-\\u12B5\\u12B8-\\u12BE\\u12C0\\u12C2-\\u12C5\\u12C8-\\u12D6\\u12D8-\\u1310\\u1312-\\u1315\\u1318-\\u135A\\u1380-\\u138F\\u13A0-\\u13F4\\u1401-\\u166C\\u166F-\\u1676\\u1681-\\u169A\\u16A0-\\u16EA\\u1700-\\u170C\\u170E-\\u1711\\u1720-\\u1731\\u1740-\\u1751\\u1760-\\u176C\\u176E-\\u1770\\u1780-\\u17B3\\u17D7\\u17DC\\u1820-\\u1877\\u1880-\\u18A8\\u18AA\\u1900-\\u191C\\u1950-\\u196D\\u1970-\\u1974\\u1980-\\u19A9\\u19C1-\\u19C7\\u1A00-\\u1A16\\u1B05-\\u1B33\\u1B45-\\u1B4B\\u1B83-\\u1BA0\\u1BAE\\u1BAF\\u1C00-\\u1C23\\u1C4D-\\u1C4F\\u1C5A-\\u1C7D\\u1D00-\\u1DBF\\u1E00-\\u1F15\\u1F18-\\u1F1D\\u1F20-\\u1F45\\u1F48-\\u1F4D\\u1F50-\\u1F57\\u1F59\\u1F5B\\u1F5D\\u1F5F-\\u1F7D\\u1F80-\\u1FB4\\u1FB6-\\u1FBC\\u1FBE\\u1FC2-\\u1FC4\\u1FC6-\\u1FCC\\u1FD0-\\u1FD3\\u1FD6-\\u1FDB\\u1FE0-\\u1FEC\\u1FF2-\\u1FF4\\u1FF6-\\u1FFC\\u2071\\u207F\\u2090-\\u2094\\u2102\\u2107\\u210A-\\u2113\\u2115\\u2119-\\u211D\\u2124\\u2126\\u2128\\u212A-\\u212D\\u212F-\\u2139\\u213C-\\u213F\\u2145-\\u2149\\u214E\\u2183\\u2184\\u2C00-\\u2C2E\\u2C30-\\u2C5E\\u2C60-\\u2C6F\\u2C71-\\u2C7D\\u2C80-\\u2CE4\\u2D00-\\u2D25\\u2D30-\\u2D65\\u2D6F\\u2D80-\\u2D96\\u2DA0-\\u2DA6\\u2DA8-\\u2DAE\\u2DB0-\\u2DB6\\u2DB8-\\u2DBE\\u2DC0-\\u2DC6\\u2DC8-\\u2DCE\\u2DD0-\\u2DD6\\u2DD8-\\u2DDE\\u2E2F\\u3005\\u3006\\u3031-\\u3035\\u303B\\u303C\\u3041-\\u3096\\u309D-\\u309F\\u30A1-\\u30FA\\u30FC-\\u30FF\\u3105-\\u312D\\u3131-\\u318E\\u31A0-\\u31B7\\u31F0-\\u31FF\\u3400\\u4DB5\\u4E00\\u9FC3\\uA000-\\uA48C\\uA500-\\uA60C\\uA610-\\uA61F\\uA62A\\uA62B\\uA640-\\uA65F\\uA662-\\uA66E\\uA67F-\\uA697\\uA717-\\uA71F\\uA722-\\uA788\\uA78B\\uA78C\\uA7FB-\\uA801\\uA803-\\uA805\\uA807-\\uA80A\\uA80C-\\uA822\\uA840-\\uA873\\uA882-\\uA8B3\\uA90A-\\uA925\\uA930-\\uA946\\uAA00-\\uAA28\\uAA40-\\uAA42\\uAA44-\\uAA4B\\uAC00\\uD7A3\\uF900-\\uFA2D\\uFA30-\\uFA6A\\uFA70-\\uFAD9\\uFB00-\\uFB06\\uFB13-\\uFB17\\uFB1D\\uFB1F-\\uFB28\\uFB2A-\\uFB36\\uFB38-\\uFB3C\\uFB3E\\uFB40\\uFB41\\uFB43\\uFB44\\uFB46-\\uFBB1\\uFBD3-\\uFD3D\\uFD50-\\uFD8F\\uFD92-\\uFDC7\\uFDF0-\\uFDFB\\uFE70-\\uFE74\\uFE76-\\uFEFC\\uFF21-\\uFF3A\\uFF41-\\uFF5A\\uFF66-\\uFFBE\\uFFC2-\\uFFC7\\uFFCA-\\uFFCF\\uFFD2-\\uFFD7\\uFFDA-\\uFFDC]"), - non_spacing_mark: new RegExp("[\\u0300-\\u036F\\u0483-\\u0487\\u0591-\\u05BD\\u05BF\\u05C1\\u05C2\\u05C4\\u05C5\\u05C7\\u0610-\\u061A\\u064B-\\u065E\\u0670\\u06D6-\\u06DC\\u06DF-\\u06E4\\u06E7\\u06E8\\u06EA-\\u06ED\\u0711\\u0730-\\u074A\\u07A6-\\u07B0\\u07EB-\\u07F3\\u0816-\\u0819\\u081B-\\u0823\\u0825-\\u0827\\u0829-\\u082D\\u0900-\\u0902\\u093C\\u0941-\\u0948\\u094D\\u0951-\\u0955\\u0962\\u0963\\u0981\\u09BC\\u09C1-\\u09C4\\u09CD\\u09E2\\u09E3\\u0A01\\u0A02\\u0A3C\\u0A41\\u0A42\\u0A47\\u0A48\\u0A4B-\\u0A4D\\u0A51\\u0A70\\u0A71\\u0A75\\u0A81\\u0A82\\u0ABC\\u0AC1-\\u0AC5\\u0AC7\\u0AC8\\u0ACD\\u0AE2\\u0AE3\\u0B01\\u0B3C\\u0B3F\\u0B41-\\u0B44\\u0B4D\\u0B56\\u0B62\\u0B63\\u0B82\\u0BC0\\u0BCD\\u0C3E-\\u0C40\\u0C46-\\u0C48\\u0C4A-\\u0C4D\\u0C55\\u0C56\\u0C62\\u0C63\\u0CBC\\u0CBF\\u0CC6\\u0CCC\\u0CCD\\u0CE2\\u0CE3\\u0D41-\\u0D44\\u0D4D\\u0D62\\u0D63\\u0DCA\\u0DD2-\\u0DD4\\u0DD6\\u0E31\\u0E34-\\u0E3A\\u0E47-\\u0E4E\\u0EB1\\u0EB4-\\u0EB9\\u0EBB\\u0EBC\\u0EC8-\\u0ECD\\u0F18\\u0F19\\u0F35\\u0F37\\u0F39\\u0F71-\\u0F7E\\u0F80-\\u0F84\\u0F86\\u0F87\\u0F90-\\u0F97\\u0F99-\\u0FBC\\u0FC6\\u102D-\\u1030\\u1032-\\u1037\\u1039\\u103A\\u103D\\u103E\\u1058\\u1059\\u105E-\\u1060\\u1071-\\u1074\\u1082\\u1085\\u1086\\u108D\\u109D\\u135F\\u1712-\\u1714\\u1732-\\u1734\\u1752\\u1753\\u1772\\u1773\\u17B7-\\u17BD\\u17C6\\u17C9-\\u17D3\\u17DD\\u180B-\\u180D\\u18A9\\u1920-\\u1922\\u1927\\u1928\\u1932\\u1939-\\u193B\\u1A17\\u1A18\\u1A56\\u1A58-\\u1A5E\\u1A60\\u1A62\\u1A65-\\u1A6C\\u1A73-\\u1A7C\\u1A7F\\u1B00-\\u1B03\\u1B34\\u1B36-\\u1B3A\\u1B3C\\u1B42\\u1B6B-\\u1B73\\u1B80\\u1B81\\u1BA2-\\u1BA5\\u1BA8\\u1BA9\\u1C2C-\\u1C33\\u1C36\\u1C37\\u1CD0-\\u1CD2\\u1CD4-\\u1CE0\\u1CE2-\\u1CE8\\u1CED\\u1DC0-\\u1DE6\\u1DFD-\\u1DFF\\u20D0-\\u20DC\\u20E1\\u20E5-\\u20F0\\u2CEF-\\u2CF1\\u2DE0-\\u2DFF\\u302A-\\u302F\\u3099\\u309A\\uA66F\\uA67C\\uA67D\\uA6F0\\uA6F1\\uA802\\uA806\\uA80B\\uA825\\uA826\\uA8C4\\uA8E0-\\uA8F1\\uA926-\\uA92D\\uA947-\\uA951\\uA980-\\uA982\\uA9B3\\uA9B6-\\uA9B9\\uA9BC\\uAA29-\\uAA2E\\uAA31\\uAA32\\uAA35\\uAA36\\uAA43\\uAA4C\\uAAB0\\uAAB2-\\uAAB4\\uAAB7\\uAAB8\\uAABE\\uAABF\\uAAC1\\uABE5\\uABE8\\uABED\\uFB1E\\uFE00-\\uFE0F\\uFE20-\\uFE26]"), - space_combining_mark: new RegExp("[\\u0903\\u093E-\\u0940\\u0949-\\u094C\\u094E\\u0982\\u0983\\u09BE-\\u09C0\\u09C7\\u09C8\\u09CB\\u09CC\\u09D7\\u0A03\\u0A3E-\\u0A40\\u0A83\\u0ABE-\\u0AC0\\u0AC9\\u0ACB\\u0ACC\\u0B02\\u0B03\\u0B3E\\u0B40\\u0B47\\u0B48\\u0B4B\\u0B4C\\u0B57\\u0BBE\\u0BBF\\u0BC1\\u0BC2\\u0BC6-\\u0BC8\\u0BCA-\\u0BCC\\u0BD7\\u0C01-\\u0C03\\u0C41-\\u0C44\\u0C82\\u0C83\\u0CBE\\u0CC0-\\u0CC4\\u0CC7\\u0CC8\\u0CCA\\u0CCB\\u0CD5\\u0CD6\\u0D02\\u0D03\\u0D3E-\\u0D40\\u0D46-\\u0D48\\u0D4A-\\u0D4C\\u0D57\\u0D82\\u0D83\\u0DCF-\\u0DD1\\u0DD8-\\u0DDF\\u0DF2\\u0DF3\\u0F3E\\u0F3F\\u0F7F\\u102B\\u102C\\u1031\\u1038\\u103B\\u103C\\u1056\\u1057\\u1062-\\u1064\\u1067-\\u106D\\u1083\\u1084\\u1087-\\u108C\\u108F\\u109A-\\u109C\\u17B6\\u17BE-\\u17C5\\u17C7\\u17C8\\u1923-\\u1926\\u1929-\\u192B\\u1930\\u1931\\u1933-\\u1938\\u19B0-\\u19C0\\u19C8\\u19C9\\u1A19-\\u1A1B\\u1A55\\u1A57\\u1A61\\u1A63\\u1A64\\u1A6D-\\u1A72\\u1B04\\u1B35\\u1B3B\\u1B3D-\\u1B41\\u1B43\\u1B44\\u1B82\\u1BA1\\u1BA6\\u1BA7\\u1BAA\\u1C24-\\u1C2B\\u1C34\\u1C35\\u1CE1\\u1CF2\\uA823\\uA824\\uA827\\uA880\\uA881\\uA8B4-\\uA8C3\\uA952\\uA953\\uA983\\uA9B4\\uA9B5\\uA9BA\\uA9BB\\uA9BD-\\uA9C0\\uAA2F\\uAA30\\uAA33\\uAA34\\uAA4D\\uAA7B\\uABE3\\uABE4\\uABE6\\uABE7\\uABE9\\uABEA\\uABEC]"), - connector_punctuation: new RegExp("[\\u005F\\u203F\\u2040\\u2054\\uFE33\\uFE34\\uFE4D-\\uFE4F\\uFF3F]") -}; - -function is_letter(ch) { - return UNICODE.letter.test(ch); -}; - -function is_digit(ch) { - ch = ch.charCodeAt(0); - return ch >= 48 && ch <= 57; //XXX: find out if "UnicodeDigit" means something else than 0..9 -}; - -function is_alphanumeric_char(ch) { - return is_digit(ch) || is_letter(ch); -}; - -function is_unicode_combining_mark(ch) { - return UNICODE.non_spacing_mark.test(ch) || UNICODE.space_combining_mark.test(ch); -}; - -function is_unicode_connector_punctuation(ch) { - return UNICODE.connector_punctuation.test(ch); -}; - -function is_identifier_start(ch) { - return ch == "$" || ch == "_" || is_letter(ch); -}; - -function is_identifier_char(ch) { - return is_identifier_start(ch) - || is_unicode_combining_mark(ch) - || is_digit(ch) - || is_unicode_connector_punctuation(ch) - || ch == "\u200c" // zero-width non-joiner - || ch == "\u200d" // zero-width joiner (in my ECMA-262 PDF, this is also 200c) - ; -}; - -function parse_js_number(num) { - if (RE_HEX_NUMBER.test(num)) { - return parseInt(num.substr(2), 16); - } else if (RE_OCT_NUMBER.test(num)) { - return parseInt(num.substr(1), 8); - } else if (RE_DEC_NUMBER.test(num)) { - return parseFloat(num); - } -}; - -function JS_Parse_Error(message, line, col, pos) { - this.message = message; - this.line = line; - this.col = col; - this.pos = pos; - try { - ({})(); - } catch(ex) { - this.stack = ex.stack; - }; -}; - -JS_Parse_Error.prototype.toString = function() { - return this.message + " (line: " + this.line + ", col: " + this.col + ", pos: " + this.pos + ")" + "\n\n" + this.stack; -}; - -function js_error(message, line, col, pos) { - throw new JS_Parse_Error(message, line, col, pos); -}; - -function is_token(token, type, val) { - return token.type == type && (val == null || token.value == val); -}; - -var EX_EOF = {}; - -function tokenizer($TEXT) { - - var S = { - text : $TEXT.replace(/\r\n?|[\n\u2028\u2029]/g, "\n").replace(/^\uFEFF/, ''), - pos : 0, - tokpos : 0, - line : 0, - tokline : 0, - col : 0, - tokcol : 0, - newline_before : false, - regex_allowed : false, - comments_before : [] - }; - - function peek() { return S.text.charAt(S.pos); }; - - function next(signal_eof) { - var ch = S.text.charAt(S.pos++); - if (signal_eof && !ch) - throw EX_EOF; - if (ch == "\n") { - S.newline_before = true; - ++S.line; - S.col = 0; - } else { - ++S.col; - } - return ch; - }; - - function eof() { - return !S.peek(); - }; - - function find(what, signal_eof) { - var pos = S.text.indexOf(what, S.pos); - if (signal_eof && pos == -1) throw EX_EOF; - return pos; - }; - - function start_token() { - S.tokline = S.line; - S.tokcol = S.col; - S.tokpos = S.pos; - }; - - function token(type, value, is_comment) { - S.regex_allowed = ((type == "operator" && !HOP(UNARY_POSTFIX, value)) || - (type == "keyword" && HOP(KEYWORDS_BEFORE_EXPRESSION, value)) || - (type == "punc" && HOP(PUNC_BEFORE_EXPRESSION, value))); - var ret = { - type : type, - value : value, - line : S.tokline, - col : S.tokcol, - pos : S.tokpos, - nlb : S.newline_before - }; - if (!is_comment) { - ret.comments_before = S.comments_before; - S.comments_before = []; - } - S.newline_before = false; - return ret; - }; - - function skip_whitespace() { - while (HOP(WHITESPACE_CHARS, peek())) - next(); - }; - - function read_while(pred) { - var ret = "", ch = peek(), i = 0; - while (ch && pred(ch, i++)) { - ret += next(); - ch = peek(); - } - return ret; - }; - - function parse_error(err) { - js_error(err, S.tokline, S.tokcol, S.tokpos); - }; - - function read_num(prefix) { - var has_e = false, after_e = false, has_x = false, has_dot = prefix == "."; - var num = read_while(function(ch, i){ - if (ch == "x" || ch == "X") { - if (has_x) return false; - return has_x = true; - } - if (!has_x && (ch == "E" || ch == "e")) { - if (has_e) return false; - return has_e = after_e = true; - } - if (ch == "-") { - if (after_e || (i == 0 && !prefix)) return true; - return false; - } - if (ch == "+") return after_e; - after_e = false; - if (ch == ".") { - if (!has_dot && !has_x) - return has_dot = true; - return false; - } - return is_alphanumeric_char(ch); - }); - if (prefix) - num = prefix + num; - var valid = parse_js_number(num); - if (!isNaN(valid)) { - return token("num", valid); - } else { - parse_error("Invalid syntax: " + num); - } - }; - - function read_escaped_char() { - var ch = next(true); - switch (ch) { - case "n" : return "\n"; - case "r" : return "\r"; - case "t" : return "\t"; - case "b" : return "\b"; - case "v" : return "\v"; - case "f" : return "\f"; - case "0" : return "\0"; - case "x" : return String.fromCharCode(hex_bytes(2)); - case "u" : return String.fromCharCode(hex_bytes(4)); - default : return ch; - } - }; - - function hex_bytes(n) { - var num = 0; - for (; n > 0; --n) { - var digit = parseInt(next(true), 16); - if (isNaN(digit)) - parse_error("Invalid hex-character pattern in string"); - num = (num << 4) | digit; - } - return num; - }; - - function read_string() { - return with_eof_error("Unterminated string constant", function(){ - var quote = next(), ret = ""; - for (;;) { - var ch = next(true); - if (ch == "\\") ch = read_escaped_char(); - else if (ch == quote) break; - ret += ch; - } - return token("string", ret); - }); - }; - - function read_line_comment() { - next(); - var i = find("\n"), ret; - if (i == -1) { - ret = S.text.substr(S.pos); - S.pos = S.text.length; - } else { - ret = S.text.substring(S.pos, i); - S.pos = i; - } - return token("comment1", ret, true); - }; - - function read_multiline_comment() { - next(); - return with_eof_error("Unterminated multiline comment", function(){ - var i = find("*/", true), - text = S.text.substring(S.pos, i), - tok = token("comment2", text, true); - S.pos = i + 2; - S.line += text.split("\n").length - 1; - S.newline_before = text.indexOf("\n") >= 0; - - // https://github.com/mishoo/UglifyJS/issues/#issue/100 - if (/^@cc_on/i.test(text)) { - warn("WARNING: at line " + S.line); - warn("*** Found \"conditional comment\": " + text); - warn("*** UglifyJS DISCARDS ALL COMMENTS. This means your code might no longer work properly in Internet Explorer."); - } - - return tok; - }); - }; - - function read_name() { - var backslash = false, name = "", ch; - while ((ch = peek()) != null) { - if (!backslash) { - if (ch == "\\") backslash = true, next(); - else if (is_identifier_char(ch)) name += next(); - else break; - } - else { - if (ch != "u") parse_error("Expecting UnicodeEscapeSequence -- uXXXX"); - ch = read_escaped_char(); - if (!is_identifier_char(ch)) parse_error("Unicode char: " + ch.charCodeAt(0) + " is not valid in identifier"); - name += ch; - backslash = false; - } - } - return name; - }; - - function read_regexp() { - return with_eof_error("Unterminated regular expression", function(){ - var prev_backslash = false, regexp = "", ch, in_class = false; - while ((ch = next(true))) if (prev_backslash) { - regexp += "\\" + ch; - prev_backslash = false; - } else if (ch == "[") { - in_class = true; - regexp += ch; - } else if (ch == "]" && in_class) { - in_class = false; - regexp += ch; - } else if (ch == "/" && !in_class) { - break; - } else if (ch == "\\") { - prev_backslash = true; - } else { - regexp += ch; - } - var mods = read_name(); - return token("regexp", [ regexp, mods ]); - }); - }; - - function read_operator(prefix) { - function grow(op) { - if (!peek()) return op; - var bigger = op + peek(); - if (HOP(OPERATORS, bigger)) { - next(); - return grow(bigger); - } else { - return op; - } - }; - return token("operator", grow(prefix || next())); - }; - - function handle_slash() { - next(); - var regex_allowed = S.regex_allowed; - switch (peek()) { - case "/": - S.comments_before.push(read_line_comment()); - S.regex_allowed = regex_allowed; - return next_token(); - case "*": - S.comments_before.push(read_multiline_comment()); - S.regex_allowed = regex_allowed; - return next_token(); - } - return S.regex_allowed ? read_regexp() : read_operator("/"); - }; - - function handle_dot() { - next(); - return is_digit(peek()) - ? read_num(".") - : token("punc", "."); - }; - - function read_word() { - var word = read_name(); - return !HOP(KEYWORDS, word) - ? token("name", word) - : HOP(OPERATORS, word) - ? token("operator", word) - : HOP(KEYWORDS_ATOM, word) - ? token("atom", word) - : token("keyword", word); - }; - - function with_eof_error(eof_error, cont) { - try { - return cont(); - } catch(ex) { - if (ex === EX_EOF) parse_error(eof_error); - else throw ex; - } - }; - - function next_token(force_regexp) { - if (force_regexp) - return read_regexp(); - skip_whitespace(); - start_token(); - var ch = peek(); - if (!ch) return token("eof"); - if (is_digit(ch)) return read_num(); - if (ch == '"' || ch == "'") return read_string(); - if (HOP(PUNC_CHARS, ch)) return token("punc", next()); - if (ch == ".") return handle_dot(); - if (ch == "/") return handle_slash(); - if (HOP(OPERATOR_CHARS, ch)) return read_operator(); - if (ch == "\\" || is_identifier_start(ch)) return read_word(); - parse_error("Unexpected character '" + ch + "'"); - }; - - next_token.context = function(nc) { - if (nc) S = nc; - return S; - }; - - return next_token; - -}; - -/* -----[ Parser (constants) ]----- */ - -var UNARY_PREFIX = array_to_hash([ - "typeof", - "void", - "delete", - "--", - "++", - "!", - "~", - "-", - "+" -]); - -var UNARY_POSTFIX = array_to_hash([ "--", "++" ]); - -var ASSIGNMENT = (function(a, ret, i){ - while (i < a.length) { - ret[a[i]] = a[i].substr(0, a[i].length - 1); - i++; - } - return ret; -})( - ["+=", "-=", "/=", "*=", "%=", ">>=", "<<=", ">>>=", "|=", "^=", "&="], - { "=": true }, - 0 -); - -var PRECEDENCE = (function(a, ret){ - for (var i = 0, n = 1; i < a.length; ++i, ++n) { - var b = a[i]; - for (var j = 0; j < b.length; ++j) { - ret[b[j]] = n; - } - } - return ret; -})( - [ - ["||"], - ["&&"], - ["|"], - ["^"], - ["&"], - ["==", "===", "!=", "!=="], - ["<", ">", "<=", ">=", "in", "instanceof"], - [">>", "<<", ">>>"], - ["+", "-"], - ["*", "/", "%"] - ], - {} -); - -var STATEMENTS_WITH_LABELS = array_to_hash([ "for", "do", "while", "switch" ]); - -var ATOMIC_START_TOKEN = array_to_hash([ "atom", "num", "string", "regexp", "name" ]); - -/* -----[ Parser ]----- */ - -function NodeWithToken(str, start, end) { - this.name = str; - this.start = start; - this.end = end; -}; - -NodeWithToken.prototype.toString = function() { return this.name; }; - -function parse($TEXT, exigent_mode, embed_tokens) { - - var S = { - input : typeof $TEXT == "string" ? tokenizer($TEXT, true) : $TEXT, - token : null, - prev : null, - peeked : null, - in_function : 0, - in_loop : 0, - labels : [] - }; - - S.token = next(); - - function is(type, value) { - return is_token(S.token, type, value); - }; - - function peek() { return S.peeked || (S.peeked = S.input()); }; - - function next() { - S.prev = S.token; - if (S.peeked) { - S.token = S.peeked; - S.peeked = null; - } else { - S.token = S.input(); - } - return S.token; - }; - - function prev() { - return S.prev; - }; - - function croak(msg, line, col, pos) { - var ctx = S.input.context(); - js_error(msg, - line != null ? line : ctx.tokline, - col != null ? col : ctx.tokcol, - pos != null ? pos : ctx.tokpos); - }; - - function token_error(token, msg) { - croak(msg, token.line, token.col); - }; - - function unexpected(token) { - if (token == null) - token = S.token; - token_error(token, "Unexpected token: " + token.type + " (" + token.value + ")"); - }; - - function expect_token(type, val) { - if (is(type, val)) { - return next(); - } - token_error(S.token, "Unexpected token " + S.token.type + ", expected " + type); - }; - - function expect(punc) { return expect_token("punc", punc); }; - - function can_insert_semicolon() { - return !exigent_mode && ( - S.token.nlb || is("eof") || is("punc", "}") - ); - }; - - function semicolon() { - if (is("punc", ";")) next(); - else if (!can_insert_semicolon()) unexpected(); - }; - - function as() { - return slice(arguments); - }; - - function parenthesised() { - expect("("); - var ex = expression(); - expect(")"); - return ex; - }; - - function add_tokens(str, start, end) { - return str instanceof NodeWithToken ? str : new NodeWithToken(str, start, end); - }; - - function maybe_embed_tokens(parser) { - if (embed_tokens) return function() { - var start = S.token; - var ast = parser.apply(this, arguments); - ast[0] = add_tokens(ast[0], start, prev()); - return ast; - }; - else return parser; - }; - - var statement = maybe_embed_tokens(function() { - if (is("operator", "/")) { - S.peeked = null; - S.token = S.input(true); // force regexp - } - switch (S.token.type) { - case "num": - case "string": - case "regexp": - case "operator": - case "atom": - return simple_statement(); - - case "name": - return is_token(peek(), "punc", ":") - ? labeled_statement(prog1(S.token.value, next, next)) - : simple_statement(); - - case "punc": - switch (S.token.value) { - case "{": - return as("block", block_()); - case "[": - case "(": - return simple_statement(); - case ";": - next(); - return as("block"); - default: - unexpected(); - } - - case "keyword": - switch (prog1(S.token.value, next)) { - case "break": - return break_cont("break"); - - case "continue": - return break_cont("continue"); - - case "debugger": - semicolon(); - return as("debugger"); - - case "do": - return (function(body){ - expect_token("keyword", "while"); - return as("do", prog1(parenthesised, semicolon), body); - })(in_loop(statement)); - - case "for": - return for_(); - - case "function": - return function_(true); - - case "if": - return if_(); - - case "return": - if (S.in_function == 0) - croak("'return' outside of function"); - return as("return", - is("punc", ";") - ? (next(), null) - : can_insert_semicolon() - ? null - : prog1(expression, semicolon)); - - case "switch": - return as("switch", parenthesised(), switch_block_()); - - case "throw": - return as("throw", prog1(expression, semicolon)); - - case "try": - return try_(); - - case "var": - return prog1(var_, semicolon); - - case "const": - return prog1(const_, semicolon); - - case "while": - return as("while", parenthesised(), in_loop(statement)); - - case "with": - return as("with", parenthesised(), statement()); - - default: - unexpected(); - } - } - }); - - function labeled_statement(label) { - S.labels.push(label); - var start = S.token, stat = statement(); - if (exigent_mode && !HOP(STATEMENTS_WITH_LABELS, stat[0])) - unexpected(start); - S.labels.pop(); - return as("label", label, stat); - }; - - function simple_statement() { - return as("stat", prog1(expression, semicolon)); - }; - - function break_cont(type) { - var name = is("name") ? S.token.value : null; - if (name != null) { - next(); - if (!member(name, S.labels)) - croak("Label " + name + " without matching loop or statement"); - } - else if (S.in_loop == 0) - croak(type + " not inside a loop or switch"); - semicolon(); - return as(type, name); - }; - - function for_() { - expect("("); - var init = null; - if (!is("punc", ";")) { - init = is("keyword", "var") - ? (next(), var_(true)) - : expression(true, true); - if (is("operator", "in")) - return for_in(init); - } - return regular_for(init); - }; - - function regular_for(init) { - expect(";"); - var test = is("punc", ";") ? null : expression(); - expect(";"); - var step = is("punc", ")") ? null : expression(); - expect(")"); - return as("for", init, test, step, in_loop(statement)); - }; - - function for_in(init) { - var lhs = init[0] == "var" ? as("name", init[1][0]) : init; - next(); - var obj = expression(); - expect(")"); - return as("for-in", init, lhs, obj, in_loop(statement)); - }; - - var function_ = maybe_embed_tokens(function(in_statement) { - var name = is("name") ? prog1(S.token.value, next) : null; - if (in_statement && !name) - unexpected(); - expect("("); - return as(in_statement ? "defun" : "function", - name, - // arguments - (function(first, a){ - while (!is("punc", ")")) { - if (first) first = false; else expect(","); - if (!is("name")) unexpected(); - a.push(S.token.value); - next(); - } - next(); - return a; - })(true, []), - // body - (function(){ - ++S.in_function; - var loop = S.in_loop; - S.in_loop = 0; - var a = block_(); - --S.in_function; - S.in_loop = loop; - return a; - })()); - }); - - function if_() { - var cond = parenthesised(), body = statement(), belse; - if (is("keyword", "else")) { - next(); - belse = statement(); - } - return as("if", cond, body, belse); - }; - - function block_() { - expect("{"); - var a = []; - while (!is("punc", "}")) { - if (is("eof")) unexpected(); - a.push(statement()); - } - next(); - return a; - }; - - var switch_block_ = curry(in_loop, function(){ - expect("{"); - var a = [], cur = null; - while (!is("punc", "}")) { - if (is("eof")) unexpected(); - if (is("keyword", "case")) { - next(); - cur = []; - a.push([ expression(), cur ]); - expect(":"); - } - else if (is("keyword", "default")) { - next(); - expect(":"); - cur = []; - a.push([ null, cur ]); - } - else { - if (!cur) unexpected(); - cur.push(statement()); - } - } - next(); - return a; - }); - - function try_() { - var body = block_(), bcatch, bfinally; - if (is("keyword", "catch")) { - next(); - expect("("); - if (!is("name")) - croak("Name expected"); - var name = S.token.value; - next(); - expect(")"); - bcatch = [ name, block_() ]; - } - if (is("keyword", "finally")) { - next(); - bfinally = block_(); - } - if (!bcatch && !bfinally) - croak("Missing catch/finally blocks"); - return as("try", body, bcatch, bfinally); - }; - - function vardefs(no_in) { - var a = []; - for (;;) { - if (!is("name")) - unexpected(); - var name = S.token.value; - next(); - if (is("operator", "=")) { - next(); - a.push([ name, expression(false, no_in) ]); - } else { - a.push([ name ]); - } - if (!is("punc", ",")) - break; - next(); - } - return a; - }; - - function var_(no_in) { - return as("var", vardefs(no_in)); - }; - - function const_() { - return as("const", vardefs()); - }; - - function new_() { - var newexp = expr_atom(false), args; - if (is("punc", "(")) { - next(); - args = expr_list(")"); - } else { - args = []; - } - return subscripts(as("new", newexp, args), true); - }; - - var expr_atom = maybe_embed_tokens(function(allow_calls) { - if (is("operator", "new")) { - next(); - return new_(); - } - if (is("operator") && HOP(UNARY_PREFIX, S.token.value)) { - return make_unary("unary-prefix", - prog1(S.token.value, next), - expr_atom(allow_calls)); - } - if (is("punc")) { - switch (S.token.value) { - case "(": - next(); - return subscripts(prog1(expression, curry(expect, ")")), allow_calls); - case "[": - next(); - return subscripts(array_(), allow_calls); - case "{": - next(); - return subscripts(object_(), allow_calls); - } - unexpected(); - } - if (is("keyword", "function")) { - next(); - return subscripts(function_(false), allow_calls); - } - if (HOP(ATOMIC_START_TOKEN, S.token.type)) { - var atom = S.token.type == "regexp" - ? as("regexp", S.token.value[0], S.token.value[1]) - : as(S.token.type, S.token.value); - return subscripts(prog1(atom, next), allow_calls); - } - unexpected(); - }); - - function expr_list(closing, allow_trailing_comma, allow_empty) { - var first = true, a = []; - while (!is("punc", closing)) { - if (first) first = false; else expect(","); - if (allow_trailing_comma && is("punc", closing)) break; - if (is("punc", ",") && allow_empty) { - a.push([ "atom", "undefined" ]); - } else { - a.push(expression(false)); - } - } - next(); - return a; - }; - - function array_() { - return as("array", expr_list("]", !exigent_mode, true)); - }; - - function object_() { - var first = true, a = []; - while (!is("punc", "}")) { - if (first) first = false; else expect(","); - if (!exigent_mode && is("punc", "}")) - // allow trailing comma - break; - var type = S.token.type; - var name = as_property_name(); - if (type == "name" && (name == "get" || name == "set") && !is("punc", ":")) { - a.push([ as_name(), function_(false), name ]); - } else { - expect(":"); - a.push([ name, expression(false) ]); - } - } - next(); - return as("object", a); - }; - - function as_property_name() { - switch (S.token.type) { - case "num": - case "string": - return prog1(S.token.value, next); - } - return as_name(); - }; - - function as_name() { - switch (S.token.type) { - case "name": - case "operator": - case "keyword": - case "atom": - return prog1(S.token.value, next); - default: - unexpected(); - } - }; - - function subscripts(expr, allow_calls) { - if (is("punc", ".")) { - next(); - return subscripts(as("dot", expr, as_name()), allow_calls); - } - if (is("punc", "[")) { - next(); - return subscripts(as("sub", expr, prog1(expression, curry(expect, "]"))), allow_calls); - } - if (allow_calls && is("punc", "(")) { - next(); - return subscripts(as("call", expr, expr_list(")")), true); - } - if (allow_calls && is("operator") && HOP(UNARY_POSTFIX, S.token.value)) { - return prog1(curry(make_unary, "unary-postfix", S.token.value, expr), - next); - } - return expr; - }; - - function make_unary(tag, op, expr) { - if ((op == "++" || op == "--") && !is_assignable(expr)) - croak("Invalid use of " + op + " operator"); - return as(tag, op, expr); - }; - - function expr_op(left, min_prec, no_in) { - var op = is("operator") ? S.token.value : null; - if (op && op == "in" && no_in) op = null; - var prec = op != null ? PRECEDENCE[op] : null; - if (prec != null && prec > min_prec) { - next(); - var right = expr_op(expr_atom(true), prec, no_in); - return expr_op(as("binary", op, left, right), min_prec, no_in); - } - return left; - }; - - function expr_ops(no_in) { - return expr_op(expr_atom(true), 0, no_in); - }; - - function maybe_conditional(no_in) { - var expr = expr_ops(no_in); - if (is("operator", "?")) { - next(); - var yes = expression(false); - expect(":"); - return as("conditional", expr, yes, expression(false, no_in)); - } - return expr; - }; - - function is_assignable(expr) { - if (!exigent_mode) return true; - switch (expr[0]) { - case "dot": - case "sub": - case "new": - case "call": - return true; - case "name": - return expr[1] != "this"; - } - }; - - function maybe_assign(no_in) { - var left = maybe_conditional(no_in), val = S.token.value; - if (is("operator") && HOP(ASSIGNMENT, val)) { - if (is_assignable(left)) { - next(); - return as("assign", ASSIGNMENT[val], left, maybe_assign(no_in)); - } - croak("Invalid assignment"); - } - return left; - }; - - var expression = maybe_embed_tokens(function(commas, no_in) { - if (arguments.length == 0) - commas = true; - var expr = maybe_assign(no_in); - if (commas && is("punc", ",")) { - next(); - return as("seq", expr, expression(true, no_in)); - } - return expr; - }); - - function in_loop(cont) { - try { - ++S.in_loop; - return cont(); - } finally { - --S.in_loop; - } - }; - - return as("toplevel", (function(a){ - while (!is("eof")) - a.push(statement()); - return a; - })([])); - -}; - -/* -----[ Utilities ]----- */ - -function curry(f) { - var args = slice(arguments, 1); - return function() { return f.apply(this, args.concat(slice(arguments))); }; -}; - -function prog1(ret) { - if (ret instanceof Function) - ret = ret(); - for (var i = 1, n = arguments.length; --n > 0; ++i) - arguments[i](); - return ret; -}; - -function array_to_hash(a) { - var ret = {}; - for (var i = 0; i < a.length; ++i) - ret[a[i]] = true; - return ret; -}; - -function slice(a, start) { - return Array.prototype.slice.call(a, start == null ? 0 : start); -}; - -function characters(str) { - return str.split(""); -}; - -function member(name, array) { - for (var i = array.length; --i >= 0;) - if (array[i] === name) - return true; - return false; -}; - -function HOP(obj, prop) { - return Object.prototype.hasOwnProperty.call(obj, prop); -}; - -var warn = function() {}; - -/* -----[ Exports ]----- */ - -exports.tokenizer = tokenizer; -exports.parse = parse; -exports.slice = slice; -exports.curry = curry; -exports.member = member; -exports.array_to_hash = array_to_hash; -exports.PRECEDENCE = PRECEDENCE; -exports.KEYWORDS_ATOM = KEYWORDS_ATOM; -exports.RESERVED_WORDS = RESERVED_WORDS; -exports.KEYWORDS = KEYWORDS; -exports.ATOMIC_START_TOKEN = ATOMIC_START_TOKEN; -exports.OPERATORS = OPERATORS; -exports.is_alphanumeric_char = is_alphanumeric_char; -exports.set_logger = function(logger) { - warn = logger; -}; diff --git a/build/lib/process.js b/build/lib/process.js deleted file mode 100644 index 3878c8d6..00000000 --- a/build/lib/process.js +++ /dev/null @@ -1,1666 +0,0 @@ -/*********************************************************************** - - A JavaScript tokenizer / parser / beautifier / compressor. - - This version is suitable for Node.js. With minimal changes (the - exports stuff) it should work on any JS platform. - - This file implements some AST processors. They work on data built - by parse-js. - - Exported functions: - - - ast_mangle(ast, options) -- mangles the variable/function names - in the AST. Returns an AST. - - - ast_squeeze(ast) -- employs various optimizations to make the - final generated code even smaller. Returns an AST. - - - gen_code(ast, options) -- generates JS code from the AST. Pass - true (or an object, see the code for some options) as second - argument to get "pretty" (indented) code. - - -------------------------------- (C) --------------------------------- - - Author: Mihai Bazon - - http://mihai.bazon.net/blog - - Distributed under the BSD license: - - Copyright 2010 (c) Mihai Bazon - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - * Redistributions of source code must retain the above - copyright notice, this list of conditions and the following - disclaimer. - - * 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 HOLDER “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 HOLDER 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. - - ***********************************************************************/ - -var jsp = require("./parse-js"), - slice = jsp.slice, - member = jsp.member, - PRECEDENCE = jsp.PRECEDENCE, - OPERATORS = jsp.OPERATORS; - -/* -----[ helper for AST traversal ]----- */ - -function ast_walker(ast) { - function _vardefs(defs) { - return [ this[0], MAP(defs, function(def){ - var a = [ def[0] ]; - if (def.length > 1) - a[1] = walk(def[1]); - return a; - }) ]; - }; - function _block(statements) { - var out = [ this[0] ]; - if (statements != null) - out.push(MAP(statements, walk)); - return out; - }; - var walkers = { - "string": function(str) { - return [ this[0], str ]; - }, - "num": function(num) { - return [ this[0], num ]; - }, - "name": function(name) { - return [ this[0], name ]; - }, - "toplevel": function(statements) { - return [ this[0], MAP(statements, walk) ]; - }, - "block": _block, - "splice": _block, - "var": _vardefs, - "const": _vardefs, - "try": function(t, c, f) { - return [ - this[0], - MAP(t, walk), - c != null ? [ c[0], MAP(c[1], walk) ] : null, - f != null ? MAP(f, walk) : null - ]; - }, - "throw": function(expr) { - return [ this[0], walk(expr) ]; - }, - "new": function(ctor, args) { - return [ this[0], walk(ctor), MAP(args, walk) ]; - }, - "switch": function(expr, body) { - return [ this[0], walk(expr), MAP(body, function(branch){ - return [ branch[0] ? walk(branch[0]) : null, - MAP(branch[1], walk) ]; - }) ]; - }, - "break": function(label) { - return [ this[0], label ]; - }, - "continue": function(label) { - return [ this[0], label ]; - }, - "conditional": function(cond, t, e) { - return [ this[0], walk(cond), walk(t), walk(e) ]; - }, - "assign": function(op, lvalue, rvalue) { - return [ this[0], op, walk(lvalue), walk(rvalue) ]; - }, - "dot": function(expr) { - return [ this[0], walk(expr) ].concat(slice(arguments, 1)); - }, - "call": function(expr, args) { - return [ this[0], walk(expr), MAP(args, walk) ]; - }, - "function": function(name, args, body) { - return [ this[0], name, args.slice(), MAP(body, walk) ]; - }, - "defun": function(name, args, body) { - return [ this[0], name, args.slice(), MAP(body, walk) ]; - }, - "if": function(conditional, t, e) { - return [ this[0], walk(conditional), walk(t), walk(e) ]; - }, - "for": function(init, cond, step, block) { - return [ this[0], walk(init), walk(cond), walk(step), walk(block) ]; - }, - "for-in": function(vvar, key, hash, block) { - return [ this[0], walk(vvar), walk(key), walk(hash), walk(block) ]; - }, - "while": function(cond, block) { - return [ this[0], walk(cond), walk(block) ]; - }, - "do": function(cond, block) { - return [ this[0], walk(cond), walk(block) ]; - }, - "return": function(expr) { - return [ this[0], walk(expr) ]; - }, - "binary": function(op, left, right) { - return [ this[0], op, walk(left), walk(right) ]; - }, - "unary-prefix": function(op, expr) { - return [ this[0], op, walk(expr) ]; - }, - "unary-postfix": function(op, expr) { - return [ this[0], op, walk(expr) ]; - }, - "sub": function(expr, subscript) { - return [ this[0], walk(expr), walk(subscript) ]; - }, - "object": function(props) { - return [ this[0], MAP(props, function(p){ - return p.length == 2 - ? [ p[0], walk(p[1]) ] - : [ p[0], walk(p[1]), p[2] ]; // get/set-ter - }) ]; - }, - "regexp": function(rx, mods) { - return [ this[0], rx, mods ]; - }, - "array": function(elements) { - return [ this[0], MAP(elements, walk) ]; - }, - "stat": function(stat) { - return [ this[0], walk(stat) ]; - }, - "seq": function() { - return [ this[0] ].concat(MAP(slice(arguments), walk)); - }, - "label": function(name, block) { - return [ this[0], name, walk(block) ]; - }, - "with": function(expr, block) { - return [ this[0], walk(expr), walk(block) ]; - }, - "atom": function(name) { - return [ this[0], name ]; - } - }; - - var user = {}; - var stack = []; - function walk(ast) { - if (ast == null) - return null; - try { - stack.push(ast); - var type = ast[0]; - var gen = user[type]; - if (gen) { - var ret = gen.apply(ast, ast.slice(1)); - if (ret != null) - return ret; - } - gen = walkers[type]; - return gen.apply(ast, ast.slice(1)); - } finally { - stack.pop(); - } - }; - - function with_walkers(walkers, cont){ - var save = {}, i; - for (i in walkers) if (HOP(walkers, i)) { - save[i] = user[i]; - user[i] = walkers[i]; - } - var ret = cont(); - for (i in save) if (HOP(save, i)) { - if (!save[i]) delete user[i]; - else user[i] = save[i]; - } - return ret; - }; - - return { - walk: walk, - with_walkers: with_walkers, - parent: function() { - return stack[stack.length - 2]; // last one is current node - }, - stack: function() { - return stack; - } - }; -}; - -/* -----[ Scope and mangling ]----- */ - -function Scope(parent) { - this.names = {}; // names defined in this scope - this.mangled = {}; // mangled names (orig.name => mangled) - this.rev_mangled = {}; // reverse lookup (mangled => orig.name) - this.cname = -1; // current mangled name - this.refs = {}; // names referenced from this scope - this.uses_with = false; // will become TRUE if with() is detected in this or any subscopes - this.uses_eval = false; // will become TRUE if eval() is detected in this or any subscopes - this.parent = parent; // parent scope - this.children = []; // sub-scopes - if (parent) { - this.level = parent.level + 1; - parent.children.push(this); - } else { - this.level = 0; - } -}; - -var base54 = (function(){ - var DIGITS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$_"; - return function(num) { - var ret = ""; - do { - ret = DIGITS.charAt(num % 54) + ret; - num = Math.floor(num / 54); - } while (num > 0); - return ret; - }; -})(); - -Scope.prototype = { - has: function(name) { - for (var s = this; s; s = s.parent) - if (HOP(s.names, name)) - return s; - }, - has_mangled: function(mname) { - for (var s = this; s; s = s.parent) - if (HOP(s.rev_mangled, mname)) - return s; - }, - toJSON: function() { - return { - names: this.names, - uses_eval: this.uses_eval, - uses_with: this.uses_with - }; - }, - - next_mangled: function() { - // we must be careful that the new mangled name: - // - // 1. doesn't shadow a mangled name from a parent - // scope, unless we don't reference the original - // name from this scope OR from any sub-scopes! - // This will get slow. - // - // 2. doesn't shadow an original name from a parent - // scope, in the event that the name is not mangled - // in the parent scope and we reference that name - // here OR IN ANY SUBSCOPES! - // - // 3. doesn't shadow a name that is referenced but not - // defined (possibly global defined elsewhere). - for (;;) { - var m = base54(++this.cname), prior; - - // case 1. - prior = this.has_mangled(m); - if (prior && this.refs[prior.rev_mangled[m]] === prior) - continue; - - // case 2. - prior = this.has(m); - if (prior && prior !== this && this.refs[m] === prior && !prior.has_mangled(m)) - continue; - - // case 3. - if (HOP(this.refs, m) && this.refs[m] == null) - continue; - - // I got "do" once. :-/ - if (!is_identifier(m)) - continue; - - return m; - } - }, - get_mangled: function(name, newMangle) { - if (this.uses_eval || this.uses_with) return name; // no mangle if eval or with is in use - var s = this.has(name); - if (!s) return name; // not in visible scope, no mangle - if (HOP(s.mangled, name)) return s.mangled[name]; // already mangled in this scope - if (!newMangle) return name; // not found and no mangling requested - - var m = s.next_mangled(); - s.rev_mangled[m] = name; - return s.mangled[name] = m; - }, - define: function(name) { - if (name != null) - return this.names[name] = name; - } -}; - -function ast_add_scope(ast) { - - var current_scope = null; - var w = ast_walker(), walk = w.walk; - var having_eval = []; - - function with_new_scope(cont) { - current_scope = new Scope(current_scope); - var ret = current_scope.body = cont(); - ret.scope = current_scope; - current_scope = current_scope.parent; - return ret; - }; - - function define(name) { - return current_scope.define(name); - }; - - function reference(name) { - current_scope.refs[name] = true; - }; - - function _lambda(name, args, body) { - var is_defun = this[0] == "defun"; - return [ this[0], is_defun ? define(name) : name, args, with_new_scope(function(){ - if (!is_defun) define(name); - MAP(args, define); - return MAP(body, walk); - })]; - }; - - return with_new_scope(function(){ - // process AST - var ret = w.with_walkers({ - "function": _lambda, - "defun": _lambda, - "with": function(expr, block) { - for (var s = current_scope; s; s = s.parent) - s.uses_with = true; - }, - "var": function(defs) { - MAP(defs, function(d){ define(d[0]) }); - }, - "const": function(defs) { - MAP(defs, function(d){ define(d[0]) }); - }, - "try": function(t, c, f) { - if (c != null) return [ - this[0], - MAP(t, walk), - [ define(c[0]), MAP(c[1], walk) ], - f != null ? MAP(f, walk) : null - ]; - }, - "name": function(name) { - if (name == "eval") - having_eval.push(current_scope); - reference(name); - } - }, function(){ - return walk(ast); - }); - - // the reason why we need an additional pass here is - // that names can be used prior to their definition. - - // scopes where eval was detected and their parents - // are marked with uses_eval, unless they define the - // "eval" name. - MAP(having_eval, function(scope){ - if (!scope.has("eval")) while (scope) { - scope.uses_eval = true; - scope = scope.parent; - } - }); - - // for referenced names it might be useful to know - // their origin scope. current_scope here is the - // toplevel one. - function fixrefs(scope, i) { - // do children first; order shouldn't matter - for (i = scope.children.length; --i >= 0;) - fixrefs(scope.children[i]); - for (i in scope.refs) if (HOP(scope.refs, i)) { - // find origin scope and propagate the reference to origin - for (var origin = scope.has(i), s = scope; s; s = s.parent) { - s.refs[i] = origin; - if (s === origin) break; - } - } - }; - fixrefs(current_scope); - - return ret; - }); - -}; - -/* -----[ mangle names ]----- */ - -function ast_mangle(ast, options) { - var w = ast_walker(), walk = w.walk, scope; - options = options || {}; - - function get_mangled(name, newMangle) { - if (!options.toplevel && !scope.parent) return name; // don't mangle toplevel - if (options.except && member(name, options.except)) - return name; - return scope.get_mangled(name, newMangle); - }; - - function get_define(name) { - // we always lookup a defined symbol for the current scope FIRST, so declared - // vars trump a DEFINE symbol, but if no such var is found, then match a DEFINE value - if (!scope.has(name)) { - if (HOP(options.defines, name)) { - return options.defines[name]; - } - } - return null; - }; - - function _lambda(name, args, body) { - var is_defun = this[0] == "defun"; - if (is_defun && name) name = get_mangled(name); - body = with_scope(body.scope, function(){ - if (!is_defun && name) name = get_mangled(name); - args = MAP(args, function(name){ return get_mangled(name) }); - return MAP(body, walk); - }); - return [ this[0], name, args, body ]; - }; - - function with_scope(s, cont) { - var _scope = scope; - scope = s; - for (var i in s.names) if (HOP(s.names, i)) { - get_mangled(i, true); - } - var ret = cont(); - ret.scope = s; - scope = _scope; - return ret; - }; - - function _vardefs(defs) { - return [ this[0], MAP(defs, function(d){ - return [ get_mangled(d[0]), walk(d[1]) ]; - }) ]; - }; - - return w.with_walkers({ - "function": _lambda, - "defun": function() { - // move function declarations to the top when - // they are not in some block. - var ast = _lambda.apply(this, arguments); - switch (w.parent()[0]) { - case "toplevel": - case "function": - case "defun": - return MAP.at_top(ast); - } - return ast; - }, - "var": _vardefs, - "const": _vardefs, - "name": function(name) { - return get_define(name) || [ this[0], get_mangled(name) ]; - }, - "try": function(t, c, f) { - return [ this[0], - MAP(t, walk), - c != null ? [ get_mangled(c[0]), MAP(c[1], walk) ] : null, - f != null ? MAP(f, walk) : null ]; - }, - "toplevel": function(body) { - var self = this; - return with_scope(self.scope, function(){ - return [ self[0], MAP(body, walk) ]; - }); - } - }, function() { - return walk(ast_add_scope(ast)); - }); -}; - -/* -----[ - - compress foo["bar"] into foo.bar, - - remove block brackets {} where possible - - join consecutive var declarations - - various optimizations for IFs: - - if (cond) foo(); else bar(); ==> cond?foo():bar(); - - if (cond) foo(); ==> cond&&foo(); - - if (foo) return bar(); else return baz(); ==> return foo?bar():baz(); // also for throw - - if (foo) return bar(); else something(); ==> {if(foo)return bar();something()} - ]----- */ - -var warn = function(){}; - -function best_of(ast1, ast2) { - return gen_code(ast1).length > gen_code(ast2[0] == "stat" ? ast2[1] : ast2).length ? ast2 : ast1; -}; - -function last_stat(b) { - if (b[0] == "block" && b[1] && b[1].length > 0) - return b[1][b[1].length - 1]; - return b; -} - -function aborts(t) { - if (t) { - t = last_stat(t); - if (t[0] == "return" || t[0] == "break" || t[0] == "continue" || t[0] == "throw") - return true; - } -}; - -function boolean_expr(expr) { - return ( (expr[0] == "unary-prefix" - && member(expr[1], [ "!", "delete" ])) || - - (expr[0] == "binary" - && member(expr[1], [ "in", "instanceof", "==", "!=", "===", "!==", "<", "<=", ">=", ">" ])) || - - (expr[0] == "binary" - && member(expr[1], [ "&&", "||" ]) - && boolean_expr(expr[2]) - && boolean_expr(expr[3])) || - - (expr[0] == "conditional" - && boolean_expr(expr[2]) - && boolean_expr(expr[3])) || - - (expr[0] == "assign" - && expr[1] === true - && boolean_expr(expr[3])) || - - (expr[0] == "seq" - && boolean_expr(expr[expr.length - 1])) - ); -}; - -function make_conditional(c, t, e) { - var make_real_conditional = function() { - if (c[0] == "unary-prefix" && c[1] == "!") { - return e ? [ "conditional", c[2], e, t ] : [ "binary", "||", c[2], t ]; - } else { - return e ? [ "conditional", c, t, e ] : [ "binary", "&&", c, t ]; - } - }; - // shortcut the conditional if the expression has a constant value - return when_constant(c, function(ast, val){ - warn_unreachable(val ? e : t); - return (val ? t : e); - }, make_real_conditional); -}; - -function empty(b) { - return !b || (b[0] == "block" && (!b[1] || b[1].length == 0)); -}; - -function is_string(node) { - return (node[0] == "string" || - node[0] == "unary-prefix" && node[1] == "typeof" || - node[0] == "binary" && node[1] == "+" && - (is_string(node[2]) || is_string(node[3]))); -}; - -var when_constant = (function(){ - - var $NOT_CONSTANT = {}; - - // this can only evaluate constant expressions. If it finds anything - // not constant, it throws $NOT_CONSTANT. - function evaluate(expr) { - switch (expr[0]) { - case "string": - case "num": - return expr[1]; - case "name": - case "atom": - switch (expr[1]) { - case "true": return true; - case "false": return false; - } - break; - case "unary-prefix": - switch (expr[1]) { - case "!": return !evaluate(expr[2]); - case "typeof": return typeof evaluate(expr[2]); - case "~": return ~evaluate(expr[2]); - case "-": return -evaluate(expr[2]); - case "+": return +evaluate(expr[2]); - } - break; - case "binary": - var left = expr[2], right = expr[3]; - switch (expr[1]) { - case "&&" : return evaluate(left) && evaluate(right); - case "||" : return evaluate(left) || evaluate(right); - case "|" : return evaluate(left) | evaluate(right); - case "&" : return evaluate(left) & evaluate(right); - case "^" : return evaluate(left) ^ evaluate(right); - case "+" : return evaluate(left) + evaluate(right); - case "*" : return evaluate(left) * evaluate(right); - case "/" : return evaluate(left) / evaluate(right); - case "-" : return evaluate(left) - evaluate(right); - case "<<" : return evaluate(left) << evaluate(right); - case ">>" : return evaluate(left) >> evaluate(right); - case ">>>" : return evaluate(left) >>> evaluate(right); - case "==" : return evaluate(left) == evaluate(right); - case "===" : return evaluate(left) === evaluate(right); - case "!=" : return evaluate(left) != evaluate(right); - case "!==" : return evaluate(left) !== evaluate(right); - case "<" : return evaluate(left) < evaluate(right); - case "<=" : return evaluate(left) <= evaluate(right); - case ">" : return evaluate(left) > evaluate(right); - case ">=" : return evaluate(left) >= evaluate(right); - case "in" : return evaluate(left) in evaluate(right); - case "instanceof" : return evaluate(left) instanceof evaluate(right); - } - } - throw $NOT_CONSTANT; - }; - - return function(expr, yes, no) { - try { - var val = evaluate(expr), ast; - switch (typeof val) { - case "string": ast = [ "string", val ]; break; - case "number": ast = [ "num", val ]; break; - case "boolean": ast = [ "name", String(val) ]; break; - default: throw new Error("Can't handle constant of type: " + (typeof val)); - } - return yes.call(expr, ast, val); - } catch(ex) { - if (ex === $NOT_CONSTANT) { - if (expr[0] == "binary" - && (expr[1] == "===" || expr[1] == "!==") - && ((is_string(expr[2]) && is_string(expr[3])) - || (boolean_expr(expr[2]) && boolean_expr(expr[3])))) { - expr[1] = expr[1].substr(0, 2); - } - else if (no && expr[0] == "binary" - && (expr[1] == "||" || expr[1] == "&&")) { - // the whole expression is not constant but the lval may be... - try { - var lval = evaluate(expr[2]); - expr = ((expr[1] == "&&" && (lval ? expr[3] : lval)) || - (expr[1] == "||" && (lval ? lval : expr[3])) || - expr); - } catch(ex2) { - // IGNORE... lval is not constant - } - } - return no ? no.call(expr, expr) : null; - } - else throw ex; - } - }; - -})(); - -function warn_unreachable(ast) { - if (!empty(ast)) - warn("Dropping unreachable code: " + gen_code(ast, true)); -}; - -function ast_squeeze(ast, options) { - options = defaults(options, { - make_seqs : true, - dead_code : true, - keep_comps : true, - no_warnings : false - }); - - var w = ast_walker(), walk = w.walk, scope; - - function negate(c) { - var not_c = [ "unary-prefix", "!", c ]; - switch (c[0]) { - case "unary-prefix": - return c[1] == "!" && boolean_expr(c[2]) ? c[2] : not_c; - case "seq": - c = slice(c); - c[c.length - 1] = negate(c[c.length - 1]); - return c; - case "conditional": - return best_of(not_c, [ "conditional", c[1], negate(c[2]), negate(c[3]) ]); - case "binary": - var op = c[1], left = c[2], right = c[3]; - if (!options.keep_comps) switch (op) { - case "<=" : return [ "binary", ">", left, right ]; - case "<" : return [ "binary", ">=", left, right ]; - case ">=" : return [ "binary", "<", left, right ]; - case ">" : return [ "binary", "<=", left, right ]; - } - switch (op) { - case "==" : return [ "binary", "!=", left, right ]; - case "!=" : return [ "binary", "==", left, right ]; - case "===" : return [ "binary", "!==", left, right ]; - case "!==" : return [ "binary", "===", left, right ]; - case "&&" : return best_of(not_c, [ "binary", "||", negate(left), negate(right) ]); - case "||" : return best_of(not_c, [ "binary", "&&", negate(left), negate(right) ]); - } - break; - } - return not_c; - }; - - function with_scope(s, cont) { - var _scope = scope; - scope = s; - var ret = cont(); - ret.scope = s; - scope = _scope; - return ret; - }; - - function rmblock(block) { - if (block != null && block[0] == "block" && block[1]) { - if (block[1].length == 1) - block = block[1][0]; - else if (block[1].length == 0) - block = [ "block" ]; - } - return block; - }; - - function _lambda(name, args, body) { - var is_defun = this[0] == "defun"; - body = with_scope(body.scope, function(){ - var ret = tighten(MAP(body, walk), "lambda"); - if (!is_defun && name && !HOP(scope.refs, name)) - name = null; - return ret; - }); - return [ this[0], name, args, body ]; - }; - - // we get here for blocks that have been already transformed. - // this function does a few things: - // 1. discard useless blocks - // 2. join consecutive var declarations - // 3. remove obviously dead code - // 4. transform consecutive statements using the comma operator - // 5. if block_type == "lambda" and it detects constructs like if(foo) return ... - rewrite like if (!foo) { ... } - function tighten(statements, block_type) { - statements = statements.reduce(function(a, stat){ - if (stat[0] == "block") { - if (stat[1]) { - a.push.apply(a, stat[1]); - } - } else { - a.push(stat); - } - return a; - }, []); - - statements = (function(a, prev){ - statements.forEach(function(cur){ - if (prev && ((cur[0] == "var" && prev[0] == "var") || - (cur[0] == "const" && prev[0] == "const"))) { - prev[1] = prev[1].concat(cur[1]); - } else { - a.push(cur); - prev = cur; - } - }); - return a; - })([]); - - if (options.dead_code) statements = (function(a, has_quit){ - statements.forEach(function(st){ - if (has_quit) { - if (member(st[0], [ "function", "defun" , "var", "const" ])) { - a.push(st); - } - else if (!options.no_warnings) - warn_unreachable(st); - } - else { - a.push(st); - if (member(st[0], [ "return", "throw", "break", "continue" ])) - has_quit = true; - } - }); - return a; - })([]); - - if (options.make_seqs) statements = (function(a, prev) { - statements.forEach(function(cur){ - if (prev && prev[0] == "stat" && cur[0] == "stat") { - prev[1] = [ "seq", prev[1], cur[1] ]; - } else { - a.push(cur); - prev = cur; - } - }); - return a; - })([]); - - if (block_type == "lambda") statements = (function(i, a, stat){ - while (i < statements.length) { - stat = statements[i++]; - if (stat[0] == "if" && !stat[3]) { - if (stat[2][0] == "return" && stat[2][1] == null) { - a.push(make_if(negate(stat[1]), [ "block", statements.slice(i) ])); - break; - } - var last = last_stat(stat[2]); - if (last[0] == "return" && last[1] == null) { - a.push(make_if(stat[1], [ "block", stat[2][1].slice(0, -1) ], [ "block", statements.slice(i) ])); - break; - } - } - a.push(stat); - } - return a; - })(0, []); - - return statements; - }; - - function make_if(c, t, e) { - return when_constant(c, function(ast, val){ - if (val) { - warn_unreachable(e); - return t; - } else { - warn_unreachable(t); - return e; - } - }, function() { - return make_real_if(c, t, e); - }); - }; - - function make_real_if(c, t, e) { - c = walk(c); - t = walk(t); - e = walk(e); - - if (empty(t)) { - c = negate(c); - t = e; - e = null; - } else if (empty(e)) { - e = null; - } else { - // if we have both else and then, maybe it makes sense to switch them? - (function(){ - var a = gen_code(c); - var n = negate(c); - var b = gen_code(n); - if (b.length < a.length) { - var tmp = t; - t = e; - e = tmp; - c = n; - } - })(); - } - if (empty(e) && empty(t)) - return [ "stat", c ]; - var ret = [ "if", c, t, e ]; - if (t[0] == "if" && empty(t[3]) && empty(e)) { - ret = best_of(ret, walk([ "if", [ "binary", "&&", c, t[1] ], t[2] ])); - } - else if (t[0] == "stat") { - if (e) { - if (e[0] == "stat") { - ret = best_of(ret, [ "stat", make_conditional(c, t[1], e[1]) ]); - } - } - else { - ret = best_of(ret, [ "stat", make_conditional(c, t[1]) ]); - } - } - else if (e && t[0] == e[0] && (t[0] == "return" || t[0] == "throw") && t[1] && e[1]) { - ret = best_of(ret, [ t[0], make_conditional(c, t[1], e[1] ) ]); - } - else if (e && aborts(t)) { - ret = [ [ "if", c, t ] ]; - if (e[0] == "block") { - if (e[1]) ret = ret.concat(e[1]); - } - else { - ret.push(e); - } - ret = walk([ "block", ret ]); - } - else if (t && aborts(e)) { - ret = [ [ "if", negate(c), e ] ]; - if (t[0] == "block") { - if (t[1]) ret = ret.concat(t[1]); - } else { - ret.push(t); - } - ret = walk([ "block", ret ]); - } - return ret; - }; - - function _do_while(cond, body) { - return when_constant(cond, function(cond, val){ - if (!val) { - warn_unreachable(body); - return [ "block" ]; - } else { - return [ "for", null, null, null, walk(body) ]; - } - }); - }; - - return w.with_walkers({ - "sub": function(expr, subscript) { - if (subscript[0] == "string") { - var name = subscript[1]; - if (is_identifier(name)) - return [ "dot", walk(expr), name ]; - else if (/^[1-9][0-9]*$/.test(name) || name === "0") - return [ "sub", walk(expr), [ "num", parseInt(name, 10) ] ]; - } - }, - "if": make_if, - "toplevel": function(body) { - return [ "toplevel", with_scope(this.scope, function(){ - return tighten(MAP(body, walk)); - }) ]; - }, - "switch": function(expr, body) { - var last = body.length - 1; - return [ "switch", walk(expr), MAP(body, function(branch, i){ - var block = tighten(MAP(branch[1], walk)); - if (i == last && block.length > 0) { - var node = block[block.length - 1]; - if (node[0] == "break" && !node[1]) - block.pop(); - } - return [ branch[0] ? walk(branch[0]) : null, block ]; - }) ]; - }, - "function": _lambda, - "defun": _lambda, - "block": function(body) { - if (body) return rmblock([ "block", tighten(MAP(body, walk)) ]); - }, - "binary": function(op, left, right) { - return when_constant([ "binary", op, walk(left), walk(right) ], function yes(c){ - return best_of(walk(c), this); - }, function no() { - return this; - }); - }, - "conditional": function(c, t, e) { - return make_conditional(walk(c), walk(t), walk(e)); - }, - "try": function(t, c, f) { - return [ - "try", - tighten(MAP(t, walk)), - c != null ? [ c[0], tighten(MAP(c[1], walk)) ] : null, - f != null ? tighten(MAP(f, walk)) : null - ]; - }, - "unary-prefix": function(op, expr) { - expr = walk(expr); - var ret = [ "unary-prefix", op, expr ]; - if (op == "!") - ret = best_of(ret, negate(expr)); - return when_constant(ret, function(ast, val){ - return walk(ast); // it's either true or false, so minifies to !0 or !1 - }, function() { return ret }); - }, - "name": function(name) { - switch (name) { - case "true": return [ "unary-prefix", "!", [ "num", 0 ]]; - case "false": return [ "unary-prefix", "!", [ "num", 1 ]]; - } - }, - "new": function(ctor, args) { - if (ctor[0] == "name" && ctor[1] == "Array" && !scope.has("Array")) { - if (args.length != 1) { - return [ "array", args ]; - } else { - return [ "call", [ "name", "Array" ], args ]; - } - } - }, - "call": function(expr, args) { - if (expr[0] == "name" && expr[1] == "Array" && args.length != 1 && !scope.has("Array")) { - return [ "array", args ]; - } - }, - "while": _do_while, - "do": _do_while - }, function() { - return walk(ast_add_scope(ast)); - }); -}; - -/* -----[ re-generate code from the AST ]----- */ - -var DOT_CALL_NO_PARENS = jsp.array_to_hash([ - "name", - "array", - "object", - "string", - "dot", - "sub", - "call", - "regexp" -]); - -function make_string(str, ascii_only) { - var dq = 0, sq = 0; - str = str.replace(/[\\\b\f\n\r\t\x22\x27\u2028\u2029]/g, function(s){ - switch (s) { - case "\\": return "\\\\"; - case "\b": return "\\b"; - case "\f": return "\\f"; - case "\n": return "\\n"; - case "\r": return "\\r"; - case "\t": return "\\t"; - case "\u2028": return "\\u2028"; - case "\u2029": return "\\u2029"; - case '"': ++dq; return '"'; - case "'": ++sq; return "'"; - } - return s; - }); - if (ascii_only) str = to_ascii(str); - if (dq > sq) return "'" + str.replace(/\x27/g, "\\'") + "'"; - else return '"' + str.replace(/\x22/g, '\\"') + '"'; -}; - -function to_ascii(str) { - return str.replace(/[\u0080-\uffff]/g, function(ch) { - var code = ch.charCodeAt(0).toString(16); - while (code.length < 4) code = "0" + code; - return "\\u" + code; - }); -}; - -var SPLICE_NEEDS_BRACKETS = jsp.array_to_hash([ "if", "while", "do", "for", "for-in", "with" ]); - -function gen_code(ast, options) { - options = defaults(options, { - indent_start : 0, - indent_level : 4, - quote_keys : false, - space_colon : false, - beautify : false, - ascii_only : false - }); - var beautify = !!options.beautify; - var indentation = 0, - newline = beautify ? "\n" : "", - space = beautify ? " " : ""; - - function encode_string(str) { - return make_string(str, options.ascii_only); - }; - - function make_name(name) { - name = name.toString(); - if (options.ascii_only) - name = to_ascii(name); - return name; - }; - - function indent(line) { - if (line == null) - line = ""; - if (beautify) - line = repeat_string(" ", options.indent_start + indentation * options.indent_level) + line; - return line; - }; - - function with_indent(cont, incr) { - if (incr == null) incr = 1; - indentation += incr; - try { return cont.apply(null, slice(arguments, 1)); } - finally { indentation -= incr; } - }; - - function add_spaces(a) { - if (beautify) - return a.join(" "); - var b = []; - for (var i = 0; i < a.length; ++i) { - var next = a[i + 1]; - b.push(a[i]); - if (next && - ((/[a-z0-9_\x24]$/i.test(a[i].toString()) && /^[a-z0-9_\x24]/i.test(next.toString())) || - (/[\+\-]$/.test(a[i].toString()) && /^[\+\-]/.test(next.toString())))) { - b.push(" "); - } - } - return b.join(""); - }; - - function add_commas(a) { - return a.join("," + space); - }; - - function parenthesize(expr) { - var gen = make(expr); - for (var i = 1; i < arguments.length; ++i) { - var el = arguments[i]; - if ((el instanceof Function && el(expr)) || expr[0] == el) - return "(" + gen + ")"; - } - return gen; - }; - - function best_of(a) { - if (a.length == 1) { - return a[0]; - } - if (a.length == 2) { - var b = a[1]; - a = a[0]; - return a.length <= b.length ? a : b; - } - return best_of([ a[0], best_of(a.slice(1)) ]); - }; - - function needs_parens(expr) { - if (expr[0] == "function" || expr[0] == "object") { - // dot/call on a literal function requires the - // function literal itself to be parenthesized - // only if it's the first "thing" in a - // statement. This means that the parent is - // "stat", but it could also be a "seq" and - // we're the first in this "seq" and the - // parent is "stat", and so on. Messy stuff, - // but it worths the trouble. - var a = slice($stack), self = a.pop(), p = a.pop(); - while (p) { - if (p[0] == "stat") return true; - if (((p[0] == "seq" || p[0] == "call" || p[0] == "dot" || p[0] == "sub" || p[0] == "conditional") && p[1] === self) || - ((p[0] == "binary" || p[0] == "assign" || p[0] == "unary-postfix") && p[2] === self)) { - self = p; - p = a.pop(); - } else { - return false; - } - } - } - return !HOP(DOT_CALL_NO_PARENS, expr[0]); - }; - - function make_num(num) { - var str = num.toString(10), a = [ str.replace(/^0\./, ".") ], m; - if (Math.floor(num) === num) { - a.push("0x" + num.toString(16).toLowerCase(), // probably pointless - "0" + num.toString(8)); // same. - if ((m = /^(.*?)(0+)$/.exec(num))) { - a.push(m[1] + "e" + m[2].length); - } - } else if ((m = /^0?\.(0+)(.*)$/.exec(num))) { - a.push(m[2] + "e-" + (m[1].length + m[2].length), - str.substr(str.indexOf("."))); - } - return best_of(a); - }; - - var generators = { - "string": encode_string, - "num": make_num, - "name": make_name, - "toplevel": function(statements) { - return make_block_statements(statements) - .join(newline + newline); - }, - "splice": function(statements) { - var parent = $stack[$stack.length - 2][0]; - if (HOP(SPLICE_NEEDS_BRACKETS, parent)) { - // we need block brackets in this case - return make_block.apply(this, arguments); - } else { - return MAP(make_block_statements(statements, true), - function(line, i) { - // the first line is already indented - return i > 0 ? indent(line) : line; - }).join(newline); - } - }, - "block": make_block, - "var": function(defs) { - return "var " + add_commas(MAP(defs, make_1vardef)) + ";"; - }, - "const": function(defs) { - return "const " + add_commas(MAP(defs, make_1vardef)) + ";"; - }, - "try": function(tr, ca, fi) { - var out = [ "try", make_block(tr) ]; - if (ca) out.push("catch", "(" + ca[0] + ")", make_block(ca[1])); - if (fi) out.push("finally", make_block(fi)); - return add_spaces(out); - }, - "throw": function(expr) { - return add_spaces([ "throw", make(expr) ]) + ";"; - }, - "new": function(ctor, args) { - args = args.length > 0 ? "(" + add_commas(MAP(args, make)) + ")" : ""; - return add_spaces([ "new", parenthesize(ctor, "seq", "binary", "conditional", "assign", function(expr){ - var w = ast_walker(), has_call = {}; - try { - w.with_walkers({ - "call": function() { throw has_call }, - "function": function() { return this } - }, function(){ - w.walk(expr); - }); - } catch(ex) { - if (ex === has_call) - return true; - throw ex; - } - }) + args ]); - }, - "switch": function(expr, body) { - return add_spaces([ "switch", "(" + make(expr) + ")", make_switch_block(body) ]); - }, - "break": function(label) { - var out = "break"; - if (label != null) - out += " " + make_name(label); - return out + ";"; - }, - "continue": function(label) { - var out = "continue"; - if (label != null) - out += " " + make_name(label); - return out + ";"; - }, - "conditional": function(co, th, el) { - return add_spaces([ parenthesize(co, "assign", "seq", "conditional"), "?", - parenthesize(th, "seq"), ":", - parenthesize(el, "seq") ]); - }, - "assign": function(op, lvalue, rvalue) { - if (op && op !== true) op += "="; - else op = "="; - return add_spaces([ make(lvalue), op, parenthesize(rvalue, "seq") ]); - }, - "dot": function(expr) { - var out = make(expr), i = 1; - if (expr[0] == "num") { - if (!/\./.test(expr[1])) - out += "."; - } else if (needs_parens(expr)) - out = "(" + out + ")"; - while (i < arguments.length) - out += "." + make_name(arguments[i++]); - return out; - }, - "call": function(func, args) { - var f = make(func); - if (needs_parens(func)) - f = "(" + f + ")"; - return f + "(" + add_commas(MAP(args, function(expr){ - return parenthesize(expr, "seq"); - })) + ")"; - }, - "function": make_function, - "defun": make_function, - "if": function(co, th, el) { - var out = [ "if", "(" + make(co) + ")", el ? make_then(th) : make(th) ]; - if (el) { - out.push("else", make(el)); - } - return add_spaces(out); - }, - "for": function(init, cond, step, block) { - var out = [ "for" ]; - init = (init != null ? make(init) : "").replace(/;*\s*$/, ";" + space); - cond = (cond != null ? make(cond) : "").replace(/;*\s*$/, ";" + space); - step = (step != null ? make(step) : "").replace(/;*\s*$/, ""); - var args = init + cond + step; - if (args == "; ; ") args = ";;"; - out.push("(" + args + ")", make(block)); - return add_spaces(out); - }, - "for-in": function(vvar, key, hash, block) { - return add_spaces([ "for", "(" + - (vvar ? make(vvar).replace(/;+$/, "") : make(key)), - "in", - make(hash) + ")", make(block) ]); - }, - "while": function(condition, block) { - return add_spaces([ "while", "(" + make(condition) + ")", make(block) ]); - }, - "do": function(condition, block) { - return add_spaces([ "do", make(block), "while", "(" + make(condition) + ")" ]) + ";"; - }, - "return": function(expr) { - var out = [ "return" ]; - if (expr != null) out.push(make(expr)); - return add_spaces(out) + ";"; - }, - "binary": function(operator, lvalue, rvalue) { - var left = make(lvalue), right = make(rvalue); - // XXX: I'm pretty sure other cases will bite here. - // we need to be smarter. - // adding parens all the time is the safest bet. - if (member(lvalue[0], [ "assign", "conditional", "seq" ]) || - lvalue[0] == "binary" && PRECEDENCE[operator] > PRECEDENCE[lvalue[1]]) { - left = "(" + left + ")"; - } - if (member(rvalue[0], [ "assign", "conditional", "seq" ]) || - rvalue[0] == "binary" && PRECEDENCE[operator] >= PRECEDENCE[rvalue[1]] && - !(rvalue[1] == operator && member(operator, [ "&&", "||", "*" ]))) { - right = "(" + right + ")"; - } - return add_spaces([ left, operator, right ]); - }, - "unary-prefix": function(operator, expr) { - var val = make(expr); - if (!(expr[0] == "num" || (expr[0] == "unary-prefix" && !HOP(OPERATORS, operator + expr[1])) || !needs_parens(expr))) - val = "(" + val + ")"; - return operator + (jsp.is_alphanumeric_char(operator.charAt(0)) ? " " : "") + val; - }, - "unary-postfix": function(operator, expr) { - var val = make(expr); - if (!(expr[0] == "num" || (expr[0] == "unary-postfix" && !HOP(OPERATORS, operator + expr[1])) || !needs_parens(expr))) - val = "(" + val + ")"; - return val + operator; - }, - "sub": function(expr, subscript) { - var hash = make(expr); - if (needs_parens(expr)) - hash = "(" + hash + ")"; - return hash + "[" + make(subscript) + "]"; - }, - "object": function(props) { - if (props.length == 0) - return "{}"; - return "{" + newline + with_indent(function(){ - return MAP(props, function(p){ - if (p.length == 3) { - // getter/setter. The name is in p[0], the arg.list in p[1][2], the - // body in p[1][3] and type ("get" / "set") in p[2]. - return indent(make_function(p[0], p[1][2], p[1][3], p[2])); - } - var key = p[0], val = make(p[1]); - if (options.quote_keys) { - key = encode_string(key); - } else if ((typeof key == "number" || !beautify && +key + "" == key) - && parseFloat(key) >= 0) { - key = make_num(+key); - } else if (!is_identifier(key)) { - key = encode_string(key); - } - return indent(add_spaces(beautify && options.space_colon - ? [ key, ":", val ] - : [ key + ":", val ])); - }).join("," + newline); - }) + newline + indent("}"); - }, - "regexp": function(rx, mods) { - return "/" + rx + "/" + mods; - }, - "array": function(elements) { - if (elements.length == 0) return "[]"; - return add_spaces([ "[", add_commas(MAP(elements, function(el){ - if (!beautify && el[0] == "atom" && el[1] == "undefined") return ""; - return parenthesize(el, "seq"); - })), "]" ]); - }, - "stat": function(stmt) { - return make(stmt).replace(/;*\s*$/, ";"); - }, - "seq": function() { - return add_commas(MAP(slice(arguments), make)); - }, - "label": function(name, block) { - return add_spaces([ make_name(name), ":", make(block) ]); - }, - "with": function(expr, block) { - return add_spaces([ "with", "(" + make(expr) + ")", make(block) ]); - }, - "atom": function(name) { - return make_name(name); - } - }; - - // The squeezer replaces "block"-s that contain only a single - // statement with the statement itself; technically, the AST - // is correct, but this can create problems when we output an - // IF having an ELSE clause where the THEN clause ends in an - // IF *without* an ELSE block (then the outer ELSE would refer - // to the inner IF). This function checks for this case and - // adds the block brackets if needed. - function make_then(th) { - if (th[0] == "do") { - // https://github.com/mishoo/UglifyJS/issues/#issue/57 - // IE croaks with "syntax error" on code like this: - // if (foo) do ... while(cond); else ... - // we need block brackets around do/while - return make([ "block", [ th ]]); - } - var b = th; - while (true) { - var type = b[0]; - if (type == "if") { - if (!b[3]) - // no else, we must add the block - return make([ "block", [ th ]]); - b = b[3]; - } - else if (type == "while" || type == "do") b = b[2]; - else if (type == "for" || type == "for-in") b = b[4]; - else break; - } - return make(th); - }; - - function make_function(name, args, body, keyword) { - var out = keyword || "function"; - if (name) { - out += " " + make_name(name); - } - out += "(" + add_commas(MAP(args, make_name)) + ")"; - return add_spaces([ out, make_block(body) ]); - }; - - function make_block_statements(statements, noindent) { - for (var a = [], last = statements.length - 1, i = 0; i <= last; ++i) { - var stat = statements[i]; - var code = make(stat); - if (code != ";") { - if (!beautify && i == last) { - if ((stat[0] == "while" && empty(stat[2])) || - (member(stat[0], [ "for", "for-in"] ) && empty(stat[4])) || - (stat[0] == "if" && empty(stat[2]) && !stat[3]) || - (stat[0] == "if" && stat[3] && empty(stat[3]))) { - code = code.replace(/;*\s*$/, ";"); - } else { - code = code.replace(/;+\s*$/, ""); - } - } - a.push(code); - } - } - return noindent ? a : MAP(a, indent); - }; - - function make_switch_block(body) { - var n = body.length; - if (n == 0) return "{}"; - return "{" + newline + MAP(body, function(branch, i){ - var has_body = branch[1].length > 0, code = with_indent(function(){ - return indent(branch[0] - ? add_spaces([ "case", make(branch[0]) + ":" ]) - : "default:"); - }, 0.5) + (has_body ? newline + with_indent(function(){ - return make_block_statements(branch[1]).join(newline); - }) : ""); - if (!beautify && has_body && i < n - 1) - code += ";"; - return code; - }).join(newline) + newline + indent("}"); - }; - - function make_block(statements) { - if (!statements) return ";"; - if (statements.length == 0) return "{}"; - return "{" + newline + with_indent(function(){ - return make_block_statements(statements).join(newline); - }) + newline + indent("}"); - }; - - function make_1vardef(def) { - var name = def[0], val = def[1]; - if (val != null) - name = add_spaces([ make_name(name), "=", parenthesize(val, "seq") ]); - return name; - }; - - var $stack = []; - - function make(node) { - var type = node[0]; - var gen = generators[type]; - if (!gen) - throw new Error("Can't find generator for \"" + type + "\""); - $stack.push(node); - var ret = gen.apply(type, node.slice(1)); - $stack.pop(); - return ret; - }; - - return make(ast); -}; - -function split_lines(code, max_line_length) { - var splits = [ 0 ]; - jsp.parse(function(){ - var next_token = jsp.tokenizer(code); - var last_split = 0; - var prev_token; - function current_length(tok) { - return tok.pos - last_split; - }; - function split_here(tok) { - last_split = tok.pos; - splits.push(last_split); - }; - function custom(){ - var tok = next_token.apply(this, arguments); - out: { - if (prev_token) { - if (prev_token.type == "keyword") break out; - } - if (current_length(tok) > max_line_length) { - switch (tok.type) { - case "keyword": - case "atom": - case "name": - case "punc": - split_here(tok); - break out; - } - } - } - prev_token = tok; - return tok; - }; - custom.context = function() { - return next_token.context.apply(this, arguments); - }; - return custom; - }()); - return splits.map(function(pos, i){ - return code.substring(pos, splits[i + 1] || code.length); - }).join("\n"); -}; - -/* -----[ Utilities ]----- */ - -function repeat_string(str, i) { - if (i <= 0) return ""; - if (i == 1) return str; - var d = repeat_string(str, i >> 1); - d += d; - if (i & 1) d += str; - return d; -}; - -function defaults(args, defs) { - var ret = {}; - if (args === true) - args = {}; - for (var i in defs) if (HOP(defs, i)) { - ret[i] = (args && HOP(args, i)) ? args[i] : defs[i]; - } - return ret; -}; - -function is_identifier(name) { - return /^[a-z_$][a-z0-9_$]*$/i.test(name) - && name != "this" - && !HOP(jsp.KEYWORDS_ATOM, name) - && !HOP(jsp.RESERVED_WORDS, name) - && !HOP(jsp.KEYWORDS, name); -}; - -function HOP(obj, prop) { - return Object.prototype.hasOwnProperty.call(obj, prop); -}; - -// some utilities - -var MAP; - -(function(){ - MAP = function(a, f, o) { - var ret = []; - for (var i = 0; i < a.length; ++i) { - var val = f.call(o, a[i], i); - if (val instanceof AtTop) ret.unshift(val.v); - else ret.push(val); - } - return ret; - }; - MAP.at_top = function(val) { return new AtTop(val) }; - function AtTop(val) { this.v = val }; -})(); - -/* -----[ Exports ]----- */ - -exports.ast_walker = ast_walker; -exports.ast_mangle = ast_mangle; -exports.ast_squeeze = ast_squeeze; -exports.gen_code = gen_code; -exports.ast_add_scope = ast_add_scope; -exports.set_logger = function(logger) { warn = logger }; -exports.make_string = make_string; -exports.split_lines = split_lines; -exports.MAP = MAP; - -// keep this last! -exports.ast_squeeze_more = require("./squeeze-more").ast_squeeze_more; diff --git a/build/lib/squeeze-more.js b/build/lib/squeeze-more.js deleted file mode 100644 index 12380af8..00000000 --- a/build/lib/squeeze-more.js +++ /dev/null @@ -1,22 +0,0 @@ -var jsp = require("./parse-js"), - pro = require("./process"), - slice = jsp.slice, - member = jsp.member, - PRECEDENCE = jsp.PRECEDENCE, - OPERATORS = jsp.OPERATORS; - -function ast_squeeze_more(ast) { - var w = pro.ast_walker(), walk = w.walk; - return w.with_walkers({ - "call": function(expr, args) { - if (expr[0] == "dot" && expr[2] == "toString" && args.length == 0) { - // foo.toString() ==> foo+"" - return [ "binary", "+", expr[1], [ "string", "" ]]; - } - } - }, function() { - return walk(ast); - }); -}; - -exports.ast_squeeze_more = ast_squeeze_more; diff --git a/build/post-compile.js b/build/post-compile.js deleted file mode 100644 index 1bbeaa6f..00000000 --- a/build/post-compile.js +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env node - -var print = require("sys").print, - src = require("fs").readFileSync(process.argv[2], "utf8"); - -// Previously done in sed but reimplemented here due to portability issues -print( src.replace( /^(\s*\*\/)(.+)/m, "$1\n$2" ) + ";" ); diff --git a/build/release-notes.js b/build/release-notes.js deleted file mode 100644 index b112d998..00000000 --- a/build/release-notes.js +++ /dev/null @@ -1,54 +0,0 @@ -#!/usr/bin/env node -/* - * jQuery Release Note Generator - */ - -var fs = require("fs"), - http = require("http"), - tmpl = require("mustache"), - extract = /(.*?)<[^"]+"component">\s*(\S+)/g; - -var opts = { - version: "1.6.2 RC 1", - short_version: "1.6.2rc1", - final_version: "1.6.2", - categories: [] -}; - -http.request({ - host: "bugs.jquery.com", - port: 80, - method: "GET", - path: "/query?status=closed&resolution=fixed&component=!web&order=component&milestone=" + opts.final_version -}, function (res) { - var data = []; - - res.on( "data", function( chunk ) { - data.push( chunk ); - }); - - res.on( "end", function() { - var match, - file = data.join(""), - cur; - - while ( (match = extract.exec( file )) ) { - if ( "#" + match[1] !== match[2] ) { - var cat = match[3]; - - if ( !cur || cur.name !== cat ) { - cur = { name: match[3], niceName: match[3].replace(/^./, function(a){ return a.toUpperCase(); }), bugs: [] }; - opts.categories.push( cur ); - } - - cur.bugs.push({ ticket: match[1], title: match[2] }); - } - } - - buildNotes(); - }); -}).end(); - -function buildNotes() { - console.log( tmpl.to_html( fs.readFileSync("release-notes.txt", "utf8"), opts ) ); -} diff --git a/build/release-notes.txt b/build/release-notes.txt deleted file mode 100644 index 1d0ae746..00000000 --- a/build/release-notes.txt +++ /dev/null @@ -1,27 +0,0 @@ -

jQuery {{version}} Released

- -

This is a preview release of jQuery. We're releasing it so that everyone can start testing the code in their applications, making sure that there are no major problems.

- -

You can get the code from the jQuery CDN:

- -
- -

You can help us by dropping that code into your existing application and letting us know that if anything no longer works. Please file a bug and be sure to mention that you're testing against jQuery {{version}}.

- -

We want to encourage everyone from the community to try and get involved in contributing back to jQuery core. We've set up a full page of information dedicated towards becoming more involved with the team. The team is here and ready to help you help us!

- -

jQuery {{version}} Change Log

- -

The current change log of the {{version}} release.

- -{{#categories}} -

{{niceName}}

- - -{{/categories}} diff --git a/build/release.js b/build/release.js deleted file mode 100644 index 7a42f998..00000000 --- a/build/release.js +++ /dev/null @@ -1,169 +0,0 @@ -#!/usr/bin/env node -/* - * jQuery Release Management - */ - -var fs = require("fs"), - child = require("child_process"), - debug = false; - -var scpURL = "jqadmin@code.origin.jquery.com:/var/www/html/code.jquery.com/", - cdnURL = "http://code.origin.jquery.com/", - - version = /^[\d.]+(?:(?:a|b|rc)\d+|pre)?$/, - versionFile = "version.txt", - - file = "dist/jquery.js", - minFile = "dist/jquery.min.js", - - files = { - "jquery-VER.js": file, - "jquery-VER.min.js": minFile - }, - - finalFiles = { - "jquery.js": file, - "jquery-latest.js": file, - "jquery.min.js": minFile, - "jquery-latest.min.js": minFile - }; - -exec( "git pull && git status", function( error, stdout, stderr ) { - if ( /Changes to be committed/i.test( stdout ) ) { - exit( "Please commit changed files before attemping to push a release." ); - - } else if ( /Changes not staged for commit/i.test( stdout ) ) { - exit( "Please stash files before attempting to push a release." ); - - } else { - setVersion(); - } -}); - -function setVersion() { - var oldVersion = fs.readFileSync( versionFile, "utf8" ); - - prompt( "New Version (was " + oldVersion + "): ", function( data ) { - if ( data && version.test( data ) ) { - fs.writeFileSync( versionFile, data ); - - exec( "git commit -a -m 'Tagging the " + data + " release.' && git push && " + - "git tag " + data + " && git push origin " + data, function() { - make( data ); - }); - - } else { - console.error( "Malformed version number, please try again." ); - setVersion(); - } - }); -} - -function make( newVersion ) { - exec( "make clean && make", function( error, stdout, stderr ) { - // TODO: Verify JSLint - - Object.keys( files ).forEach(function( oldName ) { - var value = files[ oldName ], name = oldName.replace( /VER/g, newVersion ); - - copy( value, name ); - - delete files[ oldName ]; - files[ name ] = value; - }); - - exec( "scp " + Object.keys( files ).join( " " ) + " " + scpURL, function() { - setNextVersion( newVersion ); - }); - }); -} - -function setNextVersion( newVersion ) { - var isFinal = false; - - if ( /(?:a|b|rc)\d+$/.test( newVersion ) ) { - newVersion = newVersion.replace( /(?:a|b|rc)\d+$/, "pre" ); - - } else if ( /^\d+\.\d+\.?(\d*)$/.test( newVersion ) ) { - newVersion = newVersion.replace( /^(\d+\.\d+\.?)(\d*)$/, function( all, pre, num ) { - return pre + (pre.charAt( pre.length - 1 ) !== "." ? "." : "") + (num ? parseFloat( num ) + 1 : 1) + "pre"; - }); - - isFinal = true; - } - - prompt( "Next Version [" + newVersion + "]: ", function( data ) { - if ( !data ) { - data = newVersion; - } - - if ( version.test( data ) ) { - fs.writeFileSync( versionFile, data ); - - exec( "git commit -a -m 'Updating the source version to " + data + "' && git push", function() { - if ( isFinal ) { - makeFinal( newVersion ); - } - }); - - } else { - console.error( "Malformed version number, please try again." ); - setNextVersion( newVersion ); - } - }); -} - -function makeFinal( newVersion ) { - var all = Object.keys( finalFiles ); - - // Copy all the files - all.forEach(function( name ) { - copy( finalFiles[ name ], name ); - }); - - // Upload files to CDN - exec( "scp " + all.join( " " ) + " " + scpURL, function() { - exec( "curl '" + cdnURL + "{" + all.join( "," ) + "}?reload'", function() { - console.log( "Done." ); - }); - }); -} - -function copy( oldFile, newFile ) { - if ( debug ) { - console.log( "Copying " + oldFile + " to " + newFile ); - - } else { - fs.writeFileSync( newFile, fs.readFileSync( oldFile, "utf8" ) ); - } -} - -function prompt( msg, callback ) { - process.stdout.write( msg ); - - process.stdin.resume(); - process.stdin.setEncoding( "utf8" ); - - process.stdin.once( "data", function( chunk ) { - process.stdin.pause(); - callback( chunk.replace( /\n*$/g, "" ) ); - }); -} - -function exec( cmd, fn ) { - if ( debug ) { - console.log( cmd ); - fn(); - - } else { - child.exec( cmd, fn ); - } -} - -function exit( msg ) { - if ( msg ) { - console.error( "\nError: " + msg ); - } - - process.exit( 1 ); -} diff --git a/build/runtest/env.js b/build/runtest/env.js new file mode 100644 index 00000000..e15a2263 --- /dev/null +++ b/build/runtest/env.js @@ -0,0 +1,695 @@ +/* + * Simulated browser environment for Rhino + * By John Resig + * Copyright 2007 John Resig, under the MIT License + */ + +// The window Object +var window = this; + +(function(){ + + // Browser Navigator + + window.navigator = { + get userAgent(){ + return "Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3"; + } + }; + + var curLocation = (new java.io.File("./")).toURL(); + + window.__defineSetter__("location", function(url){ + var xhr = new XMLHttpRequest(); + xhr.open("GET", url); + xhr.onreadystatechange = function(){ + curLocation = new java.net.URL( curLocation, url ); + window.document = xhr.responseXML; + + var event = document.createEvent(); + event.initEvent("load"); + window.dispatchEvent( event ); + }; + xhr.send(); + }); + + window.__defineGetter__("location", function(url){ + return { + get protocol(){ + return curLocation.getProtocol() + ":"; + }, + get href(){ + return curLocation.toString(); + }, + toString: function(){ + return this.href; + } + }; + }); + + // Timers + + var timers = []; + + window.setTimeout = function(fn, time){ + var num; + return num = setInterval(function(){ + fn(); + clearInterval(num); + }, time); + }; + + window.setInterval = function(fn, time){ + var num = timers.length; + + timers[num] = new java.lang.Thread(new java.lang.Runnable({ + run: function(){ + while (true){ + java.lang.Thread.currentThread().sleep(time); + fn(); + } + } + })); + + timers[num].start(); + + return num; + }; + + window.clearInterval = function(num){ + if ( timers[num] ) { + timers[num].stop(); + delete timers[num]; + } + }; + + // Window Events + + var events = [{}]; + + window.addEventListener = function(type, fn){ + if ( !this.uuid || this == window ) { + this.uuid = events.length; + events[this.uuid] = {}; + } + + if ( !events[this.uuid][type] ) + events[this.uuid][type] = []; + + if ( events[this.uuid][type].indexOf( fn ) < 0 ) + events[this.uuid][type].push( fn ); + }; + + window.removeEventListener = function(type, fn){ + if ( !this.uuid || this == window ) { + this.uuid = events.length; + events[this.uuid] = {}; + } + + if ( !events[this.uuid][type] ) + events[this.uuid][type] = []; + + events[this.uuid][type] = + events[this.uuid][type].filter(function(f){ + return f != fn; + }); + }; + + window.dispatchEvent = function(event){ + if ( event.type ) { + if ( this.uuid && events[this.uuid][event.type] ) { + var self = this; + + events[this.uuid][event.type].forEach(function(fn){ + fn.call( self, event ); + }); + } + + if ( this["on" + event.type] ) + this["on" + event.type].call( self, event ); + } + }; + + // DOM Document + + window.DOMDocument = function(file){ + this._file = file; + this._dom = Packages.javax.xml.parsers. + DocumentBuilderFactory.newInstance() + .newDocumentBuilder().parse(file); + + if ( !obj_nodes.containsKey( this._dom ) ) + obj_nodes.put( this._dom, this ); + }; + + DOMDocument.prototype = { + createTextNode: function(text){ + return makeNode( this._dom.createTextNode( + text.replace(/&/g, "&").replace(//g, ">")) ); + }, + createElement: function(name){ + return makeNode( this._dom.createElement(name.toLowerCase()) ); + }, + getElementsByTagName: function(name){ + return new DOMNodeList( this._dom.getElementsByTagName( + name.toLowerCase()) ); + }, + getElementById: function(id){ + var elems = this._dom.getElementsByTagName("*"); + + for ( var i = 0; i < elems.length; i++ ) { + var elem = elems.item(i); + if ( elem.getAttribute("id") == id ) + return makeNode(elem); + } + + return null; + }, + get body(){ + return this.getElementsByTagName("body")[0]; + }, + get documentElement(){ + return makeNode( this._dom.getDocumentElement() ); + }, + get ownerDocument(){ + return null; + }, + addEventListener: window.addEventListener, + removeEventListener: window.removeEventListener, + dispatchEvent: window.dispatchEvent, + get nodeName() { + return "#document"; + }, + importNode: function(node, deep){ + return makeNode( this._dom.importNode(node._dom, deep) ); + }, + toString: function(){ + return "Document" + (typeof this._file == "string" ? + ": " + this._file : ""); + }, + get innerHTML(){ + return this.documentElement.outerHTML; + }, + + get defaultView(){ + return { + getComputedStyle: function(elem){ + return { + getPropertyValue: function(prop){ + prop = prop.replace(/\-(\w)/g,function(m,c){ + return c.toUpperCase(); + }); + var val = elem.style[prop]; + + if ( prop == "opacity" && val == "" ) + val = "1"; + + return val; + } + }; + } + }; + }, + + createEvent: function(){ + return { + type: "", + initEvent: function(type){ + this.type = type; + } + }; + } + }; + + function getDocument(node){ + return obj_nodes.get(node); + } + + // DOM NodeList + + window.DOMNodeList = function(list){ + this._dom = list; + this.length = list.getLength(); + + for ( var i = 0; i < this.length; i++ ) { + var node = list.item(i); + this[i] = makeNode( node ); + } + }; + + DOMNodeList.prototype = { + toString: function(){ + return "[ " + + Array.prototype.join.call( this, ", " ) + " ]"; + }, + get outerHTML(){ + return Array.prototype.map.call( + this, function(node){return node.outerHTML;}).join(''); + } + }; + + // DOM Node + + window.DOMNode = function(node){ + this._dom = node; + }; + + DOMNode.prototype = { + get nodeType(){ + return this._dom.getNodeType(); + }, + get nodeValue(){ + return this._dom.getNodeValue(); + }, + get nodeName() { + return this._dom.getNodeName(); + }, + cloneNode: function(deep){ + return makeNode( this._dom.cloneNode(deep) ); + }, + get ownerDocument(){ + return getDocument( this._dom.ownerDocument ); + }, + get documentElement(){ + return makeNode( this._dom.documentElement ); + }, + get parentNode() { + return makeNode( this._dom.getParentNode() ); + }, + get nextSibling() { + return makeNode( this._dom.getNextSibling() ); + }, + get previousSibling() { + return makeNode( this._dom.getPreviousSibling() ); + }, + toString: function(){ + return '"' + this.nodeValue + '"'; + }, + get outerHTML(){ + return this.nodeValue; + } + }; + + // DOM Element + + window.DOMElement = function(elem){ + this._dom = elem; + this.style = { + get opacity(){ return this._opacity; }, + set opacity(val){ this._opacity = val + ""; } + }; + + // Load CSS info + var styles = (this.getAttribute("style") || "").split(/\s*;\s*/); + + for ( var i = 0; i < styles.length; i++ ) { + var style = styles[i].split(/\s*:\s*/); + if ( style.length == 2 ) + this.style[ style[0] ] = style[1]; + } + }; + + DOMElement.prototype = extend( new DOMNode(), { + get nodeName(){ + return this.tagName.toUpperCase(); + }, + get tagName(){ + return this._dom.getTagName(); + }, + toString: function(){ + return "<" + this.tagName + (this.id ? "#" + this.id : "" ) + ">"; + }, + get outerHTML(){ + var ret = "<" + this.tagName, attr = this.attributes; + + for ( var i in attr ) + ret += " " + i + "='" + attr[i] + "'"; + + if ( this.childNodes.length || this.nodeName == "SCRIPT" ) + ret += ">" + this.childNodes.outerHTML + + ""; + else + ret += "/>"; + + return ret; + }, + + get attributes(){ + var attr = {}, attrs = this._dom.getAttributes(); + + for ( var i = 0; i < attrs.getLength(); i++ ) + attr[ attrs.item(i).nodeName ] = attrs.item(i).nodeValue; + + return attr; + }, + + get innerHTML(){ + return this.childNodes.outerHTML; + }, + set innerHTML(html){ + html = html.replace(/<\/?([A-Z]+)/g, function(m){ + return m.toLowerCase(); + }); + + var nodes = this.ownerDocument.importNode( + new DOMDocument( new java.io.ByteArrayInputStream( + (new java.lang.String("" + html + "")) + .getBytes("UTF8"))).documentElement, true).childNodes; + + while (this.firstChild) + this.removeChild( this.firstChild ); + + for ( var i = 0; i < nodes.length; i++ ) + this.appendChild( nodes[i] ); + }, + + get textContent(){ + return nav(this.childNodes); + + function nav(nodes){ + var str = ""; + for ( var i = 0; i < nodes.length; i++ ) + if ( nodes[i].nodeType == 3 ) + str += nodes[i].nodeValue; + else if ( nodes[i].nodeType == 1 ) + str += nav(nodes[i].childNodes); + return str; + } + }, + set textContent(text){ + while (this.firstChild) + this.removeChild( this.firstChild ); + this.appendChild( this.ownerDocument.createTextNode(text)); + }, + + style: {}, + clientHeight: 0, + clientWidth: 0, + offsetHeight: 0, + offsetWidth: 0, + + get disabled() { + var val = this.getAttribute("disabled"); + return val != "false" && !!val; + }, + set disabled(val) { return this.setAttribute("disabled",val); }, + + get checked() { + var val = this.getAttribute("checked"); + return val != "false" && !!val; + }, + set checked(val) { return this.setAttribute("checked",val); }, + + get selected() { + if ( !this._selectDone ) { + this._selectDone = true; + + if ( this.nodeName == "OPTION" && !this.parentNode.getAttribute("multiple") ) { + var opt = this.parentNode.getElementsByTagName("option"); + + if ( this == opt[0] ) { + var select = true; + + for ( var i = 1; i < opt.length; i++ ) + if ( opt[i].selected ) { + select = false; + break; + } + + if ( select ) + this.selected = true; + } + } + } + + var val = this.getAttribute("selected"); + return val != "false" && !!val; + }, + set selected(val) { return this.setAttribute("selected",val); }, + + get className() { return this.getAttribute("class") || ""; }, + set className(val) { + return this.setAttribute("class", + val.replace(/(^\s*|\s*$)/g,"")); + }, + + get type() { return this.getAttribute("type") || ""; }, + set type(val) { return this.setAttribute("type",val); }, + + get value() { return this.getAttribute("value") || ""; }, + set value(val) { return this.setAttribute("value",val); }, + + get src() { return this.getAttribute("src") || ""; }, + set src(val) { return this.setAttribute("src",val); }, + + get id() { return this.getAttribute("id") || ""; }, + set id(val) { return this.setAttribute("id",val); }, + + getAttribute: function(name){ + return this._dom.hasAttribute(name) ? + new String( this._dom.getAttribute(name) ) : + null; + }, + setAttribute: function(name,value){ + this._dom.setAttribute(name,value); + }, + removeAttribute: function(name){ + this._dom.removeAttribute(name); + }, + + get childNodes(){ + return new DOMNodeList( this._dom.getChildNodes() ); + }, + get firstChild(){ + return makeNode( this._dom.getFirstChild() ); + }, + get lastChild(){ + return makeNode( this._dom.getLastChild() ); + }, + appendChild: function(node){ + this._dom.appendChild( node._dom ); + }, + insertBefore: function(node,before){ + this._dom.insertBefore( node._dom, before ? before._dom : before ); + }, + removeChild: function(node){ + this._dom.removeChild( node._dom ); + }, + + getElementsByTagName: DOMDocument.prototype.getElementsByTagName, + + addEventListener: window.addEventListener, + removeEventListener: window.removeEventListener, + dispatchEvent: window.dispatchEvent, + + click: function(){ + var event = document.createEvent(); + event.initEvent("click"); + this.dispatchEvent(event); + }, + submit: function(){ + var event = document.createEvent(); + event.initEvent("submit"); + this.dispatchEvent(event); + }, + focus: function(){ + var event = document.createEvent(); + event.initEvent("focus"); + this.dispatchEvent(event); + }, + blur: function(){ + var event = document.createEvent(); + event.initEvent("blur"); + this.dispatchEvent(event); + }, + get elements(){ + return this.getElementsByTagName("*"); + }, + get contentWindow(){ + return this.nodeName == "IFRAME" ? { + document: this.contentDocument + } : null; + }, + get contentDocument(){ + if ( this.nodeName == "IFRAME" ) { + if ( !this._doc ) + this._doc = new DOMDocument( + new java.io.ByteArrayInputStream((new java.lang.String( + "")) + .getBytes("UTF8"))); + return this._doc; + } else + return null; + } + }); + + // Helper method for extending one object with another + + function extend(a,b) { + for ( var i in b ) { + var g = b.__lookupGetter__(i), s = b.__lookupSetter__(i); + + if ( g || s ) { + if ( g ) + a.__defineGetter__(i, g); + if ( s ) + a.__defineSetter__(i, s); + } else + a[i] = b[i]; + } + return a; + } + + // Helper method for generating the right + // DOM objects based upon the type + + var obj_nodes = new java.util.HashMap(); + + function makeNode(node){ + if ( node ) { + if ( !obj_nodes.containsKey( node ) ) + obj_nodes.put( node, node.getNodeType() == + Packages.org.w3c.dom.Node.ELEMENT_NODE ? + new DOMElement( node ) : new DOMNode( node ) ); + + return obj_nodes.get(node); + } else + return null; + } + + // XMLHttpRequest + // Originally implemented by Yehuda Katz + + window.XMLHttpRequest = function(){ + this.headers = {}; + this.responseHeaders = {}; + }; + + XMLHttpRequest.prototype = { + open: function(method, url, async, user, password){ + this.readyState = 1; + if (async) + this.async = true; + this.method = method || "GET"; + this.url = url; + this.onreadystatechange(); + }, + setRequestHeader: function(header, value){ + this.headers[header] = value; + }, + getResponseHeader: function(header){ }, + send: function(data){ + var self = this; + + function makeRequest(){ + var url = new java.net.URL(curLocation, self.url); + + if ( url.getProtocol() == "file" ) { + if ( self.method == "PUT" ) { + var out = new java.io.FileWriter( + new java.io.File( new java.net.URI( url.toString() ) ) ), + text = new java.lang.String( data || "" ); + + out.write( text, 0, text.length() ); + out.flush(); + out.close(); + } else if ( self.method == "DELETE" ) { + var file = new java.io.File( new java.net.URI( url.toString() ) ); + file["delete"](); + } else { + var connection = url.openConnection(); + connection.connect(); + handleResponse(); + } + } else { + var connection = url.openConnection(); + + connection.setRequestMethod( self.method ); + + // Add headers to Java connection + for (var header in self.headers) + connection.addRequestProperty(header, self.headers[header]); + + connection.connect(); + + // Stick the response headers into responseHeaders + for (var i = 0; ; i++) { + var headerName = connection.getHeaderFieldKey(i); + var headerValue = connection.getHeaderField(i); + if (!headerName && !headerValue) break; + if (headerName) + self.responseHeaders[headerName] = headerValue; + } + + handleResponse(); + } + + function handleResponse(){ + self.readyState = 4; + self.status = parseInt(connection.responseCode) || undefined; + self.statusText = connection.responseMessage || ""; + + var stream = new java.io.InputStreamReader(connection.getInputStream()), + buffer = new java.io.BufferedReader(stream), line; + + while ((line = buffer.readLine()) != null) + self.responseText += line; + + self.responseXML = null; + + if ( self.responseText.match(/^\s* 5, "There must be at least 5 anchors" ); + */ +function ok(a, msg) { + log( !!a, msg ); +} + +/** + * Asserts that two arrays are the same + */ +function isSet(a, b, msg) { + var ret = true; + if ( a && b && a.length != undefined && a.length == b.length ) { + for ( var i = 0; i < a.length; i++ ) { + if ( a[i] != b[i] ) + ret = false; + } + } else + ret = false; + if ( !ret ) + log( ret, msg + " expected: " + serialArray(b) + " result: " + serialArray(a) ); + else + log( ret, msg ); +} + +/** + * Asserts that two objects are equivalent + */ +function isObj(a, b, msg) { + var ret = true; + + if ( a && b ) { + for ( var i in a ) + if ( a[i] != b[i] ) + ret = false; + + for ( i in b ) + if ( a[i] != b[i] ) + ret = false; + } else + ret = false; + + log( ret, msg ); +} + +function serialArray( a ) { + var r = []; + + if ( a && a.length ) + for ( var i = 0; i < a.length; i++ ) { + var str = a[i] ? a[i].nodeName : ""; + if ( str ) { + str = str.toLowerCase(); + if ( a[i].id ) + str += "#" + a[i].id; + } else + str = a[i]; + r.push( str ); + } + + return "[ " + r.join(", ") + " ]" +} + +/** + * Returns an array of elements with the given IDs, eg. + * @example q("main", "foo", "bar") + * @result [
, , ] + */ +function q() { + var r = []; + for ( var i = 0; i < arguments.length; i++ ) + r.push( document.getElementById( arguments[i] ) ); + return r; +} + +/** + * Asserts that a select matches the given IDs + * @example t("Check for something", "//[a]", ["foo", "baar"]); + * @result returns true if "//[a]" return two elements with the IDs 'foo' and 'baar' + */ +function t(a,b,c) { + var f = jQuery(b); + var s = ""; + for ( var i = 0; i < f.length; i++ ) + s += (s && ",") + '"' + f[i].id + '"'; + isSet(f, q.apply(q,c), a + " (" + b + ")"); +} + +/** + * Checks that the first two arguments are equal, with an optional message. + * Prints out both expected and actual values on failure. + * + * Prefered to ok( expected == actual, message ) + * + * @example equals( "Expected 2 characters.", v.formatMessage("Expected {0} characters.", 2) ); + * + * @param Object expected + * @param Object actual + * @param String message (optional) + */ +function equals(expected, actual, message) { + var result = expected == actual; + message = message || (result ? "okay" : "failed"); + log( result, result ? message + ": " + expected : message + " expected: " + expected + " actual: " + actual ); +} + +var numTests = 0, total = 0, pass = 0, fail = 0; + +function log(state, msg){ + print( (state ? "PASS" : "FAIL") + " (" + (++total) + ") " + + (currentModule ? "[" + currentModule + "] " : "") + msg ); + + numTests++; + + if ( state ) + pass++; + else + fail++; +} + +function results(){ + print( pass + " Passed, " + fail + " Failed" ); +} + +function start(){} +function stop(){} + +/** + * Trigger an event on an element. + * + * @example triggerEvent( document.body, "click" ); + * + * @param DOMElement elem + * @param String type + */ +function triggerEvent( elem, type, event ) { +/* + if ( jQuery.browser.mozilla || jQuery.browser.opera ) { + 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 ( jQuery.browser.msie ) { + elem.fireEvent("on"+type); + } +*/ +} + +/** + * Add random number to url to stop IE from caching + * + * @example url("data/test.html") + * @result "data/test.html?10538358428943" + * + * @example url("data/test.php?foo=bar") + * @result "data/test.php?foo=bar&10538358345554" + */ +function url(value) { + return value + (/\?/.test(value) ? "&" : "?") + new Date().getTime() + "" + parseInt(Math.random()*100000); +} \ No newline at end of file diff --git a/speed/benchmarker.css b/build/speed/benchmarker.css old mode 100644 new mode 100755 similarity index 100% rename from speed/benchmarker.css rename to build/speed/benchmarker.css diff --git a/speed/benchmarker.js b/build/speed/benchmarker.js old mode 100644 new mode 100755 similarity index 79% rename from speed/benchmarker.js rename to build/speed/benchmarker.js index bfcc16ed..73953d11 --- a/speed/benchmarker.js +++ b/build/speed/benchmarker.js @@ -1,42 +1,18 @@ jQuery.benchmarker.tests = [ - // Selectors from: - // http://ejohn.org/blog/selectors-that-people-actually-use/ - /* - // For Amazon.com - "#navAmazonLogo", "#navSwmSkedPop", - ".navbar", ".navGreeting", - "div", "table", - "img.navCrossshopTabCap", "span.navGreeting", - "#navbar table", "#navidWelcomeMsg span", - "div#navbar", "ul#navAmazonLogo", - "#navAmazonLogo .navAmazonLogoGatewayPanel", "#navidWelcomeMsg .navGreeting", - ".navbar .navAmazonLogoGatewayPanel", ".navbar .navGreeting", - "*", - "#navAmazonLogo li.navAmazonLogoGatewayPanel", "#navidWelcomeMsg span.navGreeting", - "a[name=top]", "form[name=site-search]", - ".navbar li", ".navbar span", - "[name=top]", "[name=site-search]", - "ul li", "a img", - "#navbar #navidWelcomeMsg", "#navbar #navSwmDWPop", - "#navbar ul li", "#navbar a img" - */ - // For Yahoo.com - "#page", "#masthead", "#mastheadhd", - ".mastheadbd", ".first", ".on", - "div", "li", "a", - "div.mastheadbd", "li.first", "li.on", - "#page div", "#dtba span", - "div#page", "div#masthead", - "#page .mastheadbd", "#page .first", - ".outer_search_container .search_container", ".searchbox_container .inputtext", - "*", - "#page div.mastheadbd", "#page li.first", - "input[name=p]", "a[name=marketplace]", - ".outer_search_container div", ".searchbox_container span", - "[name=p]", "[name=marketplace]", - "ul li", "form input", - "#page #e2econtent", "#page #e2e" - ]; + "*", + "body", "body div", "div", + "div div div", "div div", ".dialog", "div.dialog", "div .dialog", + "#speech5", "div#speech5", "div #speech5", "div > div", "div.scene div.dialog", + "div#scene1.scene div.dialog div", "#scene1 #speech1", "body > div.dialog div#speech5", + "div:nth-child(even)", "div:nth-child(odd)", + "div:nth-child(1)", "div:nth-child(2n)", + "div:nth-child(2n+3)", "div:first-child", + "div:last-child", "div:only-child", + "div:contains(CELIA)", + "div ~ div", "div + div", + "div[@class]", "div[@class=dialog]", "div[@class!=dialog]", + "div[@class^=dialog]", "div[@class$=dialog]", "div[@class*=dialog]" + ] jQuery.fn.benchmark = function() { this.each(function() { @@ -62,8 +38,8 @@ jQuery("button.retryTies").bind("click", function() { jQuery("tr:has(td.tie) td.test").benchmark() }) - jQuery("button.selectAll").bind("click", function() { jQuery("input[type=checkbox]").each(function() { this.checked = true }) }) - jQuery("button.deselectAll").bind("click", function() { jQuery("input[type=checkbox]").each(function() { this.checked = false }) }) + jQuery("button.selectAll").bind("click", function() { jQuery("input[@type=checkbox]").each(function() { this.checked = true }) }) + jQuery("button.deselectAll").bind("click", function() { jQuery("input[@type=checkbox]").each(function() { this.checked = false }) }) jQuery("#addTest").bind("click", function() { jQuery("table").append(""); @@ -101,6 +77,9 @@ var times = times || 50; var el = list[0]; var code = jQuery(el).text().replace(/^-/, ""); + if(!libraries[0].match(/^jQ/)) { + code = code.replace(/@/, ""); + } var timeArr = [] for(i = 0; i < times + 2; i++) { var time = new Date() diff --git a/build/speed/index.html b/build/speed/index.html new file mode 100755 index 00000000..b1561892 --- /dev/null +++ b/build/speed/index.html @@ -0,0 +1,513 @@ + + + + + + Speed Test + + + + + + + + +

Speed Test

+
+
+

Using the following selector expressions ( times each):

+

NOTE: Number shown is an average.

+
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Run?Test
+ +
+ + + + + + +
+
+
+

As You Like It

+
+ by William Shakespeare + +
+
+

ACT I, SCENE III. A room in the palace.

+
+
Enter CELIA and ROSALIND
+ +
+ +
CELIA
+ +
+
Why, cousin! why, Rosalind! Cupid have mercy! not a word?
+
+ +
ROSALIND
+ +
+
Not one to throw at a dog.
+
+ +
CELIA
+
+
No, thy words are too precious to be cast away upon
+ +
curs; throw some of them at me; come, lame me with reasons.
+
+ +
ROSALIND
+ +
CELIA
+
+
But is all this for your father?
+ +
+ +
+
Then there were two cousins laid up; when the one
+
should be lamed with reasons and the other mad
+
without any.
+
+ +
ROSALIND
+
+
No, some of it is for my child's father. O, how
+ +
full of briers is this working-day world!
+
+ +
CELIA
+ +
+ +
They are but burs, cousin, thrown upon thee in
+
holiday foolery: if we walk not in the trodden
+ +
paths our very petticoats will catch them.
+
+ +
ROSALIND
+ +
+
I could shake them off my coat: these burs are in my heart.
+
+ +
CELIA
+ +
+
Hem them away.
+ +
+ +
ROSALIND
+
+ +
I would try, if I could cry 'hem' and have him.
+
+ +
CELIA
+ +
+
Come, come, wrestle with thy affections.
+ +
+ +
ROSALIND
+
+
O, they take the part of a better wrestler than myself!
+ +
+ +
CELIA
+
+ +
O, a good wish upon you! you will try in time, in
+
despite of a fall. But, turning these jests out of
+
service, let us talk in good earnest: is it
+ +
possible, on such a sudden, you should fall into so
+
strong a liking with old Sir Rowland's youngest son?
+
+ +
ROSALIND
+
+
The duke my father loved his father dearly.
+ +
+ +
CELIA
+
+ +
Doth it therefore ensue that you should love his son
+ +
dearly? By this kind of chase, I should hate him,
+
for my father hated his father dearly; yet I hate
+ +
not Orlando.
+
+ +
ROSALIND
+ +
+
No, faith, hate him not, for my sake.
+
+ +
CELIA
+ +
+
Why should I not? doth he not deserve well?
+ +
+ +
ROSALIND
+ +
+
Let me love him for that, and do you love him
+
because I do. Look, here comes the duke.
+
+ +
CELIA
+
+ +
With his eyes full of anger.
+
Enter DUKE FREDERICK, with Lords
+
+ +
DUKE FREDERICK
+ +
+
Mistress, dispatch you with your safest haste
+ +
And get you from our court.
+
+ +
ROSALIND
+ +
+ +
Me, uncle?
+
+ +
DUKE FREDERICK
+
+
You, cousin
+
Within these ten days if that thou be'st found
+ +
So near our public court as twenty miles,
+
Thou diest for it.
+ +
+ +
ROSALIND
+
+
I do beseech your grace,
+ +
Let me the knowledge of my fault bear with me:
+
If with myself I hold intelligence
+ +
Or have acquaintance with mine own desires,
+
If that I do not dream or be not frantic,--
+
As I do trust I am not--then, dear uncle,
+ +
Never so much as in a thought unborn
+ +
Did I offend your highness.
+ +
+ +
DUKE FREDERICK
+
+
Thus do all traitors:
+
If their purgation did consist in words,
+ +
They are as innocent as grace itself:
+ +
Let it suffice thee that I trust thee not.
+ +
+ +
ROSALIND
+
+
Yet your mistrust cannot make me a traitor:
+ +
Tell me whereon the likelihood depends.
+ +
+ +
DUKE FREDERICK
+
+
Thou art thy father's daughter; there's enough.
+
+ +
ROSALIND
+ +
+
So was I when your highness took his dukedom;
+
So was I when your highness banish'd him:
+
Treason is not inherited, my lord;
+
Or, if we did derive it from our friends,
+ +
What's that to me? my father was no traitor:
+ +
Then, good my liege, mistake me not so much
+
To think my poverty is treacherous.
+ +
+ +
CELIA
+
+ +
Dear sovereign, hear me speak.
+ +
+ +
DUKE FREDERICK
+
+
Ay, Celia; we stay'd her for your sake,
+
Else had she with her father ranged along.
+ +
+ +
CELIA
+
+
I did not then entreat to have her stay;
+
It was your pleasure and your own remorse:
+
I was too young that time to value her;
+ +
But now I know her: if she be a traitor,
+ +
Why so am I; we still have slept together,
+
Rose at an instant, learn'd, play'd, eat together,
+
And wheresoever we went, like Juno's swans,
+ +
Still we went coupled and inseparable.
+
+ +
DUKE FREDERICK
+ +
+
She is too subtle for thee; and her smoothness,
+
Her very silence and her patience
+
Speak to the people, and they pity her.
+
Thou art a fool: she robs thee of thy name;
+ +
And thou wilt show more bright and seem more virtuous
+ +
When she is gone. Then open not thy lips:
+
Firm and irrevocable is my doom
+
Which I have pass'd upon her; she is banish'd.
+
+ +
CELIA
+ +
+
Pronounce that sentence then on me, my liege:
+
I cannot live out of her company.
+
+ +
DUKE FREDERICK
+
+
You are a fool. You, niece, provide yourself:
+ +
If you outstay the time, upon mine honour,
+
And in the greatness of my word, you die.
+
Exeunt DUKE FREDERICK and Lords
+
+ +
CELIA
+
+ +
O my poor Rosalind, whither wilt thou go?
+ +
Wilt thou change fathers? I will give thee mine.
+
I charge thee, be not thou more grieved than I am.
+
+ +
ROSALIND
+ +
+ +
I have more cause.
+
+ +
CELIA
+
+
Thou hast not, cousin;
+ +
Prithee be cheerful: know'st thou not, the duke
+ +
Hath banish'd me, his daughter?
+
+ +
ROSALIND
+
+
That he hath not.
+ +
+ +
CELIA
+
+
No, hath not? Rosalind lacks then the love
+ +
Which teacheth thee that thou and I am one:
+
Shall we be sunder'd? shall we part, sweet girl?
+ +
No: let my father seek another heir.
+ +
Therefore devise with me how we may fly,
+
Whither to go and what to bear with us;
+
And do not seek to take your change upon you,
+
To bear your griefs yourself and leave me out;
+
For, by this heaven, now at our sorrows pale,
+ +
Say what thou canst, I'll go along with thee.
+ +
+ +
ROSALIND
+
+
Why, whither shall we go?
+
+ +
CELIA
+ +
+
To seek my uncle in the forest of Arden.
+
+ +
ROSALIND
+ +
+
Alas, what danger will it be to us,
+ +
Maids as we are, to travel forth so far!
+
Beauty provoketh thieves sooner than gold.
+
+ +
CELIA
+ +
+
I'll put myself in poor and mean attire
+ +
And with a kind of umber smirch my face;
+
The like do you: so shall we pass along
+ +
And never stir assailants.
+
+ +
ROSALIND
+
+ +
Were it not better,
+
Because that I am more than common tall,
+
That I did suit me all points like a man?
+
A gallant curtle-axe upon my thigh,
+ +
A boar-spear in my hand; and--in my heart
+ +
Lie there what hidden woman's fear there will--
+ +
We'll have a swashing and a martial outside,
+
As many other mannish cowards have
+
That do outface it with their semblances.
+ +
+ +
CELIA
+
+ +
What shall I call thee when thou art a man?
+
+ +
ROSALIND
+ +
+
I'll have no worse a name than Jove's own page;
+
And therefore look you call me Ganymede.
+ +
But what will you be call'd?
+
+ +
CELIA
+ +
+
Something that hath a reference to my state
+
No longer Celia, but Aliena.
+ +
+ +
ROSALIND
+
+ +
But, cousin, what if we assay'd to steal
+
The clownish fool out of your father's court?
+
Would he not be a comfort to our travel?
+ +
+ +
CELIA
+
+ +
He'll go along o'er the wide world with me;
+ +
Leave me alone to woo him. Let's away,
+
And get our jewels and our wealth together,
+ +
Devise the fittest time and safest way
+
To hide us from pursuit that will be made
+ +
After my flight. Now go we in content
+
To liberty and not to banishment.
+
Exeunt
+
+ +
+
+ + + + + diff --git a/build/speed/jquery-1.2.1.js b/build/speed/jquery-1.2.1.js new file mode 100644 index 00000000..9fb3a8e5 --- /dev/null +++ b/build/speed/jquery-1.2.1.js @@ -0,0 +1,2992 @@ +(function(){ +/* + * jQuery 1.2.1 - New Wave Javascript + * + * Copyright (c) 2007 John Resig (jquery.com) + * Dual licensed under the MIT (MIT-LICENSE.txt) + * and GPL (GPL-LICENSE.txt) licenses. + * + * $Date: 2007-09-16 23:42:06 -0400 (Sun, 16 Sep 2007) $ + * $Rev: 3353 $ + */ + +// Map over jQuery in case of overwrite +if ( typeof jQuery != "undefined" ) + var _jQuery = jQuery; + +var jQuery = window.jQuery = function(selector, context) { + // If the context is a namespace object, return a new object + return this instanceof jQuery ? + this.init(selector, context) : + new jQuery(selector, context); +}; + +// Map over the $ in case of overwrite +if ( typeof $ != "undefined" ) + var _$ = $; + +// Map the jQuery namespace to the '$' one +window.$ = jQuery; + +var quickExpr = /^[^<]*(<(.|\s)+>)[^>]*$|^#(\w+)$/; + +jQuery.fn = jQuery.prototype = { + init: function(selector, context) { + // Make sure that a selection was provided + selector = selector || document; + + // Handle HTML strings + if ( typeof selector == "string" ) { + var m = quickExpr.exec(selector); + if ( m && (m[1] || !context) ) { + // HANDLE: $(html) -> $(array) + if ( m[1] ) + selector = jQuery.clean( [ m[1] ], context ); + + // HANDLE: $("#id") + else { + var tmp = document.getElementById( m[3] ); + if ( tmp ) + // Handle the case where IE and Opera return items + // by name instead of ID + if ( tmp.id != m[3] ) + return jQuery().find( selector ); + else { + this[0] = tmp; + this.length = 1; + return this; + } + else + selector = []; + } + + // HANDLE: $(expr) + } else + return new jQuery( context ).find( selector ); + + // HANDLE: $(function) + // Shortcut for document ready + } else if ( jQuery.isFunction(selector) ) + return new jQuery(document)[ jQuery.fn.ready ? "ready" : "load" ]( selector ); + + return this.setArray( + // HANDLE: $(array) + selector.constructor == Array && selector || + + // HANDLE: $(arraylike) + // Watch for when an array-like object is passed as the selector + (selector.jquery || selector.length && selector != window && !selector.nodeType && selector[0] != undefined && selector[0].nodeType) && jQuery.makeArray( selector ) || + + // HANDLE: $(*) + [ selector ] ); + }, + + jquery: "1.2.1", + + size: function() { + return this.length; + }, + + length: 0, + + get: function( num ) { + return num == undefined ? + + // Return a 'clean' array + jQuery.makeArray( this ) : + + // Return just the object + this[num]; + }, + + pushStack: function( a ) { + var ret = jQuery(a); + ret.prevObject = this; + return ret; + }, + + setArray: function( a ) { + this.length = 0; + Array.prototype.push.apply( this, a ); + return this; + }, + + each: function( fn, args ) { + return jQuery.each( this, fn, args ); + }, + + index: function( obj ) { + var pos = -1; + this.each(function(i){ + if ( this == obj ) pos = i; + }); + return pos; + }, + + attr: function( key, value, type ) { + var obj = key; + + // Look for the case where we're accessing a style value + if ( key.constructor == String ) + if ( value == undefined ) + return this.length && jQuery[ type || "attr" ]( this[0], key ) || undefined; + else { + obj = {}; + obj[ key ] = value; + } + + // Check to see if we're setting style values + return this.each(function(index){ + // Set all the styles + for ( var prop in obj ) + jQuery.attr( + type ? this.style : this, + prop, jQuery.prop(this, obj[prop], type, index, prop) + ); + }); + }, + + css: function( key, value ) { + return this.attr( key, value, "curCSS" ); + }, + + text: function(e) { + if ( typeof e != "object" && e != null ) + return this.empty().append( document.createTextNode( e ) ); + + var t = ""; + jQuery.each( e || this, function(){ + jQuery.each( this.childNodes, function(){ + if ( this.nodeType != 8 ) + t += this.nodeType != 1 ? + this.nodeValue : jQuery.fn.text([ this ]); + }); + }); + return t; + }, + + wrapAll: function(html) { + if ( this[0] ) + // The elements to wrap the target around + jQuery(html, this[0].ownerDocument) + .clone() + .insertBefore(this[0]) + .map(function(){ + var elem = this; + while ( elem.firstChild ) + elem = elem.firstChild; + return elem; + }) + .append(this); + + return this; + }, + + wrapInner: function(html) { + return this.each(function(){ + jQuery(this).contents().wrapAll(html); + }); + }, + + wrap: function(html) { + return this.each(function(){ + jQuery(this).wrapAll(html); + }); + }, + + append: function() { + return this.domManip(arguments, true, 1, function(a){ + this.appendChild( a ); + }); + }, + + prepend: function() { + return this.domManip(arguments, true, -1, function(a){ + this.insertBefore( a, this.firstChild ); + }); + }, + + before: function() { + return this.domManip(arguments, false, 1, function(a){ + this.parentNode.insertBefore( a, this ); + }); + }, + + after: function() { + return this.domManip(arguments, false, -1, function(a){ + this.parentNode.insertBefore( a, this.nextSibling ); + }); + }, + + end: function() { + return this.prevObject || jQuery([]); + }, + + find: function(t) { + var data = jQuery.map(this, function(a){ return jQuery.find(t,a); }); + return this.pushStack( /[^+>] [^+>]/.test( t ) || t.indexOf("..") > -1 ? + jQuery.unique( data ) : data ); + }, + + clone: function(events) { + // Do the clone + var ret = this.map(function(){ + return this.outerHTML ? jQuery(this.outerHTML)[0] : this.cloneNode(true); + }); + + // Need to set the expando to null on the cloned set if it exists + // removeData doesn't work here, IE removes it from the original as well + // this is primarily for IE but the data expando shouldn't be copied over in any browser + var clone = ret.find("*").andSelf().each(function(){ + if ( this[ expando ] != undefined ) + this[ expando ] = null; + }); + + // Copy the events from the original to the clone + if (events === true) + this.find("*").andSelf().each(function(i) { + var events = jQuery.data(this, "events"); + for ( var type in events ) + for ( var handler in events[type] ) + jQuery.event.add(clone[i], type, events[type][handler], events[type][handler].data); + }); + + // Return the cloned set + return ret; + }, + + filter: function(t) { + return this.pushStack( + jQuery.isFunction( t ) && + jQuery.grep(this, function(el, index){ + return t.apply(el, [index]); + }) || + + jQuery.multiFilter(t,this) ); + }, + + not: function(t) { + return this.pushStack( + t.constructor == String && + jQuery.multiFilter(t, this, true) || + + jQuery.grep(this, function(a) { + return ( t.constructor == Array || t.jquery ) + ? jQuery.inArray( a, t ) < 0 + : a != t; + }) + ); + }, + + add: function(t) { + return this.pushStack( jQuery.merge( + this.get(), + t.constructor == String ? + jQuery(t).get() : + t.length != undefined && (!t.nodeName || jQuery.nodeName(t, "form")) ? + t : [t] ) + ); + }, + + is: function(expr) { + return expr ? jQuery.multiFilter(expr,this).length > 0 : false; + }, + + hasClass: function(expr) { + return this.is("." + expr); + }, + + val: function( val ) { + if ( val == undefined ) { + if ( this.length ) { + var elem = this[0]; + + // We need to handle select boxes special + if ( jQuery.nodeName(elem, "select") ) { + var index = elem.selectedIndex, + a = [], + 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]; + if ( option.selected ) { + // Get the specifc value for the option + var val = jQuery.browser.msie && !option.attributes["value"].specified ? option.text : option.value; + + // We don't need an array for one selects + if ( one ) + return val; + + // Multi-Selects return an array + a.push(val); + } + } + + return a; + + // Everything else, we just grab the value + } else + return this[0].value.replace(/\r/g, ""); + } + } else + return this.each(function(){ + if ( val.constructor == Array && /radio|checkbox/.test(this.type) ) + this.checked = (jQuery.inArray(this.value, val) >= 0 || + jQuery.inArray(this.name, val) >= 0); + else if ( jQuery.nodeName(this, "select") ) { + var tmp = val.constructor == Array ? val : [val]; + + jQuery("option", this).each(function(){ + this.selected = (jQuery.inArray(this.value, tmp) >= 0 || + jQuery.inArray(this.text, tmp) >= 0); + }); + + if ( !tmp.length ) + this.selectedIndex = -1; + } else + this.value = val; + }); + }, + + html: function( val ) { + return val == undefined ? + ( this.length ? this[0].innerHTML : null ) : + this.empty().append( val ); + }, + + replaceWith: function( val ) { + return this.after( val ).remove(); + }, + + eq: function(i){ + return this.slice(i, i+1); + }, + + slice: function() { + return this.pushStack( Array.prototype.slice.apply( this, arguments ) ); + }, + + map: function(fn) { + return this.pushStack(jQuery.map( this, function(elem,i){ + return fn.call( elem, i, elem ); + })); + }, + + andSelf: function() { + return this.add( this.prevObject ); + }, + + domManip: function(args, table, dir, fn) { + var clone = this.length > 1, a; + + return this.each(function(){ + if ( !a ) { + a = jQuery.clean(args, this.ownerDocument); + if ( dir < 0 ) + a.reverse(); + } + + var obj = this; + + if ( table && jQuery.nodeName(this, "table") && jQuery.nodeName(a[0], "tr") ) + obj = this.getElementsByTagName("tbody")[0] || this.appendChild(document.createElement("tbody")); + + jQuery.each( a, function(){ + var elem = clone ? this.cloneNode(true) : this; + if ( !evalScript(0, elem) ) + fn.call( obj, elem ); + }); + }); + } +}; + +function evalScript(i, elem){ + var script = jQuery.nodeName(elem, "script"); + + if ( script ) { + if ( elem.src ) + jQuery.ajax({ url: elem.src, async: false, dataType: "script" }); + else + jQuery.globalEval( elem.text || elem.textContent || elem.innerHTML || "" ); + + if ( elem.parentNode ) + elem.parentNode.removeChild(elem); + + } else if ( elem.nodeType == 1 ) + jQuery("script", elem).each(evalScript); + + return script; +} + +jQuery.extend = jQuery.fn.extend = function() { + // copy reference to target object + var target = arguments[0] || {}, a = 1, al = arguments.length, deep = false; + + // Handle a deep copy situation + if ( target.constructor == Boolean ) { + deep = target; + target = arguments[1] || {}; + } + + // extend jQuery itself if only one argument is passed + if ( al == 1 ) { + target = this; + a = 0; + } + + var prop; + + for ( ; a < al; a++ ) + // Only deal with non-null/undefined values + if ( (prop = arguments[a]) != null ) + // Extend the base object + for ( var i in prop ) { + // Prevent never-ending loop + if ( target == prop[i] ) + continue; + + // Recurse if we're merging object values + if ( deep && typeof prop[i] == 'object' && target[i] ) + jQuery.extend( target[i], prop[i] ); + + // Don't bring in undefined values + else if ( prop[i] != undefined ) + target[i] = prop[i]; + } + + // Return the modified object + return target; +}; + +var expando = "jQuery" + (new Date()).getTime(), uuid = 0, win = {}; + +jQuery.extend({ + noConflict: function(deep) { + window.$ = _$; + if ( deep ) + window.jQuery = _jQuery; + return jQuery; + }, + + // This may seem like some crazy code, but trust me when I say that this + // is the only cross-browser way to do this. --John + isFunction: function( fn ) { + return !!fn && typeof fn != "string" && !fn.nodeName && + fn.constructor != Array && /function/i.test( fn + "" ); + }, + + // check if an element is in a XML document + isXMLDoc: function(elem) { + return elem.documentElement && !elem.body || + elem.tagName && elem.ownerDocument && !elem.ownerDocument.body; + }, + + // Evalulates a script in a global context + // Evaluates Async. in Safari 2 :-( + globalEval: function( data ) { + data = jQuery.trim( data ); + if ( data ) { + if ( window.execScript ) + window.execScript( data ); + else if ( jQuery.browser.safari ) + // safari doesn't provide a synchronous global eval + window.setTimeout( data, 0 ); + else + eval.call( window, data ); + } + }, + + nodeName: function( elem, name ) { + return elem.nodeName && elem.nodeName.toUpperCase() == name.toUpperCase(); + }, + + cache: {}, + + data: function( elem, name, data ) { + elem = elem == window ? win : elem; + + var id = elem[ expando ]; + + // Compute a unique ID for the element + if ( !id ) + id = elem[ expando ] = ++uuid; + + // Only generate the data cache if we're + // trying to access or manipulate it + if ( name && !jQuery.cache[ id ] ) + jQuery.cache[ id ] = {}; + + // Prevent overriding the named cache with undefined values + if ( data != undefined ) + jQuery.cache[ id ][ name ] = data; + + // Return the named cache data, or the ID for the element + return name ? jQuery.cache[ id ][ name ] : id; + }, + + removeData: function( elem, name ) { + elem = elem == window ? win : elem; + + var id = elem[ expando ]; + + // If we want to remove a specific section of the element's data + if ( name ) { + if ( jQuery.cache[ id ] ) { + // Remove the section of cache data + delete jQuery.cache[ id ][ name ]; + + // If we've removed all the data, remove the element's cache + name = ""; + for ( name in jQuery.cache[ id ] ) break; + if ( !name ) + jQuery.removeData( elem ); + } + + // Otherwise, we want to remove all of the element's data + } else { + // Clean up the element expando + try { + delete elem[ expando ]; + } catch(e){ + // IE has trouble directly removing the expando + // but it's ok with using removeAttribute + if ( elem.removeAttribute ) + elem.removeAttribute( expando ); + } + + // Completely remove the data cache + delete jQuery.cache[ id ]; + } + }, + + // args is for internal usage only + each: function( obj, fn, args ) { + if ( args ) { + if ( obj.length == undefined ) + for ( var i in obj ) + fn.apply( obj[i], args ); + else + for ( var i = 0, ol = obj.length; i < ol; i++ ) + if ( fn.apply( obj[i], args ) === false ) break; + + // A special, fast, case for the most common use of each + } else { + if ( obj.length == undefined ) + for ( var i in obj ) + fn.call( obj[i], i, obj[i] ); + else + for ( var i = 0, ol = obj.length, val = obj[0]; + i < ol && fn.call(val,i,val) !== false; val = obj[++i] ){} + } + + return obj; + }, + + prop: function(elem, value, type, index, prop){ + // Handle executable functions + if ( jQuery.isFunction( value ) ) + value = value.call( elem, [index] ); + + // exclude the following css properties to add px + var exclude = /z-?index|font-?weight|opacity|zoom|line-?height/i; + + // Handle passing in a number to a CSS property + return value && value.constructor == Number && type == "curCSS" && !exclude.test(prop) ? + value + "px" : + value; + }, + + className: { + // internal only, use addClass("class") + add: function( elem, c ){ + jQuery.each( (c || "").split(/\s+/), function(i, cur){ + if ( !jQuery.className.has( elem.className, cur ) ) + elem.className += ( elem.className ? " " : "" ) + cur; + }); + }, + + // internal only, use removeClass("class") + remove: function( elem, c ){ + elem.className = c != undefined ? + jQuery.grep( elem.className.split(/\s+/), function(cur){ + return !jQuery.className.has( c, cur ); + }).join(" ") : ""; + }, + + // internal only, use is(".class") + has: function( t, c ) { + return jQuery.inArray( c, (t.className || t).toString().split(/\s+/) ) > -1; + } + }, + + swap: function(e,o,f) { + for ( var i in o ) { + e.style["old"+i] = e.style[i]; + e.style[i] = o[i]; + } + f.apply( e, [] ); + for ( var i in o ) + e.style[i] = e.style["old"+i]; + }, + + css: function(e,p) { + if ( p == "height" || p == "width" ) { + var old = {}, oHeight, oWidth, d = ["Top","Bottom","Right","Left"]; + + jQuery.each( d, function(){ + old["padding" + this] = 0; + old["border" + this + "Width"] = 0; + }); + + jQuery.swap( e, old, function() { + if ( jQuery(e).is(':visible') ) { + oHeight = e.offsetHeight; + oWidth = e.offsetWidth; + } else { + e = jQuery(e.cloneNode(true)) + .find(":radio").removeAttr("checked").end() + .css({ + visibility: "hidden", position: "absolute", display: "block", right: "0", left: "0" + }).appendTo(e.parentNode)[0]; + + var parPos = jQuery.css(e.parentNode,"position") || "static"; + if ( parPos == "static" ) + e.parentNode.style.position = "relative"; + + oHeight = e.clientHeight; + oWidth = e.clientWidth; + + if ( parPos == "static" ) + e.parentNode.style.position = "static"; + + e.parentNode.removeChild(e); + } + }); + + return p == "height" ? oHeight : oWidth; + } + + return jQuery.curCSS( e, p ); + }, + + curCSS: function(elem, prop, force) { + var ret, stack = [], swap = []; + + // A helper method for determining if an element's values are broken + function color(a){ + if ( !jQuery.browser.safari ) + return false; + + var ret = document.defaultView.getComputedStyle(a,null); + return !ret || ret.getPropertyValue("color") == ""; + } + + if (prop == "opacity" && jQuery.browser.msie) { + ret = jQuery.attr(elem.style, "opacity"); + return ret == "" ? "1" : ret; + } + + if (prop.match(/float/i)) + prop = styleFloat; + + if (!force && elem.style[prop]) + ret = elem.style[prop]; + + else if (document.defaultView && document.defaultView.getComputedStyle) { + + if (prop.match(/float/i)) + prop = "float"; + + prop = prop.replace(/([A-Z])/g,"-$1").toLowerCase(); + var cur = document.defaultView.getComputedStyle(elem, null); + + if ( cur && !color(elem) ) + ret = cur.getPropertyValue(prop); + + // If the element isn't reporting its values properly in Safari + // then some display: none elements are involved + else { + // Locate all of the parent display: none elements + for ( var a = elem; a && color(a); a = a.parentNode ) + stack.unshift(a); + + // Go through and make them visible, but in reverse + // (It would be better if we knew the exact display type that they had) + for ( a = 0; a < stack.length; a++ ) + if ( color(stack[a]) ) { + swap[a] = stack[a].style.display; + stack[a].style.display = "block"; + } + + // Since we flip the display style, we have to handle that + // one special, otherwise get the value + ret = prop == "display" && swap[stack.length-1] != null ? + "none" : + document.defaultView.getComputedStyle(elem,null).getPropertyValue(prop) || ""; + + // Finally, revert the display styles back + for ( a = 0; a < swap.length; a++ ) + if ( swap[a] != null ) + stack[a].style.display = swap[a]; + } + + if ( prop == "opacity" && ret == "" ) + ret = "1"; + + } else if (elem.currentStyle) { + var newProp = prop.replace(/\-(\w)/g,function(m,c){return c.toUpperCase();}); + ret = elem.currentStyle[prop] || elem.currentStyle[newProp]; + + // From the awesome hack by Dean Edwards + // http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102291 + + // If we're not dealing with a regular pixel number + // but a number that has a weird ending, we need to convert it to pixels + if ( !/^\d+(px)?$/i.test(ret) && /^\d/.test(ret) ) { + var style = elem.style.left; + var runtimeStyle = elem.runtimeStyle.left; + elem.runtimeStyle.left = elem.currentStyle.left; + elem.style.left = ret || 0; + ret = elem.style.pixelLeft + "px"; + elem.style.left = style; + elem.runtimeStyle.left = runtimeStyle; + } + } + + return ret; + }, + + clean: function(a, doc) { + var r = []; + doc = doc || document; + + jQuery.each( a, function(i,arg){ + if ( !arg ) return; + + if ( arg.constructor == Number ) + arg = arg.toString(); + + // Convert html string into DOM nodes + if ( typeof arg == "string" ) { + // Fix "XHTML"-style tags in all browsers + arg = arg.replace(/(<(\w+)[^>]*?)\/>/g, function(m, all, tag){ + return tag.match(/^(abbr|br|col|img|input|link|meta|param|hr|area)$/i)? m : all+">"; + }); + + // Trim whitespace, otherwise indexOf won't work as expected + var s = jQuery.trim(arg).toLowerCase(), div = doc.createElement("div"), tb = []; + + var wrap = + // option or optgroup + !s.indexOf("", ""] || + + !s.indexOf("", ""] || + + s.match(/^<(thead|tbody|tfoot|colg|cap)/) && + [1, "", "
"] || + + !s.indexOf("", ""] || + + // matched above + (!s.indexOf("", ""] || + + !s.indexOf("", ""] || + + // IE can't serialize and - - - - - - -
-

Hello

-
-
-

lorem ipsum

-

dolor sit amet

-
-
-
-
    - - - diff --git a/speed/css.html b/speed/css.html deleted file mode 100644 index 4d6700cf..00000000 --- a/speed/css.html +++ /dev/null @@ -1,82 +0,0 @@ - - - - Test Event Handling Performance - - - - - - - - -

    Getting Values: Loading...

    -

    Setting Values: Loading...

    - - diff --git a/speed/event.html b/speed/event.html deleted file mode 100644 index 6d463b4d..00000000 --- a/speed/event.html +++ /dev/null @@ -1,58 +0,0 @@ - - - - Test Event Handling Performance - - - - - - - -

    Move the mouse, please!

    -

    - - diff --git a/speed/filter.html b/speed/filter.html deleted file mode 100644 index 43ee94e5..00000000 --- a/speed/filter.html +++ /dev/null @@ -1,183 +0,0 @@ - - - - Test .filter() Performance - - - - - - - -
    -

    Hello

    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
      - - - diff --git a/speed/find.html b/speed/find.html deleted file mode 100644 index d3a2dc12..00000000 --- a/speed/find.html +++ /dev/null @@ -1,179 +0,0 @@ - - - - Test .find() Performance - - - - - - - -
      -

      Hello

      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
        - - - diff --git a/speed/index.html b/speed/index.html deleted file mode 100644 index 717ca731..00000000 --- a/speed/index.html +++ /dev/null @@ -1,72 +0,0 @@ - - - - - - Speed Test - - - - - - - - -

        Speed Test

        -
        -
        -

        Using the following selector expressions ( times each):

        -

        NOTE: Number shown is an average.

        -
        - - - - - -
        - - - - - - - - - - - - - - - - - - - - - - - - - - -
        Run?Test
        - -
        - - - - - - -
        -
        -
        - - - - - diff --git a/speed/jquery-basis.js b/speed/jquery-basis.js deleted file mode 100644 index 6fe017c1..00000000 --- a/speed/jquery-basis.js +++ /dev/null @@ -1,6238 +0,0 @@ -/*! - * jQuery JavaScript Library v1.4.2 - * http://jquery.com/ - * - * Copyright 2010, John Resig - * Dual licensed under the MIT or GPL Version 2 licenses. - * http://jquery.org/license - * - * Includes Sizzle.js - * http://sizzlejs.com/ - * Copyright 2010, The Dojo Foundation - * Released under the MIT, BSD, and GPL Licenses. - * - * Date: Sat Feb 13 22:33:48 2010 -0500 - */ -(function( window, undefined ) { - -// 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 ); - }, - - // Map over jQuery in case of overwrite - _jQuery = window.jQuery, - - // Map over the $ in case of overwrite - _$ = window.$, - - // Use the correct document accordingly with window argument (sandbox) - document = window.document, - - // A central reference to the root jQuery(document) - rootjQuery, - - // A simple way to check for HTML strings or ID strings - // (both of which we optimize for) - quickExpr = /^[^<]*(<[\w\W]+>)[^>]*$|^#([\w-]+)$/, - - // Is it a simple selector - isSimple = /^.[^:#\[\.,]*$/, - - // Check if a string has a non-whitespace character in it - rnotwhite = /\S/, - - // Used for trimming whitespace - rtrim = /^(\s|\u00A0)+|(\s|\u00A0)+$/g, - - // Match a standalone tag - rsingleTag = /^<(\w+)\s*\/?>(?:<\/\1>)?$/, - - // Keep a UserAgent string for use with jQuery.browser - userAgent = navigator.userAgent, - - // For matching the engine and version of the browser - browserMatch, - - // Has the ready events already been bound? - readyBound = false, - - // The functions to execute on DOM ready - readyList = [], - - // The ready event handler - DOMContentLoaded, - - // Save a reference to some core methods - toString = Object.prototype.toString, - hasOwnProperty = Object.prototype.hasOwnProperty, - push = Array.prototype.push, - slice = Array.prototype.slice, - indexOf = Array.prototype.indexOf; - -jQuery.fn = jQuery.prototype = { - init: function( selector, context ) { - 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 ) { - this.context = document; - this[0] = document.body; - this.selector = "body"; - this.length = 1; - return this; - } - - // Handle HTML strings - if ( typeof selector === "string" ) { - // Are we dealing with HTML string or an ID? - 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] ) { - 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 = buildFragment( [ match[1] ], [ doc ] ); - selector = (ret.cacheable ? ret.fragment.cloneNode(true) : ret.fragment).childNodes; - } - - return jQuery.merge( this, selector ); - - // HANDLE: $("#id") - } else { - elem = document.getElementById( match[2] ); - - if ( elem ) { - // 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: $("TAG") - } else if ( !context && /^\w+$/.test( selector ) ) { - this.selector = selector; - this.context = document; - selector = document.getElementsByTagName( selector ); - return jQuery.merge( this, selector ); - - // 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 jQuery( 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.4.2", - - // 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.slice(num)[ 0 ] : 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 = jQuery(); - - 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(); - - // If the DOM is already ready - if ( jQuery.isReady ) { - // Execute the function immediately - fn.call( document, jQuery ); - - // Otherwise, remember the function for later - } else if ( readyList ) { - // Add the function to the wait list - readyList.push( 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 || jQuery(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() { - // copy reference to target object - var target = arguments[0] || {}, i = 1, length = arguments.length, deep = false, options, name, src, copy; - - // 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 object literal values or arrays - if ( deep && copy && ( jQuery.isPlainObject(copy) || jQuery.isArray(copy) ) ) { - var clone = src && ( jQuery.isPlainObject(src) || jQuery.isArray(src) ) ? src - : jQuery.isArray(copy) ? [] : {}; - - // 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 ) { - window.$ = _$; - - if ( deep ) { - window.jQuery = _jQuery; - } - - return jQuery; - }, - - // Is the DOM ready to be used? Set to true once it occurs. - isReady: false, - - // Handle when the DOM is ready - ready: function() { - // Make sure that the DOM is not already loaded - if ( !jQuery.isReady ) { - // Make sure body exists, at least, in case IE gets a little overzealous (ticket #5443). - if ( !document.body ) { - return setTimeout( jQuery.ready, 13 ); - } - - // Remember that the DOM is ready - jQuery.isReady = true; - - // If there are functions bound, to execute - if ( readyList ) { - // Execute all of them - var fn, i = 0; - while ( (fn = readyList[ i++ ]) ) { - fn.call( document, jQuery ); - } - - // Reset the list of functions - readyList = null; - } - - // Trigger any bound ready events - if ( jQuery.fn.triggerHandler ) { - jQuery( document ).triggerHandler( "ready" ); - } - } - }, - - bindReady: function() { - if ( readyBound ) { - return; - } - - readyBound = true; - - // Catch cases where $(document).ready() is called after the - // browser event has already occurred. - if ( document.readyState === "complete" ) { - return jQuery.ready(); - } - - // 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 toString.call(obj) === "[object Function]"; - }, - - isArray: function( obj ) { - return toString.call(obj) === "[object Array]"; - }, - - 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 || toString.call(obj) !== "[object Object]" || obj.nodeType || obj.setInterval ) { - return false; - } - - // Not own constructor property must be Object - if ( obj.constructor - && !hasOwnProperty.call(obj, "constructor") - && !hasOwnProperty.call(obj.constructor.prototype, "isPrototypeOf") ) { - 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 || hasOwnProperty.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 ); - - // Make sure the incoming data is actual JSON - // Logic borrowed from http://json.org/json2.js - if ( /^[\],:{}\s]*$/.test(data.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, "@") - .replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, "]") - .replace(/(?:^|:|,)(?:\s*\[)+/g, "")) ) { - - // Try to use the native JSON parser first - return window.JSON && window.JSON.parse ? - window.JSON.parse( data ) : - (new Function("return " + data))(); - - } else { - jQuery.error( "Invalid JSON: " + data ); - } - }, - - noop: function() {}, - - // Evalulates a script in a global context - globalEval: function( data ) { - if ( data && rnotwhite.test(data) ) { - // Inspired by code by Andrea Giammarchi - // http://webreflection.blogspot.com/2007/08/global-scope-evaluation-and-dom.html - var head = document.head || document.getElementsByTagName("head")[0] || document.documentElement, - script = document.createElement("script"); - - if ( jQuery.support.scriptEval ) { - script.appendChild( document.createTextNode( data ) ); - } else { - script.text = data; - } - - // Use insertBefore instead of appendChild to circumvent an IE6 bug. - // This arises when a base node is used (#2709). - head.insertBefore( script, head.firstChild ); - head.removeChild( script ); - } - }, - - 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 ( var value = object[0]; - i < length && callback.call( value, i, value ) !== false; value = object[++i] ) {} - } - } - - return object; - }, - - trim: function( text ) { - return (text || "").replace( rtrim, "" ); - }, - - // 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) - if ( array.length == null || typeof array === "string" || jQuery.isFunction(array) || (typeof array !== "function" && array.setInterval) ) { - push.call( ret, array ); - } else { - jQuery.merge( ret, array ); - } - } - - return ret; - }, - - inArray: function( 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; - }, - - 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 = []; - - // Go through the array, only saving the items - // that pass the validator function - for ( var i = 0, length = elems.length; i < length; i++ ) { - if ( !inv !== !callback( elems[ i ], i ) ) { - ret.push( elems[ i ] ); - } - } - - return ret; - }, - - // arg is for internal usage only - map: function( elems, callback, arg ) { - var ret = [], value; - - // Go through the array, translating each of the items to their - // new value (or values). - for ( var i = 0, length = elems.length; i < length; i++ ) { - value = callback( elems[ i ], i, arg ); - - if ( value != null ) { - ret[ ret.length ] = value; - } - } - - return ret.concat.apply( [], ret ); - }, - - // A global GUID counter for objects - guid: 1, - - proxy: function( fn, proxy, thisObject ) { - if ( arguments.length === 2 ) { - if ( typeof proxy === "string" ) { - thisObject = fn; - fn = thisObject[ proxy ]; - proxy = undefined; - - } else if ( proxy && !jQuery.isFunction( proxy ) ) { - thisObject = proxy; - proxy = undefined; - } - } - - if ( !proxy && fn ) { - proxy = function() { - return fn.apply( thisObject || this, arguments ); - }; - } - - // Set the guid of unique handler to the same of original handler, so it can be removed - if ( fn ) { - proxy.guid = fn.guid = fn.guid || proxy.guid || jQuery.guid++; - } - - // So proxy can be declared as an argument - return proxy; - }, - - // Use of jQuery.browser is frowned upon. - // More details: http://docs.jquery.com/Utilities/jQuery.browser - uaMatch: function( ua ) { - ua = ua.toLowerCase(); - - var match = /(webkit)[ \/]([\w.]+)/.exec( ua ) || - /(opera)(?:.*version)?[ \/]([\w.]+)/.exec( ua ) || - /(msie) ([\w.]+)/.exec( ua ) || - !/compatible/.test( ua ) && /(mozilla)(?:.*? rv:([\w.]+))?/.exec( ua ) || - []; - - return { browser: match[1] || "", version: match[2] || "0" }; - }, - - browser: {} -}); - -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; -} - -if ( indexOf ) { - jQuery.inArray = function( elem, array ) { - return indexOf.call( array, elem ); - }; -} - -// 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( error ) { - setTimeout( doScrollCheck, 1 ); - return; - } - - // and execute any waiting functions - jQuery.ready(); -} - -function evalScript( i, elem ) { - if ( elem.src ) { - jQuery.ajax({ - url: elem.src, - async: false, - dataType: "script" - }); - } else { - jQuery.globalEval( elem.text || elem.textContent || elem.innerHTML || "" ); - } - - if ( elem.parentNode ) { - elem.parentNode.removeChild( elem ); - } -} - -// Mutifunctional method to get and set values to a collection -// The value/s can be optionally by executed if its a function -function access( elems, key, value, exec, fn, pass ) { - var length = elems.length; - - // Setting many attributes - if ( typeof key === "object" ) { - for ( var k in key ) { - 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; -} - -function now() { - return (new Date).getTime(); -} -(function() { - - jQuery.support = {}; - - var root = document.documentElement, - script = document.createElement("script"), - div = document.createElement("div"), - id = "script" + now(); - - div.style.display = "none"; - div.innerHTML = "
        a"; - - var all = div.getElementsByTagName("*"), - a = div.getElementsByTagName("a")[0]; - - // Can't get basic test support - if ( !all || !all.length || !a ) { - return; - } - - jQuery.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 insted) - style: /red/.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: div.getElementsByTagName("input")[0].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: document.createElement("select").appendChild( document.createElement("option") ).selected, - - parentNode: div.removeChild( div.appendChild( document.createElement("div") ) ).parentNode === null, - - // Will be defined later - deleteExpando: true, - checkClone: false, - scriptEval: false, - noCloneEvent: true, - boxModel: null - }; - - script.type = "text/javascript"; - try { - script.appendChild( document.createTextNode( "window." + id + "=1;" ) ); - } catch(e) {} - - root.insertBefore( script, root.firstChild ); - - // Make sure that the execution of code works by injecting a script - // tag with appendChild/createTextNode - // (IE doesn't support this, fails, and uses .text instead) - if ( window[ id ] ) { - jQuery.support.scriptEval = true; - delete window[ id ]; - } - - // Test to see if it's possible to delete an expando from an element - // Fails in Internet Explorer - try { - delete script.test; - - } catch(e) { - jQuery.support.deleteExpando = false; - } - - root.removeChild( script ); - - if ( div.attachEvent && div.fireEvent ) { - div.attachEvent("onclick", function click() { - // Cloning a node shouldn't copy over any - // bound event handlers (IE does this) - jQuery.support.noCloneEvent = false; - div.detachEvent("onclick", click); - }); - div.cloneNode(true).fireEvent("onclick"); - } - - div = document.createElement("div"); - div.innerHTML = ""; - - var fragment = document.createDocumentFragment(); - fragment.appendChild( div.firstChild ); - - // WebKit doesn't clone checked state correctly in fragments - jQuery.support.checkClone = fragment.cloneNode(true).cloneNode(true).lastChild.checked; - - // Figure out if the W3C box model works as expected - // document.body must exist before we can do this - jQuery(function() { - var div = document.createElement("div"); - div.style.width = div.style.paddingLeft = "1px"; - - document.body.appendChild( div ); - jQuery.boxModel = jQuery.support.boxModel = div.offsetWidth === 2; - document.body.removeChild( div ).style.display = 'none'; - - div = null; - }); - - // Technique from Juriy Zaytsev - // http://thinkweb2.com/projects/prototype/detecting-event-support-without-browser-sniffing/ - var eventSupported = function( eventName ) { - var el = document.createElement("div"); - eventName = "on" + eventName; - - var isSupported = (eventName in el); - if ( !isSupported ) { - el.setAttribute(eventName, "return;"); - isSupported = typeof el[eventName] === "function"; - } - el = null; - - return isSupported; - }; - - jQuery.support.submitBubbles = eventSupported("submit"); - jQuery.support.changeBubbles = eventSupported("change"); - - // release memory in IE - root = script = div = all = a = null; -})(); - -jQuery.props = { - "for": "htmlFor", - "class": "className", - readonly: "readOnly", - maxlength: "maxLength", - cellspacing: "cellSpacing", - rowspan: "rowSpan", - colspan: "colSpan", - tabindex: "tabIndex", - usemap: "useMap", - frameborder: "frameBorder" -}; -var expando = "jQuery" + now(), uuid = 0, windowData = {}; - -jQuery.extend({ - cache: {}, - - expando:expando, - - // The following elements throw uncatchable exceptions if you - // attempt to add expando properties to them. - noData: { - "embed": true, - "object": true, - "applet": true - }, - - data: function( elem, name, data ) { - if ( elem.nodeName && jQuery.noData[elem.nodeName.toLowerCase()] ) { - return; - } - - elem = elem == window ? - windowData : - elem; - - var id = elem[ expando ], cache = jQuery.cache, thisCache; - - if ( !id && typeof name === "string" && data === undefined ) { - return null; - } - - // Compute a unique ID for the element - if ( !id ) { - id = ++uuid; - } - - // Avoid generating a new cache unless none exists and we - // want to manipulate it. - if ( typeof name === "object" ) { - elem[ expando ] = id; - thisCache = cache[ id ] = jQuery.extend(true, {}, name); - - } else if ( !cache[ id ] ) { - elem[ expando ] = id; - cache[ id ] = {}; - } - - thisCache = cache[ id ]; - - // Prevent overriding the named cache with undefined values - if ( data !== undefined ) { - thisCache[ name ] = data; - } - - return typeof name === "string" ? thisCache[ name ] : thisCache; - }, - - removeData: function( elem, name ) { - if ( elem.nodeName && jQuery.noData[elem.nodeName.toLowerCase()] ) { - return; - } - - elem = elem == window ? - windowData : - elem; - - var id = elem[ expando ], cache = jQuery.cache, thisCache = cache[ id ]; - - // If we want to remove a specific section of the element's data - if ( name ) { - if ( thisCache ) { - // Remove the section of cache data - delete thisCache[ name ]; - - // If we've removed all the data, remove the element's cache - if ( jQuery.isEmptyObject(thisCache) ) { - jQuery.removeData( elem ); - } - } - - // Otherwise, we want to remove all of the element's data - } else { - if ( jQuery.support.deleteExpando ) { - delete elem[ jQuery.expando ]; - - } else if ( elem.removeAttribute ) { - elem.removeAttribute( jQuery.expando ); - } - - // Completely remove the data cache - delete cache[ id ]; - } - } -}); - -jQuery.fn.extend({ - data: function( key, value ) { - if ( typeof key === "undefined" && this.length ) { - return jQuery.data( this[0] ); - - } 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 ) { - var data = this.triggerHandler("getData" + parts[1] + "!", [parts[0]]); - - if ( data === undefined && this.length ) { - data = jQuery.data( this[0], key ); - } - return data === undefined && parts[1] ? - this.data( parts[0] ) : - data; - } else { - return this.trigger("setData" + parts[1] + "!", [parts[0], value]).each(function() { - jQuery.data( this, key, value ); - }); - } - }, - - removeData: function( key ) { - return this.each(function() { - jQuery.removeData( this, key ); - }); - } -}); -jQuery.extend({ - queue: function( elem, type, data ) { - if ( !elem ) { - return; - } - - type = (type || "fx") + "queue"; - var q = jQuery.data( elem, type ); - - // Speed up dequeue by getting out quickly if this is just a lookup - if ( !data ) { - return q || []; - } - - if ( !q || jQuery.isArray(data) ) { - q = jQuery.data( elem, type, jQuery.makeArray(data) ); - - } else { - q.push( data ); - } - - return q; - }, - - dequeue: function( elem, type ) { - type = type || "fx"; - - var queue = jQuery.queue( elem, type ), fn = queue.shift(); - - // 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); - }); - } - } -}); - -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( i, elem ) { - 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", [] ); - } -}); -var rclass = /[\n\t]/g, - rspace = /\s+/, - rreturn = /\r/g, - rspecialurl = /href|src|style/, - rtype = /(button|input)/i, - rfocusable = /(button|input|object|select|textarea)/i, - rclickable = /^(a|area)$/i, - rradiocheck = /radio|checkbox/; - -jQuery.fn.extend({ - attr: function( name, value ) { - return access( this, name, value, true, jQuery.attr ); - }, - - removeAttr: function( name, fn ) { - return this.each(function(){ - jQuery.attr( this, name, "" ); - if ( this.nodeType === 1 ) { - this.removeAttribute( name ); - } - }); - }, - - addClass: function( value ) { - if ( jQuery.isFunction(value) ) { - return this.each(function(i) { - var self = jQuery(this); - self.addClass( value.call(this, i, self.attr("class")) ); - }); - } - - if ( value && typeof value === "string" ) { - var classNames = (value || "").split( rspace ); - - for ( var i = 0, l = this.length; i < l; i++ ) { - var elem = this[i]; - - if ( elem.nodeType === 1 ) { - if ( !elem.className ) { - elem.className = value; - - } else { - var className = " " + elem.className + " ", setClass = elem.className; - for ( var c = 0, cl = classNames.length; c < cl; c++ ) { - if ( className.indexOf( " " + classNames[c] + " " ) < 0 ) { - setClass += " " + classNames[c]; - } - } - elem.className = jQuery.trim( setClass ); - } - } - } - } - - return this; - }, - - removeClass: function( value ) { - if ( jQuery.isFunction(value) ) { - return this.each(function(i) { - var self = jQuery(this); - self.removeClass( value.call(this, i, self.attr("class")) ); - }); - } - - if ( (value && typeof value === "string") || value === undefined ) { - var classNames = (value || "").split(rspace); - - for ( var i = 0, l = this.length; i < l; i++ ) { - var elem = this[i]; - - if ( elem.nodeType === 1 && elem.className ) { - if ( value ) { - var className = (" " + elem.className + " ").replace(rclass, " "); - for ( var 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) { - var self = jQuery(this); - self.toggleClass( value.call(this, i, self.attr("class"), 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].className + " ").replace(rclass, " ").indexOf( className ) > -1 ) { - return true; - } - } - - return false; - }, - - val: function( value ) { - if ( value === undefined ) { - var elem = this[0]; - - if ( elem ) { - if ( jQuery.nodeName( elem, "option" ) ) { - return (elem.attributes.value || {}).specified ? elem.value : elem.text; - } - - // We need to handle select boxes special - if ( jQuery.nodeName( elem, "select" ) ) { - var 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 ]; - - if ( option.selected ) { - // Get the specifc 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 ); - } - } - - return values; - } - - // Handle the case where in Webkit "" is returned instead of "on" if a value isn't specified - if ( rradiocheck.test( elem.type ) && !jQuery.support.checkOn ) { - return elem.getAttribute("value") === null ? "on" : elem.value; - } - - - // Everything else, we just grab the value - return (elem.value || "").replace(rreturn, ""); - - } - - return undefined; - } - - var isFunction = jQuery.isFunction(value); - - return this.each(function(i) { - var self = jQuery(this), val = value; - - if ( this.nodeType !== 1 ) { - return; - } - - if ( isFunction ) { - val = value.call(this, i, self.val()); - } - - // Typecast each time if the value is a Function and the appended - // value is therefore different each time. - if ( typeof val === "number" ) { - val += ""; - } - - if ( jQuery.isArray(val) && rradiocheck.test( this.type ) ) { - this.checked = jQuery.inArray( self.val(), val ) >= 0; - - } else if ( jQuery.nodeName( this, "select" ) ) { - var values = jQuery.makeArray(val); - - jQuery( "option", this ).each(function() { - this.selected = jQuery.inArray( jQuery(this).val(), values ) >= 0; - }); - - if ( !values.length ) { - this.selectedIndex = -1; - } - - } else { - this.value = val; - } - }); - } -}); - -jQuery.extend({ - attrFn: { - val: true, - css: true, - html: true, - text: true, - data: true, - width: true, - height: true, - offset: true - }, - - attr: function( elem, name, value, pass ) { - // don't set attributes on text and comment nodes - if ( !elem || elem.nodeType === 3 || elem.nodeType === 8 ) { - return undefined; - } - - if ( pass && name in jQuery.attrFn ) { - return jQuery(elem)[name](value); - } - - var notxml = elem.nodeType !== 1 || !jQuery.isXMLDoc( elem ), - // Whether we are setting (or getting) - set = value !== undefined; - - // Try to normalize/fix the name - name = notxml && jQuery.props[ name ] || name; - - // Only do all the following if this is a node (faster for style) - if ( elem.nodeType === 1 ) { - // These attributes require special treatment - var special = rspecialurl.test( name ); - - // Safari mis-reports the default selected property of an option - // Accessing the parent's selectedIndex property fixes it - if ( name === "selected" && !jQuery.support.optSelected ) { - var parent = elem.parentNode; - if ( parent ) { - parent.selectedIndex; - - // Make sure that it also works with optgroups, see #5701 - if ( parent.parentNode ) { - parent.parentNode.selectedIndex; - } - } - } - - // If applicable, access the attribute via the DOM 0 way - if ( name in elem && notxml && !special ) { - if ( set ) { - // We can't allow the type property to be changed (since it causes problems in IE) - if ( name === "type" && rtype.test( elem.nodeName ) && elem.parentNode ) { - jQuery.error( "type property can't be changed" ); - } - - elem[ name ] = value; - } - - // browsers index elements by id/name on forms, give priority to attributes. - if ( jQuery.nodeName( elem, "form" ) && elem.getAttributeNode(name) ) { - return elem.getAttributeNode( name ).nodeValue; - } - - // 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/ - if ( name === "tabIndex" ) { - var attributeNode = elem.getAttributeNode( "tabIndex" ); - - return attributeNode && attributeNode.specified ? - attributeNode.value : - rfocusable.test( elem.nodeName ) || rclickable.test( elem.nodeName ) && elem.href ? - 0 : - undefined; - } - - return elem[ name ]; - } - - if ( !jQuery.support.style && notxml && name === "style" ) { - if ( set ) { - elem.style.cssText = "" + value; - } - - return elem.style.cssText; - } - - if ( set ) { - // convert the value to a string (all browsers do this but IE) see #1070 - elem.setAttribute( name, "" + value ); - } - - var attr = !jQuery.support.hrefNormalized && notxml && special ? - // Some attributes require a special call on IE - elem.getAttribute( name, 2 ) : - elem.getAttribute( name ); - - // Non-existent attributes return null, we normalize to undefined - return attr === null ? undefined : attr; - } - - // elem is actually elem.style ... set the style - // Using attr for specific style information is now deprecated. Use style instead. - return jQuery.style( elem, name, value ); - } -}); -var rnamespaces = /\.(.*)$/, - fcleanup = function( nm ) { - return nm.replace(/[^\w\s\.\|`]/g, function( ch ) { - return "\\" + ch; - }); - }; - -/* - * 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; - } - - // For whatever reason, IE has trouble passing the window object - // around, causing it to be cloned in the process - if ( elem.setInterval && ( elem !== window && !elem.frameElement ) ) { - elem = window; - } - - 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 = elemData.events || {}, - eventHandle = elemData.handle, eventHandle; - - if ( !eventHandle ) { - elemData.handle = eventHandle = function() { - // Handle the second event of a trigger and when - // an event is called after a page has unloaded - return typeof jQuery !== "undefined" && !jQuery.event.triggered ? - 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; - 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 global triggering - 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; - } - - var ret, type, fn, i = 0, all, namespaces, namespace, special, eventType, handleObj, origType, - elemData = 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 ( var 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 ( var 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 ) { - 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 ); - } - } - }, - - // bubbling is internal - trigger: function( event, data, elem /*, bubbling */ ) { - // Event object or event type - var type = event.type || event, - bubbling = arguments[3]; - - if ( !bubbling ) { - event = typeof event === "object" ? - // jQuery.Event object - event[expando] ? event : - // Object literal - jQuery.extend( jQuery.Event(type), event ) : - // Just the event type (string) - jQuery.Event(type); - - if ( type.indexOf("!") >= 0 ) { - event.type = type = type.slice(0, -1); - event.exclusive = true; - } - - // Handle a global trigger - if ( !elem ) { - // Don't bubble custom events when global (to avoid too much overhead) - event.stopPropagation(); - - // Only trigger if we've ever bound an event for it - if ( jQuery.event.global[ type ] ) { - jQuery.each( jQuery.cache, function() { - if ( this.events && this.events[type] ) { - jQuery.event.trigger( event, data, this.handle.elem ); - } - }); - } - } - - // Handle triggering a single element - - // don't do events on text and comment nodes - if ( !elem || elem.nodeType === 3 || elem.nodeType === 8 ) { - return undefined; - } - - // Clean up in case it is reused - event.result = undefined; - event.target = elem; - - // Clone the incoming data, if any - data = jQuery.makeArray( data ); - data.unshift( event ); - } - - event.currentTarget = elem; - - // Trigger the event, it is assumed that "handle" is a function - var handle = jQuery.data( elem, "handle" ); - if ( handle ) { - handle.apply( elem, data ); - } - - var parent = elem.parentNode || elem.ownerDocument; - - // Trigger an inline bound script - try { - if ( !(elem && elem.nodeName && jQuery.noData[elem.nodeName.toLowerCase()]) ) { - if ( elem[ "on" + type ] && elem[ "on" + type ].apply( elem, data ) === false ) { - event.result = false; - } - } - - // prevent IE from throwing an error for some elements with some event types, see #3533 - } catch (e) {} - - if ( !event.isPropagationStopped() && parent ) { - jQuery.event.trigger( event, data, parent, true ); - - } else if ( !event.isDefaultPrevented() ) { - var target = event.target, old, - isClick = jQuery.nodeName(target, "a") && type === "click", - special = jQuery.event.special[ type ] || {}; - - if ( (!special._default || special._default.call( elem, event ) === false) && - !isClick && !(target && target.nodeName && jQuery.noData[target.nodeName.toLowerCase()]) ) { - - try { - if ( target[ type ] ) { - // Make sure that we don't accidentally re-trigger the onFOO events - old = target[ "on" + type ]; - - if ( old ) { - target[ "on" + type ] = null; - } - - jQuery.event.triggered = true; - target[ type ](); - } - - // prevent IE from throwing an error for some elements with some event types, see #3533 - } catch (e) {} - - if ( old ) { - target[ "on" + type ] = old; - } - - jQuery.event.triggered = false; - } - } - }, - - handle: function( event ) { - var all, handlers, namespaces, namespace, events; - - event = arguments[0] = jQuery.event.fix( event || window.event ); - event.currentTarget = this; - - // Namespaced event handlers - all = event.type.indexOf(".") < 0 && !event.exclusive; - - if ( !all ) { - namespaces = event.type.split("."); - event.type = namespaces.shift(); - namespace = new RegExp("(^|\\.)" + namespaces.slice(0).sort().join("\\.(?:.*\\.)?") + "(\\.|$)"); - } - - var events = jQuery.data(this, "events"), handlers = events[ event.type ]; - - if ( events && handlers ) { - // Clone the handlers to prevent manipulation - handlers = handlers.slice(0); - - for ( var j = 0, l = handlers.length; j < l; j++ ) { - var handleObj = handlers[ j ]; - - // Filter the functions by class - if ( all || namespace.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, arguments ); - - 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 layerX layerY metaKey newValue offsetX offsetY originalTarget pageX pageY prevValue relatedNode relatedTarget screenX screenY shiftKey srcElement target toElement view wheelDelta which".split(" "), - - fix: function( event ) { - if ( event[ 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 ) { - event.target = event.srcElement || document; // Fixes #1925 where srcElement might not be defined either - } - - // 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 doc = document.documentElement, body = document.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 && ((event.charCode || event.charCode === 0) ? event.charCode : event.keyCode) ) { - event.which = 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, handleObj.origType, jQuery.extend({}, handleObj, {handler: liveHandler}) ); - }, - - remove: function( handleObj ) { - var remove = true, - type = handleObj.origType.replace(rnamespaces, ""); - - jQuery.each( jQuery.data(this, "events").live || [], function() { - if ( type === this.origType.replace(rnamespaces, "") ) { - remove = false; - return false; - } - }); - - if ( remove ) { - jQuery.event.remove( this, handleObj.origType, liveHandler ); - } - } - - }, - - beforeunload: { - setup: function( data, namespaces, eventHandle ) { - // We only want to do this special case on windows - if ( this.setInterval ) { - this.onbeforeunload = eventHandle; - } - - return false; - }, - teardown: function( namespaces, eventHandle ) { - if ( this.onbeforeunload === eventHandle ) { - this.onbeforeunload = null; - } - } - } - } -}; - -var removeEvent = document.removeEventListener ? - function( elem, type, handle ) { - elem.removeEventListener( type, handle, false ); - } : - function( elem, type, handle ) { - elem.detachEvent( "on" + type, handle ); - }; - -jQuery.Event = function( src ) { - // Allow instantiation without the 'new' keyword - if ( !this.preventDefault ) { - return new jQuery.Event( src ); - } - - // Event object - if ( src && src.type ) { - this.originalEvent = src; - this.type = src.type; - // Event type - } else { - this.type = src; - } - - // timeStamp is buggy for some events on Firefox(#3843) - // So we won't rely on the native value - this.timeStamp = now(); - - // Mark it as fixed - this[ 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) - 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 parent = event.relatedTarget; - - // Firefox sometimes assigns relatedTarget a XUL element - // which we cannot access the parentNode property of - try { - // Traverse up the tree - while ( parent && parent !== this ) { - parent = parent.parentNode; - } - - if ( parent !== this ) { - // set the correct event type - event.type = event.data; - - // handle event if we actually just moused on to a non sub-element - jQuery.event.handle.apply( this, arguments ); - } - - // assuming we've left the element since we most likely mousedover a xul element - } catch(e) { } -}, - -// 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 ( this.nodeName.toLowerCase() !== "form" ) { - jQuery.event.add(this, "click.specialSubmit", function( e ) { - var elem = e.target, type = elem.type; - - if ( (type === "submit" || type === "image") && jQuery( elem ).closest("form").length ) { - return trigger( "submit", this, arguments ); - } - }); - - jQuery.event.add(this, "keypress.specialSubmit", function( e ) { - var elem = e.target, type = elem.type; - - if ( (type === "text" || type === "password") && jQuery( elem ).closest("form").length && e.keyCode === 13 ) { - return 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 formElems = /textarea|input|select/i, - - changeFilters, - - getVal = function( elem ) { - var type = 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 ( elem.nodeName.toLowerCase() === "select" ) { - val = elem.selectedIndex; - } - - return val; - }, - - testChange = function testChange( e ) { - var elem = e.target, data, val; - - if ( !formElems.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"; - return jQuery.event.trigger( e, arguments[1], elem ); - } - }; - - jQuery.event.special.change = { - filters: { - focusout: testChange, - - click: function( e ) { - var elem = e.target, type = elem.type; - - if ( type === "radio" || type === "checkbox" || elem.nodeName.toLowerCase() === "select" ) { - return 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 = elem.type; - - if ( (e.keyCode === 13 && elem.nodeName.toLowerCase() !== "textarea") || - (e.keyCode === 32 && (type === "checkbox" || type === "radio")) || - type === "select-multiple" ) { - return 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/focus[in] is not needed anymore - 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 formElems.test( this.nodeName ); - }, - - teardown: function( namespaces ) { - jQuery.event.remove( this, ".specialChange" ); - - return formElems.test( this.nodeName ); - } - }; - - changeFilters = jQuery.event.special.change.filters; -} - -function trigger( type, elem, args ) { - args[0].type = type; - return jQuery.event.handle.apply( elem, args ); -} - -// Create "bubbling" focus and blur events -if ( document.addEventListener ) { - jQuery.each({ focus: "focusin", blur: "focusout" }, function( orig, fix ) { - jQuery.event.special[ fix ] = { - setup: function() { - this.addEventListener( orig, handler, true ); - }, - teardown: function() { - this.removeEventListener( orig, handler, true ); - } - }; - - function handler( e ) { - e = jQuery.event.fix( e ); - e.type = fix; - return jQuery.event.handle.call( this, e ); - } - }); -} - -jQuery.each(["bind", "one"], function( i, name ) { - jQuery.fn[ name ] = function( type, data, fn ) { - // Handle object literals - if ( typeof type === "object" ) { - for ( var key in type ) { - this[ name ](key, data, type[key], fn); - } - return this; - } - - if ( jQuery.isFunction( data ) ) { - fn = data; - data = undefined; - } - - var handler = name === "one" ? jQuery.proxy( fn, function( event ) { - jQuery( this ).unbind( event, handler ); - return fn.apply( this, arguments ); - }) : 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] ) { - var event = jQuery.Event( type ); - event.preventDefault(); - event.stopPropagation(); - jQuery.event.trigger( event, data, this[0] ); - return event.result; - } - }, - - toggle: function( fn ) { - // Save reference to arguments for access in closure - var args = arguments, i = 1; - - // link all the functions, so any of them can unbind this click handler - while ( i < args.length ) { - jQuery.proxy( fn, args[ i++ ] ); - } - - return this.click( jQuery.proxy( fn, 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; - })); - }, - - 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 ( jQuery.isFunction( data ) ) { - fn = data; - 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 ( type === "focus" || type === "blur" ) { - types.push( liveMap[ type ] + namespaces ); - type = type + namespaces; - - } else { - type = (liveMap[ type ] || type) + namespaces; - } - - if ( name === "live" ) { - // bind live handler - context.each(function(){ - jQuery.event.add( this, liveConvert( type, selector ), - { data: data, selector: selector, handler: fn, origType: type, origHandler: fn, preType: preType } ); - }); - - } else { - // unbind live handler - context.unbind( liveConvert( type, selector ), fn ); - } - } - - return this; - } -}); - -function liveHandler( event ) { - var stop, elems = [], selectors = [], args = arguments, - related, match, handleObj, elem, j, i, l, data, - events = jQuery.data( this, "events" ); - - // Make sure we avoid non-left-click bubbling in Firefox (#3861) - if ( event.liveFired === this || !events || !events.live || event.button && event.type === "click" ) { - return; - } - - 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++ ) { - for ( j = 0; j < live.length; j++ ) { - handleObj = live[j]; - - if ( match[i].selector === handleObj.selector ) { - elem = match[i].elem; - related = null; - - // Those two events require additional checking - if ( handleObj.preType === "mouseenter" || handleObj.preType === "mouseleave" ) { - related = jQuery( event.relatedTarget ).closest( handleObj.selector )[0]; - } - - if ( !related || related !== elem ) { - elems.push({ elem: elem, handleObj: handleObj }); - } - } - } - } - - for ( i = 0, l = elems.length; i < l; i++ ) { - match = elems[i]; - event.currentTarget = match.elem; - event.data = match.handleObj.data; - event.handleObj = match.handleObj; - - if ( match.handleObj.origHandler.apply( match.elem, args ) === false ) { - stop = false; - break; - } - } - - return stop; -} - -function liveConvert( type, selector ) { - return "live." + (type && type !== "*" ? type + "." : "") + selector.replace(/\./g, "`").replace(/ /g, "&"); -} - -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( fn ) { - return fn ? this.bind( name, fn ) : this.trigger( name ); - }; - - if ( jQuery.attrFn ) { - jQuery.attrFn[ name ] = true; - } -}); - -// Prevent memory leaks in IE -// Window isn't included so as not to unbind existing unload events -// More info: -// - http://isaacschlueter.com/2006/10/msie-memory-leaks/ -if ( window.attachEvent && !window.addEventListener ) { - window.attachEvent("onunload", function() { - for ( var id in jQuery.cache ) { - if ( jQuery.cache[ id ].handle ) { - // Try/Catch is to handle iframes being unloaded, see #4280 - try { - jQuery.event.remove( jQuery.cache[ id ].handle.elem ); - } catch(e) {} - } - } - }); -} -/*! - * Sizzle CSS Selector Engine - v1.0 - * Copyright 2009, 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; - -// 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 || []; - var origContext = context = context || document; - - if ( context.nodeType !== 1 && context.nodeType !== 9 ) { - return []; - } - - if ( !selector || typeof selector !== "string" ) { - return results; - } - - var parts = [], m, set, checkSet, extra, prune = true, contextXML = isXML(context), - soFar = selector; - - // Reset the position of the chunker regexp (start from head) - while ( (chunker.exec(""), m = chunker.exec(soFar)) !== null ) { - soFar = m[3]; - - parts.push( m[1] ); - - if ( m[2] ) { - extra = m[3]; - break; - } - } - - 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]) ) { - var ret = Sizzle.find( parts.shift(), context, contextXML ); - context = ret.expr ? Sizzle.filter( ret.expr, ret.set )[0] : ret.set[0]; - } - - if ( context ) { - var 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 ) { - var 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 ( var i = 0; checkSet[i] != null; i++ ) { - if ( checkSet[i] && (checkSet[i] === true || checkSet[i].nodeType === 1 && contains(context, checkSet[i])) ) { - results.push( set[i] ); - } - } - } else { - for ( var 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.find = function(expr, context, isXML){ - var set, match; - - if ( !expr ) { - return []; - } - - for ( var i = 0, l = Expr.order.length; i < l; i++ ) { - var type = Expr.order[i], match; - - 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(/\\/g, ""); - set = Expr.find[ type ]( match, context, isXML ); - if ( set != null ) { - expr = expr.replace( Expr.match[ type ], "" ); - break; - } - } - } - } - - if ( !set ) { - set = context.getElementsByTagName("*"); - } - - return {set: set, expr: expr}; -}; - -Sizzle.filter = function(expr, set, inplace, not){ - var old = expr, result = [], curLoop = set, match, anyFound, - isXMLFilter = set && set[0] && isXML(set[0]); - - while ( expr && set.length ) { - for ( var type in Expr.filter ) { - if ( (match = Expr.leftMatch[ type ].exec( expr )) != null && match[2] ) { - var filter = Expr.filter[ type ], found, item, 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|)\s*\]/, - TAG: /^((?:[\w\u00c0-\uFFFF\*-]|\\.)+)/, - CHILD: /:(only|nth|last|first)-child(?:\((even|odd|[\dn+-]*)\))?/, - 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"); - } - }, - relative: { - "+": function(checkSet, part){ - var isPartStr = typeof part === "string", - isTag = isPartStr && !/\W/.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 isPartStr = typeof part === "string"; - - if ( isPartStr && !/\W/.test(part) ) { - part = part.toLowerCase(); - - for ( var i = 0, l = checkSet.length; i < l; i++ ) { - var elem = checkSet[i]; - if ( elem ) { - var parent = elem.parentNode; - checkSet[i] = parent.nodeName.toLowerCase() === part ? parent : false; - } - } - } else { - for ( var i = 0, l = checkSet.length; i < l; i++ ) { - var 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 doneName = done++, checkFn = dirCheck; - - if ( typeof part === "string" && !/\W/.test(part) ) { - var nodeCheck = part = part.toLowerCase(); - checkFn = dirNodeCheck; - } - - checkFn("parentNode", part, doneName, checkSet, nodeCheck, isXML); - }, - "~": function(checkSet, part, isXML){ - var doneName = done++, checkFn = dirCheck; - - if ( typeof part === "string" && !/\W/.test(part) ) { - var nodeCheck = part = part.toLowerCase(); - 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]); - return m ? [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){ - return context.getElementsByTagName(match[1]); - } - }, - preFilter: { - CLASS: function(match, curLoop, inplace, result, not, isXML){ - match = " " + match[1].replace(/\\/g, "") + " "; - - 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]/g, " ").indexOf(match) >= 0) ) { - if ( !inplace ) { - result.push( elem ); - } - } else if ( inplace ) { - curLoop[i] = false; - } - } - } - - return false; - }, - ID: function(match){ - return match[1].replace(/\\/g, ""); - }, - TAG: function(match, curLoop){ - return match[1].toLowerCase(); - }, - CHILD: function(match){ - if ( match[1] === "nth" ) { - // 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; - } - - // TODO: Move to normal caching system - match[0] = done++; - - return match; - }, - ATTR: function(match, curLoop, inplace, result, not, isXML){ - var name = match[1].replace(/\\/g, ""); - - if ( !isXML && Expr.attrMap[name] ) { - match[1] = Expr.attrMap[name]; - } - - 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 - 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){ - return "text" === elem.type; - }, - radio: function(elem){ - return "radio" === elem.type; - }, - checkbox: function(elem){ - return "checkbox" === elem.type; - }, - file: function(elem){ - return "file" === elem.type; - }, - password: function(elem){ - return "password" === elem.type; - }, - submit: function(elem){ - return "submit" === elem.type; - }, - image: function(elem){ - return "image" === elem.type; - }, - reset: function(elem){ - return "reset" === elem.type; - }, - button: function(elem){ - return "button" === elem.type || elem.nodeName.toLowerCase() === "button"; - }, - input: function(elem){ - return /input|select|textarea|button/i.test(elem.nodeName); - } - }, - 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 || getText([ elem ]) || "").indexOf(match[3]) >= 0; - } else if ( name === "not" ) { - var not = match[3]; - - for ( var i = 0, l = not.length; i < l; i++ ) { - if ( not[i] === elem ) { - return false; - } - } - - return true; - } else { - Sizzle.error( "Syntax error, unrecognized expression: " + 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; - -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, function(all, num){ - return "\\" + (num - 0 + 1); - })); -} - -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 ret = results || []; - - if ( toString.call(array) === "[object Array]" ) { - Array.prototype.push.apply( ret, array ); - } else { - if ( typeof array.length === "number" ) { - for ( var i = 0, l = array.length; i < l; i++ ) { - ret.push( array[i] ); - } - } else { - for ( var i = 0; array[i]; i++ ) { - ret.push( array[i] ); - } - } - } - - return ret; - }; -} - -var sortOrder; - -if ( document.documentElement.compareDocumentPosition ) { - sortOrder = function( a, b ) { - if ( !a.compareDocumentPosition || !b.compareDocumentPosition ) { - if ( a == b ) { - hasDuplicate = true; - } - return a.compareDocumentPosition ? -1 : 1; - } - - var ret = a.compareDocumentPosition(b) & 4 ? -1 : a === b ? 0 : 1; - if ( ret === 0 ) { - hasDuplicate = true; - } - return ret; - }; -} else if ( "sourceIndex" in document.documentElement ) { - sortOrder = function( a, b ) { - if ( !a.sourceIndex || !b.sourceIndex ) { - if ( a == b ) { - hasDuplicate = true; - } - return a.sourceIndex ? -1 : 1; - } - - var ret = a.sourceIndex - b.sourceIndex; - if ( ret === 0 ) { - hasDuplicate = true; - } - return ret; - }; -} else if ( document.createRange ) { - sortOrder = function( a, b ) { - if ( !a.ownerDocument || !b.ownerDocument ) { - if ( a == b ) { - hasDuplicate = true; - } - return a.ownerDocument ? -1 : 1; - } - - var aRange = a.ownerDocument.createRange(), bRange = b.ownerDocument.createRange(); - aRange.setStart(a, 0); - aRange.setEnd(a, 0); - bRange.setStart(b, 0); - bRange.setEnd(b, 0); - var ret = aRange.compareBoundaryPoints(Range.START_TO_END, bRange); - if ( ret === 0 ) { - hasDuplicate = true; - } - return ret; - }; -} - -// Utility function for retreiving the text value of an array of DOM nodes -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; -} - -// 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(); - form.innerHTML = ""; - - // Inject it into the root element, check its status, and remove it quickly - var root = document.documentElement; - 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 ); - root = form = null; // release memory in IE -})(); - -(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); - }; - } - - div = null; // release memory in IE -})(); - -if ( document.querySelectorAll ) { - (function(){ - var oldSizzle = Sizzle, div = document.createElement("div"); - 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 && context.nodeType === 9 && !isXML(context) ) { - try { - return makeArray( context.querySelectorAll(query), extra ); - } catch(e){} - } - - return oldSizzle(query, context, extra, seed); - }; - - for ( var prop in oldSizzle ) { - Sizzle[ prop ] = oldSizzle[ prop ]; - } - - div = null; // release memory in IE - })(); -} - -(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]); - } - }; - - div = null; // release memory in IE -})(); - -function dirNodeCheck( dir, cur, doneName, checkSet, nodeCheck, isXML ) { - for ( var i = 0, l = checkSet.length; i < l; i++ ) { - var elem = checkSet[i]; - if ( elem ) { - elem = elem[dir]; - var match = false; - - 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 ) { - elem = elem[dir]; - var match = false; - - 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; - } - } -} - -var contains = document.compareDocumentPosition ? function(a, b){ - return !!(a.compareDocumentPosition(b) & 16); -} : function(a, b){ - return a !== b && (a.contains ? a.contains(b) : true); -}; - -var 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 tmpSet = [], later = "", match, - 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 = getText; -jQuery.isXMLDoc = isXML; -jQuery.contains = contains; - -return; - -window.Sizzle = Sizzle; - -})(); -var runtil = /Until$/, - rparentsprev = /^(?:parents|prevUntil|prevAll)/, - // Note: This RegExp should be improved, or likely pulled from Sizzle - rmultiselector = /,/, - slice = Array.prototype.slice; - -// Implement the identical functionality for filter and not -var winnow = function( elements, qualifier, keep ) { - if ( jQuery.isFunction( qualifier ) ) { - return jQuery.grep(elements, function( elem, i ) { - return !!qualifier.call( elem, i, elem ) === 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; - }); -}; - -jQuery.fn.extend({ - find: function( selector ) { - var ret = this.pushStack( "", "find", selector ), length = 0; - - for ( var 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 ( var n = length; n < ret.length; n++ ) { - for ( var 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 && jQuery.filter( selector, this ).length > 0; - }, - - closest: function( selectors, context ) { - if ( jQuery.isArray( selectors ) ) { - var ret = [], cur = this[0], match, matches = {}, selector; - - if ( cur && selectors.length ) { - for ( var i = 0, l = selectors.length; i < l; i++ ) { - selector = selectors[i]; - - if ( !matches[selector] ) { - matches[selector] = jQuery.expr.match.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 }); - delete matches[selector]; - } - } - cur = cur.parentNode; - } - } - - return ret; - } - - var pos = jQuery.expr.match.POS.test( selectors ) ? - jQuery( selectors, context || this.context ) : null; - - return this.map(function( i, cur ) { - while ( cur && cur.ownerDocument && cur !== context ) { - if ( pos ? pos.index(cur) > -1 : jQuery(cur).is(selectors) ) { - return cur; - } - cur = cur.parentNode; - } - return null; - }); - }, - - // Determine the position of an element within - // the matched set of elements - index: function( elem ) { - if ( !elem || typeof elem === "string" ) { - return jQuery.inArray( this[0], - // If it receives a string, the selector is used - // If it receives nothing, the siblings are used - elem ? jQuery( elem ) : this.parent().children() ); - } - // 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 || this.context ) : - jQuery.makeArray( 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 ); - - if ( !runtil.test( name ) ) { - selector = until; - } - - if ( selector && typeof selector === "string" ) { - ret = jQuery.filter( selector, ret ); - } - - ret = this.length > 1 ? jQuery.unique( ret ) : ret; - - if ( (this.length > 1 || rmultiselector.test( selector )) && rparentsprev.test( name ) ) { - ret = ret.reverse(); - } - - return this.pushStack( ret, name, slice.call(arguments).join(",") ); - }; -}); - -jQuery.extend({ - filter: function( expr, elems, not ) { - if ( not ) { - expr = ":not(" + expr + ")"; - } - - return 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; - } -}); -var rinlinejQuery = / jQuery\d+="(?:\d+|null)"/g, - rleadingWhitespace = /^\s+/, - rxhtmlTag = /(<([\w:]+)[^>]*?)\/>/g, - rselfClosing = /^(?:area|br|col|embed|hr|img|input|link|meta|param)$/i, - rtagName = /<([\w:]+)/, - rtbody = /"; - }, - wrapMap = { - option: [ 1, "" ], - 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 \ No newline at end of file diff --git a/src/ajax.js b/src/ajax.js index 355fd7e4..3e724880 100644 --- a/src/ajax.js +++ b/src/ajax.js @@ -1,173 +1,32 @@ -(function( jQuery ) { - -var r20 = /%20/g, - rbracket = /\[\]$/, - rCRLF = /\r?\n/g, - rhash = /#.*$/, - rheaders = /^(.*?):[ \t]*([^\r\n]*)\r?$/mg, // IE leaves an \r character at EOL - rinput = /^(?:color|date|datetime|datetime-local|email|hidden|month|number|password|range|search|tel|text|time|url|week)$/i, - // #7653, #8125, #8152: local protocol detection - rlocalProtocol = /^(?:about|app|app\-storage|.+\-extension|file|res|widget):$/, - rnoContent = /^(?:GET|HEAD)$/, - rprotocol = /^\/\//, - rquery = /\?/, - rscript = /)<[^<]*)*<\/script>/gi, - rselectTextarea = /^(?:select|textarea)/i, - rspacesAjax = /\s+/, - rts = /([?&])_=[^&]*/, - rurl = /^([\w\+\.\-]+:)(?:\/\/([^\/?#:]*)(?::(\d+))?)?/, - - // Keep a copy of the old load method - _load = jQuery.fn.load, - - /* Prefilters - * 1) They are useful to introduce custom dataTypes (see ajax/jsonp.js for an example) - * 2) These are called: - * - BEFORE asking for a transport - * - AFTER param serialization (s.data is a string if s.processData is true) - * 3) key is the dataType - * 4) the catchall symbol "*" can be used - * 5) execution will start with transport dataType and THEN continue down to "*" if needed - */ - prefilters = {}, - - /* Transports bindings - * 1) key is the dataType - * 2) the catchall symbol "*" can be used - * 3) selection will start with transport dataType and THEN go to "*" if needed - */ - transports = {}, - - // Document location - ajaxLocation, - - // Document location segments - ajaxLocParts; - -// #8138, IE may throw an exception when accessing -// a field from window.location if document.domain has been set -try { - ajaxLocation = location.href; -} catch( e ) { - // Use the href attribute of an A element - // since IE will modify it given document.location - ajaxLocation = document.createElement( "a" ); - ajaxLocation.href = ""; - ajaxLocation = ajaxLocation.href; -} - -// Segment location into parts -ajaxLocParts = rurl.exec( ajaxLocation.toLowerCase() ) || []; - -// Base "constructor" for jQuery.ajaxPrefilter and jQuery.ajaxTransport -function addToPrefiltersOrTransports( structure ) { - - // dataTypeExpression is optional and defaults to "*" - return function( dataTypeExpression, func ) { - - if ( typeof dataTypeExpression !== "string" ) { - func = dataTypeExpression; - dataTypeExpression = "*"; - } - - if ( jQuery.isFunction( func ) ) { - var dataTypes = dataTypeExpression.toLowerCase().split( rspacesAjax ), - i = 0, - length = dataTypes.length, - dataType, - list, - placeBefore; - - // For each dataType in the dataTypeExpression - for(; i < length; i++ ) { - dataType = dataTypes[ i ]; - // We control if we're asked to add before - // any existing element - placeBefore = /^\+/.test( dataType ); - if ( placeBefore ) { - dataType = dataType.substr( 1 ) || "*"; - } - list = structure[ dataType ] = structure[ dataType ] || []; - // then we add to the structure accordingly - list[ placeBefore ? "unshift" : "push" ]( func ); - } - } - }; -} - -// Base inspection function for prefilters and transports -function inspectPrefiltersOrTransports( structure, options, originalOptions, jqXHR, - dataType /* internal */, inspected /* internal */ ) { - - dataType = dataType || options.dataTypes[ 0 ]; - inspected = inspected || {}; - - inspected[ dataType ] = true; - - var list = structure[ dataType ], - i = 0, - length = list ? list.length : 0, - executeOnly = ( structure === prefilters ), - selection; - - for(; i < length && ( executeOnly || !selection ); i++ ) { - selection = list[ i ]( options, originalOptions, jqXHR ); - // If we got redirected to another dataType - // we try there if executing only and not done already - if ( typeof selection === "string" ) { - if ( !executeOnly || inspected[ selection ] ) { - selection = undefined; - } else { - options.dataTypes.unshift( selection ); - selection = inspectPrefiltersOrTransports( - structure, options, originalOptions, jqXHR, selection, inspected ); - } - } - } - // If we're only executing or nothing was selected - // we try the catchall dataType if not done already - if ( ( executeOnly || !selection ) && !inspected[ "*" ] ) { - selection = inspectPrefiltersOrTransports( - structure, options, originalOptions, jqXHR, "*", inspected ); - } - // unnecessary when only executing (prefilters) - // but it'll be ignored by the caller in that case - return selection; -} - jQuery.fn.extend({ load: function( url, params, callback ) { - if ( typeof url !== "string" && _load ) { - return _load.apply( this, arguments ); + if ( jQuery.isFunction( url ) ) + return this.bind("load", url); - // Don't do a request if no elements are being requested - } else if ( !this.length ) { - return this; - } - - var off = url.indexOf( " " ); + var off = url.indexOf(" "); if ( off >= 0 ) { - var selector = url.slice( off, url.length ); - url = url.slice( 0, off ); + var selector = url.slice(off, url.length); + url = url.slice(0, off); } + callback = callback || function(){}; + // Default to a GET request var type = "GET"; // If the second parameter was provided - if ( params ) { + if ( params ) // If it's a function if ( jQuery.isFunction( params ) ) { // We assume that it's the callback callback = params; - params = undefined; + params = null; // Otherwise, build a param string - } else if ( typeof params === "object" ) { - params = jQuery.param( params, jQuery.ajaxSettings.traditional ); + } else { + params = jQuery.param( params ); type = "POST"; } - } var self = this; @@ -177,802 +36,458 @@ jQuery.fn.extend({ type: type, dataType: "html", data: params, - // Complete callback (responseText is used internally) - complete: function( jqXHR, status, responseText ) { - // Store the response as specified by the jqXHR object - responseText = jqXHR.responseText; + complete: function(res, status){ // If successful, inject the HTML into all the matched elements - if ( jqXHR.isResolved() ) { - // #4825: Get the actual response in case - // a dataFilter is present in ajaxSettings - jqXHR.done(function( r ) { - responseText = r; - }); + if ( status == "success" || status == "notmodified" ) // See if a selector was specified self.html( selector ? // Create a dummy div to hold the results - jQuery("
        ") + jQuery("
        ") // inject the contents of the document in, removing the scripts // to avoid any 'Permission Denied' errors in IE - .append(responseText.replace(rscript, "")) + .append(res.responseText.replace(//g, "")) // Locate the specified elements .find(selector) : // If not, just inject the full result - responseText ); - } + res.responseText ); - if ( callback ) { - self.each( callback, [ responseText, status, jqXHR ] ); - } + self.each( callback, [res.responseText, status, res] ); } }); - return this; }, serialize: function() { - return jQuery.param( this.serializeArray() ); + return jQuery.param(this.serializeArray()); }, - serializeArray: function() { return this.map(function(){ - return this.elements ? jQuery.makeArray( this.elements ) : this; + return jQuery.nodeName(this, "form") ? + jQuery.makeArray(this.elements) : this; }) .filter(function(){ - return this.name && !this.disabled && - ( this.checked || rselectTextarea.test( this.nodeName ) || - rinput.test( this.type ) ); + return this.name && !this.disabled && + (this.checked || /select|textarea/i.test(this.nodeName) || + /text|hidden|password/i.test(this.type)); }) - .map(function( i, elem ){ - var val = jQuery( this ).val(); - - return val == null ? - null : - jQuery.isArray( val ) ? - jQuery.map( val, function( val, i ){ - return { name: elem.name, value: val.replace( rCRLF, "\r\n" ) }; + .map(function(i, elem){ + var val = jQuery(this).val(); + return val == null ? null : + val.constructor == Array ? + jQuery.map( val, function(val, i){ + return {name: elem.name, value: val}; }) : - { name: elem.name, value: val.replace( rCRLF, "\r\n" ) }; + {name: elem.name, value: val}; }).get(); } }); // Attach a bunch of functions for handling common AJAX events -jQuery.each( "ajaxStart ajaxStop ajaxComplete ajaxError ajaxSuccess ajaxSend".split( " " ), function( i, o ){ - jQuery.fn[ o ] = function( f ){ - return this.bind( o, f ); +jQuery.each( "ajaxStart,ajaxStop,ajaxComplete,ajaxError,ajaxSuccess,ajaxSend".split(","), function(i,o){ + jQuery.fn[o] = function(f){ + return this.bind(o, f); }; }); -jQuery.each( [ "get", "post" ], function( i, method ) { - jQuery[ method ] = function( url, data, callback, type ) { - // shift arguments if data argument was omitted - if ( jQuery.isFunction( data ) ) { - type = type || callback; - callback = data; - data = undefined; - } +var jsc = (new Date).getTime(); +jQuery.extend({ + get: function( url, data, callback, type ) { + // shift arguments if data argument was ommited + if ( jQuery.isFunction( data ) ) { + callback = data; + data = null; + } + return jQuery.ajax({ - type: method, + type: "GET", url: url, data: data, success: callback, dataType: type }); - }; -}); - -jQuery.extend({ + }, getScript: function( url, callback ) { - return jQuery.get( url, undefined, callback, "script" ); + return jQuery.get(url, null, callback, "script"); }, getJSON: function( url, data, callback ) { - return jQuery.get( url, data, callback, "json" ); + return jQuery.get(url, data, callback, "json"); }, - // Creates a full fledged settings object into target - // with both ajaxSettings and settings fields. - // If target is omitted, writes into ajaxSettings. - ajaxSetup: function ( target, settings ) { - if ( !settings ) { - // Only one parameter, we extend ajaxSettings - settings = target; - target = jQuery.extend( true, jQuery.ajaxSettings, settings ); - } else { - // target was provided, we extend into it - jQuery.extend( true, target, jQuery.ajaxSettings, settings ); + post: function( url, data, callback, type ) { + if ( jQuery.isFunction( data ) ) { + callback = data; + data = {}; } - // Flatten fields we don't want deep extended - for( var field in { context: 1, url: 1 } ) { - if ( field in settings ) { - target[ field ] = settings[ field ]; - } else if( field in jQuery.ajaxSettings ) { - target[ field ] = jQuery.ajaxSettings[ field ]; - } - } - return target; + + return jQuery.ajax({ + type: "POST", + url: url, + data: data, + success: callback, + dataType: type + }); + }, + + ajaxSetup: function( settings ) { + jQuery.extend( jQuery.ajaxSettings, settings ); }, ajaxSettings: { - url: ajaxLocation, - isLocal: rlocalProtocol.test( ajaxLocParts[ 1 ] ), global: true, type: "GET", + timeout: 0, contentType: "application/x-www-form-urlencoded", processData: true, async: true, - /* - timeout: 0, data: null, - dataType: null, username: null, password: null, - cache: null, - traditional: false, - headers: {}, - */ - accepts: { xml: "application/xml, text/xml", html: "text/html", - text: "text/plain", + script: "text/javascript, application/javascript", json: "application/json, text/javascript", - "*": "*/*" - }, - - contents: { - xml: /xml/, - html: /html/, - json: /json/ - }, - - responseFields: { - xml: "responseXML", - text: "responseText" - }, - - // List of data converters - // 1) key format is "source_type destination_type" (a single space in-between) - // 2) the catchall symbol "*" can be used for source_type - converters: { - - // Convert anything to text - "* text": window.String, - - // Text to html (true = no transformation) - "text html": true, - - // Evaluate text as a json expression - "text json": jQuery.parseJSON, - - // Parse text as xml - "text xml": jQuery.parseXML + text: "text/plain", + _default: "*/*" } }, + + // Last-Modified header cache for next request + lastModified: {}, - ajaxPrefilter: addToPrefiltersOrTransports( prefilters ), - ajaxTransport: addToPrefiltersOrTransports( transports ), + ajax: function( s ) { + var jsonp, jsre = /=\?(&|$)/g, status, data; - // Main method - ajax: function( url, options ) { + // Extend the settings, but re-extend 's' so that it can be + // checked again later (in the test suite, specifically) + s = jQuery.extend(true, s, jQuery.extend(true, {}, jQuery.ajaxSettings, s)); - // If url is an object, simulate pre-1.5 signature - if ( typeof url === "object" ) { - options = url; - url = undefined; + // convert data if not already a string + if ( s.data && s.processData && typeof s.data != "string" ) + s.data = jQuery.param(s.data); + + // Handle JSONP Parameter Callbacks + if ( s.dataType == "jsonp" ) { + if ( s.type.toLowerCase() == "get" ) { + if ( !s.url.match(jsre) ) + s.url += (s.url.match(/\?/) ? "&" : "?") + (s.jsonp || "callback") + "=?"; + } else if ( !s.data || !s.data.match(jsre) ) + s.data = (s.data ? s.data + "&" : "") + (s.jsonp || "callback") + "=?"; + s.dataType = "json"; } - // Force options to be an object - options = options || {}; + // Build temporary JSONP function + if ( s.dataType == "json" && (s.data && s.data.match(jsre) || s.url.match(jsre)) ) { + jsonp = "jsonp" + jsc++; - var // Create the final options object - s = jQuery.ajaxSetup( {}, options ), - // Callbacks context - callbackContext = s.context || s, - // Context for global events - // It's the callbackContext if one was provided in the options - // and if it's a DOM node or a jQuery collection - globalEventContext = callbackContext !== s && - ( callbackContext.nodeType || callbackContext instanceof jQuery ) ? - jQuery( callbackContext ) : jQuery.event, - // Deferreds - deferred = jQuery.Deferred(), - completeDeferred = jQuery._Deferred(), - // Status-dependent callbacks - statusCode = s.statusCode || {}, - // ifModified key - ifModifiedKey, - // Headers (they are sent all at once) - requestHeaders = {}, - requestHeadersNames = {}, - // Response headers - responseHeadersString, - responseHeaders, - // transport - transport, - // timeout handle - timeoutTimer, - // Cross-domain detection vars - parts, - // The jqXHR state - state = 0, - // To know if global events are to be dispatched - fireGlobals, - // Loop variable - i, - // Fake xhr - jqXHR = { + // Replace the =? sequence both in the query string and the data + if ( s.data ) + s.data = (s.data + "").replace(jsre, "=" + jsonp + "$1"); + s.url = s.url.replace(jsre, "=" + jsonp + "$1"); - readyState: 0, + // We need to make sure + // that a JSONP style response is executed properly + s.dataType = "script"; - // Caches the header - setRequestHeader: function( name, value ) { - if ( !state ) { - var lname = name.toLowerCase(); - name = requestHeadersNames[ lname ] = requestHeadersNames[ lname ] || name; - requestHeaders[ name ] = value; - } - return this; - }, - - // Raw string - getAllResponseHeaders: function() { - return state === 2 ? responseHeadersString : null; - }, - - // Builds headers hashtable if needed - getResponseHeader: function( key ) { - var match; - if ( state === 2 ) { - if ( !responseHeaders ) { - responseHeaders = {}; - while( ( match = rheaders.exec( responseHeadersString ) ) ) { - responseHeaders[ match[1].toLowerCase() ] = match[ 2 ]; - } - } - match = responseHeaders[ key.toLowerCase() ]; - } - return match === undefined ? null : match; - }, - - // Overrides response content-type header - overrideMimeType: function( type ) { - if ( !state ) { - s.mimeType = type; - } - return this; - }, - - // Cancel the request - abort: function( statusText ) { - statusText = statusText || "abort"; - if ( transport ) { - transport.abort( statusText ); - } - done( 0, statusText ); - return this; - } + // Handle JSONP-style loading + window[ jsonp ] = function(tmp){ + data = tmp; + success(); + complete(); + // Garbage collect + window[ jsonp ] = undefined; + try{ delete window[ jsonp ]; } catch(e){} + if ( head ) + head.removeChild( script ); }; - - // Callback for when everything is done - // It is defined here because jslint complains if it is declared - // at the end of the function (which would be more logical and readable) - function done( status, statusText, responses, headers ) { - - // Called once - if ( state === 2 ) { - return; - } - - // State is "done" now - state = 2; - - // Clear timeout if it exists - if ( timeoutTimer ) { - clearTimeout( timeoutTimer ); - } - - // Dereference transport for early garbage collection - // (no matter how long the jqXHR object will be used) - transport = undefined; - - // Cache response headers - responseHeadersString = headers || ""; - - // Set readyState - jqXHR.readyState = status ? 4 : 0; - - var isSuccess, - success, - error, - response = responses ? ajaxHandleResponses( s, jqXHR, responses ) : undefined, - lastModified, - etag; - - // If successful, handle type chaining - if ( status >= 200 && status < 300 || status === 304 ) { - - // Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode. - if ( s.ifModified ) { - - if ( ( lastModified = jqXHR.getResponseHeader( "Last-Modified" ) ) ) { - jQuery.lastModified[ ifModifiedKey ] = lastModified; - } - if ( ( etag = jqXHR.getResponseHeader( "Etag" ) ) ) { - jQuery.etag[ ifModifiedKey ] = etag; - } - } - - // If not modified - if ( status === 304 ) { - - statusText = "notmodified"; - isSuccess = true; - - // If we have data - } else { - - try { - success = ajaxConvert( s, response ); - statusText = "success"; - isSuccess = true; - } catch(e) { - // We have a parsererror - statusText = "parsererror"; - error = e; - } - } - } else { - // We extract error from statusText - // then normalize statusText and status for non-aborts - error = statusText; - if( !statusText || status ) { - statusText = "error"; - if ( status < 0 ) { - status = 0; - } - } - } - - // Set data for the fake xhr object - jqXHR.status = status; - jqXHR.statusText = statusText; - - // Success/Error - if ( isSuccess ) { - deferred.resolveWith( callbackContext, [ success, statusText, jqXHR ] ); - } else { - deferred.rejectWith( callbackContext, [ jqXHR, statusText, error ] ); - } - - // Status-dependent callbacks - jqXHR.statusCode( statusCode ); - statusCode = undefined; - - if ( fireGlobals ) { - globalEventContext.trigger( "ajax" + ( isSuccess ? "Success" : "Error" ), - [ jqXHR, s, isSuccess ? success : error ] ); - } - - // Complete - completeDeferred.resolveWith( callbackContext, [ jqXHR, statusText ] ); - - if ( fireGlobals ) { - globalEventContext.trigger( "ajaxComplete", [ jqXHR, s] ); - // Handle the global AJAX counter - if ( !( --jQuery.active ) ) { - jQuery.event.trigger( "ajaxStop" ); - } - } } - // Attach deferreds - deferred.promise( jqXHR ); - jqXHR.success = jqXHR.done; - jqXHR.error = jqXHR.fail; - jqXHR.complete = completeDeferred.done; + if ( s.dataType == "script" && s.cache == null ) + s.cache = false; - // Status-dependent callbacks - jqXHR.statusCode = function( map ) { - if ( map ) { - var tmp; - if ( state < 2 ) { - for( tmp in map ) { - statusCode[ tmp ] = [ statusCode[tmp], map[tmp] ]; - } - } else { - tmp = map[ jqXHR.status ]; - jqXHR.then( tmp, tmp ); - } - } - return this; - }; - - // Remove hash character (#7531: and string promotion) - // Add protocol if not provided (#5866: IE7 issue with protocol-less urls) - // We also use the url parameter if available - s.url = ( ( url || s.url ) + "" ).replace( rhash, "" ).replace( rprotocol, ajaxLocParts[ 1 ] + "//" ); - - // Extract dataTypes list - s.dataTypes = jQuery.trim( s.dataType || "*" ).toLowerCase().split( rspacesAjax ); - - // Determine if a cross-domain request is in order - if ( s.crossDomain == null ) { - parts = rurl.exec( s.url.toLowerCase() ); - s.crossDomain = !!( parts && - ( parts[ 1 ] != ajaxLocParts[ 1 ] || parts[ 2 ] != ajaxLocParts[ 2 ] || - ( parts[ 3 ] || ( parts[ 1 ] === "http:" ? 80 : 443 ) ) != - ( ajaxLocParts[ 3 ] || ( ajaxLocParts[ 1 ] === "http:" ? 80 : 443 ) ) ) - ); + if ( s.cache === false && s.type.toLowerCase() == "get" ) { + var ts = (new Date()).getTime(); + // try replacing _= if it is there + var ret = s.url.replace(/(\?|&)_=.*?(&|$)/, "$1_=" + ts + "$2"); + // if nothing was replaced, add timestamp to the end + s.url = ret + ((ret == s.url) ? (s.url.match(/\?/) ? "&" : "?") + "_=" + ts : ""); } - // Convert data if not already a string - if ( s.data && s.processData && typeof s.data !== "string" ) { - s.data = jQuery.param( s.data, s.traditional ); + // If data is available, append data to url for get requests + if ( s.data && s.type.toLowerCase() == "get" ) { + s.url += (s.url.match(/\?/) ? "&" : "?") + s.data; + + // IE likes to send both get and post data, prevent this + s.data = null; } - // Apply prefilters - inspectPrefiltersOrTransports( prefilters, s, options, jqXHR ); - - // If request was aborted inside a prefiler, stop there - if ( state === 2 ) { - return false; - } - - // We can fire global events as of now if asked to - fireGlobals = s.global; - - // Uppercase the type - s.type = s.type.toUpperCase(); - - // Determine if request has content - s.hasContent = !rnoContent.test( s.type ); - // Watch for a new set of requests - if ( fireGlobals && jQuery.active++ === 0 ) { + if ( s.global && ! jQuery.active++ ) jQuery.event.trigger( "ajaxStart" ); - } - // More options handling for requests with no content - if ( !s.hasContent ) { + // If we're requesting a remote document + // and trying to load JSON or Script with a GET + if ( (!s.url.indexOf("http") || !s.url.indexOf("//")) && s.dataType == "script" && s.type.toLowerCase() == "get" ) { + var head = document.getElementsByTagName("head")[0]; + var script = document.createElement("script"); + script.src = s.url; + if (s.scriptCharset) + script.charset = s.scriptCharset; - // If data is available, append data to url - if ( s.data ) { - s.url += ( rquery.test( s.url ) ? "&" : "?" ) + s.data; - // #9682: remove data so that it's not used in an eventual retry - delete s.data; + // Handle Script loading + if ( !jsonp ) { + var done = false; + + // Attach handlers for all browsers + script.onload = script.onreadystatechange = function(){ + if ( !done && (!this.readyState || + this.readyState == "loaded" || this.readyState == "complete") ) { + done = true; + success(); + complete(); + head.removeChild( script ); + } + }; } - // Get ifModifiedKey before adding the anti-cache parameter - ifModifiedKey = s.url; + head.appendChild(script); - // Add anti-cache in url if needed - if ( s.cache === false ) { - - var ts = jQuery.now(), - // try replacing _= if it is there - ret = s.url.replace( rts, "$1_=" + ts ); - - // if nothing was replaced, add timestamp to the end - s.url = ret + ( (ret === s.url ) ? ( rquery.test( s.url ) ? "&" : "?" ) + "_=" + ts : "" ); - } + // We handle everything using the script element injection + return undefined; } - // Set the correct header, if data is being sent - if ( s.data && s.hasContent && s.contentType !== false || options.contentType ) { - jqXHR.setRequestHeader( "Content-Type", s.contentType ); - } + var requestDone = false; - // Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode. - if ( s.ifModified ) { - ifModifiedKey = ifModifiedKey || s.url; - if ( jQuery.lastModified[ ifModifiedKey ] ) { - jqXHR.setRequestHeader( "If-Modified-Since", jQuery.lastModified[ ifModifiedKey ] ); - } - if ( jQuery.etag[ ifModifiedKey ] ) { - jqXHR.setRequestHeader( "If-None-Match", jQuery.etag[ ifModifiedKey ] ); - } - } + // Create the request object; Microsoft failed to properly + // implement the XMLHttpRequest in IE7, so we use the ActiveXObject when it is available + var xml = window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest(); - // Set the Accepts header for the server, depending on the dataType - jqXHR.setRequestHeader( - "Accept", - s.dataTypes[ 0 ] && s.accepts[ s.dataTypes[0] ] ? - s.accepts[ s.dataTypes[0] ] + ( s.dataTypes[ 0 ] !== "*" ? ", */*; q=0.01" : "" ) : - s.accepts[ "*" ] - ); + // Open the socket + xml.open(s.type, s.url, s.async, s.username, s.password); - // Check for headers option - for ( i in s.headers ) { - jqXHR.setRequestHeader( i, s.headers[ i ] ); - } + // Need an extra try/catch for cross domain requests in Firefox 3 + try { + // Set the correct header, if data is being sent + if ( s.data ) + xml.setRequestHeader("Content-Type", s.contentType); - // Allow custom headers/mimetypes and early abort - if ( s.beforeSend && ( s.beforeSend.call( callbackContext, jqXHR, s ) === false || state === 2 ) ) { - // Abort if not done already - jqXHR.abort(); - return false; + // Set the If-Modified-Since header, if ifModified mode. + if ( s.ifModified ) + xml.setRequestHeader("If-Modified-Since", + jQuery.lastModified[s.url] || "Thu, 01 Jan 1970 00:00:00 GMT" ); - } + // Set header so the called script knows that it's an XMLHttpRequest + xml.setRequestHeader("X-Requested-With", "XMLHttpRequest"); - // Install callbacks on deferreds - for ( i in { success: 1, error: 1, complete: 1 } ) { - jqXHR[ i ]( s[ i ] ); - } + // Set the Accepts header for the server, depending on the dataType + xml.setRequestHeader("Accept", s.dataType && s.accepts[ s.dataType ] ? + s.accepts[ s.dataType ] + ", */*" : + s.accepts._default ); + } catch(e){} - // Get transport - transport = inspectPrefiltersOrTransports( transports, s, options, jqXHR ); + // Allow custom headers/mimetypes + if ( s.beforeSend ) + s.beforeSend(xml); + + if ( s.global ) + jQuery.event.trigger("ajaxSend", [xml, s]); - // If no transport, we auto-abort - if ( !transport ) { - done( -1, "No Transport" ); - } else { - jqXHR.readyState = 1; - // Send global event - if ( fireGlobals ) { - globalEventContext.trigger( "ajaxSend", [ jqXHR, s ] ); - } - // Timeout - if ( s.async && s.timeout > 0 ) { - timeoutTimer = setTimeout( function(){ - jqXHR.abort( "timeout" ); - }, s.timeout ); - } - - try { - state = 1; - transport.send( requestHeaders, done ); - } catch (e) { - // Propagate exception as error if not done - if ( state < 2 ) { - done( -1, e ); - // Simply rethrow otherwise - } else { - jQuery.error( e ); + // Wait for a response to come back + var onreadystatechange = function(isTimeout){ + // The transfer is complete and the data is available, or the request timed out + if ( !requestDone && xml && (xml.readyState == 4 || isTimeout == "timeout") ) { + requestDone = true; + + // clear poll interval + if (ival) { + clearInterval(ival); + ival = null; } + + status = isTimeout == "timeout" && "timeout" || + !jQuery.httpSuccess( xml ) && "error" || + s.ifModified && jQuery.httpNotModified( xml, s.url ) && "notmodified" || + "success"; + + if ( status == "success" ) { + // Watch for, and catch, XML document parse errors + try { + // process the data (runs the xml through httpData regardless of callback) + data = jQuery.httpData( xml, s.dataType ); + } catch(e) { + status = "parsererror"; + } + } + + // Make sure that the request was successful or notmodified + if ( status == "success" ) { + // Cache Last-Modified header, if ifModified mode. + var modRes; + try { + modRes = xml.getResponseHeader("Last-Modified"); + } catch(e) {} // swallow exception thrown by FF if header is not available + + if ( s.ifModified && modRes ) + jQuery.lastModified[s.url] = modRes; + + // JSONP handles its own success callback + if ( !jsonp ) + success(); + } else + jQuery.handleError(s, xml, status); + + // Fire the complete handlers + complete(); + + // Stop memory leaks + if ( s.async ) + xml = null; } + }; + + if ( s.async ) { + // don't attach the handler to the request, just poll it instead + var ival = setInterval(onreadystatechange, 13); + + // Timeout checker + if ( s.timeout > 0 ) + setTimeout(function(){ + // Check to see if the request is still happening + if ( xml ) { + // Cancel the request + xml.abort(); + + if( !requestDone ) + onreadystatechange( "timeout" ); + } + }, s.timeout); + } + + // Send the data + try { + xml.send(s.data); + } catch(e) { + jQuery.handleError(s, xml, null, e); + } + + // firefox 1.5 doesn't fire statechange for sync requests + if ( !s.async ) + onreadystatechange(); + + function success(){ + // If a local callback was specified, fire it and pass it the data + if ( s.success ) + s.success( data, status ); + + // Fire the global callback + if ( s.global ) + jQuery.event.trigger( "ajaxSuccess", [xml, s] ); } - return jqXHR; + function complete(){ + // Process result + if ( s.complete ) + s.complete(xml, status); + + // The request was completed + if ( s.global ) + jQuery.event.trigger( "ajaxComplete", [xml, s] ); + + // Handle the global AJAX counter + if ( s.global && ! --jQuery.active ) + jQuery.event.trigger( "ajaxStop" ); + } + + // return XMLHttpRequest to allow aborting the request etc. + return xml; }, - // Serialize an array of form elements or a set of - // key/values into a query string - param: function( a, traditional ) { - var s = [], - add = function( key, value ) { - // If value is a function, invoke it and return its value - value = jQuery.isFunction( value ) ? value() : value; - s[ s.length ] = encodeURIComponent( key ) + "=" + encodeURIComponent( value ); - }; + handleError: function( s, xml, status, e ) { + // If a local callback was specified, fire it + if ( s.error ) s.error( xml, status, e ); - // Set traditional to true for jQuery <= 1.3.2 behavior. - if ( traditional === undefined ) { - traditional = jQuery.ajaxSettings.traditional; - } - - // If an array was passed in, assume that it is an array of form elements. - if ( jQuery.isArray( a ) || ( a.jquery && !jQuery.isPlainObject( a ) ) ) { - // Serialize the form elements - jQuery.each( a, function() { - add( this.name, this.value ); - }); - - } else { - // If traditional, encode the "old" way (the way 1.3.2 or older - // did it), otherwise encode params recursively. - for ( var prefix in a ) { - buildParams( prefix, a[ prefix ], traditional, add ); - } - } - - // Return the resulting serialization - return s.join( "&" ).replace( r20, "+" ); - } -}); - -function buildParams( prefix, obj, traditional, add ) { - if ( jQuery.isArray( obj ) ) { - // Serialize array item. - jQuery.each( obj, function( i, v ) { - if ( traditional || rbracket.test( prefix ) ) { - // Treat each array item as a scalar. - add( prefix, v ); - - } else { - // If array item is non-scalar (array or object), encode its - // numeric index to resolve deserialization ambiguity issues. - // Note that rack (as of 1.0.0) can't currently deserialize - // nested arrays properly, and attempting to do so may cause - // a server error. Possible fixes are to modify rack's - // deserialization algorithm or to provide an option or flag - // to force array serialization to be shallow. - buildParams( prefix + "[" + ( typeof v === "object" || jQuery.isArray(v) ? i : "" ) + "]", v, traditional, add ); - } - }); - - } else if ( !traditional && obj != null && typeof obj === "object" ) { - // Serialize object item. - for ( var name in obj ) { - buildParams( prefix + "[" + name + "]", obj[ name ], traditional, add ); - } - - } else { - // Serialize scalar item. - add( prefix, obj ); - } -} - -// This is still on the jQuery object... for now -// Want to move this to jQuery.ajax some day -jQuery.extend({ + // Fire the global callback + if ( s.global ) + jQuery.event.trigger( "ajaxError", [xml, s, e] ); + }, // Counter for holding the number of active queries active: 0, - // Last-Modified header cache for next request - lastModified: {}, - etag: {} + // Determines if an XMLHttpRequest was successful or not + httpSuccess: function( r ) { + try { + // IE error sometimes returns 1223 when it should be 204 so treat it as success, see #1450 + return !r.status && location.protocol == "file:" || + ( r.status >= 200 && r.status < 300 ) || r.status == 304 || r.status == 1223 || + jQuery.browser.safari && r.status == undefined; + } catch(e){} + return false; + }, + + // Determines if an XMLHttpRequest returns NotModified + httpNotModified: function( xml, url ) { + try { + var xmlRes = xml.getResponseHeader("Last-Modified"); + + // Firefox always returns 200. check Last-Modified date + return xml.status == 304 || xmlRes == jQuery.lastModified[url] || + jQuery.browser.safari && xml.status == undefined; + } catch(e){} + return false; + }, + + httpData: function( r, type ) { + var ct = r.getResponseHeader("content-type"); + var xml = type == "xml" || !type && ct && ct.indexOf("xml") >= 0; + var data = xml ? r.responseXML : r.responseText; + + if ( xml && data.documentElement.tagName == "parsererror" ) + throw "parsererror"; + + // If the type is "script", eval it in global context + if ( type == "script" ) + jQuery.globalEval( data ); + + // Get the JavaScript object, if JSON is used. + if ( type == "json" ) + data = eval("(" + data + ")"); + + return data; + }, + + // Serialize an array of form elements or a set of + // key/values into a query string + param: function( a ) { + var s = []; + + // If an array was passed in, assume that it is an array + // of form elements + if ( a.constructor == Array || a.jquery ) + // Serialize the form elements + jQuery.each( a, function(){ + s.push( encodeURIComponent(this.name) + "=" + encodeURIComponent( this.value ) ); + }); + + // Otherwise, assume that it's an object of key/value pairs + else + // Serialize the key/values + for ( var j in a ) + // If the value is an array then the key names need to be repeated + if ( a[j] && a[j].constructor == Array ) + jQuery.each( a[j], function(){ + s.push( encodeURIComponent(j) + "=" + encodeURIComponent( this ) ); + }); + else + s.push( encodeURIComponent(j) + "=" + encodeURIComponent( a[j] ) ); + + // Return the resulting serialization + return s.join("&").replace(/%20/g, "+"); + } }); - -/* Handles responses to an ajax request: - * - sets all responseXXX fields accordingly - * - finds the right dataType (mediates between content-type and expected dataType) - * - returns the corresponding response - */ -function ajaxHandleResponses( s, jqXHR, responses ) { - - var contents = s.contents, - dataTypes = s.dataTypes, - responseFields = s.responseFields, - ct, - type, - finalDataType, - firstDataType; - - // Fill responseXXX fields - for( type in responseFields ) { - if ( type in responses ) { - jqXHR[ responseFields[type] ] = responses[ type ]; - } - } - - // Remove auto dataType and get content-type in the process - while( dataTypes[ 0 ] === "*" ) { - dataTypes.shift(); - if ( ct === undefined ) { - ct = s.mimeType || jqXHR.getResponseHeader( "content-type" ); - } - } - - // Check if we're dealing with a known content-type - if ( ct ) { - for ( type in contents ) { - if ( contents[ type ] && contents[ type ].test( ct ) ) { - dataTypes.unshift( type ); - break; - } - } - } - - // Check to see if we have a response for the expected dataType - if ( dataTypes[ 0 ] in responses ) { - finalDataType = dataTypes[ 0 ]; - } else { - // Try convertible dataTypes - for ( type in responses ) { - if ( !dataTypes[ 0 ] || s.converters[ type + " " + dataTypes[0] ] ) { - finalDataType = type; - break; - } - if ( !firstDataType ) { - firstDataType = type; - } - } - // Or just use first one - finalDataType = finalDataType || firstDataType; - } - - // If we found a dataType - // We add the dataType to the list if needed - // and return the corresponding response - if ( finalDataType ) { - if ( finalDataType !== dataTypes[ 0 ] ) { - dataTypes.unshift( finalDataType ); - } - return responses[ finalDataType ]; - } -} - -// Chain conversions given the request and the original response -function ajaxConvert( s, response ) { - - // Apply the dataFilter if provided - if ( s.dataFilter ) { - response = s.dataFilter( response, s.dataType ); - } - - var dataTypes = s.dataTypes, - converters = {}, - i, - key, - length = dataTypes.length, - tmp, - // Current and previous dataTypes - current = dataTypes[ 0 ], - prev, - // Conversion expression - conversion, - // Conversion function - conv, - // Conversion functions (transitive conversion) - conv1, - conv2; - - // For each dataType in the chain - for( i = 1; i < length; i++ ) { - - // Create converters map - // with lowercased keys - if ( i === 1 ) { - for( key in s.converters ) { - if( typeof key === "string" ) { - converters[ key.toLowerCase() ] = s.converters[ key ]; - } - } - } - - // Get the dataTypes - prev = current; - current = dataTypes[ i ]; - - // If current is auto dataType, update it to prev - if( current === "*" ) { - current = prev; - // If no auto and dataTypes are actually different - } else if ( prev !== "*" && prev !== current ) { - - // Get the converter - conversion = prev + " " + current; - conv = converters[ conversion ] || converters[ "* " + current ]; - - // If there is no direct converter, search transitively - if ( !conv ) { - conv2 = undefined; - for( conv1 in converters ) { - tmp = conv1.split( " " ); - if ( tmp[ 0 ] === prev || tmp[ 0 ] === "*" ) { - conv2 = converters[ tmp[1] + " " + current ]; - if ( conv2 ) { - conv1 = converters[ conv1 ]; - if ( conv1 === true ) { - conv = conv2; - } else if ( conv2 === true ) { - conv = conv1; - } - break; - } - } - } - } - // If we found no converter, dispatch an error - if ( !( conv || conv2 ) ) { - jQuery.error( "No conversion from " + conversion.replace(" "," to ") ); - } - // If found converter is not an equivalence - if ( conv !== true ) { - // Convert with 1 or 2 converters accordingly - response = conv ? conv( response ) : conv2( conv1(response) ); - } - } - } - return response; -} - -})( jQuery ); diff --git a/src/ajax/jsonp.js b/src/ajax/jsonp.js deleted file mode 100644 index 6b0f95d5..00000000 --- a/src/ajax/jsonp.js +++ /dev/null @@ -1,79 +0,0 @@ -(function( jQuery ) { - -var jsc = jQuery.now(), - jsre = /(\=)\?(&|$)|\?\?/i; - -// Default jsonp settings -jQuery.ajaxSetup({ - jsonp: "callback", - jsonpCallback: function() { - return jQuery.expando + "_" + ( jsc++ ); - } -}); - -// Detect, normalize options and install callbacks for jsonp requests -jQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, jqXHR ) { - - var inspectData = s.contentType === "application/x-www-form-urlencoded" && - ( typeof s.data === "string" ); - - if ( s.dataTypes[ 0 ] === "jsonp" || - s.jsonp !== false && ( jsre.test( s.url ) || - inspectData && jsre.test( s.data ) ) ) { - - var responseContainer, - jsonpCallback = s.jsonpCallback = - jQuery.isFunction( s.jsonpCallback ) ? s.jsonpCallback() : s.jsonpCallback, - previous = window[ jsonpCallback ], - url = s.url, - data = s.data, - replace = "$1" + jsonpCallback + "$2"; - - if ( s.jsonp !== false ) { - url = url.replace( jsre, replace ); - if ( s.url === url ) { - if ( inspectData ) { - data = data.replace( jsre, replace ); - } - if ( s.data === data ) { - // Add callback manually - url += (/\?/.test( url ) ? "&" : "?") + s.jsonp + "=" + jsonpCallback; - } - } - } - - s.url = url; - s.data = data; - - // Install callback - window[ jsonpCallback ] = function( response ) { - responseContainer = [ response ]; - }; - - // Clean-up function - jqXHR.always(function() { - // Set callback back to previous value - window[ jsonpCallback ] = previous; - // Call if it was a function and we have a response - if ( responseContainer && jQuery.isFunction( previous ) ) { - window[ jsonpCallback ]( responseContainer[ 0 ] ); - } - }); - - // Use data converter to retrieve json after script execution - s.converters["script json"] = function() { - if ( !responseContainer ) { - jQuery.error( jsonpCallback + " was not called" ); - } - return responseContainer[ 0 ]; - }; - - // force json dataType - s.dataTypes[ 0 ] = "json"; - - // Delegate to script - return "script"; - } -}); - -})( jQuery ); diff --git a/src/ajax/script.js b/src/ajax/script.js deleted file mode 100644 index f7a91801..00000000 --- a/src/ajax/script.js +++ /dev/null @@ -1,89 +0,0 @@ -(function( jQuery ) { - -// Install script dataType -jQuery.ajaxSetup({ - accepts: { - script: "text/javascript, application/javascript, application/ecmascript, application/x-ecmascript" - }, - contents: { - script: /javascript|ecmascript/ - }, - converters: { - "text script": function( text ) { - jQuery.globalEval( text ); - return text; - } - } -}); - -// Handle cache's special case and global -jQuery.ajaxPrefilter( "script", function( s ) { - if ( s.cache === undefined ) { - s.cache = false; - } - if ( s.crossDomain ) { - s.type = "GET"; - s.global = false; - } -}); - -// Bind script tag hack transport -jQuery.ajaxTransport( "script", function(s) { - - // This transport only deals with cross domain requests - if ( s.crossDomain ) { - - var script, - head = document.head || document.getElementsByTagName( "head" )[0] || document.documentElement; - - return { - - send: function( _, callback ) { - - script = document.createElement( "script" ); - - script.async = "async"; - - if ( s.scriptCharset ) { - script.charset = s.scriptCharset; - } - - script.src = s.url; - - // Attach handlers for all browsers - script.onload = script.onreadystatechange = function( _, isAbort ) { - - if ( isAbort || !script.readyState || /loaded|complete/.test( script.readyState ) ) { - - // Handle memory leak in IE - script.onload = script.onreadystatechange = null; - - // Remove the script - if ( head && script.parentNode ) { - head.removeChild( script ); - } - - // Dereference the script - script = undefined; - - // Callback if not abort - if ( !isAbort ) { - callback( 200, "success" ); - } - } - }; - // Use insertBefore instead of appendChild to circumvent an IE6 bug. - // This arises when a base node is used (#2709 and #4378). - head.insertBefore( script, head.firstChild ); - }, - - abort: function() { - if ( script ) { - script.onload( 0, 1 ); - } - } - }; - } -}); - -})( jQuery ); diff --git a/src/ajax/xhr.js b/src/ajax/xhr.js deleted file mode 100644 index a87c3239..00000000 --- a/src/ajax/xhr.js +++ /dev/null @@ -1,218 +0,0 @@ -(function( jQuery ) { - -var // #5280: Internet Explorer will keep connections alive if we don't abort on unload - xhrOnUnloadAbort = window.ActiveXObject ? function() { - // Abort all pending requests - for ( var key in xhrCallbacks ) { - xhrCallbacks[ key ]( 0, 1 ); - } - } : false, - xhrId = 0, - xhrCallbacks; - -// Functions to create xhrs -function createStandardXHR() { - try { - return new window.XMLHttpRequest(); - } catch( e ) {} -} - -function createActiveXHR() { - try { - return new window.ActiveXObject( "Microsoft.XMLHTTP" ); - } catch( e ) {} -} - -// Create the request object -// (This is still attached to ajaxSettings for backward compatibility) -jQuery.ajaxSettings.xhr = window.ActiveXObject ? - /* Microsoft failed to properly - * implement the XMLHttpRequest in IE7 (can't request local files), - * so we use the ActiveXObject when it is available - * Additionally XMLHttpRequest can be disabled in IE7/IE8 so - * we need a fallback. - */ - function() { - return !this.isLocal && createStandardXHR() || createActiveXHR(); - } : - // For all other browsers, use the standard XMLHttpRequest object - createStandardXHR; - -// Determine support properties -(function( xhr ) { - jQuery.extend( jQuery.support, { - ajax: !!xhr, - cors: !!xhr && ( "withCredentials" in xhr ) - }); -})( jQuery.ajaxSettings.xhr() ); - -// Create transport if the browser can provide an xhr -if ( jQuery.support.ajax ) { - - jQuery.ajaxTransport(function( s ) { - // Cross domain only allowed if supported through XMLHttpRequest - if ( !s.crossDomain || jQuery.support.cors ) { - - var callback; - - return { - send: function( headers, complete ) { - - // Get a new xhr - var xhr = s.xhr(), - handle, - i; - - // Open the socket - // Passing null username, generates a login popup on Opera (#2865) - if ( s.username ) { - xhr.open( s.type, s.url, s.async, s.username, s.password ); - } else { - xhr.open( s.type, s.url, s.async ); - } - - // Apply custom fields if provided - if ( s.xhrFields ) { - for ( i in s.xhrFields ) { - xhr[ i ] = s.xhrFields[ i ]; - } - } - - // Override mime type if needed - if ( s.mimeType && xhr.overrideMimeType ) { - xhr.overrideMimeType( s.mimeType ); - } - - // X-Requested-With header - // For cross-domain requests, seeing as conditions for a preflight are - // akin to a jigsaw puzzle, we simply never set it to be sure. - // (it can always be set on a per-request basis or even using ajaxSetup) - // For same-domain requests, won't change header if already provided. - if ( !s.crossDomain && !headers["X-Requested-With"] ) { - headers[ "X-Requested-With" ] = "XMLHttpRequest"; - } - - // Need an extra try/catch for cross domain requests in Firefox 3 - try { - for ( i in headers ) { - xhr.setRequestHeader( i, headers[ i ] ); - } - } catch( _ ) {} - - // Do send the request - // This may raise an exception which is actually - // handled in jQuery.ajax (so no try/catch here) - xhr.send( ( s.hasContent && s.data ) || null ); - - // Listener - callback = function( _, isAbort ) { - - var status, - statusText, - responseHeaders, - responses, - xml; - - // Firefox throws exceptions when accessing properties - // of an xhr when a network error occured - // http://helpful.knobs-dials.com/index.php/Component_returned_failure_code:_0x80040111_(NS_ERROR_NOT_AVAILABLE) - try { - - // Was never called and is aborted or complete - if ( callback && ( isAbort || xhr.readyState === 4 ) ) { - - // Only called once - callback = undefined; - - // Do not keep as active anymore - if ( handle ) { - xhr.onreadystatechange = jQuery.noop; - if ( xhrOnUnloadAbort ) { - delete xhrCallbacks[ handle ]; - } - } - - // If it's an abort - if ( isAbort ) { - // Abort it manually if needed - if ( xhr.readyState !== 4 ) { - xhr.abort(); - } - } else { - status = xhr.status; - responseHeaders = xhr.getAllResponseHeaders(); - responses = {}; - xml = xhr.responseXML; - - // Construct response list - if ( xml && xml.documentElement /* #4958 */ ) { - responses.xml = xml; - } - responses.text = xhr.responseText; - - // Firefox throws an exception when accessing - // statusText for faulty cross-domain requests - try { - statusText = xhr.statusText; - } catch( e ) { - // We normalize with Webkit giving an empty statusText - statusText = ""; - } - - // Filter status for non standard behaviors - - // If the request is local and we have data: assume a success - // (success with no data won't get notified, that's the best we - // can do given current implementations) - if ( !status && s.isLocal && !s.crossDomain ) { - status = responses.text ? 200 : 404; - // IE - #1450: sometimes returns 1223 when it should be 204 - } else if ( status === 1223 ) { - status = 204; - } - } - } - } catch( firefoxAccessException ) { - if ( !isAbort ) { - complete( -1, firefoxAccessException ); - } - } - - // Call complete if needed - if ( responses ) { - complete( status, statusText, responses, responseHeaders ); - } - }; - - // if we're in sync mode or it's in cache - // and has been retrieved directly (IE6 & IE7) - // we need to manually fire the callback - if ( !s.async || xhr.readyState === 4 ) { - callback(); - } else { - handle = ++xhrId; - if ( xhrOnUnloadAbort ) { - // Create the active xhrs callbacks list if needed - // and attach the unload handler - if ( !xhrCallbacks ) { - xhrCallbacks = {}; - jQuery( window ).unload( xhrOnUnloadAbort ); - } - // Add to list of active xhrs callbacks - xhrCallbacks[ handle ] = callback; - } - xhr.onreadystatechange = callback; - } - }, - - abort: function() { - if ( callback ) { - callback(0,1); - } - } - }; - } - }); -} - -})( jQuery ); diff --git a/src/attributes.js b/src/attributes.js deleted file mode 100644 index 1e0e79f4..00000000 --- a/src/attributes.js +++ /dev/null @@ -1,630 +0,0 @@ -(function( jQuery ) { - -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, - rinvalidChar = /\:|^on/, - formHook, 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].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 formHook for forms and if the name contains certain characters - } else if ( formHook && name !== "className" && - (jQuery.nodeName( elem, "form" ) || rinvalidChar.test( name )) ) { - - hooks = formHook; - } - } - } - - 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; - - if ( jQuery.support.getSetAttribute ) { - // Use removeAttribute in browsers that support it - elem.removeAttribute( name ); - } else { - jQuery.attr( elem, name, "" ); - elem.removeAttributeNode( elem.getAttributeNode( 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; - } - } - }, - 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; - } - }, - // Use the value property for back compat - // Use the formHook for button elements in IE6/7 (#1954) - value: { - get: function( elem, name ) { - if ( formHook && jQuery.nodeName( elem, "button" ) ) { - return formHook.get( elem, name ); - } - return name in elem ? - elem.value : - null; - }, - set: function( elem, value, name ) { - if ( formHook && jQuery.nodeName( elem, "button" ) ) { - return formHook.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 )) !== undefined ) { - return ret; - - } else { - return elem[ name ]; - } - } - }, - - propHooks: {} -}); - -// Hook for boolean attributes -boolHook = { - get: function( elem, name ) { - // Align boolean attributes with corresponding properties - return jQuery.prop( elem, name ) ? - 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 ) { - - // propFix is more comprehensive and contains all fixes - jQuery.attrFix = jQuery.propFix; - - // Use this for any attribute on a form in IE6/7 - formHook = jQuery.attrHooks.name = jQuery.attrHooks.title = 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 ) { - // Check form objects in IE (multiple bugs related) - // Only use nodeValue if the attribute node exists on the form - var ret = elem.getAttributeNode( name ); - if ( ret ) { - ret.nodeValue = value; - return 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; - } - } - } - }); -} - -// 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); - } - } - }); -}); - -})( jQuery ); diff --git a/src/core.js b/src/core.js index ab0d9f7b..efc654fb 100644 --- a/src/core.js +++ b/src/core.js @@ -1,249 +1,151 @@ -var jQuery = (function() { +/* + * jQuery @VERSION - New Wave Javascript + * + * Copyright (c) 2008 John Resig (jquery.com) + * Dual licensed under the MIT (MIT-LICENSE.txt) + * and GPL (GPL-LICENSE.txt) licenses. + * + * $Date$ + * $Rev$ + */ -// 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 +if ( window.jQuery ) + var _jQuery = window.jQuery; - // Map over jQuery in case of overwrite - _jQuery = window.jQuery, +var jQuery = window.jQuery = function( selector, context ) { + // The jQuery object is actually just the init constructor 'enhanced' + return new jQuery.prototype.init( selector, context ); +}; - // Map over the $ in case of overwrite - _$ = window.$, +// Map over the $ in case of overwrite +if ( window.$ ) + var _$ = window.$; + +// Map the jQuery namespace to the '$' one +window.$ = jQuery; - // A central reference to the root jQuery(document) - rootjQuery, +// A simple way to check for HTML strings or ID strings +// (both of which we optimize for) +var quickExpr = /^[^<]*(<(.|\s)+>)[^>]*$|^#(\w+)$/; - // A simple way to check for HTML strings or ID strings - // (both of which we optimize for) - 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])/ig, - - // 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 = {}; +// Is it a simple selector +var isSimple = /^.[^:#\[\.]*$/; jQuery.fn = jQuery.prototype = { - constructor: jQuery, - init: function( selector, context, rootjQuery ) { - var match, elem, ret, doc; - - // Handle $(""), $(null), or $(undefined) - if ( !selector ) { - return this; - } + init: function( selector, context ) { + // Make sure that a selection was provided + selector = selector || document; // Handle $(DOMElement) if ( selector.nodeType ) { - this.context = this[0] = selector; + 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" ) { + } else 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 ); - } + var 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 ); + if ( match[1] ) + selector = jQuery.clean( [ match[1] ], context ); // HANDLE: $("#id") - } else { - elem = document.getElementById( match[2] ); + else { + var elem = document.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 ) { + // Make sure an element was located + if ( elem ) // Handle the case where IE and Opera return items // by name instead of ID - if ( elem.id !== match[2] ) { - return rootjQuery.find( selector ); - } + if ( elem.id != match[3] ) + return jQuery().find( selector ); // Otherwise, we inject the element directly into the jQuery object - this.length = 1; - this[0] = elem; - } + else { + this[0] = elem; + this.length = 1; + return this; + } - this.context = document; - this.selector = selector; - return this; + else + selector = []; } - // 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: $(expr, [context]) + // (which is just equivalent to: $(content).find(expr) + } else + return new jQuery( context ).find( selector ); // HANDLE: $(function) // Shortcut for document ready - } else if ( jQuery.isFunction( selector ) ) { - return rootjQuery.ready( selector ); - } + } else if ( jQuery.isFunction( selector ) ) + return new jQuery( document )[ jQuery.fn.ready ? "ready" : "load" ]( selector ); - if (selector.selector !== undefined) { - this.selector = selector.selector; - this.context = selector.context; - } + return this.setArray( + // HANDLE: $(array) + selector.constructor == Array && selector || - return jQuery.makeArray( selector, this ); + // HANDLE: $(arraylike) + // Watch for when an array-like object, contains DOM nodes, is passed in as the selector + (selector.jquery || selector.length && selector != window && !selector.nodeType && selector[0] != undefined && selector[0].nodeType) && jQuery.makeArray( selector ) || + + // HANDLE: $(*) + [ selector ] ); }, - - // Start with an empty selector - selector: "", - + // The current version of jQuery being used jquery: "@VERSION", - // 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 ); - }, + + // The number of elements contained in the matched element set + length: 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 num == undefined ? // Return a 'clean' array - this.toArray() : + jQuery.makeArray( this ) : // Return just the object - ( num < 0 ? this[ this.length + num ] : this[ 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 ) { + pushStack: function( elems ) { // Build a new jQuery matched element set - var ret = this.constructor(); - - if ( jQuery.isArray( elems ) ) { - push.apply( ret, elems ); - - } else { - jQuery.merge( ret, elems ); - } + var ret = jQuery( 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; }, + + // Force the current matched set of elements to become + // the specified array of elements (destroying the stack in the process) + // You should use pushStack() in order to do this, but maintain the stack + setArray: function( elems ) { + // Resetting the length to 0, then using the native Array push + // is a super-fast way to populate an object with array-like properties + this.length = 0; + Array.prototype.push.apply( this, elems ); + + return this; + }, // Execute a callback for every element in the matched set. // (You can seed the arguments with an array of args, but this is @@ -252,64 +154,420 @@ jQuery.fn = jQuery.prototype = { return jQuery.each( this, callback, args ); }, - ready: function( fn ) { - // Attach the listeners - jQuery.bindReady(); + // Determine the position of an element within + // the matched set of elements + index: function( elem ) { + var ret = -1; - // Add the callback - readyList.done( fn ); + // Locate the position of the desired element + this.each(function(i){ + if ( this == elem ) + ret = i; + }); + + return ret; + }, + + attr: function( name, value, type ) { + var options = name; + + // Look for the case where we're accessing a style value + if ( name.constructor == String ) + if ( value == undefined ) + return this.length && jQuery[ type || "attr" ]( this[0], name ) || undefined; + + else { + options = {}; + options[ name ] = value; + } + + // Check to see if we're setting style values + return this.each(function(i){ + // Set all the styles + for ( name in options ) + jQuery.attr( + type ? + this.style : + this, + name, jQuery.prop( this, options[ name ], type, i, name ) + ); + }); + }, + + css: function( key, value ) { + // ignore negative width and height values + if ( (key == 'width' || key == 'height') && parseFloat(value) < 0 ) + value = undefined; + return this.attr( key, value, "curCSS" ); + }, + + text: function( text ) { + if ( typeof text != "object" && text != null ) + return this.empty().append( (this[0] && this[0].ownerDocument || document).createTextNode( text ) ); + + var ret = ""; + + jQuery.each( text || this, function(){ + jQuery.each( this.childNodes, function(){ + if ( this.nodeType != 8 ) + ret += this.nodeType != 1 ? + this.nodeValue : + jQuery.fn.text( [ this ] ); + }); + }); + + return ret; + }, + + wrapAll: function( html ) { + if ( this[0] ) + // The elements to wrap the target around + jQuery( html, this[0].ownerDocument ) + .clone() + .insertBefore( this[0] ) + .map(function(){ + var elem = this; + + while ( elem.firstChild ) + elem = elem.firstChild; + + return elem; + }) + .append(this); return this; }, + wrapInner: function( html ) { + return this.each(function(){ + jQuery( this ).contents().wrapAll( html ); + }); + }, + + wrap: function( html ) { + return this.each(function(){ + jQuery( this ).wrapAll( html ); + }); + }, + + append: function() { + return this.domManip(arguments, true, false, function(elem){ + if (this.nodeType == 1) + this.appendChild( elem ); + }); + }, + + prepend: function() { + return this.domManip(arguments, true, true, function(elem){ + if (this.nodeType == 1) + this.insertBefore( elem, this.firstChild ); + }); + }, + + before: function() { + return this.domManip(arguments, false, false, function(elem){ + this.parentNode.insertBefore( elem, this ); + }); + }, + + after: function() { + return this.domManip(arguments, false, true, function(elem){ + this.parentNode.insertBefore( elem, this.nextSibling ); + }); + }, + + end: function() { + return this.prevObject || jQuery( [] ); + }, + + find: function( selector ) { + var elems = jQuery.map(this, function(elem){ + return jQuery.find( selector, elem ); + }); + + return this.pushStack( /[^+>] [^+>]/.test( selector ) || selector.indexOf("..") > -1 ? + jQuery.unique( elems ) : + elems ); + }, + + clone: function( events ) { + // Do the clone + var ret = this.map(function(){ + if ( jQuery.browser.msie && !jQuery.isXMLDoc(this) ) { + // IE copies events bound via attachEvent when + // using cloneNode. Calling detachEvent on the + // clone will also remove the events from the orignal + // In order to get around this, we use innerHTML. + // Unfortunately, this means some modifications to + // attributes in IE that are actually only stored + // as properties will not be copied (such as the + // the name attribute on an input). + var clone = this.cloneNode(true), + container = document.createElement("div"); + container.appendChild(clone); + return jQuery.clean([container.innerHTML])[0]; + } else + return this.cloneNode(true); + }); + + // Need to set the expando to null on the cloned set if it exists + // removeData doesn't work here, IE removes it from the original as well + // this is primarily for IE but the data expando shouldn't be copied over in any browser + var clone = ret.find("*").andSelf().each(function(){ + if ( this[ expando ] != undefined ) + this[ expando ] = null; + }); + + // Copy the events from the original to the clone + if ( events === true ) + this.find("*").andSelf().each(function(i){ + if (this.nodeType == 3) + return; + var events = jQuery.data( this, "events" ); + + for ( var type in events ) + for ( var handler in events[ type ] ) + jQuery.event.add( clone[ i ], type, events[ type ][ handler ], events[ type ][ handler ].data ); + }); + + // Return the cloned set + return ret; + }, + + filter: function( selector ) { + return this.pushStack( + jQuery.isFunction( selector ) && + jQuery.grep(this, function(elem, i){ + return selector.call( elem, i ); + }) || + + jQuery.multiFilter( selector, this ) ); + }, + + not: function( selector ) { + if ( selector.constructor == String ) + // test special case where just one selector is passed in + if ( isSimple.test( selector ) ) + return this.pushStack( jQuery.multiFilter( selector, this, true ) ); + else + selector = jQuery.multiFilter( selector, this ); + + var isArrayLike = selector.length && selector[selector.length - 1] !== undefined && !selector.nodeType; + return this.filter(function() { + return isArrayLike ? jQuery.inArray( this, selector ) < 0 : this != selector; + }); + }, + + add: function( selector ) { + return !selector ? this : this.pushStack( jQuery.merge( + this.get(), + selector.constructor == String ? + jQuery( selector ).get() : + selector.length != undefined && (!selector.nodeName || jQuery.nodeName(selector, "form")) ? + selector : [selector] ) ); + }, + + is: function( selector ) { + return selector ? + jQuery.multiFilter( selector, this ).length > 0 : + false; + }, + + hasClass: function( selector ) { + return this.is( "." + selector ); + }, + + val: function( value ) { + if ( value == undefined ) { + + if ( this.length ) { + var elem = this[0]; + + // We need to handle select boxes special + if ( jQuery.nodeName( elem, "select" ) ) { + var 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 ]; + + if ( option.selected ) { + // Get the specifc value for the option + value = jQuery.browser.msie && !option.attributes.value.specified ? option.text : option.value; + + // We don't need an array for one selects + if ( one ) + return value; + + // Multi-Selects return an array + values.push( value ); + } + } + + return values; + + // Everything else, we just grab the value + } else + return (this[0].value || "").replace(/\r/g, ""); + + } + + return undefined; + } + + return this.each(function(){ + if ( this.nodeType != 1 ) + return; + + if ( value.constructor == Array && /radio|checkbox/.test( this.type ) ) + this.checked = (jQuery.inArray(this.value, value) >= 0 || + jQuery.inArray(this.name, value) >= 0); + + else if ( jQuery.nodeName( this, "select" ) ) { + var values = value.constructor == Array ? + value : + [ value ]; + + jQuery( "option", this ).each(function(){ + this.selected = (jQuery.inArray( this.value, values ) >= 0 || + jQuery.inArray( this.text, values ) >= 0); + }); + + if ( !values.length ) + this.selectedIndex = -1; + + } else + this.value = value; + }); + }, + + html: function( value ) { + return value == undefined ? + (this.length ? + this[0].innerHTML : + null) : + this.empty().append( value ); + }, + + replaceWith: function( value ) { + return this.after( value ).remove(); + }, + 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 ); + return this.slice( i, i + 1 ); }, slice: function() { - return this.pushStack( slice.apply( this, arguments ), - "slice", slice.call(arguments).join(",") ); + return this.pushStack( Array.prototype.slice.apply( this, arguments ) ); }, map: function( callback ) { - return this.pushStack( jQuery.map(this, function( elem, i ) { + return this.pushStack( jQuery.map(this, function(elem, i){ return callback.call( elem, i, elem ); })); }, - end: function() { - return this.prevObject || this.constructor(null); + andSelf: function() { + return this.add( this.prevObject ); }, - // For internal use only. - // Behaves like an Array's method, not like a jQuery method. - push: push, - sort: [].sort, - splice: [].splice + data: function( key, value ){ + var parts = key.split("."); + parts[1] = parts[1] ? "." + parts[1] : ""; + + if ( value == null ) { + var data = this.triggerHandler("getData" + parts[1] + "!", [parts[0]]); + + if ( data == undefined && this.length ) + data = jQuery.data( this[0], key ); + + return data == null && parts[1] ? + this.data( parts[0] ) : + data; + } else + return this.trigger("setData" + parts[1] + "!", [parts[0], value]).each(function(){ + jQuery.data( this, key, value ); + }); + }, + + removeData: function( key ){ + return this.each(function(){ + jQuery.removeData( this, key ); + }); + }, + + domManip: function( args, table, reverse, callback ) { + var clone = this.length > 1, elems; + + return this.each(function(){ + if ( !elems ) { + elems = jQuery.clean( args, this.ownerDocument ); + + if ( reverse ) + elems.reverse(); + } + + var obj = this; + + if ( table && jQuery.nodeName( this, "table" ) && jQuery.nodeName( elems[0], "tr" ) ) + obj = this.getElementsByTagName("tbody")[0] || this.appendChild( this.ownerDocument.createElement("tbody") ); + + var scripts = jQuery( [] ); + + jQuery.each(elems, function(){ + var elem = clone ? + jQuery( this ).clone( true )[0] : + this; + + // execute all scripts after the elements have been injected + if ( jQuery.nodeName( elem, "script" ) ) { + scripts = scripts.add( elem ); + } else { + // Remove any inner scripts for later evaluation + if ( elem.nodeType == 1 ) + scripts = scripts.add( jQuery( "script", elem ).remove() ); + + // Inject the elements into the document + callback.call( obj, elem ); + } + }); + + scripts.each( evalScript ); + }); + } }; // Give the init function the jQuery prototype for later instantiation -jQuery.fn.init.prototype = jQuery.fn; +jQuery.prototype.init.prototype = jQuery.prototype; + +function evalScript( i, elem ) { + if ( elem.src ) + jQuery.ajax({ + url: elem.src, + async: false, + dataType: "script" + }); + + else + jQuery.globalEval( elem.text || elem.textContent || elem.innerHTML || "" ); + + if ( elem.parentNode ) + elem.parentNode.removeChild( elem ); +} jQuery.extend = jQuery.fn.extend = function() { - var options, name, src, copy, copyIsArray, clone, - target = arguments[0] || {}, - i = 1, - length = arguments.length, - deep = false; + // copy reference to target object + var target = arguments[0] || {}, i = 1, length = arguments.length, deep = false, options; // Handle a deep copy situation - if ( typeof target === "boolean" ) { + if ( target.constructor == Boolean ) { deep = target; target = arguments[1] || {}; // skip the boolean and the target @@ -317,612 +575,792 @@ jQuery.extend = jQuery.fn.extend = function() { } // Handle case when target is a string or something (possible in deep copy) - if ( typeof target !== "object" && !jQuery.isFunction(target) ) { + if ( typeof target != "object" && typeof target != "function" ) target = {}; - } // extend jQuery itself if only one argument is passed - if ( length === i ) { + if ( length == 1 ) { target = this; - --i; + i = 0; } - for ( ; i < length; i++ ) { + for ( ; i < length; i++ ) // Only deal with non-null/undefined values - if ( (options = arguments[ i ]) != null ) { + if ( (options = arguments[ i ]) != null ) // Extend the base object - for ( name in options ) { - src = target[ name ]; - copy = options[ name ]; - + for ( var name in options ) { // Prevent never-ending loop - if ( target === copy ) { + if ( target === options[ name ] ) 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 ); + // Recurse if we're merging object values + if ( deep && options[ name ] && typeof options[ name ] == "object" && target[ name ] && !options[ name ].nodeType ) + target[ name ] = jQuery.extend( target[ name ], options[ name ] ); // Don't bring in undefined values - } else if ( copy !== undefined ) { - target[ name ] = copy; - } + else if ( options[ name ] != undefined ) + target[ name ] = options[ name ]; + } - } - } // Return the modified object return target; }; +var expando = "jQuery" + (new Date()).getTime(), uuid = 0, windowData = {}; + +// exclude the following css properties to add px +var exclude = /z-?index|font-?weight|opacity|zoom|line-?height/i; + jQuery.extend({ noConflict: function( deep ) { - if ( window.$ === jQuery ) { - window.$ = _$; - } + window.$ = _$; - if ( deep && window.jQuery === jQuery ) { + if ( deep ) 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 ); - } + // See test/unit/core.js for details concerning this function. + isFunction: function( fn ) { + return !!fn && typeof fn != "string" && !fn.nodeName && + fn.constructor != Array && /function/i.test( fn + "" ); + }, + + // check if an element is in a (or is an) XML document + isXMLDoc: function( elem ) { + return elem.documentElement && !elem.body || + elem.tagName && elem.ownerDocument && !elem.ownerDocument.body; }, - // 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; - } - - // Not own constructor property must be Object - if ( obj.constructor && - !hasOwn.call(obj, "constructor") && - !hasOwn.call(obj.constructor.prototype, "isPrototypeOf") ) { - 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) + // Evalulates a script in a global context + globalEval: function( data ) { data = jQuery.trim( data ); - // Attempt to parse using the native JSON parser first - if ( window.JSON && window.JSON.parse ) { - return window.JSON.parse( data ); + if ( data ) { + // Inspired by code by Andrea Giammarchi + // http://webreflection.blogspot.com/2007/08/global-scope-evaluation-and-dom.html + var head = document.getElementsByTagName("head")[0] || document.documentElement, + script = document.createElement("script"); + + script.type = "text/javascript"; + if ( jQuery.browser.msie ) + script.text = data; + else + script.appendChild( document.createTextNode( data ) ); + + head.appendChild( script ); + head.removeChild( script ); } - - // 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 - // (xml & tmp used internally) - parseXML: function( data , xml , tmp ) { - - 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 ); - } - - tmp = xml.documentElement; - - if ( ! tmp || ! tmp.nodeName || tmp.nodeName === "parsererror" ) { - 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 ); - } - }, - - // Converts a dashed string to camelCased string; - // Used by both the css and data modules - camelCase: function( string ) { - return string.replace( rdashAlpha, fcamelCase ); }, nodeName: function( elem, name ) { - return elem.nodeName && elem.nodeName.toUpperCase() === name.toUpperCase(); + return elem.nodeName && elem.nodeName.toUpperCase() == name.toUpperCase(); + }, + + cache: {}, + + data: function( elem, name, data ) { + elem = elem == window ? + windowData : + elem; + + var id = elem[ expando ]; + + // Compute a unique ID for the element + if ( !id ) + id = elem[ expando ] = ++uuid; + + // Only generate the data cache if we're + // trying to access or manipulate it + if ( name && !jQuery.cache[ id ] ) + jQuery.cache[ id ] = {}; + + // Prevent overriding the named cache with undefined values + if ( data != undefined ) + jQuery.cache[ id ][ name ] = data; + + // Return the named cache data, or the ID for the element + return name ? + jQuery.cache[ id ][ name ] : + id; + }, + + removeData: function( elem, name ) { + elem = elem == window ? + windowData : + elem; + + var id = elem[ expando ]; + + // If we want to remove a specific section of the element's data + if ( name ) { + if ( jQuery.cache[ id ] ) { + // Remove the section of cache data + delete jQuery.cache[ id ][ name ]; + + // If we've removed all the data, remove the element's cache + name = ""; + + for ( name in jQuery.cache[ id ] ) + break; + + if ( !name ) + jQuery.removeData( elem ); + } + + // Otherwise, we want to remove all of the element's data + } else { + // Clean up the element expando + try { + delete elem[ expando ]; + } catch(e){ + // IE has trouble directly removing the expando + // but it's ok with using removeAttribute + if ( elem.removeAttribute ) + elem.removeAttribute( expando ); + } + + // Completely remove the data cache + delete jQuery.cache[ id ]; + } }, // 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 ) { + if ( object.length == undefined ) { + for ( var name in object ) + if ( callback.apply( object[ name ], args ) === false ) break; - } - } - } else { - for ( ; i < length; ) { - if ( callback.apply( object[ i++ ], args ) === false ) { + } else + for ( var i = 0, length = object.length; i < length; i++ ) + 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 ) { + if ( object.length == undefined ) { + for ( var 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; - } - } - } + } else + for ( var i = 0, length = object.length, value = object[0]; + i < length && callback.call( value, i, value ) !== false; value = object[++i] ){} } return object; }, + + prop: function( elem, value, type, i, name ) { + // Handle executable functions + if ( jQuery.isFunction( value ) ) + value = value.call( elem, i ); + + // Handle passing in a number to a CSS property + return value && value.constructor == Number && type == "curCSS" && !exclude.test( name ) ? + value + "px" : + value; + }, - // 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, "" ); + className: { + // internal only, use addClass("class") + add: function( elem, classNames ) { + jQuery.each((classNames || "").split(/\s+/), function(i, className){ + if ( elem.nodeType == 1 && !jQuery.className.has( elem.className, className ) ) + elem.className += (elem.className ? " " : "") + className; + }); }, - // results is for internal usage only - makeArray: function( array, results ) { - var ret = results || []; + // internal only, use removeClass("class") + remove: function( elem, classNames ) { + if (elem.nodeType == 1) + elem.className = classNames != undefined ? + jQuery.grep(elem.className.split(/\s+/), function(className){ + return !jQuery.className.has( classNames, className ); + }).join(" ") : + ""; + }, - 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 ); + // internal only, use is(".class") + has: function( elem, className ) { + return jQuery.inArray( className, (elem.className || elem).toString().split(/\s+/) ) > -1; + } + }, - if ( array.length == null || type === "string" || type === "function" || type === "regexp" || jQuery.isWindow( array ) ) { - push.call( ret, array ); - } else { - jQuery.merge( ret, array ); + // A method for quickly swapping in/out CSS properties to get correct calculations + swap: function( elem, options, callback ) { + var old = {}; + // Remember the old values, and insert the new ones + for ( var name in options ) { + old[ name ] = elem.style[ name ]; + elem.style[ name ] = options[ name ]; + } + + callback.call( elem ); + + // Revert the old values + for ( var name in options ) + elem.style[ name ] = old[ name ]; + }, + + css: function( elem, name, force ) { + if ( name == "width" || name == "height" ) { + var val, props = { position: "absolute", visibility: "hidden", display:"block" }, which = name == "width" ? [ "Left", "Right" ] : [ "Top", "Bottom" ]; + + function getWH() { + val = name == "width" ? elem.offsetWidth : elem.offsetHeight; + var padding = 0, border = 0; + jQuery.each( which, function() { + padding += parseFloat(jQuery.curCSS( elem, "padding" + this, true)) || 0; + border += parseFloat(jQuery.curCSS( elem, "border" + this + "Width", true)) || 0; + }); + val -= Math.round(padding + border); + } + + if ( jQuery(elem).is(":visible") ) + getWH(); + else + jQuery.swap( elem, props, getWH ); + + return Math.max(0, val); + } + + return jQuery.curCSS( elem, name, force ); + }, + + curCSS: function( elem, name, force ) { + var ret; + + // A helper method for determining if an element's values are broken + function color( elem ) { + if ( !jQuery.browser.safari ) + return false; + + var ret = document.defaultView.getComputedStyle( elem, null ); + return !ret || ret.getPropertyValue("color") == ""; + } + + // We need to handle opacity special in IE + if ( name == "opacity" && jQuery.browser.msie ) { + ret = jQuery.attr( elem.style, "opacity" ); + + return ret == "" ? + "1" : + ret; + } + // Opera sometimes will give the wrong display answer, this fixes it, see #2037 + if ( jQuery.browser.opera && name == "display" ) { + var save = elem.style.display; + elem.style.display = "block"; + elem.style.display = save; + } + + // Make sure we're using the right name for getting the float value + if ( name.match( /float/i ) ) + name = styleFloat; + + if ( !force && elem.style && elem.style[ name ] ) + ret = elem.style[ name ]; + + else if ( document.defaultView && document.defaultView.getComputedStyle ) { + + // Only "float" is needed here + if ( name.match( /float/i ) ) + name = "float"; + + name = name.replace( /([A-Z])/g, "-$1" ).toLowerCase(); + + var getComputedStyle = document.defaultView.getComputedStyle( elem, null ); + + if ( getComputedStyle && !color( elem ) ) + ret = getComputedStyle.getPropertyValue( name ); + + // If the element isn't reporting its values properly in Safari + // then some display: none elements are involved + else { + var swap = [], stack = []; + + // Locate all of the parent display: none elements + for ( var a = elem; a && color(a); a = a.parentNode ) + stack.unshift(a); + + // Go through and make them visible, but in reverse + // (It would be better if we knew the exact display type that they had) + for ( var i = 0; i < stack.length; i++ ) + if ( color( stack[ i ] ) ) { + swap[ i ] = stack[ i ].style.display; + stack[ i ].style.display = "block"; + } + + // Since we flip the display style, we have to handle that + // one special, otherwise get the value + ret = name == "display" && swap[ stack.length - 1 ] != null ? + "none" : + ( getComputedStyle && getComputedStyle.getPropertyValue( name ) ) || ""; + + // Finally, revert the display styles back + for ( var i = 0; i < swap.length; i++ ) + if ( swap[ i ] != null ) + stack[ i ].style.display = swap[ i ]; + } + + // We should always get a number back from opacity + if ( name == "opacity" && ret == "" ) + ret = "1"; + + } else if ( elem.currentStyle ) { + var camelCase = name.replace(/\-(\w)/g, function(all, letter){ + return letter.toUpperCase(); + }); + + ret = elem.currentStyle[ name ] || elem.currentStyle[ camelCase ]; + + // From the awesome hack by Dean Edwards + // http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102291 + + // If we're not dealing with a regular pixel number + // but a number that has a weird ending, we need to convert it to pixels + if ( !/^\d+(px)?$/i.test( ret ) && /^\d/.test( ret ) ) { + // Remember the original values + var style = elem.style.left, runtimeStyle = elem.runtimeStyle.left; + + // Put in the new values to get a computed value out + elem.runtimeStyle.left = elem.currentStyle.left; + elem.style.left = ret || 0; + ret = elem.style.pixelLeft + "px"; + + // Revert the changed values + elem.style.left = style; + elem.runtimeStyle.left = runtimeStyle; } } return ret; }, + + clean: function( elems, context ) { + var ret = []; + context = context || document; + // !context.createElement fails in IE with an error but returns typeof 'object' + if (typeof context.createElement == 'undefined') + context = context.ownerDocument || context[0] && context[0].ownerDocument || document; + + jQuery.each(elems, function(i, elem){ + if ( !elem ) + return; + + if ( elem.constructor == Number ) + elem = elem.toString(); + + // Convert html string into DOM nodes + if ( typeof elem == "string" ) { + // Fix "XHTML"-style tags in all browsers + elem = elem.replace(/(<(\w+)[^>]*?)\/>/g, function(all, front, tag){ + return tag.match(/^(abbr|br|col|img|input|link|meta|param|hr|area|embed)$/i) ? + all : + front + ">"; + }); + + // Trim whitespace, otherwise indexOf won't work as expected + var tags = jQuery.trim( elem ).toLowerCase(), div = context.createElement("div"); + + var wrap = + // option or optgroup + !tags.indexOf("", "" ] || + + !tags.indexOf("", "" ] || + + tags.match(/^<(thead|tbody|tfoot|colg|cap)/) && + [ 1, "", "
        " ] || + + !tags.indexOf("", "" ] || + + // matched above + (!tags.indexOf("", "" ] || + + !tags.indexOf("", "" ] || + + // IE can't serialize and - - - - - - - - - - - - - - - - - - - - -

        CSP Test Page

        - - diff --git a/test/data/atom+xml.php b/test/data/atom+xml.php deleted file mode 100644 index 944591ab..00000000 --- a/test/data/atom+xml.php +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/test/data/badjson.js b/test/data/badjson.js deleted file mode 100644 index ec41ee5d..00000000 --- a/test/data/badjson.js +++ /dev/null @@ -1 +0,0 @@ -{bad: 1} diff --git a/test/data/cow.jpg b/test/data/cow.jpg new file mode 100644 index 00000000..2c5b6722 Binary files /dev/null and b/test/data/cow.jpg differ diff --git a/test/data/dashboard.xml b/test/data/dashboard.xml index 5a6f5614..10f6b334 100644 --- a/test/data/dashboard.xml +++ b/test/data/dashboard.xml @@ -1,7 +1,7 @@ - + diff --git a/test/data/echoData.php b/test/data/echoData.php deleted file mode 100644 index a37ba515..00000000 --- a/test/data/echoData.php +++ /dev/null @@ -1 +0,0 @@ - diff --git a/test/data/echoQuery.php b/test/data/echoQuery.php deleted file mode 100644 index b72f329c..00000000 --- a/test/data/echoQuery.php +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/test/data/errorWithText.php b/test/data/errorWithText.php deleted file mode 100644 index abd87321..00000000 --- a/test/data/errorWithText.php +++ /dev/null @@ -1,5 +0,0 @@ - diff --git a/test/data/headers.php b/test/data/headers.php deleted file mode 100644 index 968f13f1..00000000 --- a/test/data/headers.php +++ /dev/null @@ -1,18 +0,0 @@ - $value ) { - - $key = str_replace( "_" , "-" , substr( $key , 0 , 5 ) == "HTTP_" ? substr( $key , 5 ) : $key ); - $headers[ $key ] = $value; - -} - -foreach( explode( "_" , $_GET[ "keys" ] ) as $key ) { - echo "$key: " . @$headers[ strtoupper( $key ) ] . "\n"; -} diff --git a/test/data/if_modified_since.php b/test/data/if_modified_since.php deleted file mode 100644 index e37a93e5..00000000 --- a/test/data/if_modified_since.php +++ /dev/null @@ -1,20 +0,0 @@ - diff --git a/test/data/json.php b/test/data/json.php index d6e0f2fc..08e3f9e3 100644 --- a/test/data/json.php +++ b/test/data/json.php @@ -1,13 +1,9 @@ - + \ No newline at end of file diff --git a/test/data/json_assigned_obj.js b/test/data/json_assigned_obj.js new file mode 100644 index 00000000..867251da --- /dev/null +++ b/test/data/json_assigned_obj.js @@ -0,0 +1 @@ +json_assigned_obj = { "test" : "worked" }; diff --git a/test/data/jsonp.php b/test/data/jsonp.php index 6c13d72e..75000252 100644 --- a/test/data/jsonp.php +++ b/test/data/jsonp.php @@ -1,14 +1,10 @@ - + diff --git a/test/data/name.php b/test/data/name.php index 64028585..a4b990e3 100644 --- a/test/data/name.php +++ b/test/data/name.php @@ -1,24 +1,29 @@ -$xml$result"; - die(); -} -$name = $_REQUEST['name']; -if($name == 'foo') { - echo "bar"; - die(); -} else if($name == 'peter') { - echo "pan"; - die(); -} - -echo 'ERROR '; +$xml$result"; + die(); +} +$name = $_REQUEST['name']; +if($name == 'foo') { + echo "bar"; + die(); +} else if($name == 'peter') { + echo "pan"; + die(); +} +$request = apache_request_headers(); +$request = $request['X-Custom-Header']; +if(strlen($request) > 0) { + echo $request; + die(); +} +echo 'ERROR '; ?> \ No newline at end of file diff --git a/test/data/offset/absolute.html b/test/data/offset/absolute.html index 9d7990a3..55d223d6 100644 --- a/test/data/offset/absolute.html +++ b/test/data/offset/absolute.html @@ -12,26 +12,12 @@ #absolute-1-1-1 { top: 1px; left: 1px; } #absolute-2 { top: 19px; left: 19px; } #marker { position: absolute; border: 2px solid #000; width: 50px; height: 50px; background: #ccc; } - p.instructions { position: absolute; bottom: 0; } - #positionTest { position: absolute; } - - - - - - - - - - - - - - - - - - - - - - -
        - - diff --git a/test/data/offset/fixed.html b/test/data/offset/fixed.html index 81ba4ca7..15855763 100644 --- a/test/data/offset/fixed.html +++ b/test/data/offset/fixed.html @@ -12,18 +12,9 @@ #forceScroll { width: 5000px; height: 5000px; } #marker { position: absolute; border: 2px solid #000; width: 50px; height: 50px; background: #ccc; } - - - - - - - - - - + - - - - - - - - - + - - - - - - - - - + - - - - - - - - - + - - - - - - - - - + - - - - - - - - - - - - - - - - - - -
        - - - diff --git a/test/data/support/boxModelIE.html b/test/data/support/boxModelIE.html deleted file mode 100644 index 1b11d2a5..00000000 --- a/test/data/support/boxModelIE.html +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/test/data/support/hiddenIFrameFF.html b/test/data/support/hiddenIFrameFF.html deleted file mode 100644 index 000ac851..00000000 --- a/test/data/support/hiddenIFrameFF.html +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/test/data/test.html b/test/data/test.html index eec028e9..fc6dc386 100644 --- a/test/data/test.html +++ b/test/data/test.html @@ -1,6 +1,6 @@ html text
        diff --git a/test/data/test.js b/test/data/test.js index 69f492dc..f8bdd091 100644 --- a/test/data/test.js +++ b/test/data/test.js @@ -1,3 +1,3 @@ -var foobar = "bar"; -jQuery('#ap').html('bar'); -ok( true, "test.js executed"); +var foobar = "bar"; +$('#ap').html('bar'); +ok( true, "test.js executed"); diff --git a/test/data/test.php b/test/data/test.php index 3d08f325..9dbea979 100644 --- a/test/data/test.php +++ b/test/data/test.php @@ -1,6 +1,6 @@ html text
        diff --git a/test/data/test2.html b/test/data/test2.html index 1df6151a..ebf610e4 100644 --- a/test/data/test2.html +++ b/test/data/test2.html @@ -1,5 +1,5 @@ diff --git a/test/data/testinit.js b/test/data/testinit.js deleted file mode 100644 index c478390d..00000000 --- a/test/data/testinit.js +++ /dev/null @@ -1,96 +0,0 @@ -var jQuery = this.jQuery || "jQuery", // For testing .noConflict() - $ = this.$ || "$", - originaljQuery = jQuery, - original$ = $; - -/** - * Returns an array of elements with the given IDs, eg. - * @example q("main", "foo", "bar") - * @result [
        , , ] - */ -function q() { - var r = []; - - for ( var i = 0; i < arguments.length; i++ ) { - r.push( document.getElementById( arguments[i] ) ); - } - - return r; -} - -/** - * Asserts that a select matches the given IDs * @example t("Check for something", "//[a]", ["foo", "baar"]); - * @result returns true if "//[a]" return two elements with the IDs 'foo' and 'baa -r' - */ -function t(a,b,c) { - var f = jQuery(b).get(), s = ""; - - for ( var i = 0; i < f.length; i++ ) { - s += (s && ",") + '"' + f[i].id + '"'; - } - - same(f, q.apply(q,c), a + " (" + b + ")"); -} - -/** - * Add random number to url to stop IE from caching - * - * @example url("data/test.html") - * @result "data/test.html?10538358428943" - * - * @example url("data/test.php?foo=bar") - * @result "data/test.php?foo=bar&10538358345554" - */ -function url(value) { - return value + (/\?/.test(value) ? "&" : "?") + new Date().getTime() + "" + parseInt(Math.random()*100000); -} - -(function () { - // Store the old counts so that we only assert on tests that have actually leaked, - // instead of asserting every time a test has leaked sometime in the past - var oldCacheLength = 0, - oldFragmentsLength = 0, - oldTimersLength = 0, - oldActive = 0; - - /** - * Ensures that tests have cleaned up properly after themselves. Should be passed as the - * teardown function on all modules' lifecycle object. - */ - this.moduleTeardown = function () { - var i, fragmentsLength = 0, cacheLength = 0; - - // Allow QUnit.reset to clean up any attached elements before checking for leaks - QUnit.reset(); - - for ( i in jQuery.cache ) { - ++cacheLength; - } - - jQuery.fragments = {}; - - for ( i in jQuery.fragments ) { - ++fragmentsLength; - } - - // Because QUnit doesn't have a mechanism for retrieving the number of expected assertions for a test, - // if we unconditionally assert any of these, the test will fail with too many assertions :| - if ( cacheLength !== oldCacheLength ) { - equals( cacheLength, oldCacheLength, "No unit tests leak memory in jQuery.cache" ); - oldCacheLength = cacheLength; - } - if ( fragmentsLength !== oldFragmentsLength ) { - equals( fragmentsLength, oldFragmentsLength, "No unit tests leak memory in jQuery.fragments" ); - oldFragmentsLength = fragmentsLength; - } - if ( jQuery.timers.length !== oldTimersLength ) { - equals( jQuery.timers.length, oldTimersLength, "No timers are still running" ); - oldTimersLength = jQuery.timers.length; - } - if ( jQuery.active !== oldActive ) { - equals( jQuery.active, 0, "No AJAX requests are still active" ); - oldActive = jQuery.active; - } - } -}()); \ No newline at end of file diff --git a/test/data/testrunner.js b/test/data/testrunner.js index 6d44b460..df57e3ac 100644 --- a/test/data/testrunner.js +++ b/test/data/testrunner.js @@ -1,33 +1,303 @@ -jQuery.noConflict(); // Allow the test to run with other libs or jQuery's. +var _config = { + fixture: null, + Test: [], + stats: { + all: 0, + bad: 0 + }, + queue: [], + blocking: true, + timeout: null, + expected: null, + currentModule: null, + asyncTimeout: 2 // seconds for async timeout +}; -// jQuery-specific QUnit.reset -(function() { - var reset = QUnit.reset, - ajaxSettings = jQuery.ajaxSettings; +var isLocal = !!(window.location.protocol == 'file:'); - QUnit.reset = function() { - reset.apply(this, arguments); - jQuery.event.global = {}; - jQuery.ajaxSettings = jQuery.extend({}, ajaxSettings); - }; -})(); +$(function() { + $('#userAgent').html(navigator.userAgent); + runTest(); +}); -// load testswarm agent -(function() { - var url = window.location.search; - url = decodeURIComponent( url.slice( url.indexOf("swarmURL=") + 9 ) ); - if ( !url || url.indexOf("http") !== 0 ) { - return; +function synchronize(callback) { + _config.queue[_config.queue.length] = callback; + if(!_config.blocking) { + process(); } +} - // (Temporarily) Disable Ajax tests to reduce network strain - isLocal = QUnit.isLocal = true; +function process() { + while(_config.queue.length && !_config.blocking) { + var call = _config.queue[0]; + _config.queue = _config.queue.slice(1); + call(); + } +} - document.write(""); -})(); +function stop(allowFailure) { + _config.blocking = true; + var handler = allowFailure ? start : function() { + ok( false, "Test timed out" ); + start(); + }; + // Disabled, caused too many random errors + //_config.timeout = setTimeout(handler, _config.asyncTimeout * 1000); +} +function start() { + // A slight delay, to avoid any current callbacks + setTimeout(function(){ + if(_config.timeout) + clearTimeout(_config.timeout); + _config.blocking = false; + process(); + }, 13); +} -// QUnit Aliases -(function() { - window.equals = window.equal; - window.same = window.deepEqual; -})(); +function runTest() { + _config.blocking = false; + var time = new Date(); + _config.fixture = document.getElementById('main').innerHTML; + synchronize(function() { + time = new Date() - time; + $("
        ").html(['

        Tests completed in ', + time, ' milliseconds.
        ', + _config.stats.bad, ' tests of ', _config.stats.all, ' failed.

        '] + .join('')) + .appendTo("body"); + $("#banner").addClass(_config.stats.bad ? "fail" : "pass"); + }); +} + +function test(name, callback, nowait) { + if(_config.currentModule) + name = _config.currentModule + " module: " + name; + + var filter = location.search.slice(1); + if ( filter && encodeURIComponent(name).indexOf(filter) == -1 ) + return; + + synchronize(function() { + _config.Test = []; + try { + callback(); + } catch(e) { + if( typeof console != "undefined" && console.error && console.warn ) { + console.error("Test " + name + " died, exception and test follows"); + console.error(e); + console.warn(callback.toString()); + } + _config.Test.push( [ false, "Died on test #" + (_config.Test.length+1) + ": " + e ] ); + } + }); + synchronize(function() { + reset(); + + // don't output pause tests + if(nowait) return; + + if(_config.expected && _config.expected != _config.Test.length) { + _config.Test.push( [ false, "Expected " + _config.expected + " assertions, but " + _config.Test.length + " were run" ] ); + } + _config.expected = null; + + var good = 0, bad = 0; + var ol = document.createElement("ol"); + ol.style.display = "none"; + var li = "", state = "pass"; + for ( var i = 0; i < _config.Test.length; i++ ) { + var li = document.createElement("li"); + li.className = _config.Test[i][0] ? "pass" : "fail"; + li.innerHTML = _config.Test[i][1]; + ol.appendChild( li ); + + _config.stats.all++; + if ( !_config.Test[i][0] ) { + state = "fail"; + bad++; + _config.stats.bad++; + } else good++; + } + + var li = document.createElement("li"); + li.className = state; + + var b = document.createElement("strong"); + b.innerHTML = name + " (" + bad + ", " + good + ", " + _config.Test.length + ")"; + b.onclick = function(){ + var n = this.nextSibling; + if ( jQuery.css( n, "display" ) == "none" ) + n.style.display = "block"; + else + n.style.display = "none"; + }; + $(b).dblclick(function(event) { + var target = jQuery(event.target).filter("strong").clone(); + if ( target.length ) { + target.children().remove(); + location.href = location.href.match(/^(.+?)(\?.*)?$/)[1] + "?" + encodeURIComponent($.trim(target.text())); + } + }); + li.appendChild( b ); + li.appendChild( ol ); + + document.getElementById("tests").appendChild( li ); + }); +} + +// call on start of module test to prepend name to all tests +function module(moduleName) { + _config.currentModule = moduleName; +} + +/** + * Specify the number of expected assertions to gurantee that failed test (no assertions are run at all) don't slip through. + */ +function expect(asserts) { + _config.expected = asserts; +} + +/** + * Resets the test setup. Useful for tests that modify the DOM. + */ +function reset() { + $("#main").html( _config.fixture ); +} + +/** + * Asserts true. + * @example ok( $("a").size() > 5, "There must be at least 5 anchors" ); + */ +function ok(a, msg) { + _config.Test.push( [ !!a, msg ] ); +} + +/** + * Asserts that two arrays are the same + */ +function isSet(a, b, msg) { + var ret = true; + if ( a && b && a.length != undefined && a.length == b.length ) { + for ( var i = 0; i < a.length; i++ ) + if ( a[i] != b[i] ) + ret = false; + } else + ret = false; + if ( !ret ) + _config.Test.push( [ ret, msg + " expected: " + serialArray(b) + " result: " + serialArray(a) ] ); + else + _config.Test.push( [ ret, msg ] ); +} + +/** + * Asserts that two objects are equivalent + */ +function isObj(a, b, msg) { + var ret = true; + + if ( a && b ) { + for ( var i in a ) + if ( a[i] != b[i] ) + ret = false; + + for ( i in b ) + if ( a[i] != b[i] ) + ret = false; + } else + ret = false; + + _config.Test.push( [ ret, msg ] ); +} + +function serialArray( a ) { + var r = []; + + if ( a && a.length ) + for ( var i = 0; i < a.length; i++ ) { + var str = a[i].nodeName; + if ( str ) { + str = str.toLowerCase(); + if ( a[i].id ) + str += "#" + a[i].id; + } else + str = a[i]; + r.push( str ); + } + + return "[ " + r.join(", ") + " ]" +} + +/** + * Returns an array of elements with the given IDs, eg. + * @example q("main", "foo", "bar") + * @result [
        , , ] + */ +function q() { + var r = []; + for ( var i = 0; i < arguments.length; i++ ) + r.push( document.getElementById( arguments[i] ) ); + return r; +} + +/** + * Asserts that a select matches the given IDs + * @example t("Check for something", "//[a]", ["foo", "baar"]); + * @result returns true if "//[a]" return two elements with the IDs 'foo' and 'baar' + */ +function t(a,b,c) { + var f = jQuery(b); + var s = ""; + for ( var i = 0; i < f.length; i++ ) + s += (s && ",") + '"' + f[i].id + '"'; + isSet(f, q.apply(q,c), a + " (" + b + ")"); +} + +/** + * Add random number to url to stop IE from caching + * + * @example url("data/test.html") + * @result "data/test.html?10538358428943" + * + * @example url("data/test.php?foo=bar") + * @result "data/test.php?foo=bar&10538358345554" + */ +function url(value) { + return value + (/\?/.test(value) ? "&" : "?") + new Date().getTime() + "" + parseInt(Math.random()*100000); +} + +/** + * Checks that the first two arguments are equal, with an optional message. + * Prints out both expected and actual values on failure. + * + * Prefered to ok( expected == actual, message ) + * + * @example equals( "Expected 2 characters.", v.formatMessage("Expected {0} characters.", 2) ); + * + * @param Object actual + * @param Object expected + * @param String message (optional) + */ +function equals(actual, expected, message) { + var result = expected == actual; + message = message || (result ? "okay" : "failed"); + _config.Test.push( [ result, result ? message + ": " + expected : message + " expected: " + expected + " actual: " + actual ] ); +} + +/** + * Trigger an event on an element. + * + * @example triggerEvent( document.body, "click" ); + * + * @param DOMElement elem + * @param String type + */ +function triggerEvent( elem, type, event ) { + if ( jQuery.browser.mozilla || jQuery.browser.opera ) { + 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 ( jQuery.browser.msie ) { + elem.fireEvent("on"+type); + } +} diff --git a/test/data/testsuite.css b/test/data/testsuite.css index 295740f5..4801becd 100644 --- a/test/data/testsuite.css +++ b/test/data/testsuite.css @@ -1,96 +1,108 @@ -/* for testing opacity set in styles in IE */ -ol#empty { opacity: 0; filter:Alpha(opacity=0) progid:DXImageTransform.Microsoft.gradient(startColorStr='#ffff0000', EndColorStr='#ffffffff'); } +body, div, h1 { font-family: 'trebuchet ms', verdana, arial; margin: 0; padding: 0 } +body {font-size: 10pt; } +h1 { padding: 15px; font-size: large; background-color: #06b; color: white; } +h2 { padding: 10px; background-color: #eee; color: black; margin: 0; font-size: small; font-weight: normal } + +.pass { color: green; } +.fail { color: red; } +p.result { margin-left: 1em; } + +#banner { height: 2em; border-bottom: 1px solid white; } +h2.pass { background-color: green; } +h2.fail { background-color: red; } + +ol#tests > li > strong { cursor:pointer; } div#fx-tests h4 { - background: red; + background: red; } div#fx-tests h4.pass { - background: green; + background: green; } div#fx-tests div.box { - background: red; - overflow: hidden; - border: 2px solid #000; + background: red url(data/cow.jpg) no-repeat; + overflow: hidden; + border: 2px solid #000; } div#fx-tests div.overflow { - overflow: visible; + overflow: visible; } div.inline { - display: inline; + display: inline; } div.autoheight { - height: auto; + height: auto; } div.autowidth { - width: auto; + width: auto; } div.autoopacity { - opacity: auto; + opacity: auto; } div.largewidth { - width: 100px; + width: 100px; } div.largeheight { - height: 100px; + height: 100px; } div.largeopacity { - filter: progid:DXImageTransform.Microsoft.Alpha(opacity=100); + filter: progid:DXImageTransform.Microsoft.Alpha(opacity=100); } div.medwidth { - width: 50px; + width: 50px; } div.medheight { - height: 50px; + height: 50px; } div.medopacity { - opacity: 0.5; - filter: progid:DXImageTransform.Microsoft.Alpha(opacity=50); + opacity: 0.5; + filter: progid:DXImageTransform.Microsoft.Alpha(opacity=50); } div.nowidth { - width: 0px; + width: 0px; } div.noheight { - height: 0px; + height: 0px; } div.noopacity { - opacity: 0; - filter: progid:DXImageTransform.Microsoft.Alpha(opacity=0); + opacity: 0; + filter: progid:DXImageTransform.Microsoft.Alpha(opacity=0); } div.hidden { - display: none; + display: none; } div#fx-tests div.widewidth { - background-repeat: repeat-x; + background-repeat: repeat-x; } div#fx-tests div.wideheight { - background-repeat: repeat-y; + background-repeat: repeat-y; } div#fx-tests div.widewidth.wideheight { - background-repeat: repeat; + background-repeat: repeat; } div#fx-tests div.noback { - background-image: none; + background-image: none; } div.chain, div.chain div { width: 100px; height: 20px; position: relative; float: left; } @@ -102,22 +114,4 @@ div.chain.test div { background: green; } div.chain.out { background: green; } div.chain.out div { background: red; display: none; } -/* tests to ensure jQuery can determine the native display mode of elements - that have been set as display: none in stylesheets */ -div#show-tests * { display: none; } - -#nothiddendiv { font-size: 16px; } -#nothiddendivchild.em { font-size: 2em; } -#nothiddendivchild.prct { font-size: 150%; } - -/* For testing type on vml in IE #7071 */ -v\:oval { behavior:url(#default#VML); display:inline-block; } - -/* 8099 changes to default styles are read correctly */ -tt { display: none; } -sup { display: none; } -dfn { display: none; } - -/* #9239 Attach a background to the body( avoid crashes in removing the test element in support ) */ -body, div { background: url(http://static.jquery.com/files/rocker/images/logo_jquery_215x53.gif) no-repeat -1000px 0; } - +div#show-tests * { display: none; } \ No newline at end of file diff --git a/test/data/text.php b/test/data/text.php index b9df4cf3..c06ef4b8 100644 --- a/test/data/text.php +++ b/test/data/text.php @@ -1,12 +1,12 @@ -Lorem ipsum dolor sit amet -consectetuer adipiscing elit -Sed lorem leo -lorem leo consectetuer adipiscing elit -Sed lorem leo -rhoncus sit amet -elementum at -bibendum at, eros -Cras at mi et tortor egestas vestibulum -sed Cras at mi vestibulum -Phasellus sed felis sit amet -orci dapibus semper. +Lorem ipsum dolor sit amet +consectetuer adipiscing elit +Sed lorem leo +lorem leo consectetuer adipiscing elit +Sed lorem leo +rhoncus sit amet +elementum at +bibendum at, eros +Cras at mi et tortor egestas vestibulum +sed Cras at mi vestibulum +Phasellus sed felis sit amet +orci dapibus semper. diff --git a/test/data/ua.txt b/test/data/ua.txt deleted file mode 100644 index b6a9dff6..00000000 --- a/test/data/ua.txt +++ /dev/null @@ -1,272 +0,0 @@ -msie 6.0 Mozilla/4.0 (compatible; MSIE 6.0; Windows 98; Win 9x 4.90; http://www.Abolimba.de) -msie 6.0 Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; JyxoToolbar1.0; http://www.Abolimba.de; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 1.1.4322) - 0 Mozilla/5.0 (compatible; ABrowse 0.4; Syllable) -webkit 420 Mozilla/5.0 (compatible; U; ABrowse 0.6; Syllable) AppleWebKit/420+ (KHTML, like Gecko) -msie 7.0 Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Acoo Browser; InfoPath.2; .NET CLR 2.0.50727; Alexa Toolbar) -msie 6.0 Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Acoo Browser; .NET CLR 1.1.4322; .NET CLR 2.0.50727) -msie 7.0 Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; Acoo Browser; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.0.04506) - 0 amaya/9.52 libwww/5.4.0 - 0 amaya/11.1 libwww/5.4.0 - 0 Amiga-AWeb/3.5.07 beta - 0 AmigaVoyager/3.4.4 (MorphOS/PPC native) - 0 AmigaVoyager/2.95 (compatible; MC680x0; AmigaOS) -msie 7.0 Mozilla/4.0 (compatible; MSIE 7.0; AOL 7.0; Windows NT 5.1; FunWebProducts) -msie 6.0 Mozilla/4.0 (compatible; MSIE 6.0; AOL 8.0; Windows NT 5.1; SV1) -msie 7.0 Mozilla/4.0 (compatible; MSIE 7.0; AOL 9.0; Windows NT 5.1; .NET CLR 1.1.4322; Zango 10.1.181.0) -msie 6.0 Mozilla/4.0 (compatible; MSIE 6.0; AOL 6.0; Windows NT 5.1) -msie 7.0 Mozilla/4.0 (compatible; MSIE 7.0; AOL 9.5; AOLBuild 4337.35; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727) -webkit 523.15 Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN) AppleWebKit/523.15 (KHTML, like Gecko, Safari/419.3) Arora/0.3 (Change: 287 c9dfb30) -webkit 527 Mozilla/5.0 (X11; U; Linux; en-US) AppleWebKit/527+ (KHTML, like Gecko, Safari/419.3) Arora/0.6 -webkit 523.15 Mozilla/5.0 (X11; U; Linux; C -) AppleWebKit/523.15 (KHTML, like Gecko, Safari/419.3) Arora/0.5 -msie 6.0 Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; Avant Browser; Avant Browser; .NET CLR 1.1.4322; .NET CLR 2.0.50727; InfoPath.1) - 0 Avant Browser (http://www.avantbrowser.com) -msie 6.0 Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; JyxoToolbar1.0; Embedded Web Browser from: http://bsalsa.com/; Avant Browser; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 1.1.4322) -msie 7.0 Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; GTB5; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; Avant Browser) -mozilla 0 Mozilla/5.0 (Windows; U; Win9x; en; Stable) Gecko/20020911 Beonex/0.8.1-stable -mozilla 0 Mozilla/5.0 (Windows; U; WinNT; en; Preview) Gecko/20020603 Beonex/0.8-stable -mozilla 1.0.2 Mozilla/5.0 (Windows; U; WinNT; en; rv:1.0.2) Gecko/20030311 Beonex/0.8.2-stable -mozilla 1.9 Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9) Gecko/2008120120 Blackbird/0.9991 -webkit 527 Mozilla/5.0 (X11; 78; CentOS; US-en) AppleWebKit/527+ (KHTML, like Gecko) Bolt/0.862 Version/3.0 Safari/523.15 -msie 6.0 Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Browzar) - 0 Bunjalloo/0.7.4(Nintendo DS;U;en) - 0 Bunjalloo/0.7.6(Nintendo DS;U;en) -mozilla 1.8.1.4pre Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en; rv:1.8.1.4pre) Gecko/20070511 Camino/1.6pre -mozilla 1.7.2 Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.7.2) Gecko/20040825 Camino/0.8.1 -mozilla 1.8.1.12 Mozilla/5.0 (Macintosh; U; Intel Mac OS X Mach-O; en; rv:1.8.1.12) Gecko/20080206 Camino/1.5.5 -mozilla 1.0.1 Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.0.1) Gecko/20030111 Chimera/0.6 -mozilla 1.8.0.10 Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.8.0.10) Gecko/20070228 Camino/1.0.4 -webkit 418.9 Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/418.9 (KHTML, like Gecko, Safari) Safari/419.3 Cheshire/1.0.ALPHA -webkit 419 Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/419 (KHTML, like Gecko, Safari/419.3) Cheshire/1.0.ALPHA -webkit 525.19 Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.19 (KHTML, like Gecko) Chrome/1.0.154.36 Safari/525.19 -webkit 525.19 Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.19 (KHTML, like Gecko) Chrome/1.0.154.53 Safari/525.19 -mozilla 1.9.0.10 Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.10) Gecko/2009042815 Firefox/3.0.10 CometBird/3.0.10 -mozilla 1.9.0.5 Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.5) Gecko/2009011615 Firefox/3.0.5 CometBird/3.0.5 -msie 7.0 Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; Crazy Browser 3.0.0 Beta2) -msie 6.0 Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; Crazy Browser 2.0.1) -msie 6.0 Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Crazy Browser 1.0.5; .NET CLR 1.1.4322; InfoPath.1) -msie 6.0 Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; Deepnet Explorer 1.5.0; .NET CLR 1.0.3705) -webkit 525.27.1 Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_6; en-us) AppleWebKit/525.27.1 (KHTML, like Gecko) Demeter/1.0.9 Safari/125 -webkit 312.8 Mozilla/5.0 (Macintosh; U; PPC Mac OS X; pl-pl) AppleWebKit/312.8 (KHTML, like Gecko, Safari) DeskBrowse/1.0 - 0 Dillo/0.8.5 - 0 Dillo/2.0 - 0 DocZilla/1.0 (Windows; U; WinNT4.0; en-US; rv:1.0.0) Gecko/20020804 - 0 DocZilla/2.7 (Windows; U; Windows NT 5.1; en-US; rv:2.7.0) Gecko/20050706 CiTEC Information -webkit 527 Mozilla/5.0 (Windows; U; Windows NT 5.1; cs-CZ) AppleWebKit/527+ (KHTML, like Gecko, Safari/419.3) Dooble - 0 Doris/1.15 [en] (Symbian) - 0 edbrowse/1.5.17-2 - 0 edbrowse/2.2.10 - 0 edbrowse/3.1.2-1 - 0 ELinks/0.13.GIT (textmode; Linux 2.6.22-2-686 i686; 148x68-3) - 0 ELinks/0.9.3 (textmode; Linux 2.6.11 i686; 79x24) - 0 Enigma Browser -mozilla 1.8.1.12 Mozilla/5.0 (X11; U; Linux i686; en; rv:1.8.1.12) Gecko/20080208 (Debian-1.8.1.12-2) Epiphany/2.20 -mozilla 1.9.0.12 Mozilla/5.0 (X11; U; Linux x86_64; en; rv:1.9.0.12) Gecko/20080528 Fedora/2.24.3-8.fc10 Epiphany/2.22 Firefox/3.0 -mozilla 1.7.3 Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.3) Gecko/20041007 Epiphany/1.4.7 -mozilla 1.5 Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.5) Gecko/20031007 Firebird/0.7 -mozilla 1.5 Mozilla/5.0 (Windows; U; Win95; en-US; rv:1.5) Gecko/20031007 Firebird/0.7 -mozilla 1.8.0.3 Mozilla/5.0 (Windows; U; Windows NT 5.0; es-ES; rv:1.8.0.3) Gecko/20060426 Firefox/1.5.0.3 -mozilla 1.9.1b2 Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; ko; rv:1.9.1b2) Gecko/20081201 Firefox/3.1b2 -mozilla 1.9.0.8 Mozilla/5.0 (Windows; U; Windows NT 5.1; cs; rv:1.9.0.8) Gecko/2009032609 Firefox/3.0.8 -mozilla 1.7.9 Mozilla/5.0 (Windows; U; WinNT4.0; en-US; rv:1.7.9) Gecko/20050711 Firefox/1.0.5 -mozilla 1.9b5 Mozilla/5.0 (X11; U; SunOS sun4u; en-US; rv:1.9b5) Gecko/2008032620 Firefox/3.0b5 -mozilla 1.8.0.5 Mozilla/5.0 (X11; U; OpenBSD i386; en-US; rv:1.8.0.5) Gecko/20060819 Firefox/1.5.0.5 -mozilla 1.9.1b3 Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1b3) Gecko/20090305 Firefox/3.1b3 GTB5 -mozilla 1.8.1.12 Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.8.1.12) Gecko/20080214 Firefox/2.0.0.12 -mozilla 1.8.1.9 Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.9) Gecko/20071113 BonEcho/2.0.0.9 -mozilla 1.8.1 Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1) Gecko/20061026 BonEcho/2.0 -mozilla 1.8.1.21pre Mozilla/5.0 (BeOS; U; Haiku BePC; en-US; rv:1.8.1.21pre) Gecko/20090227 BonEcho/2.0.0.21pre -mozilla 1.9.0.8 Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.8) Gecko/2009033017 GranParadiso/3.0.8 -mozilla 1.9.2a2pre Mozilla/5.0 (Windows; U; Windows NT 6.1; cs; rv:1.9.2a2pre) Gecko/20090912 Namoroka/3.6a2pre (.NET CLR 3.5.30729) -mozilla 1.9.2a2pre Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2a2pre) Gecko/20090901 Ubuntu/9.10 (karmic) Namoroka/3.6a2pre -mozilla 1.9.2a1 Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2a1) Gecko/20090806 Namoroka/3.6a1 -mozilla 1.9.1b3pre Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1b3pre) Gecko/20090109 Shiretoko/3.1b3pre -mozilla 1.9.1b4pre Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.1b4pre) Gecko/20090311 Shiretoko/3.1b4pre -mozilla 1.8.0.1 Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.8.0.1) Gecko/20060314 Flock/0.5.13.2 -mozilla 1.9.0.2 Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.2) Gecko/2008092122 Firefox/3.0.2 Flock/2.0b3 -webkit 525.13 Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.13 (KHTML, like Gecko) Fluid/0.9.4 Safari/525.13 -mozilla 1.7.12 Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.12) Gecko/20050929 Galeon/1.3.21 -mozilla 1.9.0.8 Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.8) Gecko/20090327 Galeon/2.0.7 -mozilla 1.9.1.5 Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.5) Gecko/20091105 Firefox/3.5.5 compat GlobalMojo/1.5.5 GlobalMojoExt/1.5 -msie 6.0 Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; GreenBrowser) -msie 7.0 Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727; GreenBrowser) -msie 7.0 Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; InfoPath.1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; GreenBrowser) - 0 HotJava/1.1.2 FCS -mozilla 0 Mozilla/3.0 (x86 [cs] Windows NT 5.1; Sun) -mozilla 1.8.0.3 Mozilla/5.1 (X11; U; Linux i686; en-US; rv:1.8.0.3) Gecko/20060425 SUSE/1.5.0.3-7 Hv3/alpha -msie 7.0 Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; SIMBAR={CFBFDAEA-F21E-4D6E-A9B0-E100A69B860F}; Hydra Browser; .NET CLR 2.0.50727; .NET CLR 1.1.4322; .NET CLR 3.0.04506.30) -msie 6.0 Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Hydra Browser; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729) - 0 IBrowse/2.3 (AmigaOS 3.9) - 0 Mozilla/5.0 (compatible; IBrowse 3.0; AmigaOS4.0) - 0 iCab/4.0 (Macintosh; U; Intel Mac OS X) - 0 Mozilla/4.5 (compatible; iCab 2.9.1; Macintosh; U; PPC) - 0 iCab/3.0.2 (Macintosh; U; PPC Mac OS X) - 0 ICE Browser/v5_4_3 (Java 1.4.2; Windows XP 5.1 x86) -mozilla 0 Mozilla/5.0 (Java 1.6.0_01; Windows XP 5.1 x86; en) ICEbrowser/v6_1_2 - 0 ICE Browser/5.05 (Java 1.4.0; Windows 2000 5.0 x86) -mozilla 1.8.1.9 Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.9) Gecko/20071030 Iceape/1.1.6 (Debian-1.1.6-3) -mozilla 1.8.1.8 Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.8.1.8) Gecko/20071008 Iceape/1.1.5 (Ubuntu-1.1.5-1ubuntu0.7.10) -mozilla 1.9.0.3 Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.3) Gecko/2008092921 IceCat/3.0.3-g1 -mozilla 1.8.1.11 Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.11) Gecko/20071203 IceCat/2.0.0.11-g1 -mozilla 1.9.0.5 Mozilla/5.0 (X11; U; Linux i686; de; rv:1.9.0.5) Gecko/2008122011 Iceweasel/3.0.5 (Debian-3.0.5-1) -mozilla 1.8.1.1 Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.8.1.1) Gecko/20061205 Iceweasel/2.0.0.1 (Debian-2.0.0.1+dfsg-4) -mozilla 1.9.0.5 Mozilla/5.0 (X11; U; Linux i686; it; rv:1.9.0.5) Gecko/2008122011 Iceweasel/3.0.5 (Debian-3.0.5-1) -msie 4.0 Mozilla/2.0 (compatible; MSIE 4.0; Windows 98) -msie 6.0 Mozilla/4.0 (Windows; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727) -msie 7.0 Mozilla/4.0 (Mozilla/4.0; MSIE 7.0; Windows NT 5.1; FDM; SV1; .NET CLR 3.0.04506.30) -msie 5.01 Mozilla/4.0 (compatible; MSIE 5.01; Windows NT) -msie 8.0 Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; SLCC1; .NET CLR 2.0.50727; .NET CLR 1.1.4322; InfoPath.2; .NET CLR 3.5.21022; .NET CLR 3.5.30729; MS-RTC LM 8; OfficeLiveConnector.1.4; OfficeLivePatch.1.3; .NET CLR 3.0.30729) -msie 6.0 Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322; Media Center PC 4.0; .NET CLR 2.0.50727) -msie 5.0b1 Mozilla/4.0 (compatible; MSIE 5.0b1; Mac_PowerPC) -msie 5.0 Mozilla/4.0 (compatible; MSIE 5.0; Windows NT;) -msie 5.23 Mozilla/4.0 (compatible; MSIE 5.23; Mac_PowerPC) -msie 6.0 Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; GTB6; Ant.com Toolbar 1.6; MSIECrawler) -msie 8.0 Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; GTB5; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.0.04506; InfoPath.2; OfficeLiveConnector.1.3; OfficeLivePatch.0.0) -msie 7.0 Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; Trident/4.0; SLCC1; .NET CLR 2.0.50727; .NET CLR 1.1.4322; InfoPath.2; .NET CLR 3.5.21022; .NET CLR 3.5.30729; MS-RTC LM 8; OfficeLiveConnector.1.4; OfficeLivePatch.1.3; .NET CLR 3.0.30729) -msie 7.0 Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; InfoPath.2) -msie 6.0 Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; iRider 2.21.1108; FDM) -webkit 528.5 Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) AppleWebKit/528.5 (KHTML, like Gecko) Iron/0.4.155.0 Safari/528.5 -webkit 528.7 Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/528.7 (KHTML, like Gecko) Iron/1.0.155.0 Safari/528.7 -webkit 525.19 Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.19 (KHTML, like Gecko) Iron/0.2.152.0 Safari/12081672.525 -webkit 531.0 Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/531.0 (KHTML, like Gecko) Iron/3.0.189.0 Safari/531.0 -mozilla 1.8.1.19 Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.8.1.19) Gecko/20081217 K-Meleon/1.5.2 -mozilla 1.8.1.21 Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.21) Gecko/20090331 K-Meleon/1.5.3 -mozilla 1.8.0.5 Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.5) Gecko/20060706 K-Meleon/1.0 -mozilla 1.8.1.21 Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.8.1.21) Gecko/20090331 K-Meleon/1.5.3 -mozilla 1.8.0.6 Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.6) Gecko/20060731 K-Ninja/2.0.2 -mozilla 1.8.1.4pre Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.4pre) Gecko/20070404 K-Ninja/2.1.3 -mozilla 1.8.1.2pre Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.2pre) Gecko/20070215 K-Ninja/2.1.1 -mozilla 1.9 Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9) Gecko/20080705 Firefox/3.0 Kapiko/3.0 -mozilla 0 Mozilla/5.0 (X11; Linux i686; U;) Gecko/20070322 Kazehakase/0.4.5 -mozilla 1.9.0.8 Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.8) Gecko Fedora/1.9.0.8-1.fc10 Kazehakase/0.5.6 -msie 6.0 Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; KKman2.0) -msie 6.0 Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; KKMAN3.2) -msie 6.0 Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; KKman3.0) - 0 Mozilla/5.0 (compatible; Konqueror/3.1-rc5; i686 Linux; 20020712) - 0 Mozilla/5.0 (compatible; Konqueror/4.3; Windows) KHTML/4.3.0 (like Gecko) - 0 Mozilla/5.0 (compatible; Konqueror/2.2.1; Linux) - 0 Mozilla/5.0 (compatible; Konqueror/3.5; SunOS) - 0 Mozilla/5.0 (compatible; Konqueror/4.1; OpenBSD) KHTML/4.1.4 (like Gecko) - 0 Links (0.96; Linux 2.4.20-18.7 i586) - 0 Links (0.98; Win32; 80x25) - 0 Links (2.1pre18; Linux 2.4.31 i686; 100x37) - 0 Links (2.1; Linux 2.6.18-gentoo-r6 x86_64; 80x24) - 0 Links (2.2; Linux 2.6.25-gentoo-r9 sparc64; 166x52) -msie 6.0 Mozilla/4.0 (compatible; MSIE 6.0; Linux 2.6.26-1-amd64) Lobo/0.98.3 -msie 6.0 Mozilla/4.0 (compatible; MSIE 6.0; Windows XP 5.1) Lobo/0.98.4 - 0 Mozilla/4.0 (compatible; Lotus-Notes/5.0; Windows-NT) - 0 Mozilla/4.0 (compatible; Lotus-Notes/6.0; Windows-NT) -msie 6.0 Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.1.4322; Lunascape 2.1.3) -mozilla 1.9.1b3pre Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1b3pre) Gecko/2008 Lunascape/4.9.9.98 -msie 6.0 Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; JyxoToolbar1.0; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 1.1.4322; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; Lunascape 5.1.4.5) -webkit 528 Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/528+ (KHTML, like Gecko, Safari/528.0) Lunascape/5.0.2.0 -mozilla 1.9.1.2 Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.2) Gecko/20090804 Firefox/3.5.2 Lunascape/5.1.4.5 - 0 Lynx/2.8.6rel.4 libwww-FM/2.14 SSL-MM/1.4.1 GNUTLS/1.6.3 - 0 Lynx/2.8.3dev.6 libwww-FM/2.14 - 0 Lynx/2.8.5dev.16 libwww-FM/2.14 SSL-MM/1.4.1 OpenSSL/0.9.7a -mozilla 1.7.12 Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.12) Gecko/20051001 Firefox/1.0.7 Madfox/0.3.2u3 -webkit 530.6 Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/530.6 (KHTML, like Gecko) Maxthon/3.0 Safari/530.6 -msie 7.0 Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; SV1; Maxthon; .NET CLR 1.1.4322) -msie 6.0 Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; MyIE2) -msie 8.0 Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; MAXTHON 2.0) - 0 Midori/0.1.7 -webkit 532 Midori/0.1.5 (X11; Linux; U; en-gb) WebKit/532+ -mozilla 1.0.1 Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.1) Gecko/20020919 -mozilla 1.7.12 Mozilla/5.0 (Windows; U; Windows NT 5.0; it-IT; rv:1.7.12) Gecko/20050915 -mozilla 1.4 Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4; MultiZilla v1.5.0.0f) Gecko/20030624 -mozilla 1.2.1 Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.2.1; MultiZilla v1.1.32 final) Gecko/20021130 - 0 NCSA_Mosaic/2.0 (Windows 3.1) - 0 NCSA_Mosaic/3.0 (Windows 95) - 0 NCSA Mosaic/1.0 (X11;SunOS 4.1.4 sun4m) - 0 NCSA_Mosaic/2.6 (X11; SunOS 4.1.3 sun4m) - 0 Mozilla/3.01 (compatible; Netbox/3.5 R92; Linux 2.2) -msie 6.0 Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; NetCaptor 7.5.4; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 1.1.4322; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729) -msie 5.01 Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0; NetCaptor 6.5.0RC1) -mozilla 1.7.5 Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5) Gecko/20060127 Netscape/8.1 -mozilla 0 Mozilla/4.04 [en] (X11; I; IRIX 5.3 IP22) -mozilla 0.9.2 Mozilla/5.0 (Windows; U; Win 9x 4.90; de-DE; rv:0.9.2) Gecko/20010726 Netscape6/6.1 -mozilla 1.8.1.12 Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.8.1.12) Gecko/20080219 Firefox/2.0.0.12 Navigator/9.0.0.6 -mozilla 0 Mozilla/4.08 [en] (WinNT; U ;Nav) -mozilla 1.0.2 Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.0.2) Gecko/20030208 Netscape/7.02 -mozilla 0 Mozilla/3.0 (Win95; I) -mozilla 0 Mozilla/4.51 [en] (Win98; U) - 0 NetSurf/2.0 (RISC OS; armv3l) - 0 NetSurf/1.2 (Linux; i686) - 0 Mozilla/4.7 (compatible; OffByOne; Windows 2000) - 0 Mozilla/4.7 (compatible; OffByOne; Windows 98) - 0 Mozilla/4.5 (compatible; OmniWeb/4.1.1-v424.6; Mac_PowerPC) - 0 OmniWeb/2.7-beta-3 OWF/1.0 -webkit 420 Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en-US) AppleWebKit/420+ (KHTML, like Gecko, Safari) OmniWeb/v595 -opera 6.0 Opera/6.0 (Windows 2000; U) [fr] -opera 7.10 Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1) Opera 7.10 [en] -opera 10.00 Opera/9.80 (Windows NT 5.1; U; cs) Presto/2.2.15 Version/10.00 -opera 5.11 Opera/5.11 (Windows 98; U) [en] -opera 9.51 Opera/9.51 (Macintosh; Intel Mac OS X; U; en) -opera 6.01 Mozilla/4.0 (compatible; MSIE 5.0; Windows NT 4.0) Opera 6.01 [en] -opera 9.02 Opera/9.02 (Windows XP; U; ru) -opera 5.12 Mozilla/4.0 (compatible; MSIE 5.0; Windows 98) Opera 5.12 [en] -opera 9.70 Opera/9.70 (Linux i686 ; U; en) Presto/2.2.1 -opera 7.03 Opera/7.03 (Windows NT 5.0; U) [en] -opera 9.24 Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; en) Opera 9.24 -mozilla 1.9.0.7 Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.7) Gecko/2009030821 Firefox/3.0.7 Orca/1.1 build 2 -mozilla 1.9.0.6 Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.6) Gecko/2009022300 Firefox/3.0.6 Orca/1.1 build 1 - 0 Mozilla/1.10 [en] (Compatible; RISC OS 3.70; Oregano 1.10) -webkit 530.0 Mozilla/5.0 (compatible; Origyn Web Browser; AmigaOS 4.1; ppc; U; en) AppleWebKit/530.0+ (KHTML, like Gecko, Safari/530.0+) -webkit 531.0 Mozilla/5.0 (compatible; Origyn Web Browser; AmigaOS 4.0; U; en) AppleWebKit/531.0+ (KHTML, like Gecko, Safari/531.0+) -webkit 528.5 Mozilla/5.0 (compatible; Origyn Web Browser; MorphOS; PPC; U) AppleWebKit/528.5+ (KHTML, like Gecko, Safari/528.5+) -msie 6.0 Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; PhaseOut-www.phaseout.net) -mozilla 1.4a Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.4a) Gecko/20030411 Phoenix/0.5 -mozilla 1.2b Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2b) Gecko/20021029 Phoenix/0.4 -webkit 527 Mozilla/5.0 (Windows; U; Windows NT 5.1; cs-CZ) AppleWebKit/527+ (KHTML, like Gecko) QtWeb Internet Browser/2.5 http://www.QtWeb.net -webkit 527 Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/527+ (KHTML, like Gecko) QtWeb Internet Browser/1.2 http://www.QtWeb.net -webkit 527 Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/527+ (KHTML, like Gecko) QtWeb Internet Browser/1.7 http://www.QtWeb.net -webkit 527 Mozilla/5.0 (X11; U; Linux; cs-CZ) AppleWebKit/527+ (KHTML, like Gecko, Safari/419.3) rekonq - 0 retawq/0.2.6c [en] (text) -webkit 312.8 Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en-us) AppleWebKit/312.8 (KHTML, like Gecko) Safari/312.6 -webkit 528.16 Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10_5_6; it-it) AppleWebKit/528.16 (KHTML, like Gecko) Version/4.0 Safari/528.16 -webkit 523.15 Mozilla/5.0 (Windows; U; Windows NT 5.1; cs-CZ) AppleWebKit/523.15 (KHTML, like Gecko) Version/3.0 Safari/523.15 -webkit 125.2 Mozilla/5.0 (Macintosh; U; PPC Mac OS X; de-de) AppleWebKit/125.2 (KHTML, like Gecko) Safari/125.7 -webkit 528.16 Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) AppleWebKit/528.16 (KHTML, like Gecko) Version/4.0 Safari/528.16 -webkit 420 Mozilla/5.0 (Macintosh; U; PPC Mac OS X; fi-fi) AppleWebKit/420+ (KHTML, like Gecko) Safari/419.3 -mozilla 1.8.1.13 Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.13) Gecko/20080313 SeaMonkey/1.1.9 -mozilla 1.9.1a2pre Mozilla/5.0 (X11; U; Linux i686; rv:1.9.1a2pre) Gecko/20080824052448 SeaMonkey/2.0a1pre -mozilla 1.8.1.6 Mozilla/5.0 (Windows; U; Win 9x 4.90; en-GB; rv:1.8.1.6) Gecko/20070802 SeaMonkey/1.1.4 -mozilla 1.9.1b3pre Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1b3pre) Gecko/20081208 SeaMonkey/2.0a3pre -mozilla 1.9a1 Mozilla/5.0 (BeOS; U; BeOS BePC; en-US; rv:1.9a1) Gecko/20060702 SeaMonkey/1.5a -mozilla 1.9.1b3pre Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1b3pre) Gecko/20081202 SeaMonkey/2.0a2 -webkit 419 Mozilla/5.0 (Macintosh; U; PPC Mac OS X; ja-jp) AppleWebKit/419 (KHTML, like Gecko) Shiira/1.2.3 Safari/125 -webkit 417.9 Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/417.9 (KHTML, like Gecko, Safari) Shiira/1.1 -webkit 418.9.1 Mozilla/5.0 (Macintosh; U; Intel Mac OS X; fr) AppleWebKit/418.9.1 (KHTML, like Gecko) Shiira Safari/125 -msie 6.0 Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1) Sleipnir/2.8.1 -msie 7.0 Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; InfoPath.1; .NET CLR 2.0.50727) Sleipnir/2.8.4 -webkit 525.27.1 Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_5; en-us) AppleWebKit/525.27.1 (KHTML, like Gecko) Stainless/0.4 Safari/525.20.1 -webkit 528.16 Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_6; en-us) AppleWebKit/528.16 (KHTML, like Gecko) Stainless/0.5.3 Safari/525.20.1 -webkit 525.18 Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_4_11; en) AppleWebKit/525.18 (KHTML, like Gecko) Sunrise/1.7.4 like Safari/4525.22 -webkit 125.5.7 Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en-us) AppleWebKit/125.5.7 (KHTML, like Gecko) SunriseBrowser/0.853 -mozilla 1.9.0.10pre Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.10pre) Gecko/2009041814 Firefox/3.0.10pre (Swiftfox) -msie 6.0 Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 1.1.4322; TheWorld) -webkit 1.1.8 Webkit/1.1.8 (Linux; en-us) Uzbl -webkit 1.1.10 Uzbl (X11; U; Linux x86_64; en-GB) AppleWebkit/1.1.10 -webkit 1.1.9 Uzbl (Webkit 1.1.9) (Linux) -webkit 1.1.10 Uzbl (U; Linux x86_64; en-GB) Webkit 1.1.10 - 0 w3m/0.5.1 - 0 w3m/0.5.2 -webkit 103u Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en-us) AppleWebKit/103u (KHTML, like Gecko) wKiosk/100 -mozilla 1.9.0.9 Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.9) Gecko/2009042410 Firefox/3.0.9 Wyzo/3.0.3 - 0 X-Smiles/1.2-20081113 -msie 7.0 Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; .NET CLR 2.0.50727; .NET CLR 1.1.4322; .NET CLR 3.0.04506.30; MEGAUPLOAD 2.0) -msie 7.0 Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30) -mozilla 1.9.0.4 Mozilla/5.0 (X11; U; Linux i686; en-GB; rv:1.9.0.4) Gecko/2008111217 Fedora/3.0.4-1.fc9 Firefox/3.0.4 -mozilla 1.9.0.4 Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.0.4) Gecko/2008102920 Firefox/3.0.4 -msie 7.0 Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.0.04506; .NET CLR 1.1.4322; FDM) -msie 6.0 mozilla/4.0 (compatible; msie 6.0; windows nt 5.1; mra 4.6 (build 01425); .net clr 2.0.50727) -msie 7.0 mozilla/4.0 (compatible; msie 7.0; windows nt 5.1; mra 4.9 (build 01863)) -msie 7.0 Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; InfoPath?.2; .NET CLR 3.5.21022; .NET CLR 3.5.30729; .NET CLR 3.0.30618; MS-RTC LM 8; .NET CLR 1.1.4322) -msie 7.0 Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; SLCC1; .NET CLR 2.0.50727; .NET CLR 3.0.04506; InfoPath?.2; .NET CLR 3.5.21022) -msie 7.0 Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Sky Broadband; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; .NET CLR 1.1.4322) -msie 7.0 Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; InfoPath.2; .NET CLR 3.5.21022; .NET CLR 3.5.30729; .NET CLR 3.0.30618; MS-RTC LM 8; .NET CLR 1.1.4322) -msie 7.0 Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; SLCC1; .NET CLR 2.0.50727; .NET CLR 3.0.04506; InfoPath.2; .NET CLR 3.5.21022) -msie 7.0 Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; GTB6; User-agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; http://bsalsa.com); .NET CLR 1.1.4322; .NET CLR 2.0.50727 -opera 10.00 Opera/9.80 (Macintosh; Intel Mac OS X; U; en) Presto/2.2.15 Version/10.00 -msie 8.0 Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; .NET CLR 1.1.4322; InfoPath?.2; .NET CLR 2.0.50727; CIBA; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729) -opera 10.00 Opera/9.80 (X11; Linux x86_64; U; de) Presto/2.2.15 Version/10.00 -opera 10.50 Opera/9.80 (Macintosh; Intel Mac OS X; U; en) Presto/2.5.18 Version/10.50 diff --git a/test/data/versioncheck.js b/test/data/versioncheck.js deleted file mode 100644 index f4b7790d..00000000 --- a/test/data/versioncheck.js +++ /dev/null @@ -1,8 +0,0 @@ -// Run minified source from dist (do make first) -// Should be loaded before QUnit but after src -(function() { - if ( /jquery\=min/.test( window.location.search ) ) { - jQuery.noConflict( true ); - document.write(unescape("%3Cscript%20src%3D%27../dist/jquery.min.js%27%3E%3C/script%3E")); - } -})(); \ No newline at end of file diff --git a/test/data/with_fries.xml b/test/data/with_fries.xml index 42f42570..88e0e49d 100644 --- a/test/data/with_fries.xml +++ b/test/data/with_fries.xml @@ -6,7 +6,7 @@ - + diff --git a/test/data/with_fries_over_jsonp.php b/test/data/with_fries_over_jsonp.php deleted file mode 100644 index 456aeb3b..00000000 --- a/test/data/with_fries_over_jsonp.php +++ /dev/null @@ -1,7 +0,0 @@ - diff --git a/test/delegatetest.html b/test/delegatetest.html deleted file mode 100644 index 169e60f7..00000000 --- a/test/delegatetest.html +++ /dev/null @@ -1,289 +0,0 @@ - - - - - - -

        Change Tests

        - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        - Change each: - - - - - - - -
        - -
        - - -
        -
        -
        -
        -
        -
        - -
        - -
        - - -
        - - - - - - - $(document).bind('change')
        - $(document).bind('click') -
        Live:SELECTMULTICHECKBOXBUTTONRADIOFILETEXTTEXTAREADOCUMENT
        Bind:SELECTMULTICHECKBOXBUTTONRADIOFILETEXTTEXTAREA
        Focusin:SELECTMULTICHECKBOXBUTTONRADIOFILETEXTTEXTAREADOCUMENT
        Focusout:SELECTMULTICHECKBOXBUTTONRADIOFILETEXTTEXTAREADOCUMENT
        Live Focus:SELECTMULTICHECKBOXBUTTONRADIOFILETEXTTEXTAREA
        Live Blur:SELECTMULTICHECKBOXBUTTONRADIOFILETEXTTEXTAREA
        Live Click:SELECTMULTICHECKBOXBUTTONRADIOFILETEXTTEXTAREADOCUMENT
        -

        Submit Tests

        - - - - - - - - - - - - - - - -
        - Submit each: - -
        - -
        -
        -
        - -
        -
        -
        - -
        -
        $(document).bind('submit')
        Results:TEXTPASSWORDBUTTONDOCUMENT
        - -

        Mouseleave Tests

        - -
        -

        Count mouse leave event

        -
        -

        mouse over here should not trigger the counter.

        -
        -

        0

        -
        - -
          - - - - diff --git a/test/fix.html b/test/fix.html new file mode 100644 index 00000000..f4edab79 --- /dev/null +++ b/test/fix.html @@ -0,0 +1,48 @@ + + + + + + + Tester + + + + + + + + +
          + Hi +
          + +
          +
          + + + diff --git a/test/index.html b/test/index.html index 4b4c9855..bca5f5ba 100644 --- a/test/index.html +++ b/test/index.html @@ -3,75 +3,35 @@ jQuery Test Suite - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + -

          jQuery Test Suite - (minified) -

          -

          -
          -

          -
            - +

            jQuery Test Suite

            + +

            + -
            +
            - + -
            -
            +
            - -
            -
              -
            1. Rice
            2. -
            3. Beans
            4. -
            5. Blinis
            6. -
            7. Tofu
            8. -
            - -
            I'm hungry. I should...
            - ...Eat lots of food... | - ...Eat a little food... | - ...Eat no food... - ...Eat a burger... - ...Eat some funyuns... - ...Eat some funyuns... -
            - -
            - - -
            - -
            - 1 - 2 -
            -
            -
            -
            fadeIn
            fadeIn
            -
            fadeOut
            fadeOut
            - -
            show
            show
            -
            hide
            hide
            - -
            togglein
            togglein
            -
            toggleout
            toggleout
            - - -
            slideUp
            slideUp
            -
            slideDown
            slideDown
            - -
            slideToggleIn
            slideToggleIn
            -
            slideToggleOut
            slideToggleOut
            - -
            fadeToggleIn
            fadeToggleIn
            -
            fadeToggleOut
            fadeToggleOut
            - -
            fadeTo
            fadeTo
            -
            - -
            -
            + +
              diff --git a/test/localfile.html b/test/localfile.html deleted file mode 100644 index c552f214..00000000 --- a/test/localfile.html +++ /dev/null @@ -1,93 +0,0 @@ - - - - - jQuery Local File Test - - - - - - - - - - - - - - - - - - - - - - - -

              jQuery Local File Test

              -

              - Introduction -

              -
                -
              • - Access this file using the "file:" protocol, -
              • -
              • - two green "OK" strings must appear below, -
              • -
              • - Empty local files will issue errors, it's a known limitation. -
              • -
              -

              - Results -

              -
                -
              • - Success: - - -
              • -
              • - Error: - - -
              • -
              -

              - Logs: -

              -
                -
              - - \ No newline at end of file diff --git a/test/networkerror.html b/test/networkerror.html deleted file mode 100644 index f98bf469..00000000 --- a/test/networkerror.html +++ /dev/null @@ -1,102 +0,0 @@ - - - - - - jQuery Network Error Test for Firefox - - - - - - - - - - - - - - - - - - - - - - - - -

              - jQuery Network Error Test for Firefox -

              -
              - This is a test page for - - #8135 - - which was reported in Firefox when accessing properties - of an XMLHttpRequest object after a network error occured. -
              -
              Take the following steps:
              -
                -
              1. - make sure you accessed this page through a web server, -
              2. -
              3. - stop the web server, -
              4. -
              5. - open the console, -
              6. -
              7. - click this - - , -
              8. -
              9. - wait for both requests to fail. -
              10. -
              -
              - Test passes if you get two log lines: -
                -
              • - the first starting with "abort", -
              • -
              • - the second starting with "complete", -
              • -
              -
              -
              - Test fails if the browser notifies an exception. -
              - - \ No newline at end of file diff --git a/test/offset.html b/test/offset.html new file mode 100644 index 00000000..f802dea3 --- /dev/null +++ b/test/offset.html @@ -0,0 +1,27 @@ + + + + + jQuery Offset Test Suite + + + + + + + +

              jQuery Offset Test Suite

              + +

              + + +
              + + +
                + + diff --git a/test/polluted.php b/test/polluted.php deleted file mode 100644 index 50fc7cd6..00000000 --- a/test/polluted.php +++ /dev/null @@ -1,99 +0,0 @@ - array( - "versions" => array( "1.1.1", "1.2.0", "1.2.3", "1.3.0", "1.3.1", "1.3.2", "1.4.0", "1.4.1", "1.4.3", "1.5.0" ), - "url" => "dojo/XYZ/dojo/dojo.xd.js" - ), - "ExtCore" => array( - "versions" => array( "3.0.0", "3.1.0" ), - "url" => "ext-core/XYZ/ext-core.js" - ), - "jQuery" => array( - "versions" => array( "1.2.3", "1.2.6", "1.3.0", "1.3.1", "1.3.2", "1.4.0", "1.4.1", "1.4.2", "1.4.3", "1.4.4", "1.5.0" ), - "url" => "jquery/XYZ/jquery.min.js" - ), - "jQueryUI" => array( - "versions" => array( "1.5.2", "1.5.3", "1.6.0", "1.7.0", "1.7.1", "1.7.2", "1.7.3", "1.8.0", "1.8.1", "1.8.2", "1.8.4", "1.8.5", "1.8.6", "1.8.7", "1.8.8", "1.8.9" ), - "url" => "jqueryui/XYZ/jquery-ui.min.js" - ), - "MooTools" => array( - "versions" => array( "1.1.1", "1.1.2", "1.2.1", "1.2.2", "1.2.3", "1.2.4", "1.2.5", "1.3.0" ), - "url" => "mootools/XYZ/mootools-yui-compressed.js" - ), - "Prototype" => array( - "versions" => array( "1.6.0.2", "1.6.0.3", "1.6.1.0", "1.7.0.0" ), - "url" => "prototype/XYZ/prototype.js" - ), - "scriptaculous" => array( - "versions" => array( "1.8.1", "1.8.2", "1.8.3" ), - "url" => "scriptaculous/XYZ/scriptaculous.js" - ), - "SWFObject" => array( - "versions" => array( "2.1", "2.2" ), - "url" => "swfobject/XYZ/swfobject.js" - ), - "YUI" => array( - "versions" => array( "2.6.0", "2.7.0", "2.8.0r4", "2.8.1", "2.8.2", "3.3.0" ), - "url" => "yui/XYZ/build/yui/yui-min.js" - ) - ); - - if( count($_POST) ) { - $includes = array(); - foreach( $_POST as $name => $ver ){ - $url = $libraries[ $name ][ "url" ]; - if( $name == "YUI" && $ver[0] == "2" ) { - $url = str_replace( "/yui", "/yuiloader", $url, $count = 2 ); - } - $include = "\n"; - if( $lib == "prototype" ) { // prototype must be included first - array_unshift( $includes, $include ); - } else { - array_push( $includes, $include ); - } - } - - $includes = implode( "\n", $includes ); - $suite = file_get_contents( "index.html" ); - echo str_replace( "", $includes, $suite ); - exit; - } -?> - - - - - Run jQuery Test Suite Polluted - - - - -

                jQuery Test Suite

                - -

                Choose other libraries to include

                - - - $data ) { - echo "
                $name"; - $i = 0; - foreach( $data[ "versions" ] as $ver ) { - $i++; - echo ""; - if( !($i % 4) ) echo "
                "; - } - echo "
                "; - } - ?> - - - - diff --git a/test/qunit b/test/qunit deleted file mode 160000 index d4f23f8a..00000000 --- a/test/qunit +++ /dev/null @@ -1 +0,0 @@ -Subproject commit d4f23f8a882d13b71768503e2db9fa33ef169ba0 diff --git a/test/readywait.html b/test/readywait.html deleted file mode 100644 index b4d8111e..00000000 --- a/test/readywait.html +++ /dev/null @@ -1,88 +0,0 @@ - - - - - - jQuery.holdReady Test - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

                - jQuery.holdReady Test -

                -

                - This is a test page for jQuery.readyWait and jQuery.holdReady, - see - #6781 - and - #8803. -

                -

                - Test for jQuery.holdReady, which can be used - by plugins and other scripts to indicate something - important to the page is still loading and needs - to block the DOM ready callbacks that are registered - with jQuery. -

                -

                - Script loaders are the most likely kind of script - to use jQuery.holdReady, but it could be used by - other things like a script that loads a CSS file - and wants to pause the DOM ready callbacks. -

                -

                - Expected Result: The text - It Worked! - appears below after about 2 seconds. -

                -

                - If there is an error in the console, - or the text does not show up, then the test failed. -

                -
                - - diff --git a/test/test.js b/test/test.js new file mode 100644 index 00000000..e76b795a --- /dev/null +++ b/test/test.js @@ -0,0 +1,41 @@ +load( "build/js/writeFile.js", "build/js/parse.js" ); + +function addParams(name, params) { + if(params.length > 0) { + name += "("; + for ( var i = 0; i < params.length; i++) { + name += params[i].type + ", "; + } + return name.substring(0, name.length - 2) + ")"; + } else { + return name + "()"; + } +} +function addTestWrapper(name, test) { + return 'test("' + name + '", function() {\n' + test + '\n});'; +} + +var dir = arguments[1]; +var jq = parse( read(arguments[0]) ); + +var testFile = []; + +String.prototype.decode = function() { + return this.replace(/</g, "<").replace(/>/g, ">").replace(/&/g, "&"); +}; + +for ( var i = 0; i < jq.length; i++ ) { + if ( jq[i].tests.length > 0 ) { + var method = jq[i]; + var name = addParams(method.name, method.params); + for(var j = 0; j < method.tests.length; j++) { + if(j > 0) { + name += "x"; + } + testFile[testFile.length] = addTestWrapper(name, method.tests[j].decode()) + "\n"; + } + } +} + +var indexFile = readFile( "build/test/index.html" ); +writeFile( dir + "/index.html", indexFile.replace( /{TESTS}/g, testFile.join("\n") ) ); diff --git a/test/unit/ajax.js b/test/unit/ajax.js index 33433922..15c4ed74 100644 --- a/test/unit/ajax.js +++ b/test/unit/ajax.js @@ -1,4 +1,4 @@ -module("ajax", { teardown: moduleTeardown }); +module("ajax"); // Safari 3 randomly crashes when running these tests, // but only in the full suite - you can run just the Ajax @@ -7,749 +7,74 @@ module("ajax", { teardown: moduleTeardown }); if ( !isLocal ) { -test("jQuery.ajax() - success callbacks", function() { +test("$.ajax() - success callbacks", function() { expect( 8 ); - - jQuery.ajaxSetup({ timeout: 0 }); - + + $.ajaxSetup({ timeout: 0 }); + stop(); - - jQuery("#foo").ajaxStart(function(){ - ok( true, "ajaxStart" ); - }).ajaxStop(function(){ - ok( true, "ajaxStop" ); - start(); - }).ajaxSend(function(){ - ok( true, "ajaxSend" ); - }).ajaxComplete(function(){ - ok( true, "ajaxComplete" ); - }).ajaxError(function(){ - ok( false, "ajaxError" ); - }).ajaxSuccess(function(){ - ok( true, "ajaxSuccess" ); - }); - - jQuery.ajax({ - url: url("data/name.html"), - beforeSend: function(){ ok(true, "beforeSend"); }, - success: function(){ ok(true, "success"); }, - error: function(){ ok(false, "error"); }, - complete: function(){ ok(true, "complete"); } - }); + + setTimeout(function(){ + $('#foo').ajaxStart(function(){ + ok( true, "ajaxStart" ); + }).ajaxStop(function(){ + ok( true, "ajaxStop" ); + start(); + }).ajaxSend(function(){ + ok( true, "ajaxSend" ); + }).ajaxComplete(function(){ + ok( true, "ajaxComplete" ); + }).ajaxError(function(){ + ok( false, "ajaxError" ); + }).ajaxSuccess(function(){ + ok( true, "ajaxSuccess" ); + }); + + $.ajax({ + url: url("data/name.html"), + beforeSend: function(){ ok(true, "beforeSend"); }, + success: function(){ ok(true, "success"); }, + error: function(){ ok(false, "error"); }, + complete: function(){ ok(true, "complete"); } + }); + }, 13); }); -test("jQuery.ajax() - success callbacks - (url, options) syntax", function() { - expect( 8 ); - - jQuery.ajaxSetup({ timeout: 0 }); - - stop(); - - setTimeout(function(){ - jQuery("#foo").ajaxStart(function(){ - ok( true, "ajaxStart" ); - }).ajaxStop(function(){ - ok( true, "ajaxStop" ); - start(); - }).ajaxSend(function(){ - ok( true, "ajaxSend" ); - }).ajaxComplete(function(){ - ok( true, "ajaxComplete" ); - }).ajaxError(function(){ - ok( false, "ajaxError" ); - }).ajaxSuccess(function(){ - ok( true, "ajaxSuccess" ); - }); - - jQuery.ajax( url("data/name.html") , { - beforeSend: function(){ ok(true, "beforeSend"); }, - success: function(){ ok(true, "success"); }, - error: function(){ ok(false, "error"); }, - complete: function(){ ok(true, "complete"); } - }); - }, 13); +test("$.ajax() - error callbacks", function() { + expect( 8 ); + stop(); + + $('#foo').ajaxStart(function(){ + ok( true, "ajaxStart" ); + }).ajaxStop(function(){ + ok( true, "ajaxStop" ); + start(); + }).ajaxSend(function(){ + ok( true, "ajaxSend" ); + }).ajaxComplete(function(){ + ok( true, "ajaxComplete" ); + }).ajaxError(function(){ + ok( true, "ajaxError" ); + }).ajaxSuccess(function(){ + ok( false, "ajaxSuccess" ); + }); + + $.ajaxSetup({ timeout: 500 }); + + $.ajax({ + url: url("data/name.php?wait=5"), + beforeSend: function(){ ok(true, "beforeSend"); }, + success: function(){ ok(false, "success"); }, + error: function(){ ok(true, "error"); }, + complete: function(){ ok(true, "complete"); } + }); }); -test("jQuery.ajax() - success callbacks (late binding)", function() { - expect( 8 ); - - jQuery.ajaxSetup({ timeout: 0 }); - - stop(); - - setTimeout(function(){ - jQuery("#foo").ajaxStart(function(){ - ok( true, "ajaxStart" ); - }).ajaxStop(function(){ - ok( true, "ajaxStop" ); - start(); - }).ajaxSend(function(){ - ok( true, "ajaxSend" ); - }).ajaxComplete(function(){ - ok( true, "ajaxComplete" ); - }).ajaxError(function(){ - ok( false, "ajaxError" ); - }).ajaxSuccess(function(){ - ok( true, "ajaxSuccess" ); - }); - - jQuery.ajax({ - url: url("data/name.html"), - beforeSend: function(){ ok(true, "beforeSend"); } - }) - .complete(function(){ ok(true, "complete"); }) - .success(function(){ ok(true, "success"); }) - .error(function(){ ok(false, "error"); }); - }, 13); -}); - -test("jQuery.ajax() - success callbacks (oncomplete binding)", function() { - expect( 8 ); - - jQuery.ajaxSetup({ timeout: 0 }); - - stop(); - - setTimeout(function(){ - jQuery("#foo").ajaxStart(function(){ - ok( true, "ajaxStart" ); - }).ajaxStop(function(){ - ok( true, "ajaxStop" ); - }).ajaxSend(function(){ - ok( true, "ajaxSend" ); - }).ajaxComplete(function(){ - ok( true, "ajaxComplete" ); - }).ajaxError(function(){ - ok( false, "ajaxError" ); - }).ajaxSuccess(function(){ - ok( true, "ajaxSuccess" ); - }); - - jQuery.ajax({ - url: url("data/name.html"), - beforeSend: function(){ ok(true, "beforeSend"); }, - complete: function(xhr) { - xhr - .complete(function(){ ok(true, "complete"); }) - .success(function(){ ok(true, "success"); }) - .error(function(){ ok(false, "error"); }) - .complete(function(){ start(); }); - } - }); - }, 13); -}); - -test("jQuery.ajax() - success callbacks (very late binding)", function() { - expect( 8 ); - - jQuery.ajaxSetup({ timeout: 0 }); - - stop(); - - setTimeout(function(){ - jQuery("#foo").ajaxStart(function(){ - ok( true, "ajaxStart" ); - }).ajaxStop(function(){ - ok( true, "ajaxStop" ); - }).ajaxSend(function(){ - ok( true, "ajaxSend" ); - }).ajaxComplete(function(){ - ok( true, "ajaxComplete" ); - }).ajaxError(function(){ - ok( false, "ajaxError" ); - }).ajaxSuccess(function(){ - ok( true, "ajaxSuccess" ); - }); - - jQuery.ajax({ - url: url("data/name.html"), - beforeSend: function(){ ok(true, "beforeSend"); }, - complete: function(xhr) { - setTimeout (function() { - xhr - .complete(function(){ ok(true, "complete"); }) - .success(function(){ ok(true, "success"); }) - .error(function(){ ok(false, "error"); }) - .complete(function(){ start(); }); - },100); - } - }); - }, 13); -}); - -test("jQuery.ajax() - success callbacks (order)", function() { - expect( 1 ); - - jQuery.ajaxSetup({ timeout: 0 }); - - stop(); - - var testString = ""; - - setTimeout(function(){ - jQuery.ajax({ - url: url("data/name.html"), - success: function( _1 , _2 , xhr ) { - xhr.success(function() { - xhr.success(function() { - testString += "E"; - }); - testString += "D"; - }); - testString += "A"; - }, - complete: function() { - strictEqual(testString, "ABCDE", "Proper order"); - start(); - } - }).success(function() { - testString += "B"; - }).success(function() { - testString += "C"; - }); - }, 13); -}); - -test("jQuery.ajax() - error callbacks", function() { - expect( 8 ); - stop(); - - jQuery("#foo").ajaxStart(function(){ - ok( true, "ajaxStart" ); - }).ajaxStop(function(){ - ok( true, "ajaxStop" ); - start(); - }).ajaxSend(function(){ - ok( true, "ajaxSend" ); - }).ajaxComplete(function(){ - ok( true, "ajaxComplete" ); - }).ajaxError(function(){ - ok( true, "ajaxError" ); - }).ajaxSuccess(function(){ - ok( false, "ajaxSuccess" ); - }); - - jQuery.ajaxSetup({ timeout: 500 }); - - jQuery.ajax({ - url: url("data/name.php?wait=5"), - beforeSend: function(){ ok(true, "beforeSend"); }, - success: function(){ ok(false, "success"); }, - error: function(){ ok(true, "error"); }, - complete: function(){ ok(true, "complete"); } - }); -}); - -test( "jQuery.ajax - multiple method signatures introduced in 1.5 ( #8107)", function() { - - expect( 4 ); - - stop(); - - jQuery.when( - jQuery.ajax().success(function() { ok( true, "With no arguments" ); }), - jQuery.ajax("data/name.html").success(function() { ok( true, "With only string URL argument" ); }), - jQuery.ajax("data/name.html", {} ).success(function() { ok( true, "With string URL param and map" ); }), - jQuery.ajax({ url: "data/name.html"} ).success(function() { ok( true, "With only map" ); }) - ).then( start, start ); - -}); - -test("jQuery.ajax() - textStatus and errorThrown values", function() { - - var nb = 2; - - expect( 2 * nb ); - stop(); - - function startN() { - if ( !( --nb ) ) { - start(); - } - } - - /* - Safari 3.x returns "OK" instead of "Not Found" - Safari 4.x doesn't have this issue so the test should be re-instated once - we drop support for 3.x - - jQuery.ajax({ - url: url("data/nonExistingURL"), - error: function( _ , textStatus , errorThrown ){ - strictEqual( textStatus, "error", "textStatus is 'error' for 404" ); - strictEqual( errorThrown, "Not Found", "errorThrown is 'Not Found' for 404"); - startN(); - } - }); - */ - - jQuery.ajax({ - url: url("data/name.php?wait=5"), - error: function( _ , textStatus , errorThrown ){ - strictEqual( textStatus, "abort", "textStatus is 'abort' for abort" ); - strictEqual( errorThrown, "abort", "errorThrown is 'abort' for abort"); - startN(); - } - }).abort(); - - jQuery.ajax({ - url: url("data/name.php?wait=5"), - error: function( _ , textStatus , errorThrown ){ - strictEqual( textStatus, "mystatus", "textStatus is 'mystatus' for abort('mystatus')" ); - strictEqual( errorThrown, "mystatus", "errorThrown is 'mystatus' for abort('mystatus')"); - startN(); - } - }).abort( "mystatus" ); -}); - -test("jQuery.ajax() - responseText on error", function() { - - expect( 1 ); - - stop(); - - jQuery.ajax({ - url: url("data/errorWithText.php"), - error: function(xhr) { - strictEqual( xhr.responseText , "plain text message" , "Test jqXHR.responseText is filled for HTTP errors" ); - }, - complete: function() { - start(); - } - }); -}); - -test(".ajax() - retry with jQuery.ajax( this )", function() { - - expect( 2 ); - - stop(); - - var firstTime = true, - previousUrl; - - jQuery.ajax({ - url: url("data/errorWithText.php"), - error: function() { - if ( firstTime ) { - firstTime = false; - jQuery.ajax( this ); - } else { - ok( true , "Test retrying with jQuery.ajax(this) works" ); - jQuery.ajax({ - url: url("data/errorWithText.php"), - data: { x: 1 }, - beforeSend: function() { - if ( !previousUrl ) { - previousUrl = this.url; - } else { - strictEqual( this.url , previousUrl, "url parameters are not re-appended" ); - start(); - return false; - } - }, - error: function() { - jQuery.ajax( this ); - } - }); - } - } - }); -}); - -test(".ajax() - headers" , function() { - - expect( 4 ); - - stop(); - - jQuery("#foo").ajaxSend(function( evt, xhr ) { - xhr.setRequestHeader( "ajax-send", "test" ); - }); - - var requestHeaders = { - siMPle: "value", - "SometHing-elsE": "other value", - OthEr: "something else" - }, - list = [], - i; - - for( i in requestHeaders ) { - list.push( i ); - } - list.push( "ajax-send" ); - - jQuery.ajax(url("data/headers.php?keys="+list.join( "_" ) ), { - - headers: requestHeaders, - success: function( data , _ , xhr ) { - var tmp = []; - for ( i in requestHeaders ) { - tmp.push( i , ": " , requestHeaders[ i ] , "\n" ); - } - tmp.push( "ajax-send: test\n" ); - tmp = tmp.join( "" ); - - strictEqual( data , tmp , "Headers were sent" ); - strictEqual( xhr.getResponseHeader( "Sample-Header" ) , "Hello World" , "Sample header received" ); - if ( jQuery.browser.mozilla ) { - ok( true, "Firefox doesn't support empty headers" ); - } else { - strictEqual( xhr.getResponseHeader( "Empty-Header" ) , "" , "Empty header received" ); - } - strictEqual( xhr.getResponseHeader( "Sample-Header2" ) , "Hello World 2" , "Second sample header received" ); - }, - error: function(){ ok(false, "error"); } - - }).then( start, start ); - -}); - -test(".ajax() - Accept header" , function() { - - expect( 1 ); - - stop(); - - jQuery.ajax(url("data/headers.php?keys=accept"), { - headers: { - Accept: "very wrong accept value" - }, - beforeSend: function( xhr ) { - xhr.setRequestHeader( "Accept", "*/*" ); - }, - success: function( data ) { - strictEqual( data , "accept: */*\n" , "Test Accept header is set to last value provided" ); - start(); - }, - error: function(){ ok(false, "error"); } - }); - -}); - -test(".ajax() - contentType" , function() { - - expect( 2 ); - - stop(); - - var count = 2; - - function restart() { - if ( ! --count ) { - start(); - } - } - - jQuery.ajax(url("data/headers.php?keys=content-type" ), { - contentType: "test", - success: function( data ) { - strictEqual( data , "content-type: test\n" , "Test content-type is sent when options.contentType is set" ); - }, - complete: function() { - restart(); - } - }); - - jQuery.ajax(url("data/headers.php?keys=content-type" ), { - contentType: false, - success: function( data ) { - strictEqual( data , "content-type: \n" , "Test content-type is not sent when options.contentType===false" ); - }, - complete: function() { - restart(); - } - }); - -}); - -test(".ajax() - protocol-less urls", function() { - expect(1); - - jQuery.ajax({ - url: "//somedomain.com", - beforeSend: function( xhr, settings ) { - equals(settings.url, location.protocol + "//somedomain.com", "Make sure that the protocol is added."); - return false; - } - }); -}); - -test(".ajax() - hash", function() { - expect(3); - - jQuery.ajax({ - url: "data/name.html#foo", - beforeSend: function( xhr, settings ) { - equals(settings.url, "data/name.html", "Make sure that the URL is trimmed."); - return false; - } - }); - - jQuery.ajax({ - url: "data/name.html?abc#foo", - beforeSend: function( xhr, settings ) { - equals(settings.url, "data/name.html?abc", "Make sure that the URL is trimmed."); - return false; - } - }); - - jQuery.ajax({ - url: "data/name.html?abc#foo", - data: { "test": 123 }, - beforeSend: function( xhr, settings ) { - equals(settings.url, "data/name.html?abc&test=123", "Make sure that the URL is trimmed."); - return false; - } - }); -}); - -test("jQuery ajax - cross-domain detection", function() { - - expect( 6 ); - - var loc = document.location, - otherPort = loc.port === 666 ? 667 : 666, - otherProtocol = loc.protocol === "http:" ? "https:" : "http:"; - - jQuery.ajax({ - dataType: "jsonp", - url: otherProtocol + "//" + loc.host, - beforeSend: function( _ , s ) { - ok( s.crossDomain , "Test different protocols are detected as cross-domain" ); - return false; - } - }); - - jQuery.ajax({ - dataType: "jsonp", - url: "app:/path", - beforeSend: function( _ , s ) { - ok( s.crossDomain , "Adobe AIR app:/ URL detected as cross-domain" ); - return false; - } - }); - - jQuery.ajax({ - dataType: "jsonp", - url: loc.protocol + "//somewebsitethatdoesnotexist-656329477541.com:" + ( loc.port || 80 ), - beforeSend: function( _ , s ) { - ok( s.crossDomain , "Test different hostnames are detected as cross-domain" ); - return false; - } - }); - - jQuery.ajax({ - dataType: "jsonp", - url: loc.protocol + "//" + loc.hostname + ":" + otherPort, - beforeSend: function( _ , s ) { - ok( s.crossDomain , "Test different ports are detected as cross-domain" ); - return false; - } - }); - - jQuery.ajax({ - dataType: "jsonp", - url: "about:blank", - beforeSend: function( _ , s ) { - ok( s.crossDomain , "Test about:blank is detected as cross-domain" ); - return false; - } - }); - - jQuery.ajax({ - dataType: "jsonp", - url: loc.protocol + "//" + loc.host, - crossDomain: true, - beforeSend: function( _ , s ) { - ok( s.crossDomain , "Test forced crossDomain is detected as cross-domain" ); - return false; - } - }); - -}); - -test(".load() - 404 error callbacks", function() { - expect( 6 ); - stop(); - - jQuery("#foo").ajaxStart(function(){ - ok( true, "ajaxStart" ); - }).ajaxStop(function(){ - ok( true, "ajaxStop" ); - start(); - }).ajaxSend(function(){ - ok( true, "ajaxSend" ); - }).ajaxComplete(function(){ - ok( true, "ajaxComplete" ); - }).ajaxError(function(){ - ok( true, "ajaxError" ); - }).ajaxSuccess(function(){ - ok( false, "ajaxSuccess" ); - }); - - jQuery("
                ").load("data/404.html", function(){ - ok(true, "complete"); - }); -}); - -test("jQuery.ajax() - abort", function() { - expect( 8 ); - stop(); - - jQuery("#foo").ajaxStart(function(){ - ok( true, "ajaxStart" ); - }).ajaxStop(function(){ - ok( true, "ajaxStop" ); - start(); - }).ajaxSend(function(){ - ok( true, "ajaxSend" ); - }).ajaxComplete(function(){ - ok( true, "ajaxComplete" ); - }); - - var xhr = jQuery.ajax({ - url: url("data/name.php?wait=5"), - beforeSend: function(){ ok(true, "beforeSend"); }, - complete: function(){ ok(true, "complete"); } - }); - - equals( xhr.readyState, 1, "XHR readyState indicates successful dispatch" ); - - xhr.abort(); - equals( xhr.readyState, 0, "XHR readyState indicates successful abortion" ); -}); - -test("Ajax events with context", function() { - expect(14); - - stop(); - var context = document.createElement("div"); - - function event(e){ - equals( this, context, e.type ); - } - - function callback(msg){ - return function(){ - equals( this, context, "context is preserved on callback " + msg ); - }; - } - - function nocallback(msg){ - return function(){ - equals( typeof this.url, "string", "context is settings on callback " + msg ); - }; - } - - jQuery("#foo").add(context) - .ajaxSend(event) - .ajaxComplete(event) - .ajaxError(event) - .ajaxSuccess(event); - - jQuery.ajax({ - url: url("data/name.html"), - beforeSend: callback("beforeSend"), - success: callback("success"), - error: callback("error"), - complete:function(){ - callback("complete").call(this); - - jQuery.ajax({ - url: url("data/404.html"), - context: context, - beforeSend: callback("beforeSend"), - error: callback("error"), - complete: function(){ - callback("complete").call(this); - - jQuery("#foo").add(context).unbind(); - - jQuery.ajax({ - url: url("data/404.html"), - beforeSend: nocallback("beforeSend"), - error: nocallback("error"), - complete: function(){ - nocallback("complete").call(this); - start(); - } - }); - } - }); - }, - context:context - }); -}); - -test("jQuery.ajax context modification", function() { - expect(1); - - stop(); - - var obj = {}; - - jQuery.ajax({ - url: url("data/name.html"), - context: obj, - beforeSend: function(){ - this.test = "foo"; - }, - complete: function() { - start(); - } - }); - - equals( obj.test, "foo", "Make sure the original object is maintained." ); -}); - -test("jQuery.ajax context modification through ajaxSetup", function() { - expect(4); - - stop(); - - var obj = {}; - - jQuery.ajaxSetup({ - context: obj - }); - - strictEqual( jQuery.ajaxSettings.context, obj, "Make sure the context is properly set in ajaxSettings." ); - - jQuery.ajax({ - url: url("data/name.html"), - complete: function() { - strictEqual( this, obj, "Make sure the original object is maintained." ); - jQuery.ajax({ - url: url("data/name.html"), - context: {}, - complete: function() { - ok( this !== obj, "Make sure overidding context is possible." ); - jQuery.ajaxSetup({ - context: false - }); - jQuery.ajax({ - url: url("data/name.html"), - beforeSend: function(){ - this.test = "foo2"; - }, - complete: function() { - ok( this !== obj, "Make sure unsetting context is possible." ); - start(); - } - }); - } - }); - } - }); -}); - -test("jQuery.ajax() - disabled globals", function() { +test("$.ajax() - disabled globals", function() { expect( 3 ); stop(); - - jQuery("#foo").ajaxStart(function(){ + + $('#foo').ajaxStart(function(){ ok( false, "ajaxStart" ); }).ajaxStop(function(){ ok( false, "ajaxStop" ); @@ -762,8 +87,8 @@ test("jQuery.ajax() - disabled globals", function() { }).ajaxSuccess(function(){ ok( false, "ajaxSuccess" ); }); - - jQuery.ajax({ + + $.ajax({ global: false, url: url("data/name.html"), beforeSend: function(){ ok(true, "beforeSend"); }, @@ -772,80 +97,35 @@ test("jQuery.ajax() - disabled globals", function() { complete: function(){ ok(true, "complete"); setTimeout(function(){ start(); }, 13); - } + } }); }); -test("jQuery.ajax - xml: non-namespace elements inside namespaced elements", function() { +test("$.ajax - xml: non-namespace elements inside namespaced elements", function() { expect(3); stop(); - jQuery.ajax({ + $.ajax({ url: url("data/with_fries.xml"), dataType: "xml", success: function(resp) { - equals( jQuery("properties", resp).length, 1, "properties in responseXML" ); - equals( jQuery("jsconf", resp).length, 1, "jsconf in responseXML" ); - equals( jQuery("thing", resp).length, 2, "things in responseXML" ); - start(); + equals( $("properties", resp).length, 1, 'properties in responseXML' ); + equals( $("jsconf", resp).length, 1, 'jsconf in responseXML' ); + equals( $("thing", resp).length, 2, 'things in responseXML' ); + start(); } }); }); -test("jQuery.ajax - xml: non-namespace elements inside namespaced elements (over JSONP)", function() { - expect(3); - stop(); - jQuery.ajax({ - url: url("data/with_fries_over_jsonp.php"), - dataType: "jsonp xml", - success: function(resp) { - equals( jQuery("properties", resp).length, 1, "properties in responseXML" ); - equals( jQuery("jsconf", resp).length, 1, "jsconf in responseXML" ); - equals( jQuery("thing", resp).length, 2, "things in responseXML" ); - start(); - }, - error: function(_1,_2,error) { - ok( false, error ); - start(); - } - }); -}); - -test("jQuery.ajax - HEAD requests", function() { - expect(2); - - stop(); - jQuery.ajax({ - url: url("data/name.html"), - type: "HEAD", - success: function(data, status, xhr){ - var h = xhr.getAllResponseHeaders(); - ok( /Date/i.test(h), "No Date in HEAD response" ); - - jQuery.ajax({ - url: url("data/name.html"), - data: { whip_it: "good" }, - type: "HEAD", - success: function(data, status, xhr){ - var h = xhr.getAllResponseHeaders(); - ok( /Date/i.test(h), "No Date in HEAD response with data" ); - start(); - } - }); - } - }); - -}); - -test("jQuery.ajax - beforeSend", function() { +test("$.ajax - beforeSend", function() { expect(1); stop(); - + var check = false; - - jQuery.ajaxSetup({ timeout: 0 }); - - jQuery.ajax({ - url: url("data/name.html"), + + $.ajaxSetup({ timeout: 0 }); + + $.ajax({ + url: url("data/name.html"), beforeSend: function(xml) { check = true; }, @@ -856,235 +136,131 @@ test("jQuery.ajax - beforeSend", function() { }); }); -test("jQuery.ajax - beforeSend, cancel request (#2688)", function() { - expect(2); - var request = jQuery.ajax({ - url: url("data/name.html"), - beforeSend: function() { - ok( true, "beforeSend got called, canceling" ); - return false; - }, - success: function() { - ok( false, "request didn't get canceled" ); - }, - complete: function() { - ok( false, "request didn't get canceled" ); - }, - error: function() { - ok( false, "request didn't get canceled" ); - } - }); - ok( request === false, "canceled request must return false instead of XMLHttpRequest instance" ); -}); +var foobar; -test("jQuery.ajax - beforeSend, cancel request manually", function() { - expect(2); - var request = jQuery.ajax({ - url: url("data/name.html"), - beforeSend: function(xhr) { - ok( true, "beforeSend got called, canceling" ); - xhr.abort(); - }, - success: function() { - ok( false, "request didn't get canceled" ); - }, - complete: function() { - ok( false, "request didn't get canceled" ); - }, - error: function() { - ok( false, "request didn't get canceled" ); - } - }); - ok( request === false, "canceled request must return false instead of XMLHttpRequest instance" ); -}); - -window.foobar = null; -window.testFoo = undefined; - -test("jQuery.ajax - dataType html", function() { +test("$.ajax - dataType html", function() { expect(5); stop(); + + foobar = null; + testFoo = undefined; var verifyEvaluation = function() { - equals( testFoo, "foo", "Check if script was evaluated for datatype html" ); - equals( foobar, "bar", "Check if script src was evaluated for datatype html" ); - - start(); + ok( testFoo == "foo", 'Check if script was evaluated for datatype html' ); + ok( foobar == "bar", 'Check if script src was evaluated for datatype html' ); + start(); }; - jQuery.ajax({ + $.ajax({ dataType: "html", url: url("data/test.html"), success: function(data) { - jQuery("#ap").html(data); - ok( data.match(/^html text/), "Check content for datatype html" ); - setTimeout(verifyEvaluation, 600); + $("#ap").html(data); + ok( data.match(/^html text/), 'Check content for datatype html' ); + setTimeout(verifyEvaluation, 600); } }); }); test("serialize()", function() { - expect(5); - - // Add html5 elements only for serialize because selector can't yet find them on non-html5 browsers - jQuery("#search").after( - ""+ - "" - ); - - equals( jQuery("#form").serialize(), - "action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&search=search&email=dave%40jquery.com&number=43&select1=&select2=3&select3=1&select3=2&select5=3", - "Check form serialization as query string"); - - equals( jQuery("#form :input").serialize(), - "action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&search=search&email=dave%40jquery.com&number=43&select1=&select2=3&select3=1&select3=2&select5=3", - "Check input serialization as query string"); - - equals( jQuery("#testForm").serialize(), - "T3=%3F%0D%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=", - "Check form serialization as query string"); - - equals( jQuery("#testForm :input").serialize(), - "T3=%3F%0D%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=", - "Check input serialization as query string"); - - equals( jQuery("#form, #testForm").serialize(), - "action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&search=search&email=dave%40jquery.com&number=43&select1=&select2=3&select3=1&select3=2&select5=3&T3=%3F%0D%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=", - "Multiple form serialization as query string"); - - /* Temporarily disabled. Opera 10 has problems with form serialization. - equals( jQuery("#form, #testForm :input").serialize(), - "action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&search=search&email=dave%40jquery.com&number=43&select1=&select2=3&select3=1&select3=2&T3=%3F%0D%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=", - "Mixed form/input serialization as query string"); - */ - jQuery("#html5email, #html5number").remove(); + expect(6); + + equals( $('#form').serialize(), + "action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&select1=&select2=3&select3=1&select3=2", + 'Check form serialization as query string'); + + equals( $('#form :input').serialize(), + "action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&select1=&select2=3&select3=1&select3=2", + 'Check input serialization as query string'); + + equals( $('#testForm').serialize(), + 'T3=%3F%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=', + 'Check form serialization as query string'); + + equals( $('#testForm :input').serialize(), + 'T3=%3F%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=', + 'Check input serialization as query string'); + + equals( $('#form, #testForm').serialize(), + "action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&select1=&select2=3&select3=1&select3=2&T3=%3F%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=", + 'Multiple form serialization as query string'); + + equals( $('#form, #testForm :input').serialize(), + "action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&select1=&select2=3&select3=1&select3=2&T3=%3F%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=", + 'Mixed form/input serialization as query string'); }); -test("jQuery.param()", function() { - expect(21); - - equals( !jQuery.ajaxSettings.traditional, true, "traditional flag, falsy by default" ); - +test("$.param()", function() { + expect(4); var params = {foo:"bar", baz:42, quux:"All your base are belong to us"}; - equals( jQuery.param(params), "foo=bar&baz=42&quux=All+your+base+are+belong+to+us", "simple" ); - + equals( $.param(params), "foo=bar&baz=42&quux=All+your+base+are+belong+to+us", "simple" ); + params = {someName: [1, 2, 3], regularThing: "blah" }; - equals( jQuery.param(params), "someName%5B%5D=1&someName%5B%5D=2&someName%5B%5D=3®ularThing=blah", "with array" ); - - params = {foo: ["a", "b", "c"]}; - equals( jQuery.param(params), "foo%5B%5D=a&foo%5B%5D=b&foo%5B%5D=c", "with array of strings" ); - - params = {foo: ["baz", 42, "All your base are belong to us"] }; - equals( jQuery.param(params), "foo%5B%5D=baz&foo%5B%5D=42&foo%5B%5D=All+your+base+are+belong+to+us", "more array" ); - - params = {foo: { bar: "baz", beep: 42, quux: "All your base are belong to us" } }; - equals( jQuery.param(params), "foo%5Bbar%5D=baz&foo%5Bbeep%5D=42&foo%5Bquux%5D=All+your+base+are+belong+to+us", "even more arrays" ); - - params = { a:[1,2], b:{ c:3, d:[4,5], e:{ x:[6], y:7, z:[8,9] }, f:true, g:false, h:undefined }, i:[10,11], j:true, k:false, l:[undefined,0], m:"cowboy hat?" }; - equals( decodeURIComponent( jQuery.param(params) ), "a[]=1&a[]=2&b[c]=3&b[d][]=4&b[d][]=5&b[e][x][]=6&b[e][y]=7&b[e][z][]=8&b[e][z][]=9&b[f]=true&b[g]=false&b[h]=undefined&i[]=10&i[]=11&j=true&k=false&l[]=undefined&l[]=0&m=cowboy+hat?", "huge structure" ); - - params = { a: [ 0, [ 1, 2 ], [ 3, [ 4, 5 ], [ 6 ] ], { b: [ 7, [ 8, 9 ], [ { c: 10, d: 11 } ], [ [ 12 ] ], [ [ [ 13 ] ] ], { e: { f: { g: [ 14, [ 15 ] ] } } }, 16 ] }, 17 ] }; - equals( decodeURIComponent( jQuery.param(params) ), "a[]=0&a[1][]=1&a[1][]=2&a[2][]=3&a[2][1][]=4&a[2][1][]=5&a[2][2][]=6&a[3][b][]=7&a[3][b][1][]=8&a[3][b][1][]=9&a[3][b][2][0][c]=10&a[3][b][2][0][d]=11&a[3][b][3][0][]=12&a[3][b][4][0][0][]=13&a[3][b][5][e][f][g][]=14&a[3][b][5][e][f][g][1][]=15&a[3][b][]=16&a[]=17", "nested arrays" ); - - params = { a:[1,2], b:{ c:3, d:[4,5], e:{ x:[6], y:7, z:[8,9] }, f:true, g:false, h:undefined }, i:[10,11], j:true, k:false, l:[undefined,0], m:"cowboy hat?" }; - equals( jQuery.param(params,true), "a=1&a=2&b=%5Bobject+Object%5D&i=10&i=11&j=true&k=false&l=undefined&l=0&m=cowboy+hat%3F", "huge structure, forced traditional" ); - - equals( decodeURIComponent( jQuery.param({ a: [1,2,3], "b[]": [4,5,6], "c[d]": [7,8,9], e: { f: [10], g: [11,12], h: 13 } }) ), "a[]=1&a[]=2&a[]=3&b[]=4&b[]=5&b[]=6&c[d][]=7&c[d][]=8&c[d][]=9&e[f][]=10&e[g][]=11&e[g][]=12&e[h]=13", "Make sure params are not double-encoded." ); - - // #7945 - equals( jQuery.param({"jquery": "1.4.2"}), "jquery=1.4.2", "Check that object with a jQuery property get serialized correctly" ); - - jQuery.ajaxSetup({ traditional: true }); - - var params = {foo:"bar", baz:42, quux:"All your base are belong to us"}; - equals( jQuery.param(params), "foo=bar&baz=42&quux=All+your+base+are+belong+to+us", "simple" ); - - params = {someName: [1, 2, 3], regularThing: "blah" }; - equals( jQuery.param(params), "someName=1&someName=2&someName=3®ularThing=blah", "with array" ); - - params = {foo: ["a", "b", "c"]}; - equals( jQuery.param(params), "foo=a&foo=b&foo=c", "with array of strings" ); - + equals( $.param(params), "someName=1&someName=2&someName=3®ularThing=blah", "with array" ); + params = {"foo[]":["baz", 42, "All your base are belong to us"]}; - equals( jQuery.param(params), "foo%5B%5D=baz&foo%5B%5D=42&foo%5B%5D=All+your+base+are+belong+to+us", "more array" ); - + equals( $.param(params), "foo%5B%5D=baz&foo%5B%5D=42&foo%5B%5D=All+your+base+are+belong+to+us", "more array" ); + params = {"foo[bar]":"baz", "foo[beep]":42, "foo[quux]":"All your base are belong to us"}; - equals( jQuery.param(params), "foo%5Bbar%5D=baz&foo%5Bbeep%5D=42&foo%5Bquux%5D=All+your+base+are+belong+to+us", "even more arrays" ); - - params = { a:[1,2], b:{ c:3, d:[4,5], e:{ x:[6], y:7, z:[8,9] }, f:true, g:false, h:undefined }, i:[10,11], j:true, k:false, l:[undefined,0], m:"cowboy hat?" }; - equals( jQuery.param(params), "a=1&a=2&b=%5Bobject+Object%5D&i=10&i=11&j=true&k=false&l=undefined&l=0&m=cowboy+hat%3F", "huge structure" ); - - params = { a: [ 0, [ 1, 2 ], [ 3, [ 4, 5 ], [ 6 ] ], { b: [ 7, [ 8, 9 ], [ { c: 10, d: 11 } ], [ [ 12 ] ], [ [ [ 13 ] ] ], { e: { f: { g: [ 14, [ 15 ] ] } } }, 16 ] }, 17 ] }; - equals( jQuery.param(params), "a=0&a=1%2C2&a=3%2C4%2C5%2C6&a=%5Bobject+Object%5D&a=17", "nested arrays (not possible when jQuery.param.traditional == true)" ); - - params = { a:[1,2], b:{ c:3, d:[4,5], e:{ x:[6], y:7, z:[8,9] }, f:true, g:false, h:undefined }, i:[10,11], j:true, k:false, l:[undefined,0], m:"cowboy hat?" }; - equals( decodeURIComponent( jQuery.param(params,false) ), "a[]=1&a[]=2&b[c]=3&b[d][]=4&b[d][]=5&b[e][x][]=6&b[e][y]=7&b[e][z][]=8&b[e][z][]=9&b[f]=true&b[g]=false&b[h]=undefined&i[]=10&i[]=11&j=true&k=false&l[]=undefined&l[]=0&m=cowboy+hat?", "huge structure, forced not traditional" ); - - params = { param1: null }; - equals( jQuery.param(params,false), "param1=null", "Make sure that null params aren't traversed." ); - - params = {"test": {"length": 3, "foo": "bar"} }; - equals( jQuery.param( params, false ), "test%5Blength%5D=3&test%5Bfoo%5D=bar", "Sub-object with a length property" ); + equals( $.param(params), "foo%5Bbar%5D=baz&foo%5Bbeep%5D=42&foo%5Bquux%5D=All+your+base+are+belong+to+us", "even more arrays" ); }); test("synchronous request", function() { expect(1); - ok( /^{ "data"/.test( jQuery.ajax({url: url("data/json_obj.js"), dataType: "text", async: false}).responseText ), "check returned text" ); + ok( /^{ "data"/.test( $.ajax({url: url("data/json_obj.js"), async: false}).responseText ), "check returned text" ); }); test("synchronous request with callbacks", function() { expect(2); var result; - jQuery.ajax({url: url("data/json_obj.js"), async: false, dataType: "text", success: function(data) { ok(true, "sucess callback executed"); result = data; } }); + $.ajax({url: url("data/json_obj.js"), async: false, success: function(data) { ok(true, "sucess callback executed"); result = data; } }); ok( /^{ "data"/.test( result ), "check returned text" ); }); test("pass-through request object", function() { expect(8); - stop(); - + stop(true); + var target = "data/name.html"; var successCount = 0; var errorCount = 0; - var errorEx = ""; + var errorEx = ""; var success = function() { successCount++; }; - jQuery("#foo").ajaxError(function (e, xml, s, ex) { + $("#foo").ajaxError(function (e, xml, s, ex) { errorCount++; - errorEx += ": " + xml.status; + errorEx += ": " + xml.status; }); - jQuery("#foo").one("ajaxStop", function () { + $("#foo").one('ajaxStop', function () { equals(successCount, 5, "Check all ajax calls successful"); equals(errorCount, 0, "Check no ajax errors (status" + errorEx + ")"); - jQuery("#foo").unbind("ajaxError"); - + $("#foo").unbind('ajaxError'); start(); }); - - ok( jQuery.get(url(target), success), "get" ); - ok( jQuery.post(url(target), success), "post" ); - ok( jQuery.getScript(url("data/test.js"), success), "script" ); - ok( jQuery.getJSON(url("data/json_obj.js"), success), "json" ); - ok( jQuery.ajax({url: url(target), success: success}), "generic" ); + + ok( $.get(url(target), success), "get" ); + ok( $.post(url(target), success), "post" ); + ok( $.getScript(url("data/test.js"), success), "script" ); + ok( $.getJSON(url("data/json_obj.js"), success), "json" ); + ok( $.ajax({url: url(target), success: success}), "generic" ); }); test("ajax cache", function () { expect(18); - stop(); - + var count = 0; - jQuery("#firstp").bind("ajaxSuccess", function (e, xml, s) { + $("#firstp").bind("ajaxSuccess", function (e, xml, s) { var re = /_=(.*?)(&|$)/g; - var oldOne = null; + var oldOne = null; for (var i = 0; i < 6; i++) { - var ret = re.exec(s.url); + var ret = re.exec(s.url); if (!ret) { break; } - oldOne = ret[1]; + oldOne = ret[1]; } equals(i, 1, "Test to make sure only one 'no-cache' parameter is there"); ok(oldOne != "tobereplaced555", "Test to be sure parameter (if it was there) was replaced"); @@ -1092,52 +268,51 @@ test("ajax cache", function () { start(); }); - ok( jQuery.ajax({url: "data/text.php", cache:false}), "test with no parameters" ); - ok( jQuery.ajax({url: "data/text.php?pizza=true", cache:false}), "test with 1 parameter" ); - ok( jQuery.ajax({url: "data/text.php?_=tobereplaced555", cache:false}), "test with _= parameter" ); - ok( jQuery.ajax({url: "data/text.php?pizza=true&_=tobereplaced555", cache:false}), "test with 1 parameter plus _= one" ); - ok( jQuery.ajax({url: "data/text.php?_=tobereplaced555&tv=false", cache:false}), "test with 1 parameter plus _= one before it" ); - ok( jQuery.ajax({url: "data/text.php?name=David&_=tobereplaced555&washere=true", cache:false}), "test with 2 parameters surrounding _= one" ); + ok( $.ajax({url: "data/text.php", cache:false}), "test with no parameters" ); + ok( $.ajax({url: "data/text.php?pizza=true", cache:false}), "test with 1 parameter" ); + ok( $.ajax({url: "data/text.php?_=tobereplaced555", cache:false}), "test with _= parameter" ); + ok( $.ajax({url: "data/text.php?pizza=true&_=tobereplaced555", cache:false}), "test with 1 parameter plus _= one" ); + ok( $.ajax({url: "data/text.php?_=tobereplaced555&tv=false", cache:false}), "test with 1 parameter plus _= one before it" ); + ok( $.ajax({url: "data/text.php?name=David&_=tobereplaced555&washere=true", cache:false}), "test with 2 parameters surrounding _= one" ); }); -/* - * Test disabled. - * The assertions expect that the passed-in object will be modified, - * which shouldn't be the case. Fixes #5439. test("global ajaxSettings", function() { - expect(2); + expect(3); var tmp = jQuery.extend({}, jQuery.ajaxSettings); - var orig = { url: "data/with_fries.xml" }; + var orig = { url: "data/with_fries.xml", data: null }; var t; - jQuery.ajaxSetup({ data: {foo: "bar", bar: "BAR"} }); + $.ajaxSetup({ data: {foo: 'bar', bar: 'BAR'} }); - t = jQuery.extend({}, orig); + t = jQuery.extend({}, orig); + $.ajax(t); + ok( t.url.indexOf('foo') > -1 && t.url.indexOf('bar') > -1, "Check extending null" ); + + t = jQuery.extend({}, orig); t.data = {}; - jQuery.ajax(t); - ok( t.url.indexOf("foo") > -1 && t.url.indexOf("bar") > -1, "Check extending {}" ); - - t = jQuery.extend({}, orig); - t.data = { zoo: "a", ping: "b" }; - jQuery.ajax(t); - ok( t.url.indexOf("ping") > -1 && t.url.indexOf("zoo") > -1 && t.url.indexOf("foo") > -1 && t.url.indexOf("bar") > -1, "Check extending { zoo: "a", ping: "b" }" ); + $.ajax(t); + ok( t.url.indexOf('foo') > -1 && t.url.indexOf('bar') > -1, "Check extending {}" ); + t = jQuery.extend({}, orig); + t.data = { zoo: 'a', ping: 'b' }; + $.ajax(t); + ok( t.url.indexOf('ping') > -1 && t.url.indexOf('zoo') > -1 && t.url.indexOf('foo') > -1 && t.url.indexOf('bar') > -1, "Check extending { zoo: 'a', ping: 'b' }" ); + jQuery.ajaxSettings = tmp; }); -*/ test("load(String)", function() { expect(1); - stop(); // check if load can be called with only url - jQuery("#first").load("data/name.html", start); + stop(true); // check if load can be called with only url + $('#first').load("data/name.html", start); }); test("load('url selector')", function() { expect(1); - stop(); // check if load can be called with only url - jQuery("#first").load("data/test3.html div.user", function(){ - equals( jQuery(this).children("div").length, 2, "Verify that specific elements were injected" ); + stop(true); // check if load can be called with only url + $('#first').load("data/test3.html div.user", function(){ + equals( $(this).children("div").length, 2, "Verify that specific elements were injected" ); start(); }); }); @@ -1145,21 +320,21 @@ test("load('url selector')", function() { test("load(String, Function) with ajaxSetup on dataType json, see #2046", function() { expect(1); stop(); - jQuery.ajaxSetup({ dataType: "json" }); - jQuery("#first").ajaxComplete(function (e, xml, s) { + $.ajaxSetup({ dataType: "json" }); + $("#first").ajaxComplete(function (e, xml, s) { equals( s.dataType, "html", "Verify the load() dataType was html" ); - jQuery("#first").unbind("ajaxComplete"); - jQuery.ajaxSetup({ dataType: "" }); + $("#first").unbind("ajaxComplete"); + $.ajaxSetup({ dataType: "" }); start(); }); - jQuery("#first").load("data/test3.html"); + $('#first').load("data/test3.html"); }); test("load(String, Function) - simple: inject text into DOM", function() { expect(2); stop(); - jQuery("#first").load(url("data/name.html"), function() { - ok( /^ERROR/.test(jQuery("#first").text()), "Check if content was injected into the DOM" ); + $('#first').load(url("data/name.html"), function() { + ok( /^ERROR/.test($('#first').text()), 'Check if content was injected into the DOM' ); start(); }); }); @@ -1167,17 +342,17 @@ test("load(String, Function) - simple: inject text into DOM", function() { test("load(String, Function) - check scripts", function() { expect(7); stop(); - + window.testFoo = undefined; + window.foobar = null; var verifyEvaluation = function() { - equals( foobar, "bar", "Check if script src was evaluated after load" ); - equals( jQuery("#ap").html(), "bar", "Check if script evaluation has modified DOM"); - - start(); + equals( foobar, "bar", 'Check if script src was evaluated after load' ); + equals( $('#ap').html(), 'bar', 'Check if script evaluation has modified DOM'); + start(); }; - jQuery("#first").load(url("data/test.html"), function() { - ok( jQuery("#first").html().match(/^html text/), "Check content after loading html" ); - equals( jQuery("#foo").html(), "foo", "Check if script evaluation has modified DOM"); - equals( testFoo, "foo", "Check if script was evaluated after load" ); + $('#first').load(url('data/test.html'), function() { + ok( $('#first').html().match(/^html text/), 'Check content after loading html' ); + equals( $('#foo').html(), 'foo', 'Check if script evaluation has modified DOM'); + equals( testFoo, "foo", 'Check if script was evaluated after load' ); setTimeout(verifyEvaluation, 600); }); }); @@ -1185,367 +360,225 @@ test("load(String, Function) - check scripts", function() { test("load(String, Function) - check file with only a script tag", function() { expect(3); stop(); - - jQuery("#first").load(url("data/test2.html"), function() { - equals( jQuery("#foo").html(), "foo", "Check if script evaluation has modified DOM"); - equals( testFoo, "foo", "Check if script was evaluated after load" ); - + testFoo = undefined; + $('#first').load(url('data/test2.html'), function() { + ok( $('#foo').html() == 'foo', 'Check if script evaluation has modified DOM'); + ok( testFoo == "foo", 'Check if script was evaluated after load' ); start(); }); }); -test("load(String, Function) - dataFilter in ajaxSettings", function() { +test("$.get(String, Hash, Function) - parse xml and use text() on nodes", function() { expect(2); stop(); - jQuery.ajaxSetup({ dataFilter: function() { return "Hello World"; } }); - var div = jQuery("
                ").load(url("data/name.html"), function(responseText) { - strictEqual( div.html(), "Hello World" , "Test div was filled with filtered data" ); - strictEqual( responseText, "Hello World" , "Test callback receives filtered data" ); - jQuery.ajaxSetup({ dataFilter: 0 }); - start(); - }); -}); - -test("load(String, Object, Function)", function() { - expect(2); - stop(); - - jQuery("
                ").load(url("data/params_html.php"), { foo: 3, bar: "ok" }, function() { - var $post = jQuery(this).find("#post"); - equals( $post.find("#foo").text(), "3", "Check if a hash of data is passed correctly"); - equals( $post.find("#bar").text(), "ok", "Check if a hash of data is passed correctly"); - start(); - }); -}); - -test("load(String, String, Function)", function() { - expect(2); - stop(); - - jQuery("
                ").load(url("data/params_html.php"), "foo=3&bar=ok", function() { - var $get = jQuery(this).find("#get"); - equals( $get.find("#foo").text(), "3", "Check if a string of data is passed correctly"); - equals( $get.find("#bar").text(), "ok", "Check if a of data is passed correctly"); - start(); - }); -}); - -test("jQuery.get(String, Function) - data in ajaxSettings (#8277)", function() { - expect(1); - stop(); - jQuery.ajaxSetup({ - data: "helloworld" - }); - jQuery.get(url("data/echoQuery.php"), function(data) { - ok( /helloworld$/.test( data ), "Data from ajaxSettings was used"); - jQuery.ajaxSetup({ - data: null - }); - start(); - }); -}); - -test("jQuery.get(String, Hash, Function) - parse xml and use text() on nodes", function() { - expect(2); - stop(); - jQuery.get(url("data/dashboard.xml"), function(xml) { + $.get(url('data/dashboard.xml'), function(xml) { var content = []; - jQuery("tab", xml).each(function() { - content.push(jQuery(this).text()); + $('tab', xml).each(function() { + content.push($(this).text()); }); - equals( content[0], "blabla", "Check first tab"); - equals( content[1], "blublu", "Check second tab"); + equals( content[0], 'blabla', 'Check first tab'); + equals( content[1], 'blublu', 'Check second tab'); start(); }); }); -test("jQuery.getScript(String, Function) - with callback", function() { - expect(3); +test("$.getScript(String, Function) - with callback", function() { + expect(2); stop(); - jQuery.getScript(url("data/test.js"), function( data, _, jqXHR ) { - equals( foobar, "bar", "Check if script was evaluated" ); - strictEqual( data, jqXHR.responseText, "Same-domain script requests returns the source of the script (#8082)" ); + window.foobar = null; + $.getScript(url("data/test.js"), function() { + equals( foobar, "bar", 'Check if script was evaluated' ); setTimeout(start, 100); }); }); -test("jQuery.getScript(String, Function) - no callback", function() { +test("$.getScript(String, Function) - no callback", function() { expect(1); + stop(true); + $.getScript(url("data/test.js"), start); +}); + +test("$.ajax() - JSONP, Local", function() { + expect(7); + + var count = 0; + function plus(){ if ( ++count == 7 ) start(); } + stop(); - jQuery.getScript(url("data/test.js"), function(){ - start(); - }); -}); -jQuery.each( [ "Same Domain", "Cross Domain" ] , function( crossDomain , label ) { - - test("jQuery.ajax() - JSONP, " + label, function() { - expect(20); - - var count = 0; - function plus(){ if ( ++count == 18 ) start(); } - - stop(); - - jQuery.ajax({ - url: "data/jsonp.php", - dataType: "jsonp", - crossDomain: crossDomain, - success: function(data){ - ok( data.data, "JSON results returned (GET, no callback)" ); - plus(); - }, - error: function(data){ - ok( false, "Ajax error JSON (GET, no callback)" ); - plus(); - } - }); - - jQuery.ajax({ - url: "data/jsonp.php?callback=?", - dataType: "jsonp", - crossDomain: crossDomain, - success: function(data){ - ok( data.data, "JSON results returned (GET, url callback)" ); - plus(); - }, - error: function(data){ - ok( false, "Ajax error JSON (GET, url callback)" ); - plus(); - } - }); - - jQuery.ajax({ - url: "data/jsonp.php", - dataType: "jsonp", - crossDomain: crossDomain, - data: "callback=?", - success: function(data){ - ok( data.data, "JSON results returned (GET, data callback)" ); - plus(); - }, - error: function(data){ - ok( false, "Ajax error JSON (GET, data callback)" ); - plus(); - } - }); - - jQuery.ajax({ - url: "data/jsonp.php?callback=??", - dataType: "jsonp", - crossDomain: crossDomain, - success: function(data){ - ok( data.data, "JSON results returned (GET, url context-free callback)" ); - plus(); - }, - error: function(data){ - ok( false, "Ajax error JSON (GET, url context-free callback)" ); - plus(); - } - }); - - jQuery.ajax({ - url: "data/jsonp.php", - dataType: "jsonp", - crossDomain: crossDomain, - data: "callback=??", - success: function(data){ - ok( data.data, "JSON results returned (GET, data context-free callback)" ); - plus(); - }, - error: function(data){ - ok( false, "Ajax error JSON (GET, data context-free callback)" ); - plus(); - } - }); - - jQuery.ajax({ - url: "data/jsonp.php/??", - dataType: "jsonp", - crossDomain: crossDomain, - success: function(data){ - ok( data.data, "JSON results returned (GET, REST-like)" ); - plus(); - }, - error: function(data){ - ok( false, "Ajax error JSON (GET, REST-like)" ); - plus(); - } - }); - - jQuery.ajax({ - url: "data/jsonp.php/???json=1", - dataType: "jsonp", - crossDomain: crossDomain, - success: function(data){ - strictEqual( jQuery.type(data), "array", "JSON results returned (GET, REST-like with param)" ); - plus(); - }, - error: function(data){ - ok( false, "Ajax error JSON (GET, REST-like with param)" ); - plus(); - } - }); - - jQuery.ajax({ - url: "data/jsonp.php", - dataType: "jsonp", - crossDomain: crossDomain, - jsonp: "callback", - success: function(data){ - ok( data.data, "JSON results returned (GET, data obj callback)" ); - plus(); - }, - error: function(data){ - ok( false, "Ajax error JSON (GET, data obj callback)" ); - plus(); - } - }); - - window.jsonpResults = function(data) { - ok( data.data, "JSON results returned (GET, custom callback function)" ); - window.jsonpResults = undefined; + $.ajax({ + url: "data/jsonp.php", + dataType: "jsonp", + success: function(data){ + ok( data.data, "JSON results returned (GET, no callback)" ); plus(); - }; + }, + error: function(data){ + ok( false, "Ajax error JSON (GET, no callback)" ); + plus(); + } + }); - jQuery.ajax({ - url: "data/jsonp.php", - dataType: "jsonp", - crossDomain: crossDomain, - jsonpCallback: "jsonpResults", - success: function(data){ - ok( data.data, "JSON results returned (GET, custom callback name)" ); - plus(); - }, - error: function(data){ - ok( false, "Ajax error JSON (GET, custom callback name)" ); - plus(); - } - }); + $.ajax({ + url: "data/jsonp.php?callback=?", + dataType: "jsonp", + success: function(data){ + ok( data.data, "JSON results returned (GET, url callback)" ); + plus(); + }, + error: function(data){ + ok( false, "Ajax error JSON (GET, url callback)" ); + plus(); + } + }); - jQuery.ajax({ - url: "data/jsonp.php", - dataType: "jsonp", - crossDomain: crossDomain, - jsonpCallback: "functionToCleanUp", - success: function(data){ - ok( data.data, "JSON results returned (GET, custom callback name to be cleaned up)" ); - strictEqual( window.functionToCleanUp, undefined, "Callback was removed (GET, custom callback name to be cleaned up)" ); - plus(); - var xhr; - jQuery.ajax({ - url: "data/jsonp.php", - dataType: "jsonp", - crossDomain: crossDomain, - jsonpCallback: "functionToCleanUp", - beforeSend: function( jqXHR ) { - xhr = jqXHR; - return false; - } - }); - xhr.error(function() { - ok( true, "Ajax error JSON (GET, custom callback name to be cleaned up)" ); - strictEqual( window.functionToCleanUp, undefined, "Callback was removed after early abort (GET, custom callback name to be cleaned up)" ); - plus(); - }); - }, - error: function(data){ - ok( false, "Ajax error JSON (GET, custom callback name to be cleaned up)" ); - plus(); - } - }); + $.ajax({ + url: "data/jsonp.php", + dataType: "jsonp", + data: "callback=?", + success: function(data){ + ok( data.data, "JSON results returned (GET, data callback)" ); + plus(); + }, + error: function(data){ + ok( false, "Ajax error JSON (GET, data callback)" ); + plus(); + } + }); - jQuery.ajax({ - type: "POST", - url: "data/jsonp.php", - dataType: "jsonp", - crossDomain: crossDomain, - success: function(data){ - ok( data.data, "JSON results returned (POST, no callback)" ); - plus(); - }, - error: function(data){ - ok( false, "Ajax error JSON (GET, data obj callback)" ); - plus(); - } - }); + $.ajax({ + url: "data/jsonp.php", + dataType: "jsonp", + jsonp: "callback", + success: function(data){ + ok( data.data, "JSON results returned (GET, data obj callback)" ); + plus(); + }, + error: function(data){ + ok( false, "Ajax error JSON (GET, data obj callback)" ); + plus(); + } + }); - jQuery.ajax({ - type: "POST", - url: "data/jsonp.php", - data: "callback=?", - dataType: "jsonp", - crossDomain: crossDomain, - success: function(data){ - ok( data.data, "JSON results returned (POST, data callback)" ); - plus(); - }, - error: function(data){ - ok( false, "Ajax error JSON (POST, data callback)" ); - plus(); - } - }); + $.ajax({ + type: "POST", + url: "data/jsonp.php", + dataType: "jsonp", + success: function(data){ + ok( data.data, "JSON results returned (POST, no callback)" ); + plus(); + }, + error: function(data){ + ok( false, "Ajax error JSON (GET, data obj callback)" ); + plus(); + } + }); - jQuery.ajax({ - type: "POST", - url: "data/jsonp.php", - jsonp: "callback", - dataType: "jsonp", - crossDomain: crossDomain, - success: function(data){ - ok( data.data, "JSON results returned (POST, data obj callback)" ); - plus(); - }, - error: function(data){ - ok( false, "Ajax error JSON (POST, data obj callback)" ); - plus(); - } - }); - - //#7578 - jQuery.ajax({ - url: "data/jsonp.php", - dataType: "jsonp", - crossDomain: crossDomain, - beforeSend: function(){ - strictEqual( this.cache, false, "cache must be false on JSON request" ); - plus(); - return false; - } - }); - - jQuery.ajax({ - url: "data/jsonp.php?callback=XXX", - dataType: "jsonp", - jsonp: false, - jsonpCallback: "XXX", - crossDomain: crossDomain, - beforeSend: function() { - ok( /^data\/jsonp.php\?callback=XXX&_=\d+$/.test( this.url ) , - "The URL wasn't messed with (GET, custom callback name with no url manipulation)" ); - plus(); - }, - success: function(data){ - ok( data.data, "JSON results returned (GET, custom callback name with no url manipulation)" ); - plus(); - }, - error: function(data){ - ok( false, "Ajax error JSON (GET, custom callback name with no url manipulation)" ); - plus(); - } - }); + $.ajax({ + type: "POST", + url: "data/jsonp.php", + data: "callback=?", + dataType: "jsonp", + success: function(data){ + ok( data.data, "JSON results returned (POST, data callback)" ); + plus(); + }, + error: function(data){ + ok( false, "Ajax error JSON (POST, data callback)" ); + plus(); + } + }); + $.ajax({ + type: "POST", + url: "data/jsonp.php", + jsonp: "callback", + dataType: "jsonp", + success: function(data){ + ok( data.data, "JSON results returned (POST, data obj callback)" ); + plus(); + }, + error: function(data){ + ok( false, "Ajax error JSON (POST, data obj callback)" ); + plus(); + } }); }); -test("jQuery.ajax() - script, Remote", function() { +test("$.ajax() - JSONP, Remote", function() { + expect(4); + + var count = 0; + function plus(){ if ( ++count == 4 ) start(); } + + var base = window.location.href.replace(/\?.*$/, ""); + + stop(); + + $.ajax({ + url: base + "data/jsonp.php", + dataType: "jsonp", + success: function(data){ + ok( data.data, "JSON results returned (GET, no callback)" ); + plus(); + }, + error: function(data){ + ok( false, "Ajax error JSON (GET, no callback)" ); + plus(); + } + }); + + $.ajax({ + url: base + "data/jsonp.php?callback=?", + dataType: "jsonp", + success: function(data){ + ok( data.data, "JSON results returned (GET, url callback)" ); + plus(); + }, + error: function(data){ + ok( false, "Ajax error JSON (GET, url callback)" ); + plus(); + } + }); + + $.ajax({ + url: base + "data/jsonp.php", + dataType: "jsonp", + data: "callback=?", + success: function(data){ + ok( data.data, "JSON results returned (GET, data callback)" ); + plus(); + }, + error: function(data){ + ok( false, "Ajax error JSON (GET, data callback)" ); + plus(); + } + }); + + $.ajax({ + url: base + "data/jsonp.php", + dataType: "jsonp", + jsonp: "callback", + success: function(data){ + ok( data.data, "JSON results returned (GET, data obj callback)" ); + plus(); + }, + error: function(data){ + ok( false, "Ajax error JSON (GET, data obj callback)" ); + plus(); + } + }); +}); + +test("$.ajax() - script, Remote", function() { expect(2); - var base = window.location.href.replace(/[^\/]*$/, ""); + var base = window.location.href.replace(/\?.*$/, ""); stop(); - jQuery.ajax({ + window.foobar = null; + $.ajax({ url: base + "data/test.js", dataType: "script", success: function(data){ @@ -1555,38 +588,36 @@ test("jQuery.ajax() - script, Remote", function() { }); }); -test("jQuery.ajax() - script, Remote with POST", function() { +test("$.ajax() - script, Remote with POST", function() { expect(3); - var base = window.location.href.replace(/[^\/]*$/, ""); + var base = window.location.href.replace(/\?.*$/, ""); stop(); - jQuery.ajax({ + window.foobar = null; + $.ajax({ url: base + "data/test.js", type: "POST", dataType: "script", success: function(data, status){ - ok( foobar, "Script results returned (POST, no callback)" ); - equals( status, "success", "Script results returned (POST, no callback)" ); - start(); - }, - error: function(xhr) { - ok( false, "ajax error, status code: " + xhr.status ); + ok( foobar, "Script results returned (GET, no callback)" ); + equals( status, "success", "Script results returned (GET, no callback)" ); start(); } }); }); -test("jQuery.ajax() - script, Remote with scheme-less URL", function() { +test("$.ajax() - script, Remote with scheme-less URL", function() { expect(2); - var base = window.location.href.replace(/[^\/]*$/, ""); + var base = window.location.href.replace(/\?.*$/, ""); base = base.replace(/^.*?\/\//, "//"); stop(); - jQuery.ajax({ + window.foobar = null; + $.ajax({ url: base + "data/test.js", dataType: "script", success: function(data){ @@ -1596,275 +627,139 @@ test("jQuery.ajax() - script, Remote with scheme-less URL", function() { }); }); -test("jQuery.ajax() - malformed JSON", function() { - expect(2); - - stop(); - - jQuery.ajax({ - url: "data/badjson.js", - dataType: "json", - success: function(){ - ok( false, "Success." ); - start(); - }, - error: function(xhr, msg, detailedMsg) { - equals( "parsererror", msg, "A parse error occurred." ); - ok( /^(Invalid|SyntaxError|exception)/i.test(detailedMsg), "Detailed parsererror message provided" ); - start(); - } - }); -}); - -test("jQuery.ajax() - script by content-type", function() { - expect(2); - - stop(); - - jQuery.when( - - jQuery.ajax({ - url: "data/script.php", - data: { header: "script" } - }), - - jQuery.ajax({ - url: "data/script.php", - data: { header: "ecma" } - }) - - ).then( start, start ); -}); - -test("jQuery.ajax() - json by content-type", function() { - expect(5); - - stop(); - - jQuery.ajax({ - url: "data/json.php", - data: { header: "json", json: "array" }, - success: function( json ) { - ok( json.length >= 2, "Check length"); - equals( json[0].name, "John", "Check JSON: first, name" ); - equals( json[0].age, 21, "Check JSON: first, age" ); - equals( json[1].name, "Peter", "Check JSON: second, name" ); - equals( json[1].age, 25, "Check JSON: second, age" ); - start(); - } - }); -}); - -test("jQuery.ajax() - json by content-type disabled with options", function() { - expect(6); - - stop(); - - jQuery.ajax({ - url: url("data/json.php"), - data: { header: "json", json: "array" }, - contents: { - json: false - }, - success: function( text ) { - equals( typeof text , "string" , "json wasn't auto-determined" ); - var json = jQuery.parseJSON( text ); - ok( json.length >= 2, "Check length"); - equals( json[0].name, "John", "Check JSON: first, name" ); - equals( json[0].age, 21, "Check JSON: first, age" ); - equals( json[1].name, "Peter", "Check JSON: second, name" ); - equals( json[1].age, 25, "Check JSON: second, age" ); - start(); - } - }); -}); - -test("jQuery.getJSON(String, Hash, Function) - JSON array", function() { - expect(5); - stop(); - jQuery.getJSON(url("data/json.php"), {json: "array"}, function(json) { - ok( json.length >= 2, "Check length"); - equals( json[0].name, "John", "Check JSON: first, name" ); - equals( json[0].age, 21, "Check JSON: first, age" ); - equals( json[1].name, "Peter", "Check JSON: second, name" ); - equals( json[1].age, 25, "Check JSON: second, age" ); - start(); - }); -}); - -test("jQuery.getJSON(String, Function) - JSON object", function() { - expect(2); - stop(); - jQuery.getJSON(url("data/json.php"), function(json) { - if (json && json.data) { - equals( json.data.lang, "en", "Check JSON: lang" ); - equals( json.data.length, 25, "Check JSON: length" ); - } - start(); - }); -}); - -test("jQuery.getJSON - Using Native JSON", function() { - expect(2); - - var old = window.JSON; - JSON = { - parse: function(str){ - ok( true, "Verifying that parse method was run" ); - return true; - } - }; - - stop(); - jQuery.getJSON(url("data/json.php"), function(json) { - window.JSON = old; - equals( json, true, "Verifying return value" ); - start(); - }); -}); - -test("jQuery.getJSON(String, Function) - JSON object with absolute url to local content", function() { - expect(2); - - var base = window.location.href.replace(/[^\/]*$/, ""); - - stop(); - jQuery.getJSON(url(base + "data/json.php"), function(json) { - equals( json.data.lang, "en", "Check JSON: lang" ); - equals( json.data.length, 25, "Check JSON: length" ); - start(); - }); -}); - -test("jQuery.post - data", 3, function() { - stop(); - - jQuery.when( - jQuery.post( url( "data/name.php" ), { xml: "5-2", length: 3 }, function( xml ) { - jQuery( "math", xml ).each( function() { - equals( jQuery( "calculation", this ).text(), "5-2", "Check for XML" ); - equals( jQuery( "result", this ).text(), "3", "Check for XML" ); - }); - }), - - jQuery.ajax({ - url: url("data/echoData.php"), - type: "POST", - data: { - "test": { - "length": 7, - "foo": "bar" - } - }, - success: function( data ) { - strictEqual( data, "test%5Blength%5D=7&test%5Bfoo%5D=bar", "Check if a sub-object with a length param is serialized correctly"); - } - }) - ).then( start, start ); - -}); - -test("jQuery.post(String, Hash, Function) - simple with xml", function() { +test("$.getJSON(String, Hash, Function) - JSON array", function() { expect(4); stop(); - var done = 0; - - jQuery.post(url("data/name.php"), {xml: "5-2"}, function(xml){ - jQuery("math", xml).each(function() { - equals( jQuery("calculation", this).text(), "5-2", "Check for XML" ); - equals( jQuery("result", this).text(), "3", "Check for XML" ); - }); - if ( ++done === 2 ) start(); - }); - - jQuery.post(url("data/name.php?xml=5-2"), {}, function(xml){ - jQuery("math", xml).each(function() { - equals( jQuery("calculation", this).text(), "5-2", "Check for XML" ); - equals( jQuery("result", this).text(), "3", "Check for XML" ); - }); - if ( ++done === 2 ) start(); + $.getJSON(url("data/json.php"), {json: "array"}, function(json) { + ok( json[0].name == 'John', 'Check JSON: first, name' ); + ok( json[0].age == 21, 'Check JSON: first, age' ); + ok( json[1].name == 'Peter', 'Check JSON: second, name' ); + ok( json[1].age == 25, 'Check JSON: second, age' ); + start(); }); }); -test("jQuery.ajaxSetup({timeout: Number}) - with global timeout", function() { +test("$.getJSON(String, Function) - JSON object", function() { + expect(2); stop(); + $.getJSON(url("data/json.php"), function(json) { + ok( json.data.lang == 'en', 'Check JSON: lang' ); + ok( json.data.length == 25, 'Check JSON: length' ); + start(); + }); +}); +test("$.getJSON(String, Function) - JSON object with absolute url to local content", function() { + expect(2); + + var base = window.location.href.replace(/\?.*$/, ""); + + stop(); + $.getJSON(url(base + "data/json.php"), function(json) { + ok( json.data.lang == 'en', 'Check JSON: lang' ); + ok( json.data.length == 25, 'Check JSON: length' ); + start(); + }); +}); + +test("$.post(String, Hash, Function) - simple with xml", function() { + expect(4); + stop(); + $.post(url("data/name.php"), {xml: "5-2"}, function(xml){ + $('math', xml).each(function() { + ok( $('calculation', this).text() == '5-2', 'Check for XML' ); + ok( $('result', this).text() == '3', 'Check for XML' ); + }); + }); + + $.post(url("data/name.php?xml=5-2"), {}, function(xml){ + $('math', xml).each(function() { + ok( $('calculation', this).text() == '5-2', 'Check for XML' ); + ok( $('result', this).text() == '3', 'Check for XML' ); + }); + start(); + }); +}); + +test("$.ajaxSetup({timeout: Number}) - with global timeout", function() { + stop(); + var passed = 0; - jQuery.ajaxSetup({timeout: 1000}); - + $.ajaxSetup({timeout: 1000}); + var pass = function() { passed++; if ( passed == 2 ) { - ok( true, "Check local and global callbacks after timeout" ); - jQuery("#qunit-fixture").unbind("ajaxError"); + ok( true, 'Check local and global callbacks after timeout' ); + $('#main').unbind("ajaxError"); start(); } }; - + var fail = function(a,b,c) { - ok( false, "Check for timeout failed " + a + " " + b ); + ok( false, 'Check for timeout failed ' + a + ' ' + b ); start(); }; - - jQuery("#qunit-fixture").ajaxError(pass); - - jQuery.ajax({ + + $('#main').ajaxError(pass); + + $.ajax({ type: "GET", url: url("data/name.php?wait=5"), error: pass, success: fail }); - + // reset timeout - jQuery.ajaxSetup({timeout: 0}); + $.ajaxSetup({timeout: 0}); }); -test("jQuery.ajaxSetup({timeout: Number}) with localtimeout", function() { +test("$.ajaxSetup({timeout: Number}) with localtimeout", function() { stop(); - jQuery.ajaxSetup({timeout: 50}); + $.ajaxSetup({timeout: 50}); - jQuery.ajax({ + $.ajax({ type: "GET", - timeout: 15000, + timeout: 5000, url: url("data/name.php?wait=1"), error: function() { - ok( false, "Check for local timeout failed" ); + ok( false, 'Check for local timeout failed' ); start(); }, success: function() { - ok( true, "Check for local timeout" ); - start(); + ok( true, 'Check for local timeout' ); + start(); } }); // reset timeout - jQuery.ajaxSetup({timeout: 0}); + $.ajaxSetup({timeout: 0}); }); -test("jQuery.ajax - simple get", function() { +test("$.ajax - simple get", function() { expect(1); stop(); - jQuery.ajax({ + $.ajax({ type: "GET", url: url("data/name.php?name=foo"), success: function(msg){ - equals( msg, "bar", "Check for GET" ); - start(); + ok( msg == 'bar', 'Check for GET' ); + start(); } }); }); -test("jQuery.ajax - simple post", function() { +test("$.ajax - simple post", function() { expect(1); stop(); - jQuery.ajax({ + $.ajax({ type: "POST", url: url("data/name.php"), data: "name=peter", success: function(msg){ - equals( msg, "pan", "Check for POST" ); - start(); + ok( msg == 'pan', 'Check for POST' ); + start(); } }); }); @@ -1872,21 +767,20 @@ test("jQuery.ajax - simple post", function() { test("ajaxSetup()", function() { expect(1); stop(); - jQuery.ajaxSetup({ + $.ajaxSetup({ url: url("data/name.php?name=foo"), success: function(msg){ - equals( msg, "bar", "Check for GET" ); + ok( msg == 'bar', 'Check for GET' ); start(); } }); - jQuery.ajax(); + $.ajax(); }); -/* test("custom timeout does not set error message when timeout occurs, see #970", function() { stop(); - jQuery.ajax({ - url: "data/name.php?wait=1", + $.ajax({ + url: "data/name.php?wait=10", timeout: 500, error: function(request, status) { ok( status != null, "status shouldn't be null in error handler" ); @@ -1895,377 +789,6 @@ test("custom timeout does not set error message when timeout occurs, see #970", } }); }); -*/ - -test("data option: evaluate function values (#2806)", function() { - stop(); - jQuery.ajax({ - url: "data/echoQuery.php", - data: { - key: function() { - return "value"; - } - }, - success: function(result) { - equals( result, "key=value" ); - start(); - } - }); -}); - -test("data option: empty bodies for non-GET requests", function() { - stop(); - jQuery.ajax({ - url: "data/echoData.php", - data: undefined, - type: "post", - success: function(result) { - equals( result, "" ); - start(); - } - }); -}); - -var ifModifiedNow = new Date(); - -jQuery.each( { " (cache)": true, " (no cache)": false }, function( label, cache ) { - - test("jQuery.ajax - If-Modified-Since support" + label, function() { - expect( 3 ); - - stop(); - - var url = "data/if_modified_since.php?ts=" + ifModifiedNow++; - - jQuery.ajax({ - url: url, - ifModified: true, - cache: cache, - success: function(data, status) { - equals(status, "success" ); - - jQuery.ajax({ - url: url, - ifModified: true, - cache: cache, - success: function(data, status) { - if ( data === "FAIL" ) { - ok(jQuery.browser.opera, "Opera is incapable of doing .setRequestHeader('If-Modified-Since')."); - ok(jQuery.browser.opera, "Opera is incapable of doing .setRequestHeader('If-Modified-Since')."); - } else { - equals(status, "notmodified"); - ok(data == null, "response body should be empty"); - } - start(); - }, - error: function() { - // Do this because opera simply refuses to implement 304 handling :( - // A feature-driven way of detecting this would be appreciated - // See: http://gist.github.com/599419 - ok(jQuery.browser.opera, "error"); - ok(jQuery.browser.opera, "error"); - start(); - } - }); - }, - error: function() { - equals(false, "error"); - // Do this because opera simply refuses to implement 304 handling :( - // A feature-driven way of detecting this would be appreciated - // See: http://gist.github.com/599419 - ok(jQuery.browser.opera, "error"); - start(); - } - }); - }); - - test("jQuery.ajax - Etag support" + label, function() { - expect( 3 ); - - stop(); - - var url = "data/etag.php?ts=" + ifModifiedNow++; - - jQuery.ajax({ - url: url, - ifModified: true, - cache: cache, - success: function(data, status) { - equals(status, "success" ); - - jQuery.ajax({ - url: url, - ifModified: true, - cache: cache, - success: function(data, status) { - if ( data === "FAIL" ) { - ok(jQuery.browser.opera, "Opera is incapable of doing .setRequestHeader('If-None-Match')."); - ok(jQuery.browser.opera, "Opera is incapable of doing .setRequestHeader('If-None-Match')."); - } else { - equals(status, "notmodified"); - ok(data == null, "response body should be empty"); - } - start(); - }, - error: function() { - // Do this because opera simply refuses to implement 304 handling :( - // A feature-driven way of detecting this would be appreciated - // See: http://gist.github.com/599419 - ok(jQuery.browser.opera, "error"); - ok(jQuery.browser.opera, "error"); - start(); - } - }); - }, - error: function() { - // Do this because opera simply refuses to implement 304 handling :( - // A feature-driven way of detecting this would be appreciated - // See: http://gist.github.com/599419 - ok(jQuery.browser.opera, "error"); - start(); - } - }); - }); -}); - -test("jQuery ajax - failing cross-domain", function() { - - expect( 2 ); - - stop(); - - var i = 2; - - jQuery.ajax({ - url: "http://somewebsitethatdoesnotexist-67864863574657654.com", - success: function(){ ok( false , "success" ); }, - error: function(xhr,_,e){ ok( true , "file not found: " + xhr.status + " => " + e ); }, - complete: function() { if ( ! --i ) start(); } - }); - - jQuery.ajax({ - url: "http://www.google.com", - success: function(){ ok( false , "success" ); }, - error: function(xhr,_,e){ ok( true , "access denied: " + xhr.status + " => " + e ); }, - complete: function() { if ( ! --i ) start(); } - }); - -}); - -test("jQuery ajax - atom+xml", function() { - - stop(); - - jQuery.ajax({ - url: url( "data/atom+xml.php" ), - success: function(){ ok( true , "success" ); }, - error: function(){ ok( false , "error" ); }, - complete: function() { start(); } - }); - -}); - -test( "jQuery.ajax - Location object as url (#7531)", 1, function () { - var success = false; - try { - var xhr = jQuery.ajax({ url: window.location }); - success = true; - xhr.abort(); - } catch (e) {} - - ok( success, "document.location did not generate exception" ); -}); - -test( "jQuery.ajax - statusCode" , function() { - - var count = 12; - - expect( 20 ); - stop(); - - function countComplete() { - if ( ! --count ) { - start(); - } - } - - function createStatusCodes( name , isSuccess ) { - name = "Test " + name + " " + ( isSuccess ? "success" : "error" ); - return { - 200: function() { - ok( isSuccess , name ); - }, - 404: function() { - ok( ! isSuccess , name ); - } - }; - } - - jQuery.each( { - "data/name.html": true, - "data/someFileThatDoesNotExist.html": false - } , function( uri , isSuccess ) { - - jQuery.ajax( url( uri ) , { - statusCode: createStatusCodes( "in options" , isSuccess ), - complete: countComplete - }); - - jQuery.ajax( url( uri ) , { - complete: countComplete - }).statusCode( createStatusCodes( "immediately with method" , isSuccess ) ); - - jQuery.ajax( url( uri ) , { - complete: function(jqXHR) { - jqXHR.statusCode( createStatusCodes( "on complete" , isSuccess ) ); - countComplete(); - } - }); - - jQuery.ajax( url( uri ) , { - complete: function(jqXHR) { - setTimeout( function() { - jqXHR.statusCode( createStatusCodes( "very late binding" , isSuccess ) ); - countComplete(); - } , 100 ); - } - }); - - jQuery.ajax( url( uri ) , { - statusCode: createStatusCodes( "all (options)" , isSuccess ), - complete: function(jqXHR) { - jqXHR.statusCode( createStatusCodes( "all (on complete)" , isSuccess ) ); - setTimeout( function() { - jqXHR.statusCode( createStatusCodes( "all (very late binding)" , isSuccess ) ); - countComplete(); - } , 100 ); - } - }).statusCode( createStatusCodes( "all (immediately with method)" , isSuccess ) ); - - var testString = ""; - - jQuery.ajax( url( uri ), { - success: function( a , b , jqXHR ) { - ok( isSuccess , "success" ); - var statusCode = {}; - statusCode[ jqXHR.status ] = function() { - testString += "B"; - }; - jqXHR.statusCode( statusCode ); - testString += "A"; - }, - error: function( jqXHR ) { - ok( ! isSuccess , "error" ); - var statusCode = {}; - statusCode[ jqXHR.status ] = function() { - testString += "B"; - }; - jqXHR.statusCode( statusCode ); - testString += "A"; - }, - complete: function() { - strictEqual( testString , "AB" , "Test statusCode callbacks are ordered like " + - ( isSuccess ? "success" : "error" ) + " callbacks" ); - countComplete(); - } - } ); - - }); -}); - -test("jQuery.ajax - transitive conversions", function() { - - expect( 8 ); - - stop(); - - jQuery.when( - - jQuery.ajax( url("data/json.php") , { - converters: { - "json myJson": function( data ) { - ok( true , "converter called" ); - return data; - } - }, - dataType: "myJson", - success: function() { - ok( true , "Transitive conversion worked" ); - strictEqual( this.dataTypes[0] , "text" , "response was retrieved as text" ); - strictEqual( this.dataTypes[1] , "myjson" , "request expected myjson dataType" ); - } - }), - - jQuery.ajax( url("data/json.php") , { - converters: { - "json myJson": function( data ) { - ok( true , "converter called (*)" ); - return data; - } - }, - contents: false, /* headers are wrong so we ignore them */ - dataType: "* myJson", - success: function() { - ok( true , "Transitive conversion worked (*)" ); - strictEqual( this.dataTypes[0] , "text" , "response was retrieved as text (*)" ); - strictEqual( this.dataTypes[1] , "myjson" , "request expected myjson dataType (*)" ); - } - }) - - ).then( start , start ); - -}); - -test("jQuery.ajax - overrideMimeType", function() { - - expect( 2 ); - - stop(); - - jQuery.when( - - jQuery.ajax( url("data/json.php") , { - beforeSend: function( xhr ) { - xhr.overrideMimeType( "application/json" ); - }, - success: function( json ) { - ok( json.data , "Mimetype overriden using beforeSend" ); - } - }), - - jQuery.ajax( url("data/json.php") , { - mimeType: "application/json", - success: function( json ) { - ok( json.data , "Mimetype overriden using mimeType option" ); - } - }) - - ).then( start , start ); - -}); - -test("jQuery.ajax - abort in prefilter", function() { - - expect( 1 ); - - jQuery.ajaxPrefilter(function( options, _, jqXHR ) { - if ( options.abortInPrefilter ) { - jqXHR.abort(); - } - }); - - strictEqual( jQuery.ajax({ - abortInPrefilter: true, - error: function() { - ok( false, "error callback called" ); - } - }), false, "Request was properly aborted early by the prefilter" ); - -}); - -test("jQuery.ajax - active counter", function() { - ok( jQuery.active == 0, "ajax active counter should be zero: " + jQuery.active ); -}); } diff --git a/test/unit/attributes.js b/test/unit/attributes.js deleted file mode 100644 index 4716e5b5..00000000 --- a/test/unit/attributes.js +++ /dev/null @@ -1,1057 +0,0 @@ -module("attributes", { teardown: moduleTeardown }); - -var bareObj = function(value) { return value; }; -var functionReturningObj = function(value) { return (function() { return value; }); }; - - -test("jQuery.attrFix/jQuery.propFix integrity test", function() { - expect(2); - - // This must be maintained and equal jQuery.attrFix when appropriate - // Ensure that accidental or erroneous property - // overwrites don't occur - // This is simply for better code coverage and future proofing. - var props = { - tabindex: "tabIndex", - readonly: "readOnly", - "for": "htmlFor", - "class": "className", - maxlength: "maxLength", - cellspacing: "cellSpacing", - cellpadding: "cellPadding", - rowspan: "rowSpan", - colspan: "colSpan", - usemap: "useMap", - frameborder: "frameBorder", - contenteditable: "contentEditable" - }, - propsShouldBe; - - if ( !jQuery.support.getSetAttribute ) { - propsShouldBe = props; - } else { - propsShouldBe = { - tabindex: "tabIndex" - }; - } - - deepEqual(propsShouldBe, jQuery.attrFix, "jQuery.attrFix passes integrity check"); - deepEqual(props, jQuery.propFix, "jQuery.propFix passes integrity check"); -}); - -test("attr(String)", function() { - expect(45); - - equals( jQuery("#text1").attr("type"), "text", "Check for type attribute" ); - equals( jQuery("#radio1").attr("type"), "radio", "Check for type attribute" ); - equals( jQuery("#check1").attr("type"), "checkbox", "Check for type attribute" ); - equals( jQuery("#simon1").attr("rel"), "bookmark", "Check for rel attribute" ); - equals( jQuery("#google").attr("title"), "Google!", "Check for title attribute" ); - equals( jQuery("#mark").attr("hreflang"), "en", "Check for hreflang attribute" ); - equals( jQuery("#en").attr("lang"), "en", "Check for lang attribute" ); - equals( jQuery("#simon").attr("class"), "blog link", "Check for class attribute" ); - equals( jQuery("#name").attr("name"), "name", "Check for name attribute" ); - equals( jQuery("#text1").attr("name"), "action", "Check for name attribute" ); - ok( jQuery("#form").attr("action").indexOf("formaction") >= 0, "Check for action attribute" ); - equals( jQuery("#text1").attr("value", "t").attr("value"), "t", "Check setting the value attribute" ); - equals( jQuery("
                ").attr("value"), "t", "Check setting custom attr named 'value' on a div" ); - equals( jQuery("#form").attr("blah", "blah").attr("blah"), "blah", "Set non-existant attribute on a form" ); - equals( jQuery("#foo").attr("height"), undefined, "Non existent height attribute should return undefined" ); - - // [7472] & [3113] (form contains an input with name="action" or name="id") - var extras = jQuery("").appendTo("#testForm"); - equals( jQuery("#form").attr("action","newformaction").attr("action"), "newformaction", "Check that action attribute was changed" ); - equals( jQuery("#testForm").attr("target"), undefined, "Retrieving target does not equal the input with name=target" ); - equals( jQuery("#testForm").attr("target", "newTarget").attr("target"), "newTarget", "Set target successfully on a form" ); - equals( jQuery("#testForm").removeAttr("id").attr("id"), undefined, "Retrieving id does not equal the input with name=id after id is removed [#7472]" ); - // Bug #3685 (form contains input with name="name") - equals( jQuery("#testForm").attr("name"), undefined, "Retrieving name does not retrieve input with name=name" ); - extras.remove(); - - equals( jQuery("#text1").attr("maxlength"), "30", "Check for maxlength attribute" ); - equals( jQuery("#text1").attr("maxLength"), "30", "Check for maxLength attribute" ); - equals( jQuery("#area1").attr("maxLength"), "30", "Check for maxLength attribute" ); - - // using innerHTML in IE causes href attribute to be serialized to the full path - jQuery("").attr({ "id": "tAnchor5", "href": "#5" }).appendTo("#qunit-fixture"); - equals( jQuery("#tAnchor5").attr("href"), "#5", "Check for non-absolute href (an anchor)" ); - - // list attribute is readonly by default in browsers that support it - jQuery("#list-test").attr("list", "datalist"); - equals( jQuery("#list-test").attr("list"), "datalist", "Check setting list attribute" ); - - // Related to [5574] and [5683] - var body = document.body, $body = jQuery(body); - - strictEqual( $body.attr("foo"), undefined, "Make sure that a non existent attribute returns undefined" ); - - body.setAttribute("foo", "baz"); - equals( $body.attr("foo"), "baz", "Make sure the dom attribute is retrieved when no expando is found" ); - - $body.attr("foo","cool"); - equals( $body.attr("foo"), "cool", "Make sure that setting works well when both expando and dom attribute are available" ); - - body.removeAttribute("foo"); // Cleanup - - var select = document.createElement("select"), optgroup = document.createElement("optgroup"), option = document.createElement("option"); - optgroup.appendChild( option ); - select.appendChild( optgroup ); - - equal( jQuery( option ).attr("selected"), "selected", "Make sure that a single option is selected, even when in an optgroup." ); - - var $img = jQuery("").appendTo("body"); - equals( $img.attr("width"), "215", "Retrieve width attribute an an element with display:none." ); - equals( $img.attr("height"), "53", "Retrieve height attribute an an element with display:none." ); - - // Check for style support - ok( !!~jQuery("#dl").attr("style").indexOf("position"), "Check style attribute getter, also normalize css props to lowercase" ); - ok( !!~jQuery("#foo").attr("style", "position:absolute;").attr("style").indexOf("position"), "Check style setter" ); - - // Check value on button element (#1954) - var $button = jQuery("").insertAfter("#button"); - equals( $button.attr("value"), "foobar", "Value retrieval on a button does not return innerHTML" ); - equals( $button.attr("value", "baz").html(), "text", "Setting the value does not change innerHTML" ); - - // Attributes with a colon on a table element (#1591) - equals( jQuery("#table").attr("test:attrib"), undefined, "Retrieving a non-existent attribute on a table with a colon does not throw an error." ); - equals( jQuery("#table").attr("test:attrib", "foobar").attr("test:attrib"), "foobar", "Setting an attribute on a table with a colon does not throw an error." ); - - var $form = jQuery("
                ").appendTo("#qunit-fixture"); - equal( $form.attr("class"), "something", "Retrieve the class attribute on a form." ); - - var $a = jQuery("
                Click").appendTo("#qunit-fixture"); - equal( $a.attr("onclick"), "something()", "Retrieve ^on attribute without anonymous function wrapper." ); - - ok( jQuery("
                ").attr("doesntexist") === undefined, "Make sure undefined is returned when no attribute is found." ); - ok( jQuery("
                ").attr("title") === undefined, "Make sure undefined is returned when no attribute is found." ); - equal( jQuery("
                ").attr("title", "something").attr("title"), "something", "Set the title attribute." ); - ok( jQuery().attr("doesntexist") === undefined, "Make sure undefined is returned when no element is there." ); - equal( jQuery("
                ").attr("value"), undefined, "An unset value on a div returns undefined." ); - equal( jQuery("").attr("value"), "", "An unset value on an input returns current value." ); -}); - -if ( !isLocal ) { - test("attr(String) in XML Files", function() { - expect(3); - stop(); - jQuery.get("data/dashboard.xml", function( xml ) { - equal( jQuery( "locations", xml ).attr("class"), "foo", "Check class attribute in XML document" ); - equal( jQuery( "location", xml ).attr("for"), "bar", "Check for attribute in XML document" ); - equal( jQuery( "location", xml ).attr("checked"), "different", "Check that hooks are not attached in XML document" ); - start(); - }); - }); -} - -test("attr(String, Function)", function() { - expect(2); - equals( jQuery("#text1").attr("value", function() { return this.id; })[0].value, "text1", "Set value from id" ); - equals( jQuery("#text1").attr("title", function(i) { return i; }).attr("title"), "0", "Set value with an index"); -}); - -test("attr(Hash)", function() { - expect(3); - var pass = true; - jQuery("div").attr({foo: "baz", zoo: "ping"}).each(function(){ - if ( this.getAttribute("foo") != "baz" && this.getAttribute("zoo") != "ping" ) pass = false; - }); - ok( pass, "Set Multiple Attributes" ); - equals( jQuery("#text1").attr({value: function() { return this.id; }})[0].value, "text1", "Set attribute to computed value #1" ); - equals( jQuery("#text1").attr({title: function(i) { return i; }}).attr("title"), "0", "Set attribute to computed value #2"); - -}); - -test("attr(String, Object)", function() { - expect(69); - - var div = jQuery("div").attr("foo", "bar"), - fail = false; - - for ( var i = 0; i < div.size(); i++ ) { - if ( div.get(i).getAttribute("foo") != "bar" ){ - fail = i; - break; - } - } - - equals( fail, false, "Set Attribute, the #" + fail + " element didn't get the attribute 'foo'" ); - - ok( jQuery("#foo").attr({ "width": null }), "Try to set an attribute to nothing" ); - - jQuery("#name").attr("name", "something"); - equals( jQuery("#name").attr("name"), "something", "Set name attribute" ); - jQuery("#name").attr("name", null); - equals( jQuery("#name").attr("name"), undefined, "Remove name attribute" ); - var $input = jQuery("", { name: "something" }); - equals( $input.attr("name"), "something", "Check element creation gets/sets the name attribute." ); - - jQuery("#check2").prop("checked", true).prop("checked", false).attr("checked", true); - equals( document.getElementById("check2").checked, true, "Set checked attribute" ); - equals( jQuery("#check2").prop("checked"), true, "Set checked attribute" ); - equals( jQuery("#check2").attr("checked"), "checked", "Set checked attribute" ); - jQuery("#check2").attr("checked", false); - equals( document.getElementById("check2").checked, false, "Set checked attribute" ); - equals( jQuery("#check2").prop("checked"), false, "Set checked attribute" ); - equals( jQuery("#check2").attr("checked"), undefined, "Set checked attribute" ); - jQuery("#text1").attr("readonly", true); - equals( document.getElementById("text1").readOnly, true, "Set readonly attribute" ); - equals( jQuery("#text1").prop("readOnly"), true, "Set readonly attribute" ); - equals( jQuery("#text1").attr("readonly"), "readonly", "Set readonly attribute" ); - jQuery("#text1").attr("readonly", false); - equals( document.getElementById("text1").readOnly, false, "Set readonly attribute" ); - equals( jQuery("#text1").prop("readOnly"), false, "Set readonly attribute" ); - equals( jQuery("#text1").attr("readonly"), undefined, "Set readonly attribute" ); - - jQuery("#check2").prop("checked", true); - equals( document.getElementById("check2").checked, true, "Set checked attribute" ); - equals( jQuery("#check2").prop("checked"), true, "Set checked attribute" ); - equals( jQuery("#check2").attr("checked"), "checked", "Set checked attribute" ); - jQuery("#check2").prop("checked", false); - equals( document.getElementById("check2").checked, false, "Set checked attribute" ); - equals( jQuery("#check2").prop("checked"), false, "Set checked attribute" ); - equals( jQuery("#check2").attr("checked"), undefined, "Set checked attribute" ); - - jQuery("#check2").attr("checked", "checked"); - equal( document.getElementById("check2").checked, true, "Set checked attribute with 'checked'" ); - equal( jQuery("#check2").prop("checked"), true, "Set checked attribute" ); - equal( jQuery("#check2").attr("checked"), "checked", "Set checked attribute" ); - - jQuery("#text1").prop("readOnly", true); - equals( document.getElementById("text1").readOnly, true, "Set readonly attribute" ); - equals( jQuery("#text1").prop("readOnly"), true, "Set readonly attribute" ); - equals( jQuery("#text1").attr("readonly"), "readonly", "Set readonly attribute" ); - jQuery("#text1").prop("readOnly", false); - equals( document.getElementById("text1").readOnly, false, "Set readonly attribute" ); - equals( jQuery("#text1").prop("readOnly"), false, "Set readonly attribute" ); - equals( jQuery("#text1").attr("readonly"), undefined, "Set readonly attribute" ); - - jQuery("#name").attr("maxlength", "5"); - equals( document.getElementById("name").maxLength, 5, "Set maxlength attribute" ); - jQuery("#name").attr("maxLength", "10"); - equals( document.getElementById("name").maxLength, 10, "Set maxlength attribute" ); - - var $text = jQuery("#text1").attr("autofocus", true); - if ( "autofocus" in $text[0] ) { - equals( $text.attr("autofocus"), "autofocus", "Set boolean attributes to the same name"); - } else { - equals( $text.attr("autofocus"), undefined, "autofocus stays undefined in browsers that do not support it(F<4)"); - } - equals( $text.attr("autofocus", false).attr("autofocus"), undefined, "Setting autofocus attribute to false removes it"); - equals( $text.attr("data-something", true).data("something"), true, "Setting data attributes are not affected by boolean settings"); - equals( $text.attr("data-another", false).data("another"), false, "Setting data attributes are not affected by boolean settings" ); - equals( $text.attr("aria-disabled", false).attr("aria-disabled"), "false", "Setting aria attributes are not affected by boolean settings"); - $text.removeData("something").removeData("another").removeAttr("aria-disabled"); - - jQuery("#foo").attr("contenteditable", true); - equals( jQuery("#foo").attr("contenteditable"), "true", "Enumerated attributes are set properly" ); - - var attributeNode = document.createAttribute("irrelevant"), - commentNode = document.createComment("some comment"), - textNode = document.createTextNode("some text"), - obj = {}; - - jQuery.each( [commentNode, textNode, attributeNode], function( i, elem ) { - var $elem = jQuery( elem ); - $elem.attr( "nonexisting", "foo" ); - strictEqual( $elem.attr("nonexisting"), undefined, "attr(name, value) works correctly on comment and text nodes (bug #7500)." ); - }); - - jQuery.each( [window, document, obj, "#firstp"], function( i, elem ) { - var $elem = jQuery( elem ); - strictEqual( $elem.attr("nonexisting"), undefined, "attr works correctly for non existing attributes (bug #7500)." ); - equal( $elem.attr("something", "foo" ).attr("something"), "foo", "attr falls back to prop on unsupported arguments" ); - }); - - var table = jQuery("#table").append("cellcellcellcellcell"), - td = table.find("td:first"); - td.attr("rowspan", "2"); - equals( td[0].rowSpan, 2, "Check rowspan is correctly set" ); - td.attr("colspan", "2"); - equals( td[0].colSpan, 2, "Check colspan is correctly set" ); - table.attr("cellspacing", "2"); - equals( table[0].cellSpacing, "2", "Check cellspacing is correctly set" ); - - equals( jQuery("#area1").attr("value"), "foobar", "Value attribute retrieves the property for backwards compatibility." ); - - // for #1070 - jQuery("#name").attr("someAttr", "0"); - equals( jQuery("#name").attr("someAttr"), "0", "Set attribute to a string of \"0\"" ); - jQuery("#name").attr("someAttr", 0); - equals( jQuery("#name").attr("someAttr"), "0", "Set attribute to the number 0" ); - jQuery("#name").attr("someAttr", 1); - equals( jQuery("#name").attr("someAttr"), "1", "Set attribute to the number 1" ); - - // using contents will get comments regular, text, and comment nodes - var j = jQuery("#nonnodes").contents(); - - j.attr("name", "attrvalue"); - equals( j.attr("name"), "attrvalue", "Check node,textnode,comment for attr" ); - j.removeAttr("name"); - - QUnit.reset(); - - // Type - var type = jQuery("#check2").attr("type"); - var thrown = false; - try { - jQuery("#check2").attr("type","hidden"); - } catch(e) { - thrown = true; - } - ok( thrown, "Exception thrown when trying to change type property" ); - equals( type, jQuery("#check2").attr("type"), "Verify that you can't change the type of an input element" ); - - var check = document.createElement("input"); - var thrown = true; - try { - jQuery(check).attr("type", "checkbox"); - } catch(e) { - thrown = false; - } - ok( thrown, "Exception thrown when trying to change type property" ); - equals( "checkbox", jQuery(check).attr("type"), "Verify that you can change the type of an input element that isn't in the DOM" ); - - var check = jQuery(""); - var thrown = true; - try { - check.attr("type","checkbox"); - } catch(e) { - thrown = false; - } - ok( thrown, "Exception thrown when trying to change type property" ); - equals( "checkbox", check.attr("type"), "Verify that you can change the type of an input element that isn't in the DOM" ); - - var button = jQuery("#button"); - var thrown = false; - try { - button.attr("type","submit"); - } catch(e) { - thrown = true; - } - ok( thrown, "Exception thrown when trying to change type property" ); - equals( "button", button.attr("type"), "Verify that you can't change the type of a button element" ); - - var $radio = jQuery("", { "value": "sup", "type": "radio" }).appendTo("#testForm"); - equals( $radio.val(), "sup", "Value is not reset when type is set after value on a radio" ); - - // Setting attributes on svg elements (bug #3116) - var $svg = jQuery("" - + "" - + "").appendTo("body"); - equals( $svg.attr("cx", 100).attr("cx"), "100", "Set attribute on svg element" ); - $svg.remove(); -}); - -test("attr(jquery_method)", function(){ - expect(7); - - var $elem = jQuery("
                "), - elem = $elem[0]; - - // one at a time - $elem.attr({html: "foo"}, true); - equals( elem.innerHTML, "foo", "attr(html)"); - - $elem.attr({text: "bar"}, true); - equals( elem.innerHTML, "bar", "attr(text)"); - - $elem.attr({css: {color: "red"}}, true); - ok( /^(#ff0000|red)$/i.test(elem.style.color), "attr(css)"); - - $elem.attr({height: 10}, true); - equals( elem.style.height, "10px", "attr(height)"); - - // Multiple attributes - - $elem.attr({ - width:10, - css:{ paddingLeft:1, paddingRight:1 } - }, true); - - equals( elem.style.width, "10px", "attr({...})"); - equals( elem.style.paddingLeft, "1px", "attr({...})"); - equals( elem.style.paddingRight, "1px", "attr({...})"); -}); - -if ( !isLocal ) { - test("attr(String, Object) - Loaded via XML document", function() { - expect(2); - stop(); - jQuery.get("data/dashboard.xml", function( xml ) { - var titles = []; - jQuery( "tab", xml ).each(function() { - titles.push( jQuery(this).attr("title") ); - }); - equals( titles[0], "Location", "attr() in XML context: Check first title" ); - equals( titles[1], "Users", "attr() in XML context: Check second title" ); - start(); - }); - }); -} - -test("attr('tabindex')", function() { - expect(8); - - // elements not natively tabbable - equals(jQuery("#listWithTabIndex").attr("tabindex"), 5, "not natively tabbable, with tabindex set to 0"); - equals(jQuery("#divWithNoTabIndex").attr("tabindex"), undefined, "not natively tabbable, no tabindex set"); - - // anchor with href - equals(jQuery("#linkWithNoTabIndex").attr("tabindex"), 0, "anchor with href, no tabindex set"); - equals(jQuery("#linkWithTabIndex").attr("tabindex"), 2, "anchor with href, tabindex set to 2"); - equals(jQuery("#linkWithNegativeTabIndex").attr("tabindex"), -1, "anchor with href, tabindex set to -1"); - - // anchor without href - equals(jQuery("#linkWithNoHrefWithNoTabIndex").attr("tabindex"), undefined, "anchor without href, no tabindex set"); - equals(jQuery("#linkWithNoHrefWithTabIndex").attr("tabindex"), 1, "anchor without href, tabindex set to 2"); - equals(jQuery("#linkWithNoHrefWithNegativeTabIndex").attr("tabindex"), -1, "anchor without href, no tabindex set"); -}); - -test("attr('tabindex', value)", function() { - expect(9); - - var element = jQuery("#divWithNoTabIndex"); - equals(element.attr("tabindex"), undefined, "start with no tabindex"); - - // set a positive string - element.attr("tabindex", "1"); - equals(element.attr("tabindex"), 1, "set tabindex to 1 (string)"); - - // set a zero string - element.attr("tabindex", "0"); - equals(element.attr("tabindex"), 0, "set tabindex to 0 (string)"); - - // set a negative string - element.attr("tabindex", "-1"); - equals(element.attr("tabindex"), -1, "set tabindex to -1 (string)"); - - // set a positive number - element.attr("tabindex", 1); - equals(element.attr("tabindex"), 1, "set tabindex to 1 (number)"); - - // set a zero number - element.attr("tabindex", 0); - equals(element.attr("tabindex"), 0, "set tabindex to 0 (number)"); - - // set a negative number - element.attr("tabindex", -1); - equals(element.attr("tabindex"), -1, "set tabindex to -1 (number)"); - - element = jQuery("#linkWithTabIndex"); - equals(element.attr("tabindex"), 2, "start with tabindex 2"); - - element.attr("tabindex", -1); - equals(element.attr("tabindex"), -1, "set negative tabindex"); -}); - -test("removeAttr(String)", function() { - expect(7); - equals( jQuery("#mark").removeAttr( "class" )[0].className, "", "remove class" ); - equals( jQuery("#form").removeAttr("id").attr("id"), undefined, "Remove id" ); - equals( jQuery("#foo").attr("style", "position:absolute;").removeAttr("style").attr("style"), undefined, "Check removing style attribute" ); - equals( jQuery("#form").attr("style", "position:absolute;").removeAttr("style").attr("style"), undefined, "Check removing style attribute on a form" ); - equals( jQuery("#fx-test-group").attr("height", "3px").removeAttr("height").css("height"), "1px", "Removing height attribute has no effect on height set with style attribute" ); - - jQuery("#check1").removeAttr("checked").prop("checked", true).removeAttr("checked"); - equals( document.getElementById("check1").checked, false, "removeAttr sets boolean properties to false" ); - jQuery("#text1").prop("readOnly", true).removeAttr("readonly"); - equals( document.getElementById("text1").readOnly, false, "removeAttr sets boolean properties to false" ); -}); - -test("prop(String, Object)", function() { - expect(30); - - equals( jQuery("#text1").prop("value"), "Test", "Check for value attribute" ); - equals( jQuery("#text1").prop("value", "Test2").prop("defaultValue"), "Test", "Check for defaultValue attribute" ); - equals( jQuery("#select2").prop("selectedIndex"), 3, "Check for selectedIndex attribute" ); - equals( jQuery("#foo").prop("nodeName").toUpperCase(), "DIV", "Check for nodeName attribute" ); - equals( jQuery("#foo").prop("tagName").toUpperCase(), "DIV", "Check for tagName attribute" ); - equals( jQuery(""); - $select1.val(valueObj( 4 )); - equals( $select1.val(), "4", "Should be possible to set the val() to a newly created option" ); - - // using contents will get comments regular, text, and comment nodes - var j = jQuery("#nonnodes").contents(); - j.val(valueObj( "asdf" )); - equals( j.val(), "asdf", "Check node,textnode,comment with val()" ); - j.removeAttr("value"); -} - -test("val(String/Number)", function() { - testVal(bareObj); -}); - -test("val(Function)", function() { - testVal(functionReturningObj); -}); - -test( "val(Array of Numbers) (Bug #7123)", function() { - expect(4); - jQuery("#form").append(""); - var elements = jQuery("input[name=arrayTest]").val([ 1, 2 ]); - ok( elements[0].checked, "First element was checked" ); - ok( elements[1].checked, "Second element was checked" ); - ok( !elements[2].checked, "Third element was unchecked" ); - ok( !elements[3].checked, "Fourth element remained unchecked" ); - - elements.remove(); -}); - -test("val(Function) with incoming value", function() { - expect(10); - - QUnit.reset(); - var oldVal = jQuery("#text1").val(); - - jQuery("#text1").val(function(i, val) { - equals( val, oldVal, "Make sure the incoming value is correct." ); - return "test"; - }); - - equals( document.getElementById("text1").value, "test", "Check for modified (via val(String)) value of input element" ); - - oldVal = jQuery("#text1").val(); - - jQuery("#text1").val(function(i, val) { - equals( val, oldVal, "Make sure the incoming value is correct." ); - return 67; - }); - - equals( document.getElementById("text1").value, "67", "Check for modified (via val(Number)) value of input element" ); - - oldVal = jQuery("#select1").val(); - - jQuery("#select1").val(function(i, val) { - equals( val, oldVal, "Make sure the incoming value is correct." ); - return "3"; - }); - - equals( jQuery("#select1").val(), "3", "Check for modified (via val(String)) value of select element" ); - - oldVal = jQuery("#select1").val(); - - jQuery("#select1").val(function(i, val) { - equals( val, oldVal, "Make sure the incoming value is correct." ); - return 2; - }); - - equals( jQuery("#select1").val(), "2", "Check for modified (via val(Number)) value of select element" ); - - jQuery("#select1").append(""); - - oldVal = jQuery("#select1").val(); - - jQuery("#select1").val(function(i, val) { - equals( val, oldVal, "Make sure the incoming value is correct." ); - return 4; - }); - - equals( jQuery("#select1").val(), "4", "Should be possible to set the val() to a newly created option" ); -}); - -// testing if a form.reset() breaks a subsequent call to a select element's .val() (in IE only) -test("val(select) after form.reset() (Bug #2551)", function() { - expect(3); - - jQuery("
                ").appendTo("#qunit-fixture"); - - jQuery("#kkk").val( "gf" ); - - document.kk.reset(); - - equal( jQuery("#kkk")[0].value, "cf", "Check value of select after form reset." ); - equal( jQuery("#kkk").val(), "cf", "Check value of select after form reset." ); - - // re-verify the multi-select is not broken (after form.reset) by our fix for single-select - same( jQuery("#select3").val(), ["1", "2"], "Call val() on a multiple=\"multiple\" select" ); - - jQuery("#kk").remove(); -}); - -var testAddClass = function(valueObj) { - expect(9); - - var div = jQuery("div"); - div.addClass( valueObj("test") ); - var pass = true; - for ( var i = 0; i < div.size(); i++ ) { - if ( !~div.get(i).className.indexOf("test") ) { - pass = false; - } - } - ok( pass, "Add Class" ); - - // using contents will get regular, text, and comment nodes - var j = jQuery("#nonnodes").contents(); - j.addClass( valueObj("asdf") ); - ok( j.hasClass("asdf"), "Check node,textnode,comment for addClass" ); - - div = jQuery("
                "); - - div.addClass( valueObj("test") ); - equals( div.attr("class"), "test", "Make sure there's no extra whitespace." ); - - div.attr("class", " foo"); - div.addClass( valueObj("test") ); - equals( div.attr("class"), "foo test", "Make sure there's no extra whitespace." ); - - div.attr("class", "foo"); - div.addClass( valueObj("bar baz") ); - equals( div.attr("class"), "foo bar baz", "Make sure there isn't too much trimming." ); - - div.removeClass(); - div.addClass( valueObj("foo") ).addClass( valueObj("foo") ) - equal( div.attr("class"), "foo", "Do not add the same class twice in separate calls." ); - - div.addClass( valueObj("fo") ); - equal( div.attr("class"), "foo fo", "Adding a similar class does not get interrupted." ); - div.removeClass().addClass("wrap2"); - ok( div.addClass("wrap").hasClass("wrap"), "Can add similarly named classes"); - - div.removeClass(); - div.addClass( valueObj("bar bar") ); - equal( div.attr("class"), "bar", "Do not add the same class twice in the same call." ); -}; - -test("addClass(String)", function() { - testAddClass(bareObj); -}); - -test("addClass(Function)", function() { - testAddClass(functionReturningObj); -}); - -test("addClass(Function) with incoming value", function() { - expect(45); - var div = jQuery("div"), old = div.map(function(){ - return jQuery(this).attr("class") || ""; - }); - - div.addClass(function(i, val) { - if ( this.id !== "_firebugConsole") { - equals( val, old[i], "Make sure the incoming value is correct." ); - return "test"; - } - }); - - var pass = true; - for ( var i = 0; i < div.length; i++ ) { - if ( div.get(i).className.indexOf("test") == -1 ) pass = false; - } - ok( pass, "Add Class" ); -}); - -var testRemoveClass = function(valueObj) { - expect(7); - - var $divs = jQuery("div"); - - $divs.addClass("test").removeClass( valueObj("test") ); - - ok( !$divs.is(".test"), "Remove Class" ); - - QUnit.reset(); - $divs = jQuery("div"); - - $divs.addClass("test").addClass("foo").addClass("bar"); - $divs.removeClass( valueObj("test") ).removeClass( valueObj("bar") ).removeClass( valueObj("foo") ); - - ok( !$divs.is(".test,.bar,.foo"), "Remove multiple classes" ); - - QUnit.reset(); - $divs = jQuery("div"); - - // Make sure that a null value doesn't cause problems - $divs.eq(0).addClass("test").removeClass( valueObj(null) ); - ok( $divs.eq(0).is(".test"), "Null value passed to removeClass" ); - - $divs.eq(0).addClass("test").removeClass( valueObj("") ); - ok( $divs.eq(0).is(".test"), "Empty string passed to removeClass" ); - - // using contents will get regular, text, and comment nodes - var j = jQuery("#nonnodes").contents(); - j.removeClass( valueObj("asdf") ); - ok( !j.hasClass("asdf"), "Check node,textnode,comment for removeClass" ); - - var div = document.createElement("div"); - div.className = " test foo "; - - jQuery(div).removeClass( valueObj("foo") ); - equals( div.className, "test", "Make sure remaining className is trimmed." ); - - div.className = " test "; - - jQuery(div).removeClass( valueObj("test") ); - equals( div.className, "", "Make sure there is nothing left after everything is removed." ); -}; - -test("removeClass(String) - simple", function() { - testRemoveClass(bareObj); -}); - -test("removeClass(Function) - simple", function() { - testRemoveClass(functionReturningObj); -}); - -test("removeClass(Function) with incoming value", function() { - expect(45); - - var $divs = jQuery("div").addClass("test"), old = $divs.map(function(){ - return jQuery(this).attr("class"); - }); - - $divs.removeClass(function(i, val) { - if ( this.id !== "_firebugConsole" ) { - equals( val, old[i], "Make sure the incoming value is correct." ); - return "test"; - } - }); - - ok( !$divs.is(".test"), "Remove Class" ); - - QUnit.reset(); -}); - -var testToggleClass = function(valueObj) { - expect(17); - - var e = jQuery("#firstp"); - ok( !e.is(".test"), "Assert class not present" ); - e.toggleClass( valueObj("test") ); - ok( e.is(".test"), "Assert class present" ); - e.toggleClass( valueObj("test") ); - ok( !e.is(".test"), "Assert class not present" ); - - // class name with a boolean - e.toggleClass( valueObj("test"), false ); - ok( !e.is(".test"), "Assert class not present" ); - e.toggleClass( valueObj("test"), true ); - ok( e.is(".test"), "Assert class present" ); - e.toggleClass( valueObj("test"), false ); - ok( !e.is(".test"), "Assert class not present" ); - - // multiple class names - e.addClass("testA testB"); - ok( (e.is(".testA.testB")), "Assert 2 different classes present" ); - e.toggleClass( valueObj("testB testC") ); - ok( (e.is(".testA.testC") && !e.is(".testB")), "Assert 1 class added, 1 class removed, and 1 class kept" ); - e.toggleClass( valueObj("testA testC") ); - ok( (!e.is(".testA") && !e.is(".testB") && !e.is(".testC")), "Assert no class present" ); - - // toggleClass storage - e.toggleClass(true); - ok( e[0].className === "", "Assert class is empty (data was empty)" ); - e.addClass("testD testE"); - ok( e.is(".testD.testE"), "Assert class present" ); - e.toggleClass(); - ok( !e.is(".testD.testE"), "Assert class not present" ); - ok( jQuery._data(e[0], "__className__") === "testD testE", "Assert data was stored" ); - e.toggleClass(); - ok( e.is(".testD.testE"), "Assert class present (restored from data)" ); - e.toggleClass(false); - ok( !e.is(".testD.testE"), "Assert class not present" ); - e.toggleClass(true); - ok( e.is(".testD.testE"), "Assert class present (restored from data)" ); - e.toggleClass(); - e.toggleClass(false); - e.toggleClass(); - ok( e.is(".testD.testE"), "Assert class present (restored from data)" ); - - // Cleanup - e.removeClass("testD"); - jQuery.removeData(e[0], "__className__", true); -}; - -test("toggleClass(String|boolean|undefined[, boolean])", function() { - testToggleClass(bareObj); -}); - -test("toggleClass(Function[, boolean])", function() { - testToggleClass(functionReturningObj); -}); - -test("toggleClass(Fucntion[, boolean]) with incoming value", function() { - expect(14); - - var e = jQuery("#firstp"), old = e.attr("class") || ""; - ok( !e.is(".test"), "Assert class not present" ); - - e.toggleClass(function(i, val) { - equals( val, old, "Make sure the incoming value is correct." ); - return "test"; - }); - ok( e.is(".test"), "Assert class present" ); - - old = e.attr("class"); - - e.toggleClass(function(i, val) { - equals( val, old, "Make sure the incoming value is correct." ); - return "test"; - }); - ok( !e.is(".test"), "Assert class not present" ); - - old = e.attr("class"); - - // class name with a boolean - e.toggleClass(function(i, val, state) { - equals( val, old, "Make sure the incoming value is correct." ); - equals( state, false, "Make sure that the state is passed in." ); - return "test"; - }, false ); - ok( !e.is(".test"), "Assert class not present" ); - - old = e.attr("class"); - - e.toggleClass(function(i, val, state) { - equals( val, old, "Make sure the incoming value is correct." ); - equals( state, true, "Make sure that the state is passed in." ); - return "test"; - }, true ); - ok( e.is(".test"), "Assert class present" ); - - old = e.attr("class"); - - e.toggleClass(function(i, val, state) { - equals( val, old, "Make sure the incoming value is correct." ); - equals( state, false, "Make sure that the state is passed in." ); - return "test"; - }, false ); - ok( !e.is(".test"), "Assert class not present" ); - - // Cleanup - e.removeClass("test"); - jQuery.removeData(e[0], "__className__", true); -}); - -test("addClass, removeClass, hasClass", function() { - expect(17); - - var jq = jQuery("

                Hi

                "), x = jq[0]; - - jq.addClass("hi"); - equals( x.className, "hi", "Check single added class" ); - - jq.addClass("foo bar"); - equals( x.className, "hi foo bar", "Check more added classes" ); - - jq.removeClass(); - equals( x.className, "", "Remove all classes" ); - - jq.addClass("hi foo bar"); - jq.removeClass("foo"); - equals( x.className, "hi bar", "Check removal of one class" ); - - ok( jq.hasClass("hi"), "Check has1" ); - ok( jq.hasClass("bar"), "Check has2" ); - - var jq = jQuery("

                "); - ok( jq.hasClass("class1"), "Check hasClass with line feed" ); - ok( jq.is(".class1"), "Check is with line feed" ); - ok( jq.hasClass("class2"), "Check hasClass with tab" ); - ok( jq.is(".class2"), "Check is with tab" ); - ok( jq.hasClass("cla.ss3"), "Check hasClass with dot" ); - ok( jq.hasClass("class4"), "Check hasClass with carriage return" ); - ok( jq.is(".class4"), "Check is with carriage return" ); - - jq.removeClass("class2"); - ok( jq.hasClass("class2")==false, "Check the class has been properly removed" ); - jq.removeClass("cla"); - ok( jq.hasClass("cla.ss3"), "Check the dotted class has not been removed" ); - jq.removeClass("cla.ss3"); - ok( jq.hasClass("cla.ss3")==false, "Check the dotted class has been removed" ); - jq.removeClass("class4"); - ok( jq.hasClass("class4")==false, "Check the class has been properly removed" ); -}); diff --git a/test/unit/core.js b/test/unit/core.js index 3a155352..3cb90aa7 100644 --- a/test/unit/core.js +++ b/test/unit/core.js @@ -1,4 +1,4 @@ -module("core", { teardown: moduleTeardown }); +module("core"); test("Basic requirements", function() { expect(7); @@ -8,354 +8,100 @@ test("Basic requirements", function() { ok( document.getElementsByTagName, "getElementsByTagName" ); ok( RegExp, "RegExp" ); ok( jQuery, "jQuery" ); - ok( $, "$" ); + ok( $, "$()" ); }); -test("jQuery()", function() { - expect(29); - - // Basic constructor's behavior - - equals( jQuery().length, 0, "jQuery() === jQuery([])" ); - equals( jQuery(undefined).length, 0, "jQuery(undefined) === jQuery([])" ); - equals( jQuery(null).length, 0, "jQuery(null) === jQuery([])" ); - equals( jQuery("").length, 0, "jQuery('') === jQuery([])" ); - equals( jQuery("#").length, 0, "jQuery('#') === jQuery([])" ); - - var obj = jQuery("div"); - equals( jQuery(obj).selector, "div", "jQuery(jQueryObj) == jQueryObj" ); - - // can actually yield more than one, when iframes are included, the window is an array as well - equals( jQuery(window).length, 1, "Correct number of elements generated for jQuery(window)" ); - - - var main = jQuery("#qunit-fixture"); - same( jQuery("div p", main).get(), q("sndp", "en", "sap"), "Basic selector with jQuery object as context" ); - +test("$()", function() { + expect(4); + + var main = $("#main"); + isSet( $("div p", main).get(), q("sndp", "en", "sap"), "Basic selector with jQuery object as context" ); + /* // disabled since this test was doing nothing. i tried to fix it but i'm not sure // what the expected behavior should even be. FF returns "\n" for the text node // make sure this is handled - var crlfContainer = jQuery('

                \r\n

                '); + var crlfContainer = $('

                \r\n

                '); var x = crlfContainer.contents().get(0).nodeValue; equals( x, what???, "Check for \\r and \\n in jQuery()" ); */ - + /* // Disabled until we add this functionality in var pass = true; try { - jQuery("
                Testing
                ").appendTo(document.getElementById("iframe").contentDocument.body); + $("
                Testing
                ").appendTo(document.getElementById("iframe").contentDocument.body); } catch(e){ pass = false; } - ok( pass, "jQuery('<tag>') needs optional document parameter to ease cross-frame DOM wrangling, see #968" );*/ + ok( pass, "$('<tag>') needs optional document parameter to ease cross-frame DOM wrangling, see #968" );*/ - var code = jQuery(""); + var code = $(""); equals( code.length, 1, "Correct number of elements generated for code" ); - equals( code.parent().length, 0, "Make sure that the generated HTML has no parent." ); - var img = jQuery(""); + var img = $(""); equals( img.length, 1, "Correct number of elements generated for img" ); - equals( img.parent().length, 0, "Make sure that the generated HTML has no parent." ); - var div = jQuery("

                "); + var div = $("

                "); equals( div.length, 4, "Correct number of elements generated for div hr code b" ); - equals( div.parent().length, 0, "Make sure that the generated HTML has no parent." ); - - equals( jQuery([1,2,3]).get(1), 2, "Test passing an array to the factory" ); - - equals( jQuery(document.body).get(0), jQuery("body").get(0), "Test passing an html node to the factory" ); - - var exec = false; - - var elem = jQuery("
                ", { - width: 10, - css: { paddingLeft:1, paddingRight:1 }, - click: function(){ ok(exec, "Click executed."); }, - text: "test", - "class": "test2", - id: "test3" - }); - - equals( elem[0].style.width, "10px", "jQuery() quick setter width"); - equals( elem[0].style.paddingLeft, "1px", "jQuery quick setter css"); - equals( elem[0].style.paddingRight, "1px", "jQuery quick setter css"); - equals( elem[0].childNodes.length, 1, "jQuery quick setter text"); - equals( elem[0].firstChild.nodeValue, "test", "jQuery quick setter text"); - equals( elem[0].className, "test2", "jQuery() quick setter class"); - equals( elem[0].id, "test3", "jQuery() quick setter id"); - - exec = true; - elem.click(); - - // manually clean up detached elements - elem.remove(); - - for ( var i = 0; i < 3; ++i ) { - elem = jQuery(""); - } - equals( elem[0].defaultValue, "TEST", "Ensure cached nodes are cloned properly (Bug #6655)" ); - - // manually clean up detached elements - elem.remove(); - - equals( jQuery("
                ").length, 1, "Make sure whitespace is trimmed." ); - equals( jQuery(" a
                b ").length, 1, "Make sure whitespace and other characters are trimmed." ); - - var long = ""; - for ( var i = 0; i < 128; i++ ) { - long += "12345678"; - } - - equals( jQuery("
                " + long + "
                ").length, 1, "Make sure whitespace is trimmed on long strings." ); - equals( jQuery(" a
                " + long + "
                b ").length, 1, "Make sure whitespace and other characters are trimmed on long strings." ); }); -test("selector state", function() { - expect(31); - - var test; - - test = jQuery(undefined); - equals( test.selector, "", "Empty jQuery Selector" ); - equals( test.context, undefined, "Empty jQuery Context" ); - - test = jQuery(document); - equals( test.selector, "", "Document Selector" ); - equals( test.context, document, "Document Context" ); - - test = jQuery(document.body); - equals( test.selector, "", "Body Selector" ); - equals( test.context, document.body, "Body Context" ); - - test = jQuery("#qunit-fixture"); - equals( test.selector, "#qunit-fixture", "#qunit-fixture Selector" ); - equals( test.context, document, "#qunit-fixture Context" ); - - test = jQuery("#notfoundnono"); - equals( test.selector, "#notfoundnono", "#notfoundnono Selector" ); - equals( test.context, document, "#notfoundnono Context" ); - - test = jQuery("#qunit-fixture", document); - equals( test.selector, "#qunit-fixture", "#qunit-fixture Selector" ); - equals( test.context, document, "#qunit-fixture Context" ); - - test = jQuery("#qunit-fixture", document.body); - equals( test.selector, "#qunit-fixture", "#qunit-fixture Selector" ); - equals( test.context, document.body, "#qunit-fixture Context" ); - - // Test cloning - test = jQuery(test); - equals( test.selector, "#qunit-fixture", "#qunit-fixture Selector" ); - equals( test.context, document.body, "#qunit-fixture Context" ); - - test = jQuery(document.body).find("#qunit-fixture"); - equals( test.selector, "#qunit-fixture", "#qunit-fixture find Selector" ); - equals( test.context, document.body, "#qunit-fixture find Context" ); - - test = jQuery("#qunit-fixture").filter("div"); - equals( test.selector, "#qunit-fixture.filter(div)", "#qunit-fixture filter Selector" ); - equals( test.context, document, "#qunit-fixture filter Context" ); - - test = jQuery("#qunit-fixture").not("div"); - equals( test.selector, "#qunit-fixture.not(div)", "#qunit-fixture not Selector" ); - equals( test.context, document, "#qunit-fixture not Context" ); - - test = jQuery("#qunit-fixture").filter("div").not("div"); - equals( test.selector, "#qunit-fixture.filter(div).not(div)", "#qunit-fixture filter, not Selector" ); - equals( test.context, document, "#qunit-fixture filter, not Context" ); - - test = jQuery("#qunit-fixture").filter("div").not("div").end(); - equals( test.selector, "#qunit-fixture.filter(div)", "#qunit-fixture filter, not, end Selector" ); - equals( test.context, document, "#qunit-fixture filter, not, end Context" ); - - test = jQuery("#qunit-fixture").parent("body"); - equals( test.selector, "#qunit-fixture.parent(body)", "#qunit-fixture parent Selector" ); - equals( test.context, document, "#qunit-fixture parent Context" ); - - test = jQuery("#qunit-fixture").eq(0); - equals( test.selector, "#qunit-fixture.slice(0,1)", "#qunit-fixture eq Selector" ); - equals( test.context, document, "#qunit-fixture eq Context" ); - - var d = "
                "; - equals( - jQuery(d).appendTo(jQuery(d)).selector, - jQuery(d).appendTo(d).selector, - "manipulation methods make same selector for jQuery objects" - ); -}); - -test( "globalEval", function() { - - expect( 3 ); - - jQuery.globalEval( "var globalEvalTest = true;" ); - ok( window.globalEvalTest, "Test variable declarations are global" ); - - window.globalEvalTest = false; - - jQuery.globalEval( "globalEvalTest = true;" ); - ok( window.globalEvalTest, "Test variable assignments are global" ); - - window.globalEvalTest = false; - - jQuery.globalEval( "this.globalEvalTest = true;" ); - ok( window.globalEvalTest, "Test context (this) is the window object" ); - - window.globalEvalTest = undefined; -}); - -if ( !isLocal ) { test("browser", function() { - stop(); - - jQuery.get("data/ua.txt", function(data){ - var uas = data.split("\n"); - expect( (uas.length - 1) * 2 ); - - jQuery.each(uas, function(){ - var parts = this.split("\t"); - if ( parts[2] ) { - var ua = jQuery.uaMatch( parts[2] ); - equals( ua.browser, parts[0], "Checking browser for " + parts[2] ); - equals( ua.version, parts[1], "Checking version string for " + parts[2] ); - } - }); - - start(); - }); + expect(13); + var browsers = { + //Internet Explorer + "Mozilla/5.0 (Windows; U; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)": "6.0", + "Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 5.1; .NET CLR 1.1.4322; InfoPath.1; .NET CLR 2.0.50727)": "7.0", + /** Failing #1876 + * "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; .NET CLR 2.0.50727; .NET CLR 1.1.4322; .NET CLR 3.0.04506.30)": "7.0", + */ + //Browsers with Gecko engine + //Mozilla + "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.12) Gecko/20050915" : "1.7.12", + //Firefox + "Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3": "1.8.1.3", + //Netscape + "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5) Gecko/20070321 Netscape/8.1.3" : "1.7.5", + //Flock + "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.11) Gecko/20070321 Firefox/1.5.0.11 Flock/0.7.12" : "1.8.0.11", + //Opera browser + "Opera/9.20 (X11; Linux x86_64; U; en)": "9.20", + "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; en) Opera 9.20" : "9.20", + "Mozilla/5.0 (Windows NT 5.1; U; pl; rv:1.8.0) Gecko/20060728 Firefox/1.5.0 Opera 9.20": "9.20", + //WebKit engine + "Mozilla/5.0 (Macintosh; U; PPC Mac OS X; sv-se) AppleWebKit/418.9 (KHTML, like Gecko) Safari/419.3": "418.9", + "Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/418.8 (KHTML, like Gecko) Safari/419.3" : "418.8", + "Mozilla/5.0 (Macintosh; U; PPC Mac OS X; sv-se) AppleWebKit/312.8 (KHTML, like Gecko) Safari/312.5": "312.8", + //Other user agent string + "Other browser's user agent 1.0":null + }; + for (var i in browsers) { + var v = i.toLowerCase().match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ); // RegEx from Core jQuery.browser.version check + version = v ? v[1] : null; + equals( version, browsers[i], "Checking UA string" ); + } }); -} test("noConflict", function() { - expect(7); + expect(6); + + var old = jQuery; + var newjQuery = jQuery.noConflict(); - var $$ = jQuery; + ok( newjQuery == old, "noConflict returned the jQuery object" ); + ok( jQuery == old, "Make sure jQuery wasn't touched." ); + ok( $ == "$", "Make sure $ was reverted." ); - equals( jQuery, jQuery.noConflict(), "noConflict returned the jQuery object" ); - equals( jQuery, $$, "Make sure jQuery wasn't touched." ); - equals( $, original$, "Make sure $ was reverted." ); + jQuery = $ = old; - jQuery = $ = $$; + newjQuery = jQuery.noConflict(true); - equals( jQuery.noConflict(true), $$, "noConflict returned the jQuery object" ); - equals( jQuery, originaljQuery, "Make sure jQuery was reverted." ); - equals( $, original$, "Make sure $ was reverted." ); - ok( $$("#qunit-fixture").html("test"), "Make sure that jQuery still works." ); + ok( newjQuery == old, "noConflict returned the jQuery object" ); + ok( jQuery == "jQuery", "Make sure jQuery was reverted." ); + ok( $ == "$", "Make sure $ was reverted." ); - jQuery = $$; -}); - -test("trim", function() { - expect(9); - - var nbsp = String.fromCharCode(160); - - equals( jQuery.trim("hello "), "hello", "trailing space" ); - equals( jQuery.trim(" hello"), "hello", "leading space" ); - equals( jQuery.trim(" hello "), "hello", "space on both sides" ); - equals( jQuery.trim(" " + nbsp + "hello " + nbsp + " "), "hello", " " ); - - equals( jQuery.trim(), "", "Nothing in." ); - equals( jQuery.trim( undefined ), "", "Undefined" ); - equals( jQuery.trim( null ), "", "Null" ); - equals( jQuery.trim( 5 ), "5", "Number" ); - equals( jQuery.trim( false ), "false", "Boolean" ); -}); - -test("type", function() { - expect(23); - - equals( jQuery.type(null), "null", "null" ); - equals( jQuery.type(undefined), "undefined", "undefined" ); - equals( jQuery.type(true), "boolean", "Boolean" ); - equals( jQuery.type(false), "boolean", "Boolean" ); - equals( jQuery.type(Boolean(true)), "boolean", "Boolean" ); - equals( jQuery.type(0), "number", "Number" ); - equals( jQuery.type(1), "number", "Number" ); - equals( jQuery.type(Number(1)), "number", "Number" ); - equals( jQuery.type(""), "string", "String" ); - equals( jQuery.type("a"), "string", "String" ); - equals( jQuery.type(String("a")), "string", "String" ); - equals( jQuery.type({}), "object", "Object" ); - equals( jQuery.type(/foo/), "regexp", "RegExp" ); - equals( jQuery.type(new RegExp("asdf")), "regexp", "RegExp" ); - equals( jQuery.type([1]), "array", "Array" ); - equals( jQuery.type(new Date()), "date", "Date" ); - equals( jQuery.type(new Function("return;")), "function", "Function" ); - equals( jQuery.type(function(){}), "function", "Function" ); - equals( jQuery.type(window), "object", "Window" ); - equals( jQuery.type(document), "object", "Document" ); - equals( jQuery.type(document.body), "object", "Element" ); - equals( jQuery.type(document.createTextNode("foo")), "object", "TextNode" ); - equals( jQuery.type(document.getElementsByTagName("*")), "object", "NodeList" ); -}); - -test("isPlainObject", function() { - expect(14); - - stop(); - - // The use case that we want to match - ok(jQuery.isPlainObject({}), "{}"); - - // Not objects shouldn't be matched - ok(!jQuery.isPlainObject(""), "string"); - ok(!jQuery.isPlainObject(0) && !jQuery.isPlainObject(1), "number"); - ok(!jQuery.isPlainObject(true) && !jQuery.isPlainObject(false), "boolean"); - ok(!jQuery.isPlainObject(null), "null"); - ok(!jQuery.isPlainObject(undefined), "undefined"); - - // Arrays shouldn't be matched - ok(!jQuery.isPlainObject([]), "array"); - - // Instantiated objects shouldn't be matched - ok(!jQuery.isPlainObject(new Date), "new Date"); - - var fn = function(){}; - - // Functions shouldn't be matched - ok(!jQuery.isPlainObject(fn), "fn"); - - // Again, instantiated objects shouldn't be matched - ok(!jQuery.isPlainObject(new fn), "new fn (no methods)"); - - // Makes the function a little more realistic - // (and harder to detect, incidentally) - fn.prototype = {someMethod: function(){}}; - - // Again, instantiated objects shouldn't be matched - ok(!jQuery.isPlainObject(new fn), "new fn"); - - // DOM Element - ok(!jQuery.isPlainObject(document.createElement("div")), "DOM Element"); - - // Window - ok(!jQuery.isPlainObject(window), "window"); - - try { - var iframe = document.createElement("iframe"); - document.body.appendChild(iframe); - - window.iframeDone = function(otherObject){ - // Objects from other windows should be matched - ok(jQuery.isPlainObject(new otherObject), "new otherObject"); - document.body.removeChild( iframe ); - start(); - }; - - var doc = iframe.contentDocument || iframe.contentWindow.document; - doc.open(); - doc.write(""); - doc.close(); - } catch(e) { - document.body.removeChild( iframe ); - - ok(true, "new otherObject - iframes not supported"); - start(); - } + jQuery = $ = old; }); test("isFunction", function() { - expect(19); + expect(21); // Make sure that false values return false ok( !jQuery.isFunction(), "No Value" ); @@ -366,10 +112,10 @@ test("isFunction", function() { // Check built-ins // Safari uses "(Internal Function)" - ok( jQuery.isFunction(String), "String Function("+String+")" ); - ok( jQuery.isFunction(Array), "Array Function("+Array+")" ); - ok( jQuery.isFunction(Object), "Object Function("+Object+")" ); - ok( jQuery.isFunction(Function), "Function Function("+Function+")" ); + ok( jQuery.isFunction(String), "String Function" ); + ok( jQuery.isFunction(Array), "Array Function" ); + ok( jQuery.isFunction(Object), "Object Function" ); + ok( jQuery.isFunction(Function), "Function Function" ); // When stringified, this could be misinterpreted var mystr = "function"; @@ -393,8 +139,7 @@ test("isFunction", function() { ok( !jQuery.isFunction(obj), "Object Element" ); // IE says this is an object - // Since 1.3, this isn't supported (#2968) - //ok( jQuery.isFunction(obj.getAttribute), "getAttribute Function" ); + ok( jQuery.isFunction(obj.getAttribute), "getAttribute Function" ); var nodes = document.body.childNodes; @@ -402,7 +147,7 @@ test("isFunction", function() { ok( !jQuery.isFunction(nodes), "childNodes Property" ); var first = document.body.firstChild; - + // Normal elements are reported ok everywhere ok( !jQuery.isFunction(first), "A normal DOM Element" ); @@ -411,8 +156,7 @@ test("isFunction", function() { document.body.appendChild( input ); // IE says this is an object - // Since 1.3, this isn't supported (#2968) - //ok( jQuery.isFunction(input.focus), "A default function property" ); + ok( jQuery.isFunction(input.focus), "A default function property" ); document.body.removeChild( input ); @@ -441,183 +185,98 @@ test("isFunction", function() { }); }); -test("isXMLDoc - HTML", function() { - expect(4); +var foo = false; - ok( !jQuery.isXMLDoc( document ), "HTML document" ); - ok( !jQuery.isXMLDoc( document.documentElement ), "HTML documentElement" ); - ok( !jQuery.isXMLDoc( document.body ), "HTML Body Element" ); +test("$('html')", function() { + expect(6); - var iframe = document.createElement("iframe"); - document.body.appendChild( iframe ); - - try { - var body = jQuery(iframe).contents()[0]; - - try { - ok( !jQuery.isXMLDoc( body ), "Iframe body element" ); - } catch(e) { - ok( false, "Iframe body element exception" ); - } - - } catch(e) { - ok( true, "Iframe body element - iframe not working correctly" ); - } - - document.body.removeChild( iframe ); -}); - -if ( !isLocal ) { -test("isXMLDoc - XML", function() { - expect(3); - stop(); - jQuery.get("data/dashboard.xml", function(xml) { - ok( jQuery.isXMLDoc( xml ), "XML document" ); - ok( jQuery.isXMLDoc( xml.documentElement ), "XML documentElement" ); - ok( jQuery.isXMLDoc( jQuery("tab", xml)[0] ), "XML Tab Element" ); - start(); - }); -}); -} - -test("isWindow", function() { - expect( 12 ); - - ok( jQuery.isWindow(window), "window" ); - ok( !jQuery.isWindow(), "empty" ); - ok( !jQuery.isWindow(null), "null" ); - ok( !jQuery.isWindow(undefined), "undefined" ); - ok( !jQuery.isWindow(document), "document" ); - ok( !jQuery.isWindow(document.documentElement), "documentElement" ); - ok( !jQuery.isWindow(""), "string" ); - ok( !jQuery.isWindow(1), "number" ); - ok( !jQuery.isWindow(true), "boolean" ); - ok( !jQuery.isWindow({}), "object" ); - // HMMM - // ok( !jQuery.isWindow({ setInterval: function(){} }), "fake window" ); - ok( !jQuery.isWindow(/window/), "regexp" ); - ok( !jQuery.isWindow(function(){}), "function" ); -}); - -test("jQuery('html')", function() { - expect(18); - - QUnit.reset(); - jQuery.foo = false; - var s = jQuery("")[0]; + reset(); + foo = false; + var s = $("")[0]; ok( s, "Creating a script" ); - ok( !jQuery.foo, "Make sure the script wasn't executed prematurely" ); - jQuery("body").append(""); - ok( jQuery.foo, "Executing a scripts contents in the right context" ); + ok( !foo, "Make sure the script wasn't executed prematurely" ); + $("body").append(s); + ok( foo, "Executing a scripts contents in the right context" ); + + reset(); + ok( $("")[0], "Creating a link" ); + + reset(); - // Test multi-line HTML - var div = jQuery("
                \r\nsome text\n

                some p

                \nmore text\r\n
                ")[0]; - equals( div.nodeName.toUpperCase(), "DIV", "Make sure we're getting a div." ); - equals( div.firstChild.nodeType, 3, "Text node." ); - equals( div.lastChild.nodeType, 3, "Text node." ); - equals( div.childNodes[1].nodeType, 1, "Paragraph." ); - equals( div.childNodes[1].firstChild.nodeType, 3, "Paragraph text." ); - - QUnit.reset(); - ok( jQuery("")[0], "Creating a link" ); - - ok( !jQuery("'); - equals( jQuery.makeArray( 0 )[0], 0 , "Pass makeArray a number" ); + $("#main").html('foo
                '); - equals( jQuery.makeArray( "foo" )[0], "foo", "Pass makeArray a string" ); + // it was decided that waiting to execute ALL scripts makes sense since nested ones have to wait anyway so this test case is changed, see #1959 + $("#main").html(""); - equals(jQuery(".replacewith").length, 1, "Check number of elements in page."); - jQuery(".replacewith").remove(); - - QUnit.reset(); - - jQuery("#qunit-fixture").append("
                "); - equals( jQuery("#qunit-fixture").find("div[id=replaceWith]").length, 1, "Make sure only one div exists." ); - - jQuery("#replaceWith").replaceWith( val("
                ") ); - equals( jQuery("#qunit-fixture").find("div[id=replaceWith]").length, 1, "Make sure only one div exists." ); - - jQuery("#replaceWith").replaceWith( val("
                ") ); - equals( jQuery("#qunit-fixture").find("div[id=replaceWith]").length, 1, "Make sure only one div exists." ); -} - -test("replaceWith(String|Element|Array<Element>|jQuery)", function() { - testReplaceWith(bareObj); -}); - -test("replaceWith(Function)", function() { - testReplaceWith(functionReturningObj); - - expect(22); - - var y = jQuery("#yahoo")[0]; - - jQuery(y).replaceWith(function(){ - equals( this, y, "Make sure the context is coming in correctly." ); - }); - - QUnit.reset(); -}); - -test("replaceWith(string) for more than one element", function(){ - expect(3); - - equals(jQuery("#foo p").length, 3, "ensuring that test data has not changed"); - - jQuery("#foo p").replaceWith("bar"); - equals(jQuery("#foo span").length, 3, "verify that all the three original element have been replaced"); - equals(jQuery("#foo p").length, 0, "verify that all the three original element have been replaced"); -}); - -test("replaceAll(String|Element|Array<Element>|jQuery)", function() { - expect(10); - jQuery("buga").replaceAll("#yahoo"); - ok( jQuery("#replace")[0], "Replace element with string" ); - ok( !jQuery("#yahoo")[0], "Verify that original element is gone, after string" ); - - QUnit.reset(); - jQuery(document.getElementById("first")).replaceAll("#yahoo"); - ok( jQuery("#first")[0], "Replace element with element" ); - ok( !jQuery("#yahoo")[0], "Verify that original element is gone, after element" ); - - QUnit.reset(); - jQuery([document.getElementById("first"), document.getElementById("mark")]).replaceAll("#yahoo"); - ok( jQuery("#first")[0], "Replace element with array of elements" ); - ok( jQuery("#mark")[0], "Replace element with array of elements" ); - ok( !jQuery("#yahoo")[0], "Verify that original element is gone, after array of elements" ); - - QUnit.reset(); - jQuery("#mark, #first").replaceAll("#yahoo"); - ok( jQuery("#first")[0], "Replace element with set of elements" ); - ok( jQuery("#mark")[0], "Replace element with set of elements" ); - ok( !jQuery("#yahoo")[0], "Verify that original element is gone, after set of elements" ); -}); - -test("jQuery.clone() (#8017)", function() { - - expect(2); - - ok( jQuery.clone && jQuery.isFunction( jQuery.clone ) , "jQuery.clone() utility exists and is a function."); - - var main = jQuery("#qunit-fixture")[0], - clone = jQuery.clone( main ); - - equals( main.childNodes.length, clone.childNodes.length, "Simple child length to ensure a large dom tree copies correctly" ); -}); - -test("clone() (#8070)", function () { - expect(2); - - jQuery("").appendTo("#qunit-fixture"); - var selects = jQuery(".test8070"); - selects.append(""); - - equals( selects[0].childNodes.length, 2, "First select got two nodes" ); - equals( selects[1].childNodes.length, 2, "Second select got two nodes" ); - - selects.remove(); -}); - -test("clone()", function() { - expect(37); - equals( "This is a normal link: Yahoo", jQuery("#en").text(), "Assert text for #en" ); - var clone = jQuery("#yahoo").clone(); - equals( "Try them out:Yahoo", jQuery("#first").append(clone).text(), "Check for clone" ); - equals( "This is a normal link: Yahoo", jQuery("#en").text(), "Reassert text for #en" ); - - var cloneTags = [ - "", "", "
                ", "
                ", - "