Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

many improvements #2

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

redbow-kimee
Copy link

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.

  1. quotations in attributes to better separate no-js arguments
  2. extensible api, instead of tweaking if-statements to add new actions, simply put new attributes in an object (no.targetType)
  3. clear warnings in the javascript console when there are malformed or invalid actions
  4. immediately and timeout event listeners
  • immediately will cause no-js to run an action right after it finishes processing a document
  • timeout will cause no-js to use window.setTimeout and window.setInterval
  1. use <meta> tags to declare templates of actions and apply them to tags later.

@ifedapoolarewaju
Copy link
Owner

@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.

@redbow-kimee
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants