[Moo] Mootools Factory Pattern: input needed

5 messages Options
Embed this post
Permalink
jiggliemon-2

[Moo] Mootools Factory Pattern: input needed

Reply Threaded More More options
Print post
Permalink

Because i love the Joomla file structure so much and the factory
pattern, I decided to implement something similar with my JS library.

My page loads by default, Core.js, More.js, Agro.js, and template.js
by default.
I'm getting all kinds of errors in the Firebug. Mainly i think it's an
issue of setting what would be a static property in in php for
"comments".  How would i assign a global property so that the rest of
the methods can reach it?



In my template.js file i have:
-----------------------------------------
window.addEvent('domready', function() {

        var agro = new Agro();

        var comments = agro.getComments();
        alert(comments.toString);
});


in my Agro.js file it has:
-----------------------------------------
var Agro = new Class({
        comments:null,
        Implements: [Events, Options],

        options: {
                comments: null,
        },
        initialize: function(){
                console.log('Agro class loaded');
        },
        getComments: function(){
                if(!$chk(window.Asset)) getMore();
                if(!$chk(window.AgroComments)){
                        new Asset.javascript('/media/system/js/agro/comments.js',{
                                onload: function(){
                                        this.comments = new AgroComments();
                                        console.log('comments has finally loaded.');
                                }
                        });
                }
                return this.comments;
        }
});
Agro.implement(new Events, new Options);


in my Comments.js file it has:
-----------------------------------------
var AgroComments = new Class({
        Implements: [Events, Options],
        options: {},
        initialize: function(){
                console.log('AgroComments has been initialized.');
        },
        raise: function(error){
                alert(error);
        },
        toString:'totally'
});

AgroComments.implement(new Events, new Options);

---------------------
---------------------
---------------------
csuwldcat

[Moo] Re: Mootools Factory Pattern: input needed

Reply Threaded More More options
Print post
Permalink

Are you essentially trying to preload a script before firing a
function, initializer, or dependent code chunk?  If so check this
out:  http://blog.citycrawler.com/?p=47

- Daniel

On Nov 3, 5:17 pm, jiggliemon <[hidden email]> wrote:

> Because i love the Joomla file structure so much and the factory
> pattern, I decided to implement something similar with my JS library.
>
> My page loads by default, Core.js, More.js, Agro.js, and template.js
> by default.
> I'm getting all kinds of errors in the Firebug. Mainly i think it's an
> issue of setting what would be a static property in in php for
> "comments".  How would i assign a global property so that the rest of
> the methods can reach it?
>
> In my template.js file i have:
> -----------------------------------------
> window.addEvent('domready', function() {
>
>         var agro = new Agro();
>
>         var comments = agro.getComments();
>         alert(comments.toString);
>
> });
>
> in my Agro.js file it has:
> -----------------------------------------
> var Agro = new Class({
>         comments:null,
>         Implements: [Events, Options],
>
>         options: {
>                 comments: null,
>         },
>         initialize: function(){
>                 console.log('Agro class loaded');
>         },
>         getComments: function(){
>                 if(!$chk(window.Asset)) getMore();
>                 if(!$chk(window.AgroComments)){
>                         new Asset.javascript('/media/system/js/agro/comments.js',{
>                                 onload: function(){
>                                         this.comments = new AgroComments();
>                                         console.log('comments has finally loaded.');
>                                 }
>                         });
>                 }
>                 return this.comments;
>         }});
>
> Agro.implement(new Events, new Options);
>
> in my Comments.js file it has:
> -----------------------------------------
> var AgroComments = new Class({
>         Implements: [Events, Options],
>         options: {},
>         initialize: function(){
>                 console.log('AgroComments has been initialized.');
>         },
>         raise: function(error){
>                 alert(error);
>         },
>         toString:'totally'
>
> });
>
> AgroComments.implement(new Events, new Options);
>
> ---------------------
> ---------------------
> ---------------------
jiggliemon-2

[Moo] Re: Mootools Factory Pattern: input needed

Reply Threaded More More options
Print post
Permalink

At it's root, it's a problem with Asset.javascript().  What's
happening is Asset grabs the JS file, but the javascript moves on
before it's completed loading.  Even when I add functions to onload
they're being called too late.

Is there another way to get a javascript file without Asset?  I need
somthing that i can attach an onComplete function to, and not have it
move on w/o completing.

Request.JSON?
Request?

-Chase

On Nov 3, 11:27 pm, csuwldcat <[hidden email]> wrote:

> Are you essentially trying to preload a script before firing a
> function, initializer, or dependent code chunk?  If so check this
> out:  http://blog.citycrawler.com/?p=47
>
> - Daniel
> le
> On Nov 3, 5:17 pm, jiggliemon <[hidden email]> wrote:
>
> > Because i love the Joomla file structure so much and the factory
> > pattern, I decided to implement something similar with my JS library.
>
> > My page loads by default, Core.js, More.js, Agro.js, and template.js
> > by default.
> > I'm getting all kinds of errors in the Firebug. Mainly i think it's an
> > issue of setting what would be a static property in in php for
> > "comments".  How would i assign a global property so that the rest of
> > the methods can reach it?
>
> > In my template.js file i have:
> > -----------------------------------------
> > window.addEvent('domready', function() {
>
> >         var agro = new Agro();
>
> >         var comments = agro.getComments();
> >         alert(comments.toString);
>
> > });
>
> > in my Agro.js file it has:
> > -----------------------------------------
> > var Agro = new Class({
> >         comments:null,
> >         Implements: [Events, Options],
>
> >         options: {
> >                 comments: null,
> >         },
> >         initialize: function(){
> >                 console.log('Agro class loaded');
> >         },
> >         getComments: function(){
> >                 if(!$chk(window.Asset)) getMore();
> >                 if(!$chk(window.AgroComments)){
> >                         new Asset.javascript('/media/system/js/agro/comments.js',{
> >                                 onload: function(){
> >                                         this.comments = new AgroComments();
> >                                         console.log('comments has finally loaded.');
> >                                 }
> >                         });
> >                 }
> >                 return this.comments;
> >         }});
>
> > Agro.implement(new Events, new Options);
>
> > in my Comments.js file it has:
> > -----------------------------------------
> > var AgroComments = new Class({
> >         Implements: [Events, Options],
> >         options: {},
> >         initialize: function(){
> >                 console.log('AgroComments has been initialized.');
> >         },
> >         raise: function(error){
> >                 alert(error);
> >         },
> >         toString:'totally'
>
> > });
>
> > AgroComments.implement(new Events, new Options);
>
> > ---------------------
> > ---------------------
> > ---------------------
anutron

[Moo] Re: Mootools Factory Pattern: input needed

Reply Threaded More More options
Print post
Permalink
new Element('script', {src: url, events: { load: fn } }).inject(document.head)

On Wed, Nov 4, 2009 at 4:41 PM, jiggliemon <[hidden email]> wrote:

At it's root, it's a problem with Asset.javascript().  What's
happening is Asset grabs the JS file, but the javascript moves on
before it's completed loading.  Even when I add functions to onload
they're being called too late.

Is there another way to get a javascript file without Asset?  I need
somthing that i can attach an onComplete function to, and not have it
move on w/o completing.

Request.JSON?
Request?

-Chase

On Nov 3, 11:27 pm, csuwldcat <[hidden email]> wrote:
> Are you essentially trying to preload a script before firing a
> function, initializer, or dependent code chunk?  If so check this
> out:  http://blog.citycrawler.com/?p=47
>
> - Daniel
> le
> On Nov 3, 5:17 pm, jiggliemon <[hidden email]> wrote:
>
> > Because i love the Joomla file structure so much and the factory
> > pattern, I decided to implement something similar with my JS library.
>
> > My page loads by default, Core.js, More.js, Agro.js, and template.js
> > by default.
> > I'm getting all kinds of errors in the Firebug. Mainly i think it's an
> > issue of setting what would be a static property in in php for
> > "comments".  How would i assign a global property so that the rest of
> > the methods can reach it?
>
> > In my template.js file i have:
> > -----------------------------------------
> > window.addEvent('domready', function() {
>
> >         var agro = new Agro();
>
> >         var comments = agro.getComments();
> >         alert(comments.toString);
>
> > });
>
> > in my Agro.js file it has:
> > -----------------------------------------
> > var Agro = new Class({
> >         comments:null,
> >         Implements: [Events, Options],
>
> >         options: {
> >                 comments: null,
> >         },
> >         initialize: function(){
> >                 console.log('Agro class loaded');
> >         },
> >         getComments: function(){
> >                 if(!$chk(window.Asset)) getMore();
> >                 if(!$chk(window.AgroComments)){
> >                         new Asset.javascript('/media/system/js/agro/comments.js',{
> >                                 onload: function(){
> >                                         this.comments = new AgroComments();
> >                                         console.log('comments has finally loaded.');
> >                                 }
> >                         });
> >                 }
> >                 return this.comments;
> >         }});
>
> > Agro.implement(new Events, new Options);
>
> > in my Comments.js file it has:
> > -----------------------------------------
> > var AgroComments = new Class({
> >         Implements: [Events, Options],
> >         options: {},
> >         initialize: function(){
> >                 console.log('AgroComments has been initialized.');
> >         },
> >         raise: function(error){
> >                 alert(error);
> >         },
> >         toString:'totally'
>
> > });
>
> > AgroComments.implement(new Events, new Options);
>
> > ---------------------
> > ---------------------
> > ---------------------

The MooTools Tutorial: www.mootorial.com Clientcide: www.clientcide.com
nwhite-2

[Moo] Re: Mootools Factory Pattern: input needed

Reply Threaded More More options
Print post
Permalink
In reply to this post by jiggliemon-2
I know there is issues with onload on scripts. The implementation isn't the same across browsers and I know its broken in some older ones. If you really need this behavior you could use the Request object.


Request.JS = new Class({
Extends : Request,
options : {
context : window
},
success : function(text){
this.options.context.eval(text,this.options.context);
this.onSuccess(this.options.context,text);
}
});


Not tested. I threw the context option in for shits and giggles. When using eval you can define a scope but this doesn't work in Mozilla who explicitly states:

eval is a top-level function and is not associated with any object.

So the second param is set for Mozilla.

This options would allow you to use Group. The disadvantages being you lose out on caching, however if your into pain you could probably rig a solution using Dom Storage. I know FB does some of this with some their content ( the caching ).





On Wed, Nov 4, 2009 at 4:41 PM, jiggliemon <[hidden email]> wrote:

At it's root, it's a problem with Asset.javascript().  What's
happening is Asset grabs the JS file, but the javascript moves on
before it's completed loading.  Even when I add functions to onload
they're being called too late.

Is there another way to get a javascript file without Asset?  I need
somthing that i can attach an onComplete function to, and not have it
move on w/o completing.

Request.JSON?
Request?

-Chase

On Nov 3, 11:27 pm, csuwldcat <[hidden email]> wrote:
> Are you essentially trying to preload a script before firing a
> function, initializer, or dependent code chunk?  If so check this
> out:  http://blog.citycrawler.com/?p=47
>
> - Daniel
> le
> On Nov 3, 5:17 pm, jiggliemon <[hidden email]> wrote:
>
> > Because i love the Joomla file structure so much and the factory
> > pattern, I decided to implement something similar with my JS library.
>
> > My page loads by default, Core.js, More.js, Agro.js, and template.js
> > by default.
> > I'm getting all kinds of errors in the Firebug. Mainly i think it's an
> > issue of setting what would be a static property in in php for
> > "comments".  How would i assign a global property so that the rest of
> > the methods can reach it?
>
> > In my template.js file i have:
> > -----------------------------------------
> > window.addEvent('domready', function() {
>
> >         var agro = new Agro();
>
> >         var comments = agro.getComments();
> >         alert(comments.toString);
>
> > });
>
> > in my Agro.js file it has:
> > -----------------------------------------
> > var Agro = new Class({
> >         comments:null,
> >         Implements: [Events, Options],
>
> >         options: {
> >                 comments: null,
> >         },
> >         initialize: function(){
> >                 console.log('Agro class loaded');
> >         },
> >         getComments: function(){
> >                 if(!$chk(window.Asset)) getMore();
> >                 if(!$chk(window.AgroComments)){
> >                         new Asset.javascript('/media/system/js/agro/comments.js',{
> >                                 onload: function(){
> >                                         this.comments = new AgroComments();
> >                                         console.log('comments has finally loaded.');
> >                                 }
> >                         });
> >                 }
> >                 return this.comments;
> >         }});
>
> > Agro.implement(new Events, new Options);
>
> > in my Comments.js file it has:
> > -----------------------------------------
> > var AgroComments = new Class({
> >         Implements: [Events, Options],
> >         options: {},
> >         initialize: function(){
> >                 console.log('AgroComments has been initialized.');
> >         },
> >         raise: function(error){
> >                 alert(error);
> >         },
> >         toString:'totally'
>
> > });
>
> > AgroComments.implement(new Events, new Options);
>
> > ---------------------
> > ---------------------
> > ---------------------