i had a problem and solving which required a functionality built in mootools
. so i began dissecting it.
there a function a am interested in
IframeShim.destroy
its like this
destroy: function(){
if (this.shim) this.shim.destroy();
return this;
}
now what i cant understand in this what is shim
.
Paricularly what i am trying to understand is
Request.JSONP.cancel
its code is like this
cancel: function(){
if (this.running) this.clear().fireEvent('cancel');
return this;
}
now this cancel calls clear
whose code is like this
clear: function(){
this.running = false;
if (this.script){
this.script.destro开发者_JAVA技巧y();
this.script = null;
}
return this;
}
now in this clear function i can see destroy()
which takes me to shim
(see code at the top) and i m stuck.
All these functions are in mootools-more.js
Help?
it would be great if somebody could provide a plain javascript implementation of Request.JSONP.cancel
Does it have a JQuery
alternative?
The destroy that is being called by the Request.JSONP.clear
method isn't IframeShim.destory
, it's part of the mootools core. Here's the source:
destroy: function(){
var children = clean(this).getElementsByTagName('*');
Array.each(children, clean);
Element.dispose(this);
return null;
},
All that Element.dispose
does is call the native jasvascript DOM method Node.removeChild which deletes an element from the DOM.
So all JSONP.cancel is doing is seeing if a script DOM node was added via Request.JSONP.cancel
. If it was, it removes the script element from from the DOM via removeChild.
The important thing is that it set the running
flag to false. If you look at Request.JSONP.success
, the first thing it does before calling your callback function is check if the running
flag is set to false, and if it is, it returns immediately. This effectively "cancels" the execution.
If you meant does it cancel the HTTP request, the answer is no, it does not.
精彩评论