Description
V1
http://jsbin.com/duvayova/1/edit
V2
http://jsbin.com/ditogatu/5/edit
I had no net for a couple of days (ooooh the humanity!) so played with your code for something to do.
Originally I was only interested in changing eval to new Function to speed things up, but ended up doing a little more.
I dont even know if I'm going to use this, but was thinking of maybe doing some svg and will want something like this. I like your version coz its simple and works....the best sort of code.
Anywayz, was just passing time and trying out some ideas, cant say at all if even any of them are actually good ideas ;)
Do what ever you want with this.
Things I changed....
Compile evals
The thing I was originally interested in...then I got carried away ;)
Instead of using evals as they where used, I tried using new Function instead to get an increase in speed, please check.....
http://jsperf.com/eval-vs-new-function-constructor/6
I then changed that to using an eval to compile a function in an anonymous function, for the below...
Remove the need for $ before variables
This just makes things cleaner to me.
I ended up making two versions to try out two ideas.
V1 - Uses new Function and passes the global variables to the function through its parameters.
V2 - Uses the fact that VLEX is defined within an anonymous function to pull it off. All variables to do with VLEX are attached to VLEX to avoid collisions and only those I wish are exposed to the scripts.
Personally I prefer V2 but I wonder about speed....variable lookup Vs parameter passing, I guess
Removed $ in the code
Tried to get it so that $ and _ aren't used anywhere to avoid any future probs with jQuery and Underscore...but then used it for the default for store as I couldn't think of anything else and you "probably" aren't going to need jQuery in a VLEX script.
Use requestFrame
The "idea" here was to try and make it more efficient by only updating when truly necessary and only once....seems to have made a difference but wouldn't know how to rate the difference....I just went by how it looks when I move it on the screen and the new way is alot smoother.
In the past when Ive done things with mousemove or resize they fire so often it was a problem. And I'm pretty sure I read something to do with the idea if you only do these sort of things on the requestframe then the browser only redraws once.
Store....for the lack of a better name
This is something to bridge between the VLEX and the outside world, which you already had.
Right now you can change the variable name to be used within the scripts for this through options. But Id think about removing that ability. It makes for inconsistent scripts (between users) and I wonder if theres any speed benefit to calling a function with no parameters? You could just attach variables/woteva to VLEX, but thats likely to cause a collision.
$$
Due to the way it now works you can use "this" in your scripts as the function is attached to the node.
elParent
Assumes the parent of el wont change.
data attributes
Where not meant to be making up attributes how we like, apparently they should start with "data-". Personally I hate this (its so freakn ugly), but some html validators spit on it and so some people may want to be able to use "data-vlex".
Usual Disclaimer
Im not the best coder and all that, not the worst either tho ;)
Im prone to lots of dumb mistakes and have the worst memory of any coder.
Take all my advice/suggestions with a pinch of salt and double check everything.