intro
Hello,
I'm trying to develop some plugin or/*and* object in javascript, which will control some properties over some object. It will also use jQuery, to ease development.
idea
This is in pseudocode to give you an idea, since I can't really describe it in english with the right words, it's impossible to go and use google to find out what I want to use (and learn).
I will have plugin (maybe object?) with some variables and methods:
plugin hideshow(startupconfig){
var c, //collection
add: function(what){
c += what;
},
do: function(){
c.show().hide().stop(); //example code
}
}
and I will use it this way (or sort-of):
var p = new Plugin();
p
.add($('p#simple'))
.add($('p#simple2'))
.do();
note
I'm not really looking for jQuery plugin tutorials - it's more like usage of one object in document in javascript, jQuery is mentione only because it will be used to modify dom and simplify selectors, jQuery plugin maybe just for that one little function add
.
I'm looking for something, that will sit on top of my document and call functions from itselft based on timer, or user actions, or whatever.
problems
- I don't really know where to start with construction of this object/plugin
- I'm not really sure how to maintain one variable, which is collection of jQuery objects (something like
$('#simple, #simple2');
) - I would maybe like to extedn jQuery with
$.fn.addToPlugin
to use chaining of objects, but that should be simple (really justeach( p.add($(this)); )
) - My biggest problem is obviously that i can't explain what I want.
I hope I make any sense, ideas, links or advices appreciated.
edit
It's something like this, I just can't figure out how it's called/used in javascript - example in pseudo PHP:
class Foo() {
$collection;
$timer, $action;
function onTimer(){
foreach($collection as $e){
$e->someAction();
}
}
function add($e){
$collection[] = $e;
}
function start(){
$timer->start( onTimer() );
}
function->stop(){
$timer->stop();
}
}
var f = new Foo();
Foo.add(something);
Foo.start();