Archived
This has been replaced by https://github.com/ReedOverflow/JS-Classes, a much better library, and this one will receive no more updates.
It has more recently been replaced by Autowire, which i'm not gonna bother to link
javascript-dom
a simple way to map css classes to javsacript classes. I might improve the docs and code with time, but I made this for myself, so I probably won't worry too much about it.
See my StackOverflow post for an example of it actually working.
Call JDOMProcessor.pageLoaded();
after your jdom
functions have been loaded.
You may do whatever you want with the source code. Distribute, modify, include in your own project and sell, or whatever.
Usage is very simple. Write your HTML with css classes (which you should be doing anyway) and add the 'jdom' css class when you want it mapped to a javscript function.
i.e.:
<body>
<div class="jdom div"> <!-- I wouldn't name a class 'div', but i'm just showing an example -->
<a class="jdom legal trademark">
some interesting title
</a>
</div>
</body>
And to define how they function, define one function for each (I'll go over the (weirdish) naming conventions in a second) i.e.:
//for the outer div, class = "jdom div"
function jdomDiv_div(parent,element){ //you can rename parent and element to, say, body and div respectively
alert(element.innerHTML);
}
//for the inner span, class = "jdom legal trademark". I'll rename my params here
function jdomDivSpan_cool_span(div,a){
a.href = '/legal/trademark.html';
a.target = '_blank';
//assign functions, too. That's the main reason I made jdom.
a.onclick = function(){
return confirm('do you want to read some legaleez?');
}
}
Now, for some stupid reason, you will alert the inner html of element on page load. AND you'll set the href and target for a link. AND now if you click on the a tag, user will have to confirm before leaving.
Naming Conventions:
There are three parts,- 'jdom' - this always prepends functions using this jdom
- Tags - (optional) includes Parent tag and Element tag
- classes - the css classes of the html element