Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix issue #57 - when registering event handlers through jQuery, also …

…trigger event handlers through jQuery
  • Loading branch information...
commit 1cbe9c59c95947b1fc10f80d17513d833d41c79a 1 parent 0ea4695
@SteveSanderson SteveSanderson authored
View
4 build/output/knockout-latest.debug.js
@@ -190,7 +190,9 @@ ko.utils = new (function () {
if (!(element && element.nodeType))
throw new Error("element must be a DOM node when calling triggerEvent");
- if (typeof document.createEvent == "function") {
+ if (typeof jQuery != "undefined") {
+ jQuery(element)['trigger'](eventType);
+ } else if (typeof document.createEvent == "function") {
if (typeof element.dispatchEvent == "function") {
var eventCategory = (eventType == "click" ? "MouseEvents" : "HTMLEvents"); // Might need to account for other event names at some point
var event = document.createEvent(eventCategory);
View
14 build/output/knockout-latest.js
@@ -8,13 +8,13 @@ p.a=new function(){var d=/^(\s|\u00A0)+|(\s|\u00A0)+$/g;return{ba:["authenticity
f;e++)p.a.g(a,b[e])<0&&a.push(b[e]);return a},K:function(b,a){b=b||[];for(var e=[],f=0,g=b.length;f<g;f++)e.push(a(b[f]));return e},J:function(b,a){b=b||[];for(var e=[],f=0,g=b.length;f<g;f++)a(b[f])&&e.push(b[f]);return e},L:function(b,a){for(var e=0,f=a.length;e<f;e++)b.push(a[e])},aa:function(b){for(;b.firstChild;)p.removeNode(b.firstChild)},Va:function(b,a){p.a.aa(b);a&&p.a.h(a,function(a){b.appendChild(a)})},ka:function(b,a){var e=b.nodeType?[b]:b;if(e.length>0){for(var f=e[0],g=f.parentNode,
d=0,i=a.length;d<i;d++)g.insertBefore(a[d],f);d=0;for(i=e.length;d<i;d++)p.removeNode(e[d])}},ma:function(b,a){navigator.userAgent.indexOf("MSIE 6")>=0?b.setAttribute("selected",a):b.selected=a},ca:function(b,a){if(!b||b.nodeType!=1)return[];var e=[];b.getAttribute(a)!==o&&e.push(b);for(var f=b.getElementsByTagName("*"),d=0,h=f.length;d<h;d++)f[d].getAttribute(a)!==o&&e.push(f[d]);return e},m:function(b){return(b||"").replace(d,"")},Ya:function(b,a){for(var e=[],f=(b||"").split(a),d=0,h=f.length;d<
h;d++){var i=p.a.m(f[d]);i!==""&&e.push(i)}return e},Wa:function(b,a){b=b||"";if(a.length>b.length)return!1;return b.substring(0,a.length)===a},Ga:function(b,a){if(a===n)return(new Function("return "+b))();with(a)return eval("("+b+")")},Ea:function(b,a){if(a.compareDocumentPosition)return(a.compareDocumentPosition(b)&16)==16;for(;b!=o;){if(b==a)return!0;b=b.parentNode}return!1},O:function(b){return p.a.Ea(b,document)},q:function(b,a,e){typeof jQuery!="undefined"?jQuery(b).bind(a,e):typeof b.addEventListener==
-"function"?b.addEventListener(a,e,!1):typeof b.attachEvent!="undefined"?b.attachEvent("on"+a,function(a){e.call(b,a)}):c(Error("Browser doesn't support addEventListener or attachEvent"))},qa:function(b,a){(!b||!b.nodeType)&&c(Error("element must be a DOM node when calling triggerEvent"));if(typeof document.createEvent=="function")if(typeof b.dispatchEvent=="function"){var e=document.createEvent(a=="click"?"MouseEvents":"HTMLEvents");e.initEvent(a,!0,!0,window,0,0,0,0,0,!1,!1,!1,!1,0,b);b.dispatchEvent(e)}else c(Error("The supplied element doesn't support dispatchEvent"));
-else if(typeof b.fireEvent!="undefined"){if(a=="click"&&b.tagName=="INPUT"&&(b.type.toLowerCase()=="checkbox"||b.type.toLowerCase()=="radio"))b.checked=b.checked!==!0;b.fireEvent("on"+a)}else c(Error("Browser doesn't support triggering events"))},d:function(b){return p.B(b)?b():b},Da:function(b,a){return p.a.g((b.className||"").split(/\s+/),a)>=0},pa:function(b,a,e){var f=p.a.Da(b,a);if(e&&!f)b.className=(b.className||"")+" "+a;else if(f&&!e){e=(b.className||"").split(/\s+/);f="";for(var d=0;d<e.length;d++)e[d]!=
-a&&(f+=e[d]+" ");b.className=p.a.m(f)}},Sa:function(b,a){b=p.a.d(b);a=p.a.d(a);for(var e=[],f=b;f<=a;f++)e.push(f);return e},ga:function(b){for(var a=[],e=b.length-1;e>=0;e--)a.push(b[e]);return a},Q:/MSIE 6/i.test(navigator.userAgent),La:/MSIE 7/i.test(navigator.userAgent),da:function(b,a){for(var e=p.a.ga(b.getElementsByTagName("INPUT")).concat(p.a.ga(b.getElementsByTagName("TEXTAREA"))),f=typeof a=="string"?function(e){return e.name===a}:function(e){return a.test(e.name)},d=[],h=e.length-1;h>=
-0;h--)f(e[h])&&d.push(e[h]);return d},D:function(b){if(typeof b=="string"&&(b=p.a.m(b))){if(window.JSON&&window.JSON.parse)return window.JSON.parse(b);return(new Function("return "+b))()}return o},V:function(b){(typeof JSON=="undefined"||typeof JSON.stringify=="undefined")&&c(Error("Cannot find JSON.stringify(). Some browsers (e.g., IE < 8) don't support it natively, but you can overcome this by adding a script reference to json2.js, downloadable from http://www.json.org/json2.js"));return JSON.stringify(p.a.d(b))},
-Ra:function(b,a,e){e=e||{};var f=e.params||{},d=e.includeFields||this.ba,h=b;if(typeof b=="object"&&b.tagName=="FORM"){h=b.action;for(var i=d.length-1;i>=0;i--)for(var j=p.a.da(b,d[i]),k=j.length-1;k>=0;k--)f[j[k].name]=j[k].value}a=p.a.d(a);var l=document.createElement("FORM");l.style.display="none";l.action=h;l.method="post";for(var q in a)b=document.createElement("INPUT"),b.name=q,b.value=p.a.V(p.a.d(a[q])),l.appendChild(b);for(q in f)b=document.createElement("INPUT"),b.name=q,b.value=f[q],l.appendChild(b);
-document.body.appendChild(l);e.submitter?e.submitter(l):l.submit();setTimeout(function(){l.parentNode.removeChild(l)},0)}}};p.b("ko.utils",p.a);p.b("ko.utils.arrayForEach",p.a.h);p.b("ko.utils.arrayFirst",p.a.xa);p.b("ko.utils.arrayFilter",p.a.J);p.b("ko.utils.arrayGetDistinctValues",p.a.$);p.b("ko.utils.arrayIndexOf",p.a.g);p.b("ko.utils.arrayMap",p.a.K);p.b("ko.utils.arrayPushAll",p.a.L);p.b("ko.utils.arrayRemoveItem",p.a.M);p.b("ko.utils.fieldsIncludedWithJsonPost",p.a.ba);
-p.b("ko.utils.getElementsHavingAttribute",p.a.ca);p.b("ko.utils.getFormFields",p.a.da);p.b("ko.utils.postJson",p.a.Ra);p.b("ko.utils.parseJson",p.a.D);p.b("ko.utils.registerEventHandler",p.a.q);p.b("ko.utils.stringifyJson",p.a.V);p.b("ko.utils.range",p.a.Sa);p.b("ko.utils.toggleDomNodeCssClass",p.a.pa);p.b("ko.utils.triggerEvent",p.a.qa);p.b("ko.utils.unwrapObservable",p.a.d);
+"function"?b.addEventListener(a,e,!1):typeof b.attachEvent!="undefined"?b.attachEvent("on"+a,function(a){e.call(b,a)}):c(Error("Browser doesn't support addEventListener or attachEvent"))},qa:function(b,a){(!b||!b.nodeType)&&c(Error("element must be a DOM node when calling triggerEvent"));if(typeof jQuery!="undefined")jQuery(b).trigger(a);else if(typeof document.createEvent=="function")if(typeof b.dispatchEvent=="function"){var e=document.createEvent(a=="click"?"MouseEvents":"HTMLEvents");e.initEvent(a,
+!0,!0,window,0,0,0,0,0,!1,!1,!1,!1,0,b);b.dispatchEvent(e)}else c(Error("The supplied element doesn't support dispatchEvent"));else if(typeof b.fireEvent!="undefined"){if(a=="click"&&b.tagName=="INPUT"&&(b.type.toLowerCase()=="checkbox"||b.type.toLowerCase()=="radio"))b.checked=b.checked!==!0;b.fireEvent("on"+a)}else c(Error("Browser doesn't support triggering events"))},d:function(b){return p.B(b)?b():b},Da:function(b,a){return p.a.g((b.className||"").split(/\s+/),a)>=0},pa:function(b,a,e){var f=
+p.a.Da(b,a);if(e&&!f)b.className=(b.className||"")+" "+a;else if(f&&!e){e=(b.className||"").split(/\s+/);f="";for(var d=0;d<e.length;d++)e[d]!=a&&(f+=e[d]+" ");b.className=p.a.m(f)}},Sa:function(b,a){b=p.a.d(b);a=p.a.d(a);for(var e=[],f=b;f<=a;f++)e.push(f);return e},ga:function(b){for(var a=[],e=b.length-1;e>=0;e--)a.push(b[e]);return a},Q:/MSIE 6/i.test(navigator.userAgent),La:/MSIE 7/i.test(navigator.userAgent),da:function(b,a){for(var e=p.a.ga(b.getElementsByTagName("INPUT")).concat(p.a.ga(b.getElementsByTagName("TEXTAREA"))),
+f=typeof a=="string"?function(e){return e.name===a}:function(e){return a.test(e.name)},d=[],h=e.length-1;h>=0;h--)f(e[h])&&d.push(e[h]);return d},D:function(b){if(typeof b=="string"&&(b=p.a.m(b))){if(window.JSON&&window.JSON.parse)return window.JSON.parse(b);return(new Function("return "+b))()}return o},V:function(b){(typeof JSON=="undefined"||typeof JSON.stringify=="undefined")&&c(Error("Cannot find JSON.stringify(). Some browsers (e.g., IE < 8) don't support it natively, but you can overcome this by adding a script reference to json2.js, downloadable from http://www.json.org/json2.js"));
+return JSON.stringify(p.a.d(b))},Ra:function(b,a,e){e=e||{};var f=e.params||{},d=e.includeFields||this.ba,h=b;if(typeof b=="object"&&b.tagName=="FORM"){h=b.action;for(var i=d.length-1;i>=0;i--)for(var j=p.a.da(b,d[i]),k=j.length-1;k>=0;k--)f[j[k].name]=j[k].value}a=p.a.d(a);var l=document.createElement("FORM");l.style.display="none";l.action=h;l.method="post";for(var q in a)b=document.createElement("INPUT"),b.name=q,b.value=p.a.V(p.a.d(a[q])),l.appendChild(b);for(q in f)b=document.createElement("INPUT"),
+b.name=q,b.value=f[q],l.appendChild(b);document.body.appendChild(l);e.submitter?e.submitter(l):l.submit();setTimeout(function(){l.parentNode.removeChild(l)},0)}}};p.b("ko.utils",p.a);p.b("ko.utils.arrayForEach",p.a.h);p.b("ko.utils.arrayFirst",p.a.xa);p.b("ko.utils.arrayFilter",p.a.J);p.b("ko.utils.arrayGetDistinctValues",p.a.$);p.b("ko.utils.arrayIndexOf",p.a.g);p.b("ko.utils.arrayMap",p.a.K);p.b("ko.utils.arrayPushAll",p.a.L);p.b("ko.utils.arrayRemoveItem",p.a.M);
+p.b("ko.utils.fieldsIncludedWithJsonPost",p.a.ba);p.b("ko.utils.getElementsHavingAttribute",p.a.ca);p.b("ko.utils.getFormFields",p.a.da);p.b("ko.utils.postJson",p.a.Ra);p.b("ko.utils.parseJson",p.a.D);p.b("ko.utils.registerEventHandler",p.a.q);p.b("ko.utils.stringifyJson",p.a.V);p.b("ko.utils.range",p.a.Sa);p.b("ko.utils.toggleDomNodeCssClass",p.a.pa);p.b("ko.utils.triggerEvent",p.a.qa);p.b("ko.utils.unwrapObservable",p.a.d);
Function.prototype.bind||(Function.prototype.bind=function(d){var b=this,a=Array.prototype.slice.call(arguments);d=a.shift();return function(){return b.apply(d,a.concat(Array.prototype.slice.call(arguments)))}});
p.a.e=new function(){var d=0,b="__ko__"+(new Date).getTime(),a={};return{get:function(a,b){var d=p.a.e.getAll(a,!1);return d===n?n:d[b]},set:function(a,b,d){d===n&&p.a.e.getAll(a,!1)===n||(p.a.e.getAll(a,!0)[b]=d)},getAll:function(e,f){var g=e[b];if(!g){if(!f)return;g=e[b]="ko"+d++;a[g]={}}return a[g]},clear:function(e){var f=e[b];f&&(delete a[f],e[b]=o)}}};
p.a.p=new function(){function d(e,b){var d=p.a.e.get(e,a);d===n&&b&&(d=[],p.a.e.set(e,a,d));return d}function b(a){var b=d(a,!1);if(b){b=b.slice(0);for(var g=0;g<b.length;g++)b[g](a)}p.a.e.clear(a);typeof jQuery=="function"&&typeof jQuery.cleanData=="function"&&jQuery.cleanData([a])}var a="__ko_domNodeDisposal__"+(new Date).getTime();return{Z:function(a,b){typeof b!="function"&&c(Error("Callback must be a function"));d(a,!0).push(b)},ja:function(b,f){var g=d(b,!1);g&&(p.a.M(g,f),g.length==0&&p.a.e.set(b,
View
4 src/utils.js
@@ -174,7 +174,9 @@ ko.utils = new (function () {
if (!(element && element.nodeType))
throw new Error("element must be a DOM node when calling triggerEvent");
- if (typeof document.createEvent == "function") {
+ if (typeof jQuery != "undefined") {
+ jQuery(element)['trigger'](eventType);
+ } else if (typeof document.createEvent == "function") {
if (typeof element.dispatchEvent == "function") {
var eventCategory = (eventType == "click" ? "MouseEvents" : "HTMLEvents"); // Might need to account for other event names at some point
var event = document.createEvent(eventCategory);
Please sign in to comment.
Something went wrong with that request. Please try again.