Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

ender bridge & integration tests

  • Loading branch information...
commit 4bcf05ffe12cfcf0bf8744d2ebc1627c554eed92 1 parent d7497bf
@rvagg rvagg authored
Showing with 1,584 additions and 690 deletions.
  1. +1,434 −640 integration/ender.js
  2. +111 −18 integration/index.html
  3. +39 −32 src/ender.js
View
2,074 integration/ender.js
1,434 additions, 640 deletions not shown
View
129 integration/index.html
@@ -2,27 +2,120 @@
<html lang="en-us">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
- <title>ender integration</title>
+ <title>Ender Integration Test</title>
+ <style type="text/css">
+ body {
+ font: 300 12px 'helvetica neue', helvetica, arial;
+ }
+ fieldset {
+ padding: 5px;
+ margin : 5px;
+ border : solid 1px;
+ }
+ fieldset:nth-child(6n+1) { border-color: red; }
+ fieldset:nth-child(6n+2) { border-color: orange; }
+ fieldset:nth-child(6n+3) { border-color: yellow; }
+ fieldset:nth-child(6n+4) { border-color: green; }
+ fieldset:nth-child(6n+5) { border-color: blue; }
+ fieldset:nth-child(6n+6) { border-color: purple; }
+ </style>
+ </head>
+
+ <body>
+
+ <div id="tests"></div>
+
<script src="ender.js"></script>
- <script type="text/javascript" id="scr">
+
+ <script type="text/javascript">
+ var fixtureOuter = '<fieldset><legend></legend><pre><code></code></pre></fieldset>'
+ , tests = 0
+
+ , test = function (name, html, cb) {
+ $(fixtureOuter)
+ .attr('id', 'test' + (++tests))
+ .appendTo('#tests')
+ .down('legend')
+ .text('Test #' + ': ' + name)
+ .after(html)
+ .up('fieldset')
+ .down('> pre > code')
+ .html(cb.toString().replace(/^function \([^\)]*\) \{\n/, '').replace(/^\s{12,14}/gm, '').replace(/\n\}$/, ''))
+ cb(tests)
+ }
+
$.domReady(function () {
- $('#test').delegate('#clickme', 'click', function (e) {
- alert('delegated')
- })
+
+ test(
+ // name
+ 'delegate()'
+ // fixture
+ , '<p>clicking me shouldn\'t do anything</p>'
+ + '<p id="clickme" style="background:#ff5;">#clickme, delegated event</p>'
+ + '<p>clicking me shouldn\'t do anything</p>'
+ // execute
+ , function (index) {
+ $('#test' + index).delegate('#clickme', 'click', function (e) {
+ alert('delegated')
+ })
+ }
+ )
+
+ test(
+ // name
+ 'on() style delegation'
+ // fixture
+ , '<p>clicking me shouldn\'t do anything</p>'
+ + '<p id="clickme2" style="background:#ff5;">#clickme, delegated event</p>'
+ + '<p>clicking me shouldn\'t do anything</p>'
+ // execute
+ , function (index) {
+ $('#test' + index).on('click', '#clickme2', function (e) {
+ alert('delegated')
+ })
+ }
+ )
+
+ test(
+ // name
+ 'click()'
+ // fixture
+ , '<p id="directclick" style="background:#ff5;">#directclick, click() event</p>'
+ // execute
+ , function () {
+ $('#directclick').click(function (e) { alert('click()!') })
+ }
+ )
+
+ test(
+ // name
+ 'one()'
+ // fixture
+ , '<p id="one" style="background:#ff5;">#one, click event should work only once</p>'
+ // execute
+ , function () {
+ $('#one').one('click', function (e) { alert('click()!') })
+ }
+ )
+
+ test(
+ // name
+ 'stop()'
+ // fixture
+ , '<p style="background:#ff5;">#stopper, typing in here should not result in characters: <input type="text" id="stopper"></p>'
+ // execute
+ , function (index) {
+ $('#test' + index).on('keydown', function () {
+ alert('SHOULD NOT GET THIS!')
+ })
+ $('#stopper').on('keydown', function (e) {
+ e.stop()
+ })
+ }
+ )
})
</script>
- <script type="text/javascript">
- $.domReady(function () { $('code').text($('#scr')[0].innerHTML) })
- </script>
- </head>
- <body>
- <p>this is an integration test page for the Ender bridge</p>
- <fieldset id="test" style="padding:20px;margin:20px;border:solid 1px red;">
- <legend>#test</legend>
- <p>clicking me shouldn't do anything</p>
- <p id="clickme" style="background:#ff5;">#clickme, delegated event</p>
- <p>clicking me shouldn't do anything</p>
- </fieldset>
- <pre><code></code></pre>
+
</body>
+
</html>
View
71 src/ender.js
@@ -1,46 +1,53 @@
!function ($) {
var b = require('bean')
+
, integrate = function (method, type, method2) {
var _args = type ? [type] : []
return function () {
for (var i = 0, l = this.length; i < l; i++) {
- if (!arguments.length && method == 'add' && type) method = 'fire'
+ if (!arguments.length && method == 'on' && type) method = 'fire'
b[method].apply(this, [this[i]].concat(_args, Array.prototype.slice.call(arguments, 0)))
}
return this
}
}
- , add = integrate('add')
- , remove = integrate('remove')
- , fire = integrate('fire')
+
+ , add = integrate('add')
+ , on = integrate('on')
+ , one = integrate('one')
+ , off = integrate('off')
+ , fire = integrate('fire')
+ , clone = integrate('clone')
+
+ , hover = function (enter, leave, i) { // i for internal
+ for (i = this.length; i--;) {
+ b.on.call(this, this[i], 'mouseenter', enter)
+ b.on.call(this, this[i], 'mouseleave', leave)
+ }
+ return this
+ }
, methods = {
- on: add // NOTE: .on() is likely to change in the near future, don't rely on this as-is see https://github.com/fat/bean/issues/55
- , addListener: add
- , bind: add
- , listen: add
- , delegate: add
-
- , one: integrate('one')
-
- , off: remove
- , unbind: remove
- , unlisten: remove
- , removeListener: remove
- , undelegate: remove
-
- , emit: fire
- , trigger: fire
-
- , cloneEvents: integrate('clone')
-
- , hover: function (enter, leave, i) { // i for internal
- for (i = this.length; i--;) {
- b.add.call(this, this[i], 'mouseenter', enter)
- b.add.call(this, this[i], 'mouseleave', leave)
- }
- return this
- }
+ on : on
+ , addListener : on
+ , bind : on
+ , listen : on
+ , delegate : add // jQuery compat, same arg order as add()
+
+ , one : one
+
+ , off : off
+ , unbind : off
+ , unlisten : off
+ , removeListener : off
+ , undelegate : off
+
+ , emit : fire
+ , trigger : fire
+
+ , cloneEvents : clone
+
+ , hover : hover
}
, shortcuts =
@@ -49,10 +56,10 @@
+ 'mousemove resize scroll select submit unload').split(' ')
for (var i = shortcuts.length; i--;) {
- methods[shortcuts[i]] = integrate('add', shortcuts[i])
+ methods[shortcuts[i]] = integrate('on', shortcuts[i])
}
b.setSelectorEngine($)
$.ender(methods, true)
-}(ender)
+}(ender);
Please sign in to comment.
Something went wrong with that request. Please try again.