nojs
nojs copied to clipboard
many improvements
Apologies for changing sooo much, but I really loved the idea of this library, and thought I'd contribute the following changes, which is basically most of the code. although I'm pretty sure I've made it API backwards compatible.
- quotations in attributes to better separate no-js arguments
- extensible api, instead of tweaking if-statements to add new actions, simply put new attributes in an object (
no.targetType
) - clear warnings in the javascript console when there are malformed or invalid actions
-
immediately
andtimeout
event listeners
-
immediately
will cause no-js to run an action right after it finishes processing a document -
timeout
will cause no-js to usewindow.setTimeout
andwindow.setInterval
- use
<meta>
tags to declare templates of actions and apply them to tags later.
@RedBow thank you so much for this PR! Looks really good so far (I am still reviewing the code)!
One part I'm unsure about though, is the templates. What is the use case for this? From my perspective, I feel it's a bit counter-intuitive (and less readable) when compared with the readability of the other features of no.js
. I also feel like it doesn't really save you much by using them, because you still have to write out the on-click-apply-template
attribute, then one might as well just write the actual attribute which is being refactored into a template itself.
Hey, I thought of that mainly to group many actions together and use them multiple times. Here is a few excerpts from a JSP that I was working on.
First is a template with many actions.
<meta no-js="prepEditTag 3" set-value-1="#editTagId $0"
set-value-2="#editTagAction edit" set-value-3="#tag $1"
set-form="editTag featured $2"
copy-html="#description '#tag$0 td:nth-child(n+3)'"
set-text="#editTagH2 'Edit Tag'"
apply-template="openModal #editTagModal" />
and here's where i invoke it (for each occurence in a list)
<button no-js on-click-apply-template="prepEditTag '<%=
tag.id %>' '<%= tag.tag.replaceAll("\'", "\\\'") %>' <%=
tag.featured ? "true" : "false" %>">
Edit
</button>
the targets that it acts on are just a form in a modal elsewhere in the JSP document.