Giter Site home page Giter Site logo

Comments (15)

soundstep avatar soundstep commented on July 17, 2024

What kind of special attributes? And what would they do?

There's a big chance that most of what you want to do will work on inline elements, unless it is a special functionality, such as the data-src on an img tag. Simple string replacement for example should just work.

Can you provide some examples?

from soma-template.

arumtaunsaram avatar arumtaunsaram commented on July 17, 2024

I'd like to use data-show attribute for img tags with a static src value. My problem is that the img tags I use is inline elements but when I set data-show attributes in HTML and true in JavaScript to the tags, they are turned to be block elements.

<!-- In a template -->
<img data-show="{{post.isFlamed}}" src="img/flamed.png">

So now I write code as below.
HTML:

<!-- In a template -->
<img style="display:{{post.styleFlamed}}" src="img/flamed.png">

JS:

template.scope.styleFlamed = 'inline'
// or
template.scope.styleFlamed = 'none'

It is good If I can eliminate css styles from JS codes in the purview of management of graphic designs.
So, I desire special attributes like data-show-inline or wish the template engine detect computed display style value when it makes templates and apply the value when it is shown.

from soma-template.

soundstep avatar soundstep commented on July 17, 2024

oh css inline, right.
Yes data-show and data-hide is using block and none.

However data-show if just a convenience. Check if this would solve your problem:

<img class="{{post.getIsFlamed()}}" src="img/flamed.png">
.styleFlamed {
    display: inline;
}
.styleNotFlamed {
    display: none;
}
scope.post.getIsFlamed = function() {
    return condition ? 'styleFlamed' : 'styleNotFlamed';
}

You can also send parameters to the getIsFlamed function, string or other variables from the scope.

from soma-template.

arumtaunsaram avatar arumtaunsaram commented on July 17, 2024

Thank you for your nice suggestion. I'll take this approach.

from soma-template.

soundstep avatar soundstep commented on July 17, 2024

Great!

from soma-template.

uiii avatar uiii commented on July 17, 2024

There is a simple solution for that. Just remove the display: none instead of setting display: block. It can be done by using element.style.display = ''

from soma-template.

arumtaunsaram avatar arumtaunsaram commented on July 17, 2024

@uiii
Thank you for your kind recommendation. I will take it into consideration for future use.

from soma-template.

uiii avatar uiii commented on July 17, 2024

@arumtaunsaram Just to be sure - my recomenadation is for the soma-template developer not for soma-template user.

from soma-template.

soundstep avatar soundstep commented on July 17, 2024

@uiii
I'll re-open that one and see what it involves.

from soma-template.

uiii avatar uiii commented on July 17, 2024

There is just one thing to consider - what are data-show and data-hide attributes intended for. If they just set inline style display:none if particular condition occures, then my recommendation is the right one. But if data-show evaluated to true should show element otherwise should hide it despite of the styles set to the element in css stylesheet (data-hide analogicaly) then my solution does not satisfy it.

from soma-template.

soundstep avatar soundstep commented on July 17, 2024

If you write this:

<img data-show="false" />

Then yes it should be hidden.

from soma-template.

uiii avatar uiii commented on July 17, 2024

So, when I write this

<style>
.hidden {
   display: none;
}
</style>
<img data-show="true" class="hidden" />

Will be img hidden or not?

EDIT: I vote for hidden.

from soma-template.

uiii avatar uiii commented on July 17, 2024

I've created a pull request for this. #4

from soma-template.

soundstep avatar soundstep commented on July 17, 2024

That's the other way around. Inline styles take priority on classes, that's why it is kind of bad using them.
http://plnkr.co/edit/QS1pY2Kr8LiAJZRcJE7a?p=preview

from soma-template.

soundstep avatar soundstep commented on July 17, 2024

Pull request is merged. I close.
Thanks @uiii

from soma-template.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.