As we discussed on IM, the parent.document || part would be untennable
(since it would make all iframed copies of jQuery incapable of operating
within the frame itself).

Would the resulting change,

(function(document){


})(document);

be acceptable?

--John


On Tue, Jul 14, 2009 at 11:32 AM, Andrea Giammarchi <
andrea.giammar...@gmail.com> wrote:

> Solved: jQuery In A Sandbox
>
> Guys, forget all that crap I wrote precedent emails ... I did not think
> about a truly simple change that will not affect anything, will be extremely
> simple to maintain, and will make jQuery automatically "sandboxable"
>
> This is my latest snippet via Elsewhere:
>
>         // the callback you would use for ready (with $ as jQuery
> argument)
>         function onDocumentReady($){
>             $("body").html("test");
>          };
>
>         new Elsewhere("jquery-1.3.2.js")
>             .execute(function(onDocumentReady){
>                 (parent.jQuery = jQuery)(function(){
>                     onDocumentReady(jQuery);
>                 });
>             }, [
>                 onDocumentReady
>             ])
>         ;
>
> That's it ... and this is all I have done to jQuery library itself:
>
> line 12, begninning of the closure ...
> (function(*document*){
>
> line 4376, the end of the closure and its call:
>
> })(*parent.document || document*);
>
> With this ridiculous change, jQuery becomes instantly loadable via iframe
> or main document.
>
> Best Regards,
> Andrea Giammarchi
>
>
> On Mon, Jul 13, 2009 at 2:43 PM, Andrea Giammarchi <
> andrea.giammar...@gmail.com> wrote:
>
>> Last summary ... this code is the best I have tried so far but I still
>> miss the jQuery init method cause I am forcing it via an array returned by
>> Sizzle
>>
>> parent.jQuery = (function(){
>>     function $jQuery(){};
>>     function $(selector, context){
>>         return init.call(new $jQuery, Sizzle(selector, context ||
>> document));
>>     };
>>     var document = parent.document,
>>         init = jQuery.fn.init,
>>         Sizzle = jQuery.find,
>>         k
>>     ;
>>     for(k in jQuery)
>>         $[k] = jQuery[k]
>>     ;
>>     $.prototype = $jQuery.prototype = jQuery.fn;
>>     return $;
>> })();
>>
>> all this stuff does not make sense if i introduced in-scope document and I
>> set it in the sandbox ( in any case if I create a sandbox for jQuery it does
>> not make sense to redefine it more than once, agree? )
>>
>> jQuery.setDefaultDocument(parent.document);
>> parent.jQuery = jQuery;
>>
>> that's it, I prefer much more latest snippet. In both case the injected
>> ready method cause an error. In few words that method assumes the body is
>> ready. I do not remember why the body is necessary, I tried with
>> documentElement and I obtained same results.
>>
>> Can anybody refresh my memory explaining me the reason there is an
>> injected 0 index callback by default in bindReady?
>>
>> Thanks
>>
>>
>> On Mon, Jul 13, 2009 at 10:23 AM, Andrea Giammarchi <
>> andrea.giammar...@gmail.com> wrote:
>>
>>> As quick update, I successfully tested this code from the sandbox:
>>>
>>> parent.jQuery = (function(){
>>>     var $ = Function(),
>>>         document = parent.document,
>>>         init = jQuery.fn.init,
>>>         Sizzle = jQuery.find
>>>     ;
>>>     $.prototype = jQuery.fn;
>>>     return function(selector, context){
>>>         return init.call(new $, Sizzle(selector, context || document));
>>>     };
>>> })();
>>>
>>> from the parent document and with these selectors:
>>>
>>> jQuery("#test").html("Select By Id");
>>> jQuery(".test").html("Select By class");
>>> jQuery("div:eq(2)").html("Select By Tag Name");
>>>
>>> everything worked perfectly except an error with jQuery on line 3230
>>>
>>> 3225 // document.body must exist before we can do this
>>> 3226 jQuery(function(){
>>> 3227 var div = document.createElement("div");
>>> 3228 div.style.width = div.style.paddingLeft = "1px";
>>> 3229
>>> 3230 document.body.appendChild( div );
>>> 3231 jQuery.boxModel = jQuery.support.boxModel = div.offsetWidth === 2;
>>> 3232 document.body.removeChild( div ).style.display = 'none';
>>> 3233 });
>>>
>>> ... any clue?
>>>
>>> Regards
>>>
>>
>>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"jQuery Development" group.
To post to this group, send email to jquery-dev@googlegroups.com
To unsubscribe from this group, send email to 
jquery-dev+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/jquery-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to