Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fixed for ender-js 0.4.0, $() != arraylike

  • Loading branch information...
commit e937d9151dd953ab27bf00f84bbd75934c6aab69 1 parent 48fe7e3
@rvagg rvagg authored
View
2  README.md
@@ -7,7 +7,7 @@ The happs
$ git clone git://github.com/ded/reqwest.git reqwest
$ cd !$
- $ npm install -d
+ $ npm install
$ make
API
View
18 build.json
@@ -7,20 +7,30 @@
]
}
, "JSHINT_OPTS": {
- "boss": true
+ "predef": [ "define", "module", "ActiveXObject" ]
+ , "boss": true
+ , "bitwise": true
+ , "shadow": true
+ , "trailing": true
+ , "latedef": true
, "forin": false
, "curly": false
- , "debug": false
, "devel": false
, "evil": true
, "regexp": false
- , "undef": false
+ , "undef": true
, "sub": true
, "white": false
, "indent": 2
- , "whitespace": true
+ , "trailing": true
, "asi": true
, "laxbreak": true
+ , "eqnull": true
+ , "browser": true
, "laxcomma": true
+ , "proto": true
+ , "expr": true
+ , "es5": true
+ , "strict": false
}
}
View
14 src/ender.js
@@ -1,18 +1,20 @@
!function ($) {
var r = require('reqwest')
, integrate = function(method) {
- return function () {
- var args = (this && this.length > 0 ? this : []).concat(Array.prototype.slice.call(arguments, 0))
- return r[method].apply(null, args)
+ return function() {
+ var args = Array.prototype.slice.call(arguments, 0)
+ , i = (this && this.length) || 0
+ while (i--) args.unshift(this[i])
+ return r[method].apply(null, args)
+ }
}
- }
, s = integrate('serialize')
, sa = integrate('serializeArray')
$.ender({
ajax: r
- , serialize: s
- , serializeArray: sa
+ , serialize: r.serialize
+ , serializeArray: r.serializeArray
, toQueryString: r.toQueryString
})
View
4 src/reqwest.js
@@ -4,10 +4,8 @@
else this[name] = definition()
}('reqwest', function () {
- var context = this
- , win = window
+ var win = window
, doc = document
- , old = context.reqwest
, twoHundo = /^20\d$/
, byTag = 'getElementsByTagName'
, readyState = 'readyState'
View
11 tests/ender-stub.js
@@ -1,11 +0,0 @@
-window['require'] = function(name) {
- return window[name]
-}
-window['ender'] = {
- _boosh: {},
- ender: function(m, b) {
- for (i in m) {
- (b ? ender._boosh : ender)[i] = m[i]
- }
- }
-}
View
117 tests/ender.js
@@ -0,0 +1,117 @@
+/*!
+ * Ender: open module JavaScript framework (client-lib)
+ * copyright Dustin Diaz & Jacob Thornton 2011-2012 (@ded @fat)
+ * http://ender.no.de
+ * License MIT
+ */
+(function (context) {
+
+ // a global object for node.js module compatiblity
+ // ============================================
+
+ context['global'] = context
+
+ // Implements simple module system
+ // losely based on CommonJS Modules spec v1.1.1
+ // ============================================
+
+ var modules = {}
+ , old = context['$']
+ , oldRequire = context['require']
+ , oldProvide = context['provide']
+
+ function require (identifier) {
+ // modules can be required from ender's build system, or found on the window
+ var module = modules['$' + identifier] || window[identifier]
+ if (!module) throw new Error("Ender Error: Requested module '" + identifier + "' has not been defined.")
+ return module
+ }
+
+ function provide (name, what) {
+ return (modules['$' + name] = what)
+ }
+
+ context['provide'] = provide
+ context['require'] = require
+
+ function aug(o, o2) {
+ for (var k in o2) k != 'noConflict' && k != '_VERSION' && (o[k] = o2[k])
+ return o
+ }
+
+ /**
+ * main Ender return object
+ * @constructor
+ * @param {Array|Node|string} s a CSS selector or DOM node(s)
+ * @param {Array.|Node} r a root node(s)
+ */
+ function Ender(s, r) {
+ var elements
+ , i
+
+ this.selector = s
+ // string || node || nodelist || window
+ if (typeof s == 'undefined') {
+ elements = []
+ this.selector = ''
+ } else if (typeof s == 'string' || s.nodeName || (s.length && 'item' in s) || s == window) {
+ elements = ender._select(s, r)
+ } else {
+ elements = isFinite(s.length) ? s : [s]
+ }
+ this.length = elements.length
+ for (i = this.length; i--;) this[i] = elements[i]
+ }
+
+ /**
+ * @param {function(el, i, inst)} fn
+ * @param {Object} opt_scope
+ * @returns {Ender}
+ */
+ Ender.prototype['forEach'] = function (fn, opt_scope) {
+ var i, l
+ // opt out of native forEach so we can intentionally call our own scope
+ // defaulting to the current item and be able to return self
+ for (i = 0, l = this.length; i < l; ++i) i in this && fn.call(opt_scope || this[i], this[i], i, this)
+ // return self for chaining
+ return this
+ }
+
+ Ender.prototype.$ = ender // handy reference to self
+
+
+ function ender(s, r) {
+ return new Ender(s, r)
+ }
+
+ ender['_VERSION'] = '0.4.3-dev'
+
+ ender.fn = Ender.prototype // for easy compat to jQuery plugins
+
+ ender.ender = function (o, chain) {
+ aug(chain ? Ender.prototype : ender, o)
+ }
+
+ ender._select = function (s, r) {
+ if (typeof s == 'string') return (r || document).querySelectorAll(s)
+ if (s.nodeName) return [s]
+ return s
+ }
+
+
+ // use callback to receive Ender's require & provide
+ ender.noConflict = function (callback) {
+ context['$'] = old
+ if (callback) {
+ context['provide'] = oldProvide
+ context['require'] = oldRequire
+ callback(require, provide, this)
+ }
+ return this
+ }
+
+ if (typeof module !== 'undefined' && module.exports) module.exports = ender
+ // use subscript notation as extern for Closure compilation
+ context['ender'] = context['$'] = context['ender'] || ender
+
+}(this));
View
4 tests/tests.html
@@ -6,7 +6,7 @@
<link rel="stylesheet" href="/node_modules/sink-test/src/sink.css" type="text/css">
<script src="/node_modules/valentine/valentine.js"></script>
<script src="/node_modules/sink-test/src/sink.js"></script>
- <script src="/tests/ender-stub.js"></script>
+ <script src="/tests/ender.js"></script>
<script src="/src/reqwest.js"></script>
<script src="/src/ender.js"></script>
<style type="text/css">
@@ -39,7 +39,7 @@
</form>
<form action="/baa" method="get">
<textarea name="T3" rows="2" cols="15">?
-A B
+A B
Z</textarea>
<input type="hidden" name="H1" value="x" /> <!-- 0 -->
<input type="hidden" name="H2" /> <!-- 1 -->
View
15 tests/tests.js
@@ -1,3 +1,4 @@
+/*global reqwest:true, sink:true, start:true, ender:true, v:true */
!function (ajax) {
var FakeXHR = function () {
this.args = {}
@@ -534,8 +535,8 @@
ok(sameValue(sh[name], value), 'serialize(' + str + ', {type:\'map\'})')
} else {
// the cases where an element shouldn't show up at all, checkbox not checked for example
- ok(sa.length == 0, 'serialize(' + str + ', {type:\'array\'}) is []')
- ok(v.keys(sh).length == 0, 'serialize(' + str + ', {type:\'map\'}) is {}')
+ ok(sa.length === 0, 'serialize(' + str + ', {type:\'array\'}) is []')
+ ok(v.keys(sh).length === 0, 'serialize(' + str + ', {type:\'map\'}) is {}')
}
}
@@ -547,7 +548,7 @@
function executeMultiArgumentMethod(method, argType, options) {
var els = [ foo, bar, choices ]
- , ths = argType === BIND_ARGS ? els : null
+ , ths = argType === BIND_ARGS ? ender(els) : null
, args = argType === PASS_ARGS ? els : []
if (!!options) args.push(options)
@@ -662,7 +663,7 @@
sHelper.reset()
test('correctly serialize textarea', function (complete) {
- textarea = sHelper.formElements(1, 'textarea', 0)
+ var textarea = sHelper.formElements(1, 'textarea', 0)
// the texarea has 2 different newline styles, should come out as normalized CRLF as per forms spec
ok('T3=%3F%0D%0AA+B%0D%0AZ' == ajax.serialize(textarea), 'serialize(textarea)')
var sa = ajax.serialize(textarea, { type: 'array' })
@@ -921,17 +922,17 @@
})
test('$(element, element, element...).serialize()', function (complete) {
- sHelper.testMultiArgumentSerialize(ender._boosh.serialize, 'ender', BIND_ARGS)
+ sHelper.testMultiArgumentSerialize(ender.fn.serialize, 'ender', BIND_ARGS)
complete()
})
test('$(element, element, element...).serialize({type:\'array\'})', function (complete) {
- sHelper.testMultiArgumentSerializeArray(ender._boosh.serialize, 'ender', BIND_ARGS)
+ sHelper.testMultiArgumentSerializeArray(ender.fn.serialize, 'ender', BIND_ARGS)
complete()
})
test('$(element, element, element...).serialize({type:\'map\'})', function (complete) {
- sHelper.testMultiArgumentSerializeHash(ender._boosh.serialize, 'ender', BIND_ARGS)
+ sHelper.testMultiArgumentSerializeHash(ender.fn.serialize, 'ender', BIND_ARGS)
complete()
})
Please sign in to comment.
Something went wrong with that request. Please try again.