Ember: How to script with intervals - ember.js

I have a span-area like this
<span class="blinky">I'm blinking</span>
and now I want it to blink.
In vanilla JS, I would write a simple piece of code using jQuery which starts an interval for this.
However: How can I implement this in ember in a proper way?

I write a full solution for blinking
First, let's create CSS for blinking
.blinky {
animation: changecolor 0.5s infinite;
-moz-animation: changecolor 0.5s infinite;
-webkit-animation: changecolor 0.5s infinite;
-ms-animation: changecolor 0.5s infinite;
-o-animation: changecolor 0.5s infinite;
}
#keyframes changecolortask {
0% {
color: #pre-text-color;
}
100% {
color: #pre-text-color;
border: 2px solid #blink-bg;
}
}
/* Mozilla Browser */
#-moz-keyframes changecolortask {
0% {
color: #pre-text-color;
}
100% {
color: #pre-text-color;
border: 4px solid #blink-bg;
}
}
/* WebKit browser Safari and Chrome */
#-webkit-keyframes changecolortask {
0% {
color: #pre-text-color;
}
100% {
color: #pre-text-color;
border: 4px solid #blink-bg;
}
}
/* IE 9,10*/
#-ms-keyframes changecolortask {
0% {
color: #pre-text-color;
}
100% {
color: #pre-text-color;
border: 4px solid #blink-bg;
}
}
/* Opera Browser*/
#-o-keyframes changecolortask {
0% {
color: #pre-text-color;
}
100% {
color: #pre-text-color;
border: 4px solid #blink-bg;
}
}
#keyframes changecolor {
0% {
color: #pre-text-color;
background: #pre-bg;
}
100% {
color: #pre-text-color;
background: #blink-bg;
}
}
/* Mozilla Browser */
#-moz-keyframes changecolor {
0% {
color: #pre-text-color;
background: #pre-bg;
}
100% {
color: #pre-text-color;
background: #blink-bg;
}
}
/* WebKit browser Safari and Chrome */
#-webkit-keyframes changecolor {
0% {
color: #pre-text-color;
background: #pre-bg;
}
100% {
color: #pre-text-color;
background: #blink-bg;
}
}
/* IE 9,10*/
#-ms-keyframes changecolor {
0% {
color: #pre-text-color;
background: #pre-bg;
}
100% {
color: #pre-text-color;
background: #blink-bg;
}
}
/* Opera Browser*/
#-o-keyframes changecolor {
0% {
color: #pre-text-color;
background: red;
}
100% {
color: #pre-text-color;
background: #blink-bg;
}
}
Then where you want to use this in the controller, route or Component declare
blinky: null,
now we need to have an action or you need to initialize it depends on how you want to use it, let's assume you want to add this Blinky class for 3seconds while clicking on a button so we would do the following code :
actions: {
myChangeColor: function() {
this.set('blinky', 'blinkery');//set your class to property
// remove blinker after 1 sec, it must be passed to reference for 'this' so easily we can bind that.
setTimeout(function() {
this.set('blink', ' ');
}.bind(this), 3000);
}
}
Now you need to use it in template for example in my example you simply add this property in your proper line of template like :
<div class="row well {{blinky}}"> //whatever </div>
now suppose you have a button which myChangeColor action
<button type="submit" class="btn btn-success btn-block" {{action "blinky"}}>make me blinky for 3 seconds !</button>
that's it.
Depends on what you want and how you want to use this action and class you can implement it in different ways, However, the way of implementation is the same.
Note: you can also use animation.css library to have more class either you can add your Vanilla javascript code in the action.
If you want to use this in a component depends on how you want to use, you may have to work with didInsertElement() {} and willDestroyElement() {} . As an example see the following code:
let blinker;
export default Ember.Component.extend({
tagName: 'span',
blink: null,
interval: 3000,
init() {
this._super(...arguments);
this.set('blink','');
},
didInsertElement() { // when you enter route
this._super(...arguments);
blinker = setInterval(function() {
this.set('blink', 'blinky');
}.bind(this), this.get('interval'));
},
willDestroyElement() { // when you leave route
this._super(...arguments);
clearInterval(blinker);
}
});
I hope this can help you.

Related

Angular 2 material tab active color customize

I was looking to customize the active color for md-tab.
The classes in chrome dev console shows ==> -mat-tab-label mat-ripple mat-tab-label-active. But none has any border bottom. There was a chevron class which i tried to change, but no effect.
I tried /deep/ with almost all classes. Dint work.
Also checked md-tab-header, but nowhere am seeing even that color! Any help would be appreciated :)
Try to it's work for me
::ng-deep .mat-ink-bar {
background-color:#ee2925 !important;}
It's worked for me in Angular 6
.mat-tab-group.mat-primary .mat-ink-bar, .mat-tab-nav-bar.mat-primary .mat-ink-bar {
background-color: #1f29a2;
}
Works in Angular 7
.mat-tab-group.mat-primary .mat-ink-bar,.mat-tab-nav-bar.mat-primary .mat-ink-bar {
background-color: #2C702A;
}
To customize the active underline, modify this class
mat-ink-bar{ background-color:#fff; }
In your component, set ViewEncapsulation to None and add the styles in your component.css file.
Changes in Typescript code:
import {Component, ViewEncapsulation} from '#angular/core';
#Component({
....
encapsulation: ViewEncapsulation.None
})
Component CSS:
/* Styles for tab labels */
.mat-tab-label {
min-width: 25px !important;
padding: 5px;
background-color: transparent;
color: red;
font-weight: 700;
}
/* Styles for the active tab label */
.mat-tab-label.mat-tab-label-active {
min-width: 25px !important;
padding: 5px;
background-color: transparent;
color: red;
font-weight: 700;
}
/* Styles for the ink bar */
.mat-ink-bar {
background-color: green;
}
.mat-tab-group.mat-primary .mat-ink-bar, .mat-tab-nav-bar.mat-primary .mat-ink-bar{
background: black;
}
This works with Angular 10.
This solution is tested and works fine in Angular 10 -
.tabs .mat-tab-label.mat-tab-label-active {
background-color: #5e70db;
opacity: 1 !important;
}
.tabs .mat-ink-bar {
background-color: #3f51b5 !important;
}
any of those solutions didn't work for me but i did a general solution without use the encapsulation.none
/* Styles for tab labels */
::ng-deep .mat-tab-label {
min-width: 25px !important;
padding: 5px;
background-color: transparent;
color: red;
font-weight: 700;
}
/* Styles for the active tab label */
::ng-deep .mat-tab-label.mat-tab-label-active {
min-width: 25px !important;
padding: 5px;
background-color: transparent;
color: red;
font-weight: 700;
}
/* Styles for the ink bar */
::ng-deep .mat-ink-bar {
background-color: green;
}
using ::ng-deep you are telling to css inside material being overrite, then you can customice it

SharePoint Online cannot expand web part zone width

I have a blog subsite on a SharePoint Online (2013) site that by default has 3 web part zones: BlogNavigator, Left and Right (ordered from left to right).
The layout of the zones is frustrating, because the Left zone, which houses the actual content for the site, is relatively narrow considering the amount of available space to the right of the Right zone.
When I move all the Web Parts from the Right zone into BlogNavigator, the Left zone maintains its size, even though there is room to expand rightward.
I have tried manually declaring the Left zone ContainerWidth on the page file in SP Designer, I have tried applying a CSS file to the page to set the width, but nothing seems to work.
I have even removed all references to the Right zone on the page file, removing it completely, but the Left zone still remains its original width.
Is there some way I can alter this zone?
The out-of-the-box SharePoint page layouts use a peculiar grid framework to layout the different webpart zones.
This framework, which is defined in the layout css, uses display: table and display: table-cell to position the zones in the horizontal layout.
Table layouts usually result in odd sizing issues similar to how you have described.
In a project that I have worked on recently, I needed to fix the table layout to be more rigid so that there were no sizing issues. The site I was working on was a Publishing site so I am not sure if the classes are the same on you blog but here is the CSS I used to tweak the grid framework.
#DeltaPlaceHolderMain .ms-table {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-ms-flex-wrap: wrap;
flex-wrap: wrap;
margin-left: -15px;
margin-right: -15px;
width: auto; }
#DeltaPlaceHolderMain .ms-table > div[class*="tableCol"] {
-webkit-box-flex: 1;
-ms-flex: 1 0 auto;
flex: 1 0 auto;
padding-left: 15px;
padding-right: 15px;
box-sizing: border-box; }
#DeltaPlaceHolderMain .tableCol-75,
#DeltaPlaceHolderMain .tableCol-33,
#DeltaPlaceHolderMain .tableCol-25,
#DeltaPlaceHolderMain .tableCol-50 {
width: 100%;
display: block;
min-width: 0; }
#contentBox {
padding-left: 15px;
padding-right: 15px; }
#titleAreaRow {
display: table; }
#contentRow {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-ms-flex-wrap: wrap;
flex-wrap: wrap; }
#sideNavBox {
margin-right: 5px; }
#contentBox {
min-width: 0;
margin: 0;
-webkit-box-flex: 1;
-ms-flex: 1 0;
flex: 1 0; }
#s4-titlerow,
#contentRow {
max-width: 1450px;
margin: 0 auto; }
#media screen and (min-width: 1020px) {
#DeltaPlaceHolderMain .tableCol-75 {
width: 66.666%; }
#DeltaPlaceHolderMain .tableCol-33 {
width: 33.333%;
}
#DeltaPlaceHolderMain .tableCol-25 {
width: 33.333%; }
#DeltaPlaceHolderMain .tableCol-50 {
width: 50%; } }
#media screen and (min-width: 1340px) {
#DeltaPlaceHolderMain .tableCol-75 {
width: 75%; }
#DeltaPlaceHolderMain .tableCol-25 {
width: 25%; } }
* {
outline: none; }
html {
-webkit-text-size-adjust: 100%; }
/* Sidenav */
#sideNavBox {
min-width: 180px;
max-width: 300px;
width: auto; }

How can I cause a legend to appear to the right of the pie (Chart.JS)?

I'm creating a fairly simple pie chart with Chart.JS like so:
var data = {
labels: [
"Bananas (18%)",
"Lettuce, Romaine (14%)",
"Melons, Watermelon (10%)",
"Pineapple (10%)",
"Berries (10%)",
"Lettuce, Spring Mix (9%)",
"Broccoli (8%)",
"Melons, Honeydew (7%)",
"Grapes (7%)",
"Melons, Cantaloupe (7%)"
],
datasets: [
{
data: [2755, 2256, 1637, 1608, 1603, 1433, 1207, 1076, 1056, 1048],
backgroundColor: [
"#FFE135",
"#3B5323",
"#fc6c85",
"#ffec89",
"#021c3d",
"#3B5323",
"#046b00",
"#cef45a",
"#421C52",
"#FEA620"
]
}
]
};
var optionsPie = {
responsive: true,
scaleBeginAtZero: true,
tooltips: {
callbacks: {
label: function (tooltipItem, data) {
return data.labels[tooltipItem.index] + ": " +
formatter.format(data.datasets[tooltipItem.datasetIndex].data[tooltipItem.index]);
}
}
}
};
var ctx = $("#top10ItemsChart").get(0).getContext("2d");
var top10PieChart = new Chart(ctx,
{
type: 'pie',
data: data,
options: optionsPie
});
$("#top10Legend").html(top10PieChart.generateLegend());
It looks decent:
...but I want the pie on the left and the legend on the right, with the legend vertically stacked. How can I accompilish that objective?
UPDATE
I tried this:
CSS
.pieLegend li span {
display: inline-block;
width: 12px;
height: 12px;
margin-right: 5px;
}
HTML
<div id="pie_legend" class="pieLegend"></div>
...as suggested in the accepted answer here, but it makes no difference whatsoever.
UPDATE 2
Fixing the bad ID caused the new legend to display, and adding the "display: false" to the options caused the original one to disappear, but the new one still appears below the pie, crowding outside of its div and bleeding into the quadrant below it (shown hovering over bananas):
UPDATE 3
Here's how it looks with the accepted answer's code applied:
The pie is still puny, but this is much better than it was (and answers the question).
You have to turn the default legend off in the options first with:
legend: {
display: false
},
Also your id selector for your legend was wrong. Fiddle.
Wrap the chart in the <div> and set the height and width of that since the canvas will be responsive to its container, then set the canvas's div and the legend's div as display:inline-block.
HTML
<div id="kpi">
<div id="container">
<canvas id="top10ItemsChart"></canvas>
</div>
<div id="top10Legend" class="pieLegend"></div>
</div>
CSS
#kpi{
height: 400px;
width: 100%;
border: 1px solid black;
background-color: white;
}
.pieLegend li span {
display: inline-block;
width: 12px;
height: 12px;
margin-right: 5px;
}
#top10Legend {
display: inline-block;
}
#container {
display: inline-block;
height: 50%;
width: 50%;
}
#top10Legend>ul{
list-style:none;
}
Another way to right align the legend is to add:
legend: {
position:"right"
}
To the Chart options
JSfiddle

How to change parent view classname on child view load?

I need to change the parent view classname on child view load the code would be like
var ChildView = Em.View.extend({
willInsertElement : function() {
this.get('parentView').set('classnames',['ChildView']);
},
template : Em.Handlebars.compile(template)
});
Regards
Chandru.
Use classNameBindings and send the event from the child view to update the property.
Consider this example:
{{#view App.AParentView}}
{{view App.AChildView}}
{{/view}}
The app:
App = Ember.Application.create();
App.AParentView = Em.View.extend({
bgColor: 'lightgray',
classNames: ['parent-view'],
classNameBindings: 'bgColor',
updateBg: function(bg) {
this.set('bgColor', bg);
}
});
App.AChildView = Em.View.extend({
classNames: ['child-view', 'blue'],
willInsertElement: function() {
this.get('parentView').send('updateBg', 'green');
}
});
The CSS to see it actually working:
html, body {
margin: 20px;
}
.parent-view {
padding: 4rem;
}
.child-view {
padding: 2rem;
}
.lightgray {
background-color: lightgray;
color: black;
}
.blue {
background-color: blue;
}
.green {
background-color: green;
}
See the jsbin here.

How to center-align svg-based Google Charts (since they have position: absolute)

Does anybody please have an idea how to center-align the new (i.e. svg-based) Google Charts?
When I inspect the chart elements at my web page (please scroll down to the jQuery Tabs with several Google Charts at that page), I see that the chart itself is given an absolute position:
<div style="position: absolute; left: 0px; top: 0px; width: 100%; height: 100%; ">
<svg width="800" height="500" style="overflow: hidden; ">
I'm not sure why Google does it, but it breaks my layout (other than that the charts work well for me):
My CSS-code:
h1,h2,h3,p,div,form {
text-align: center;
}
And I've also tried adding there:
margin-left: auto;
margin-right: auto;
My JavaScript-code:
var money_data;
var money_chart;
var money_options = {
width: 800,
height: 500,
legend: {position: 'top'},
areaOpacity: 1.0,
vAxis: {format: '# $'},
hAxis: {title: 'Номер недели', titleTextStyle: {color: 'blue'}, slantedText: true, viewWindow: {min: 39, max: 52}},
colors: ['CCFFCC', '66CC66', 'FF9999'],
animation: {duration: 1000, easing: 'out'}
};
function initMoney() {
$.ajax({
url: '/money-json.php',
data: { id: 'OK408547485023' },
dataType: 'json'
}).done(function(jsonData) {
money_data = new google.visualization.DataTable(jsonData);
money_chart = new google.visualization.SteppedAreaChart(document.getElementById('money_chart'));
google.visualization.events.addListener(money_chart, 'ready', function() {
$('#money_slider').slider('enable');
});
drawMoney();
});
}
function drawMoney() {
money_chart.draw(money_data, money_options);
}
If no CSS-based solution possible here, could I maybe use JavaScript to move the SVG to the same x-position as the money_slider while enabling the latter (please see the above code)?
You could set the size of money_chart DIV to the size of the graph ( I am guessing 800px ) and use auto margins like this.
#money_chart{
margin-left: auto;
margin-right: auto;
width: 800px;
}
You will need to make the chart side another div here is my code and it works for me
.chart_outside{
position:relative;
display: inline;
border: 2px solid #FFF;
width: 500px;
height: 460px;
background: #000;
margin: 5px 5px 5px 5px;
}
.chart_inside{
position:absolute;
right:0px
;top:0px;
}