Created
May 19, 2011 08:44
-
-
Save jackey/980417 to your computer and use it in GitHub Desktop.
small event driver programe
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
/** | |
* @description Ajax Form object. Depend on the jQuery and jquery.form.js | |
* @param | |
*/ | |
function AjaxForm(settings) { | |
this.settings = settings; | |
this.action = {}; | |
this.__load(settings.url, settings.form_id); | |
}; | |
AjaxForm.prototype.__load = function (url, form_id) { | |
var This = this; | |
$.ajax({ | |
dataType:'JSON', | |
type:'GET', | |
url:This.settings.url, | |
data:{tpl: This.settings.form_id}, | |
success: function (response, status) { | |
// Fire event listener | |
This.emmit('loaded', {form: $(response.data), response:response, status:status}); | |
}, | |
complete: function (response, status) { | |
This.emmit('complete', {response:response, status:status}); | |
} | |
}); | |
}; | |
AjaxForm.prototype.submit = function (callback) { | |
var This = this; | |
This.__load(this.settings.url, this.settings.form_id, function (action, form, source) { | |
if (action == 'success') { | |
callback('load', source); | |
} | |
}); | |
}; | |
AjaxForm.prototype.on = function (action, callback) { | |
if (typeof(this.action[action]) != undefined) { | |
this.action[action].push(callback); | |
} | |
else { | |
this.action.propotype.action = [callback]; | |
} | |
}; | |
AjaxForm.prototype.emmit = function (action, data) { | |
if (this.action.hasOwnProperty(action)) { | |
while (this.action[action].length) { | |
var callback = this.action[action].shift(); | |
calback(data); | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The AjaxForm.on method can not work. can someguys point me the error ?