forked from cujojs/wire
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added jquery dom selector plugin, mimics other dom.query plugins. Pro…
…totype factory can now take any wireable as the prototype--e.g. any ref, object literal, etc. but also retains backward compatibility with passing just a refName string. Automated unit tests for prototype factory.
- Loading branch information
1 parent
ed59241
commit e9fa60a
Showing
7 changed files
with
148 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule curl
updated
38 files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<!DOCTYPE HTML> | ||
<html lang="en-US"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>wire/jquery/dom test</title> | ||
|
||
<script src="../util/doh/runner.js"></script> | ||
<script src="../test-config.js"></script> | ||
|
||
<script type="text/javascript"> | ||
require(['wire'], function(wire) { | ||
wire({ | ||
plugins: [ | ||
// { module: 'wire/debug' }, | ||
{ module: 'wire/jquery/dom' } | ||
], | ||
node1: { $ref: 'dom.query!#node1' }, | ||
divs: { $ref: 'dom.query!.test' }, | ||
div: { $ref: 'dom.query!.test', i: 0 } | ||
}).then( | ||
function(context) { | ||
doh.register('jquery/dom', [ | ||
function(doh) { | ||
// Sizzle always returns an array, so test | ||
// against the first | ||
doh.assertEqual(1, context.node1.length); | ||
doh.assertEqual('node1', context.node1[0].id); | ||
}, | ||
function(doh) { | ||
doh.assertEqual(3, context.divs.length); | ||
}, | ||
function(doh) { | ||
// Using the plugin's i option to extract a single | ||
// node | ||
doh.assertEqual('test one', context.div.className); | ||
} | ||
]); | ||
|
||
doh.run(); | ||
}, | ||
function(err) { | ||
console.log(err); | ||
} | ||
); | ||
}); | ||
</script> | ||
</head> | ||
<body> | ||
<div> | ||
<p id="node1"></p> | ||
</div> | ||
<div class="test one"></div> | ||
<div class="test two"></div> | ||
<div class="test three"></div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* @license Copyright (c) 2010-2011 Brian Cavalier | ||
* LICENSE: see the LICENSE.txt file. If file is missing, this file is subject | ||
* to the MIT License at: http://www.opensource.org/licenses/mit-license.php. | ||
*/ | ||
|
||
/** | ||
* dom.js | ||
*/ | ||
define(['js!jquery-1.7.min.js', 'wire/domReady'], function(jquery, domReady) { | ||
|
||
function resolveQuery(resolver, name, refObj /*, wire */) { | ||
|
||
domReady(function() { | ||
var result, i; | ||
|
||
result = jQuery(name); | ||
i = refObj.i; | ||
|
||
if (typeof i == 'number') { | ||
if (i < result.length) { | ||
resolver.resolve(result[i]); | ||
} else { | ||
resolver.reject(new Error("Query '" + name + "' returned " + result.length + " items while expecting at least " + (refObj.i + 1))); | ||
} | ||
} else { | ||
resolver.resolve(jQuery.makeArray(result)); | ||
} | ||
}); | ||
|
||
} | ||
|
||
/** | ||
* The plugin instance. Can be the same for all wiring runs | ||
*/ | ||
var plugin = { | ||
resolvers: { | ||
'dom.query': resolveQuery | ||
} | ||
}; | ||
|
||
return { | ||
wire$plugin: function(/*ready, destroyed, options*/) { | ||
return plugin; | ||
} | ||
}; | ||
|
||
}); |