Comments (15)
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.
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.
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.
Thank you for your nice suggestion. I'll take this approach.
from soma-template.
Great!
from soma-template.
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.
@uiii
Thank you for your kind recommendation. I will take it into consideration for future use.
from soma-template.
@arumtaunsaram Just to be sure - my recomenadation is for the soma-template developer not for soma-template user.
from soma-template.
@uiii
I'll re-open that one and see what it involves.
from soma-template.
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.
If you write this:
<img data-show="false" />
Then yes it should be hidden.
from soma-template.
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.
I've created a pull request for this. #4
from soma-template.
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.
Pull request is merged. I close.
Thanks @uiii
from soma-template.
Related Issues (20)
- Parse functions in parameters HOT 1
- data-repeat undefined parameter HOT 1
- Setting value should use the content attribute HOT 3
- angular like "filters" in data-repeat HOT 2
- Update Typescript definition HOT 1
- demos/people doesn't work under Firefox HOT 1
- Can't pass arguments to helper function nor perform arithmetic operations. HOT 2
- missing license and copyright HOT 2
- data-click type events not working on iOS
- 2 questions HOT 2
- conditional if/else ? HOT 6
- Possible confusion involving template re-compilation HOT 2
- Run-time compiled templates not initialising nested templates HOT 1
- Template constructor, named variables not honored HOT 1
- soma-template swallowing errors in services, templates HOT 2
- data-repeat incorrectly rendering when initially blank, then subsequently rendered with items HOT 1
- Late instantiation of templates doesn't work as expected
- data-skip attributes from scoped variables (Tokens) HOT 2
- Make the docs more clear about the use of npm install HOT 2
- data-enabled attribute
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from soma-template.