├── .gitignore ├── .jshintrc ├── .npmignore ├── .travis.yml ├── Gruntfile.js ├── LICENSE-MIT ├── README.md ├── lib └── node-jquery.js ├── package.json ├── src └── .gitkeep └── test ├── collections.js ├── core.js ├── css.js ├── dom.js ├── fixtures ├── core.html ├── css.css └── css.html ├── fn.js ├── index.js ├── objects.js ├── selector.js ├── sub.js ├── type.js └── utils.js /.gitignore: -------------------------------------------------------------------------------- 1 | tmp/ 2 | node_modules/ 3 | src/jquery-*.js -------------------------------------------------------------------------------- /.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "predef": [ 3 | "__dirname", 4 | "require", 5 | "exports" 6 | ], 7 | "curly": true, 8 | "eqeqeq": true, 9 | "immed": true, 10 | "latedef": true, 11 | "newcap": true, 12 | "noarg": true, 13 | "sub": true, 14 | "undef": true, 15 | "boss": true, 16 | "eqnull": true, 17 | "browser": false, 18 | "node": true, 19 | "unused": true, 20 | "indent": 2, 21 | "trailing": true 22 | } -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | /node_modules/ 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "0.8" 4 | - "0.10" 5 | 6 | before_script: 7 | - npm install -g grunt-cli 8 | - grunt download 9 | 10 | script: 11 | - grunt jshint 12 | - grunt test -------------------------------------------------------------------------------- /Gruntfile.js: -------------------------------------------------------------------------------- 1 | var fs = require('fs'); 2 | var path = require('path'); 3 | var http = require('http'); 4 | 5 | module.exports = function(grunt) { 6 | 7 | var async = grunt.util.async; 8 | var log = grunt.log; 9 | 10 | // Available versions of jQuery on CDN 11 | var jQVersions = ['1.6.4', '1.7.2', '1.8.3', '1.9.1', '2.0.0']; 12 | var cdnHost = 'code.jquery.com'; 13 | var destDir = path.join(__dirname, 'src'); 14 | 15 | function fetchjQuery(jQVersion, callback) { 16 | 17 | var name = 'jquery-' + jQVersion + '.js'; 18 | var filePath = path.join(destDir, name); 19 | 20 | // If file already exists, then don't download it again 21 | if(fs.existsSync(filePath)) { 22 | log.writeln('\u25e6', name); 23 | setTimeout(callback, 100); 24 | return; 25 | } 26 | 27 | // Stream the response in to files 28 | var stream = fs.createWriteStream(filePath, { 29 | 'encoding': 'utf8' 30 | }); 31 | 32 | http.request({ 33 | 'host': cdnHost, 34 | 'path': '/' + name, 35 | 'headers': { 36 | 'Host': cdnHost 37 | } 38 | }, function(response) { 39 | response.setEncoding('utf8'); 40 | response.on('data', stream.write.bind(stream)); 41 | response.on('end', function() { 42 | stream.end(); 43 | log.writeln('\u2713', name); 44 | setTimeout(callback, 100); 45 | }); 46 | response.on('error', function(e) { 47 | log.writeln('error', e, name); 48 | }); 49 | }).end(); 50 | } 51 | 52 | grunt.registerTask('download', 'Download jQuery versions from CDN', function() { 53 | // This task is async 54 | var done = this.async(); 55 | async.forEach(jQVersions, fetchjQuery, done); 56 | }); 57 | 58 | // Project configuration. 59 | grunt.initConfig({ 60 | 'pkg': grunt.file.readJSON('package.json'), 61 | 'nodeunit': { 62 | 'files': 'test/index.js' 63 | }, 64 | 'watch': { 65 | 'files': ['test/**/*.js'], 66 | 'tasks': ['nodeunit'], 67 | 'options': { 68 | 'debounceDelay': 250 69 | } 70 | }, 71 | 'jshint': { 72 | 'files': ['Gruntfile.js', 'lib/**/*.js', 'test/**/*.js'], 73 | 'options': { 74 | 'jshintrc': '.jshintrc' 75 | } 76 | } 77 | }); 78 | 79 | // Load grunt plugins 80 | grunt.loadNpmTasks('grunt-contrib-nodeunit'); 81 | grunt.loadNpmTasks('grunt-contrib-watch'); 82 | grunt.loadNpmTasks('grunt-contrib-jshint'); 83 | 84 | // Register tasks. 85 | grunt.registerTask('default', ['jshint', 'download', 'nodeunit']); 86 | 87 | // Alias "test" to "nodeunit" 88 | grunt.registerTask('test', ['nodeunit']); 89 | 90 | }; 91 | -------------------------------------------------------------------------------- /LICENSE-MIT: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012 James Morrin 2 | 3 | Permission is hereby granted, free of charge, to any person 4 | obtaining a copy of this software and associated documentation 5 | files (the "Software"), to deal in the Software without 6 | restriction, including without limitation the rights to use, 7 | copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the 9 | Software is furnished to do so, subject to the following 10 | conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 17 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 19 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | OLD 2 | === 3 | 4 | **Deprecated** 5 | 6 | Don't use the actual code in this repo. It's obsolete and only kept around for legacy apps. jquery added support for node in 2.1.x. Use that instead. 7 | 8 | 9 | NEW: How to use jQuery >= 2.1.x in Node.js 10 | === 11 | 12 | How to use jQuery >= 2.x in Node.js >= 0.10 13 | 14 | 15 | ```bash 16 | npm install -S 'jquery@>=2.1' 17 | npm install -S 'jsdom@3.1.2' 18 | ``` 19 | 20 | (Note that version 3.1.2 of jsdom is required, because as of jsdom version 4.0.0, jsdom no longer works 21 | with Node.js. If you use Io.js rather than Node.js, you can use the latest 4.x release of jsdom.) 22 | 23 | `testjq.js`: 24 | ```javascript 25 | (function () { 26 | 'use strict'; 27 | 28 | var env = require('jsdom').env 29 | , html = '

Hello World!

Heya Big World!' 30 | ; 31 | 32 | // first argument can be html string, filename, or url 33 | env(html, function (errors, window) { 34 | console.log(errors); 35 | 36 | var $ = require('jquery')(window) 37 | ; 38 | 39 | console.log($('.hello').text()); 40 | }); 41 | }()); 42 | ``` 43 | 44 | The instructions above are for the new [official jquery](http://github.com/jquery/jquery) which, for some reason, doesn't have instructions for node in their README. 45 | 46 | -------------------------------------------------------------------------------- /lib/node-jquery.js: -------------------------------------------------------------------------------- 1 | (function () { 2 | 3 | 'use strict'; 4 | 5 | var jsdom = require('jsdom').jsdom; 6 | var contextify = require('jsdom/node_modules/contextify'); 7 | var fs = require('fs'); 8 | var path = require('path'); 9 | 10 | var availableVersions = { 11 | 'default': '1.8.3', 12 | '1.6': '1.6.4', 13 | '1.6.4': '1.6.4', 14 | '1.7': '1.7.2', 15 | '1.7.2': '1.7.2', 16 | '1.8': '1.8.3', 17 | '1.8.3': '1.8.3', 18 | '1.9': '1.9.1', 19 | '1.9.1': '1.9.1', 20 | '2.0': '2.0.0', 21 | '2.0.0': '2.0.0' 22 | }; 23 | 24 | function create(window, version) { 25 | 26 | // Create a window, if one doesn't already exists 27 | var document; 28 | if ( !window || !window.document) { 29 | 30 | // Create a jsdom window 31 | document = jsdom(''); 32 | window = document.createWindow(); 33 | } else { 34 | document = window.document; 35 | } 36 | 37 | // assume window is a jsdom instance... 38 | // jsdom includes an incomplete version of XMLHttpRequest 39 | window.XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest; 40 | 41 | // trick jQuery into thinking CORS is supported (should be in node-XMLHttpRequest) 42 | window.XMLHttpRequest.prototype.withCredentials = false; 43 | 44 | // Create a sandbox to initialize jquery in 45 | var sandbox = contextify({ 46 | 'console' : console, 47 | 'window' : window, 48 | 'document': document, 49 | 'location': window.location, 50 | 'navigator': window.navigator, 51 | 'XMLHttpRequest': window.XMLHttpRequest, 52 | 'setTimeout': window.setTimeout 53 | }); 54 | 55 | // default to 1.8 56 | version = availableVersions[version || 'default'] || availableVersions['default']; 57 | var jQFile = 'src/jquery-' + version + '.js'; 58 | 59 | // Read jQuery source into memory & eval it in the sandbox 60 | var jQSourcePath = path.join(__dirname, '..', jQFile); 61 | var jQSource = fs.readFileSync(jQSourcePath).toString(); 62 | sandbox.run(jQSource, jQFile); 63 | 64 | return window.jQuery; 65 | } 66 | 67 | module.exports = { 68 | 'create': create 69 | }; 70 | 71 | }()); 72 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "jquery", 3 | "description": "jQuery: The Write Less, Do More, JavaScript Library (packaged for Node.JS)", 4 | "version": "2.0.0", 5 | "url": "http://jquery.com", 6 | "homepage": "https://github.com/coolaj86/node-jquery", 7 | "author": { 8 | "name": "James Morrin", 9 | "email": "treasonx@gmail.com" 10 | }, 11 | "repository": { 12 | "type": "git", 13 | "url": "git://github.com/coolaj86/node-jquery.git" 14 | }, 15 | "bugs": { 16 | "url": "https://github.com/coolaj86/node-jquery/issues" 17 | }, 18 | "licenses": [ 19 | { 20 | "type": "MIT", 21 | "url": "https://github.com/coolaj86/node-jquery/blob/master/LICENSE-MIT" 22 | } 23 | ], 24 | "main": "lib/node-jquery", 25 | "engines": { 26 | "node": ">=0.6" 27 | }, 28 | "scripts": { 29 | "test": "grunt test" 30 | }, 31 | "dependencies": { 32 | "jsdom": "~0.5.7", 33 | "xmlhttprequest": "~1.5.0" 34 | }, 35 | "devDependencies": { 36 | "grunt": "~0.4.1", 37 | "nodeunit": "~0.7.4", 38 | "grunt-contrib-nodeunit": "~0.1.2", 39 | "grunt-contrib-jshint": "~0.3.0", 40 | "grunt-contrib-watch": "~0.3.1" 41 | }, 42 | "keywords": [ 43 | "util", 44 | "dom", 45 | "jquery" 46 | ] 47 | } 48 | -------------------------------------------------------------------------------- /src/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HorseAJ86/node-jquery/088ce4ad88d8a9a255d2277b6d223b0f05bd41b4/src/.gitkeep -------------------------------------------------------------------------------- /test/collections.js: -------------------------------------------------------------------------------- 1 | module.exports = function(ctx) { 2 | 3 | 'use strict'; 4 | 5 | var q = ctx.q; 6 | 7 | return { 8 | "slice()": function(test) { 9 | 10 | var jQuery = ctx.$; 11 | 12 | test.expect(7); 13 | 14 | var $links = jQuery("#ap a"); 15 | 16 | test.same( $links.slice(1,2).get(), q("groups"), "slice(1,2)" ); 17 | test.same( $links.slice(1).get(), q("groups", "anchor1", "mark"), "slice(1)" ); 18 | test.same( $links.slice(0,3).get(), q("google", "groups", "anchor1"), "slice(0,3)" ); 19 | test.same( $links.slice(-1).get(), q("mark"), "slice(-1)" ); 20 | 21 | test.same( $links.eq(1).get(), q("groups"), "eq(1)" ); 22 | test.same( $links.eq('2').get(), q("anchor1"), "eq('2')" ); 23 | test.same( $links.eq(-1).get(), q("mark"), "eq(-1)" ); 24 | test.done(); 25 | }, 26 | 27 | "each(Function)": function(test) { 28 | 29 | var jQuery = ctx.$; 30 | 31 | test.expect(1); 32 | 33 | var div = jQuery("div"); 34 | div.each(function() { 35 | this.foo = 'zoo'; 36 | }); 37 | 38 | var pass = true; 39 | for ( var i = 0; i < div.size(); i++ ) { 40 | if ( div.get(i).foo !== "zoo" ) { 41 | pass = false; 42 | } 43 | } 44 | test.ok( pass, "Execute a function, Relative" ); 45 | test.done(); 46 | }, 47 | 48 | "first()/last()": function(test) { 49 | 50 | var jQuery = ctx.$; 51 | 52 | test.expect(4); 53 | 54 | var $links = jQuery("#ap a"), $none = jQuery("asdf"); 55 | 56 | test.same( $links.first().get(), q("google"), "first()" ); 57 | test.same( $links.last().get(), q("mark"), "last()" ); 58 | 59 | test.same( $none.first().get(), [], "first() none" ); 60 | test.same( $none.last().get(), [], "last() none" ); 61 | test.done(); 62 | }, 63 | 64 | "map()": function(test) { 65 | 66 | var jQuery = ctx.$; 67 | 68 | test.expect(2);//test.expect(6); 69 | 70 | test.same( 71 | jQuery("#ap").map(function() { 72 | return jQuery(this).find("a").get(); 73 | }).get(), 74 | q("google", "groups", "anchor1", "mark"), 75 | "Array Map" 76 | ); 77 | 78 | test.same( 79 | jQuery("#ap > a").map(function(){ 80 | return this.parentNode; 81 | }).get(), 82 | q("ap","ap","ap"), 83 | "Single Map" 84 | ); 85 | test.done(); 86 | 87 | return;//these haven't been accepted yet 88 | 89 | // //for #2616 90 | // var keys = jQuery.map( {a:1,b:2}, function( v, k ){ 91 | // return k; 92 | // }, [ ] ); 93 | 94 | // test.equals( keys.join(""), "ab", "Map the keys from a hash to an array" ); 95 | 96 | // var values = jQuery.map( {a:1,b:2}, function( v, k ){ 97 | // return v; 98 | // }, [ ] ); 99 | 100 | // test.equals( values.join(""), "12", "Map the values from a hash to an array" ); 101 | 102 | // var scripts = document.getElementsByTagName("script"); 103 | // var mapped = jQuery.map( scripts, function( v, k ){ 104 | // return v; 105 | // }, {length:0} ); 106 | 107 | // test.equals( mapped.length, scripts.length, "Map an array(-like) to a hash" ); 108 | 109 | // var flat = jQuery.map( Array(4), function( v, k ){ 110 | // return k % 2 ? k : [k,k,k];//try mixing array and regular returns 111 | // }); 112 | 113 | // test.equals( flat.join(""), "00012223", "try the new flatten technique(#2616)" ); 114 | }, 115 | 116 | "jQuery.merge()": function(test) { 117 | 118 | var jQuery = ctx.$; 119 | 120 | test.expect(8); 121 | 122 | var parse = jQuery.merge; 123 | 124 | test.same( parse([],[]), [], "Empty arrays" ); 125 | 126 | test.same( parse([1],[2]), [1,2], "Basic" ); 127 | test.same( parse([1,2],[3,4]), [1,2,3,4], "Basic" ); 128 | 129 | test.same( parse([1,2],[]), [1,2], "Second empty" ); 130 | test.same( parse([],[1,2]), [1,2], "First empty" ); 131 | 132 | // Fixed at [5998], #3641 133 | test.same( parse([-2,-1], [0,1,2]), [-2,-1,0,1,2], "Second array including a zero (falsy)"); 134 | 135 | // After fixing #5527 136 | test.same( parse([], [null, undefined]), [null, undefined], "Second array including null and undefined values"); 137 | test.same( parse({length:0}, [1,2]), {length:2, 0:1, 1:2}, "First array like"); 138 | test.done(); 139 | }, 140 | 141 | "jQuery.each(Object,Function)": function(test) { 142 | 143 | var jQuery = ctx.$; 144 | 145 | test.expect(13); 146 | 147 | jQuery.each( [0,1,2], function(i, n){ 148 | test.equals( i, n, "Check array iteration" ); 149 | }); 150 | 151 | jQuery.each( [5,6,7], function(i, n){ 152 | test.equals( i, n - 5, "Check array iteration" ); 153 | }); 154 | 155 | jQuery.each( { name: "name", lang: "lang" }, function(i, n) { 156 | test.equals( i, n, "Check object iteration" ); 157 | }); 158 | 159 | var total = 0; 160 | jQuery.each([1,2,3], function(i,v) { 161 | total += v; 162 | }); 163 | test.equals( total, 6, "Looping over an array" ); 164 | total = 0; 165 | jQuery.each([1,2,3], function(i,v) { 166 | total += v; 167 | if ( i === 1 ) { 168 | return false; 169 | } 170 | }); 171 | test.equals( total, 3, "Looping over an array, with break" ); 172 | total = 0; 173 | jQuery.each({"a":1,"b":2,"c":3}, function(i,v){ 174 | total += v; 175 | }); 176 | test.equals( total, 6, "Looping over an object" ); 177 | total = 0; 178 | jQuery.each({"a":3,"b":3,"c":3}, function(i,v){ 179 | total += v; 180 | return false; 181 | }); 182 | test.equals( total, 3, "Looping over an object, with break" ); 183 | 184 | var f = function(){}; 185 | f.foo = 'bar'; 186 | jQuery.each(f, function(i){ 187 | f[i] = 'baz'; 188 | }); 189 | test.equals( "baz", f.foo, "Loop over a function" ); 190 | test.done(); 191 | }, 192 | 193 | "jQuery.makeArray": function(test) { 194 | 195 | var jQuery = ctx.$; 196 | var document = ctx.document; 197 | var window = ctx.window; 198 | 199 | test.expect(17); 200 | 201 | test.equals( jQuery.makeArray(jQuery('html>*'))[0].nodeName.toUpperCase(), "HEAD", "Pass makeArray a jQuery object" ); 202 | 203 | test.equals( jQuery.makeArray(document.getElementsByName("PWD")).slice(0,1)[0].name, "PWD", "Pass makeArray a nodelist" ); 204 | 205 | test.equals( (function(){ return jQuery.makeArray(arguments); })(1,2).join(""), "12", "Pass makeArray an arguments array" ); 206 | 207 | test.equals( jQuery.makeArray([1,2,3]).join(""), "123", "Pass makeArray a real array" ); 208 | 209 | test.equals( jQuery.makeArray().length, 0, "Pass nothing to makeArray and test.expect an empty array" ); 210 | 211 | test.equals( jQuery.makeArray( 0 )[0], 0 , "Pass makeArray a number" ); 212 | 213 | test.equals( jQuery.makeArray( "foo" )[0], "foo", "Pass makeArray a string" ); 214 | 215 | test.equals( jQuery.makeArray( true )[0].constructor, Boolean, "Pass makeArray a boolean" ); 216 | 217 | test.equals( jQuery.makeArray( document.createElement("div") )[0].nodeName.toUpperCase(), "DIV", "Pass makeArray a single node" ); 218 | 219 | test.equals( jQuery.makeArray( {length:2, 0:"a", 1:"b"} ).join(""), "ab", "Pass makeArray an array like map (with length)" ); 220 | 221 | test.ok( !!jQuery.makeArray( document.documentElement.childNodes ).slice(0,1)[0].nodeName, "Pass makeArray a childNodes array" ); 222 | 223 | // function, is tricky as it has length 224 | test.equals( jQuery.makeArray( function(){ return 1;} )[0](), 1, "Pass makeArray a function" ); 225 | 226 | //window, also has length 227 | test.equals( jQuery.makeArray(window)[0], window, "Pass makeArray the window" ); 228 | 229 | test.equals( jQuery.makeArray(/a/)[0].constructor, RegExp, "Pass makeArray a regex" ); 230 | 231 | test.equals( jQuery.makeArray(document.getElementById('form')).length, 2, "Pass makeArray a form (treat as elements)" ); 232 | 233 | // For #5610 234 | test.same( jQuery.makeArray({'length': '0'}), [], "Make sure object is coerced properly."); 235 | test.same( jQuery.makeArray({'length': '5'}), [], "Make sure object is coerced properly."); 236 | test.done(); 237 | } 238 | }; 239 | }; -------------------------------------------------------------------------------- /test/core.js: -------------------------------------------------------------------------------- 1 | module.exports = function(ctx) { 2 | 3 | 'use strict'; 4 | 5 | var q = ctx.q; 6 | 7 | return { 8 | 9 | "Basic requirements": function(test) { 10 | 11 | var jQuery, $; 12 | jQuery = $ = ctx.$; 13 | var document = ctx.document; 14 | 15 | test.expect(7); 16 | test.ok( Array.prototype.push, "Array.push()" ); 17 | test.ok( Function.prototype.apply, "Function.apply()" ); 18 | test.ok( document.getElementById, "getElementById" ); 19 | test.ok( document.getElementsByTagName, "getElementsByTagName" ); 20 | test.ok( RegExp, "RegExp" ); 21 | test.ok( jQuery, "jQuery" ); 22 | test.ok( $, "$" ); 23 | test.done(); 24 | }, 25 | 26 | "jQuery()": function(test) { 27 | 28 | var jQuery = ctx.$; 29 | var window = ctx.window; 30 | var document = ctx.document; 31 | 32 | test.expect(24); 33 | // Basic constructor's behavior 34 | 35 | test.equals( jQuery().length, 0, "jQuery() === jQuery([])" ); 36 | test.equals( jQuery(undefined).length, 0, "jQuery(undefined) === jQuery([])" ); 37 | test.equals( jQuery(null).length, 0, "jQuery(null) === jQuery([])" ); 38 | test.equals( jQuery("").length, 0, "jQuery('') === jQuery([])" ); 39 | 40 | var obj = jQuery("div"); 41 | test.equals( jQuery(obj).selector, "div", "jQuery(jQueryObj) == jQueryObj" ); 42 | 43 | // can actually yield more than one, when iframes are included, the window is an array as well 44 | test.equals( jQuery(window).length, 1, "Correct number of elements generated for jQuery(window)" ); 45 | 46 | 47 | var main = jQuery("#main"); 48 | test.same( jQuery("div p", main).get(), q("sndp", "en", "sap"), "Basic selector with jQuery object as context" ); 49 | 50 | /* 51 | // disabled since this test was doing nothing. i tried to fix it but i'm not sure 52 | // what the expected behavior should even be. FF returns "\n" for the text node 53 | // make sure this is handled 54 | var crlfContainer = jQuery('

\r\n

'); 55 | var x = crlfContainer.contents().get(0).nodeValue; 56 | equals( x, what???, "Check for \\r and \\n in jQuery()" ); 57 | */ 58 | 59 | /* // Disabled until we add this functionality in 60 | var pass = true; 61 | try { 62 | jQuery("
Testing
").appendTo(document.getElementById("iframe").contentDocument.body); 63 | } catch(e){ 64 | pass = false; 65 | } 66 | ok( pass, "jQuery('<tag>') needs optional document parameter to ease cross-frame DOM wrangling, see #968" );*/ 67 | 68 | var code = jQuery(""); 69 | test.equals( code.length, 1, "Correct number of elements generated for code" ); 70 | test.equals( code.parent().length, 0, "Make sure that the generated HTML has no parent." ); 71 | var img = jQuery(""); 72 | test.equals( img.length, 1, "Correct number of elements generated for img" ); 73 | test.equals( img.parent().length, 0, "Make sure that the generated HTML has no parent." ); 74 | var div = jQuery("

"); 75 | test.equals( div.length, 4, "Correct number of elements generated for div hr code b" ); 76 | test.equals( div.parent().length, 0, "Make sure that the generated HTML has no parent." ); 77 | 78 | test.equals( jQuery([1,2,3]).get(1), 2, "Test passing an array to the factory" ); 79 | 80 | test.equals( jQuery(document.body).get(0), jQuery('body').get(0), "Test passing an html node to the factory" ); 81 | 82 | var exec = false; 83 | 84 | var elem = jQuery("
", { 85 | width: 10, 86 | css: { paddingLeft:1, paddingRight:1 }, 87 | click: function(){ test.ok(exec, "Click executed."); }, 88 | text: "test", 89 | "class": "test2", 90 | id: "test3" 91 | }); 92 | 93 | test.equals( elem[0].style.width, '10px', 'jQuery() quick setter width'); 94 | test.equals( elem[0].style.paddingLeft, '1px', 'jQuery quick setter css'); 95 | test.equals( elem[0].style.paddingRight, '1px', 'jQuery quick setter css'); 96 | test.equals( elem[0].childNodes.length, 1, 'jQuery quick setter text'); 97 | test.equals( elem[0].firstChild.nodeValue, "test", 'jQuery quick setter text'); 98 | test.equals( elem[0].className, "test2", 'jQuery() quick setter class'); 99 | test.equals( elem[0].id, "test3", 'jQuery() quick setter id'); 100 | 101 | exec = true; 102 | elem.click(); 103 | 104 | // manually clean up detached elements 105 | elem.remove(); 106 | 107 | for ( var i = 0; i < 3; ++i ) { 108 | elem = jQuery(""); 109 | } 110 | test.equals( elem[0].defaultValue, "TEST", "Ensure cached nodes are cloned properly (Bug #6655)" ); 111 | 112 | // manually clean up detached elements 113 | elem.remove(); 114 | test.done(); 115 | }, 116 | 117 | "noConflict": function(test) { 118 | 119 | var jQuery, $; 120 | jQuery = $ = ctx.$; 121 | 122 | test.expect(7); 123 | 124 | var originaljQuery = jQuery, 125 | original$ = $, 126 | $$ = jQuery; 127 | 128 | test.equals( jQuery, jQuery.noConflict(), "noConflict returned the jQuery object" ); 129 | test.equals( jQuery, $$, "Make sure jQuery wasn't touched." ); 130 | test.equals( $, original$, "Make sure $ was reverted." ); 131 | 132 | jQuery = $ = $$; 133 | 134 | test.equals( jQuery.noConflict(true), $$, "noConflict returned the jQuery object" ); 135 | test.equals( jQuery, originaljQuery, "Make sure jQuery was reverted." ); 136 | test.equals( $, original$, "Make sure $ was reverted." ); 137 | test.ok( $$("#main").html("test"), "Make sure that jQuery still works." ); 138 | 139 | jQuery = $$; 140 | test.done(); 141 | } 142 | }; 143 | }; -------------------------------------------------------------------------------- /test/css.js: -------------------------------------------------------------------------------- 1 | module.exports = function(ctx) { 2 | 3 | 'use strict'; 4 | 5 | return { 6 | "css(String|Hash)": function(test) { 7 | 8 | var jQuery = ctx.$; 9 | 10 | test.expect(18); 11 | 12 | //test.equals( jQuery('#main').css("display"), 'block', 'Check for css property "display"'); 13 | 14 | test.ok( jQuery('#nothiddendiv').is(':visible'), 'Modifying CSS display: Assert element is visible'); 15 | jQuery('#nothiddendiv').css({display: 'none'}); 16 | test.ok( !jQuery('#nothiddendiv').is(':visible'), 'Modified CSS display: Assert element is hidden'); 17 | jQuery('#nothiddendiv').css({display: 'block'}); 18 | test.ok( jQuery('#nothiddendiv').is(':visible'), 'Modified CSS display: Assert element is visible'); 19 | 20 | var div = jQuery( "
" ); 21 | 22 | // These should be "auto" (or some better value) 23 | // temporarily provide "0px" for backwards compat 24 | test.equals( div.css("width"), "0px", "Width on disconnected node." ); 25 | test.equals( div.css("height"), "0px", "Height on disconnected node." ); 26 | 27 | div.css({ width: 4, height: 4 }); 28 | 29 | test.equals( div.css("width"), "4px", "Width on disconnected node." ); 30 | test.equals( div.css("height"), "4px", "Height on disconnected node." ); 31 | 32 | var div2 = jQuery( "