07.10.2016, 13:58 (This post was last modified: 07.10.2016, 13:58 by buuuudzik.)
(13.06.2016, 09:18)Erwin van der Zwart Wrote:
(13.06.2016, 09:02)admin Wrote: You can also replace [0].innerHTML with jQuery's .html()
Thanks Admin,
The code will be like this then:
Here is the final sample for changing color with css based on setpoint and actual value difference.
Give the first setpoint these additional classes 'Setp Setp_1', the 2nd 'Setp Setp_2', the 3th 'Setp Setp_3' etc
Give the first actual these additional classes 'Temp Temp_1', the 2nd 'Temp Temp_2', the 3th 'Temp Temp_3' etc
So all setpoints will have 2 additional classes (Setp and Setp_nr) and all actuals will have 2 additional classes (Temp and Temp_nr)
Make sure to use incredimental sequense 1,2,3,4,5 etc. without gaps as Temp_nr and Setp_nr (the number makes the match between both)
Put this code in your custom JavaScript:
Code:
$(function(){
// Set color values
var defaultcolor = $('.Temp').css("color") // Use color that is default set on the object
var highcolor = 'rgb(0, 153, 204)' // Blue
var lowcolor = 'rgb(204, 153, 0)' // Orange
// Function to change colors on values
function CheckSetpointandValue(){
// Check if and how many elements there are with additional class 'Temp'
if ($(".Temp").length > 0){
// Set number of items to loop through based on additional class 'Temp' items
var TempValueItems = $(".Temp").length // Determine number of compare items
// Set difference between actual and setpoint to change color
var MinimalDifference = 0.5 // Determine minnimal difference between setpoint and actual temperature
// Loop to items to set CSS
for (i = 1; (i-1) < TempValueItems; i++) {
// Set conditions for Setp_nr and Temp_nr
if ( Number( $(".Temp_" + i).html() ) > ( Number( $(".Setp_" + i).html() ) + MinimalDifference ) ){
$(".Temp_" + i).css("color", highcolor);
} else if ( ( Number( $(".Temp_" + i).html() ) + MinimalDifference ) < Number( $(".Setp_" + i).html() ) ){
$(".Temp_" + i).css("color", lowcolor);
} else {
$(".Temp_" + i).css("color", defaultcolor);
}
}
}
}
// Check for changes on value of item with Temp
$('.Temp').bind("DOMSubtreeModified",function(){
CheckSetpointandValue();
});
// Check for changes on value of item with Setp
$('.Setp').bind("DOMSubtreeModified",function(){
CheckSetpointandValue();
});
// Initial execution
CheckSetpointandValue();
});
BR,
Erwin
When temperature or setpoint is in the Objects with some unit e.g. '°C' there must be additional lines for delete this unit from the text.
This could be in this way:
Code:
// Loop to items to set CSS
for (i = 1; (i-1) < TempValueItems; i++) {
// Set conditions for Setp_nr and Temp_nr
temperature = ( $(".Temp_" + i).html() ).slice(0, -2);
setpoint = ( $(".Setp_" + i).html() ).slice(0, -2);
if ( temperature > ( setpoint + MinimalDifference ) ){
$(".Temp_" + i).css("color", highcolor);
} else if ( ( temperature + MinimalDifference ) < setpoint ){
$(".Temp_" + i).css("color", lowcolor);
07.10.2016, 19:41 (This post was last modified: 07.10.2016, 20:24 by buuuudzik.)
(07.10.2016, 17:38)admin Wrote: Try replacing Number(...) calls with parseFloat(...). Then it won't matter whether you have units/suffix set or not.
It works good So this is ready. I've checked also the possibility of using one pair (Temp_1 and Setp_1) in a few places, when you have actual temperature presented in a few places. You must add to every 2, 3, 4 etc. actual temp only 'Temp_x' and it works.
Only it not work on iPhone 5s and iPad Air2 when temperature is on the widget. On PC it working also on the widget. Do you know what could be the reason?
08.10.2016, 17:58 (This post was last modified: 08.10.2016, 22:51 by Erwin van der Zwart.)
Hi,
Here is a update: Use this script:
Code:
$(function(){
$('iframe').load(function() {
var iframeInnerElement = $('iframe').contents().find('#bloktext').get(0);
iframeInnerElement.innerHTML = "Erwin van der Zwart";
});
});
Your <p> element where the text actualy is has no id. Make sure you have set it like this:
#blok > p {
position:absolute;
margin:0;
white-space:nowrap;
animation:przesun 20s linear infinite;
-webkit-animation:przesun 20s linear infinite; /* dla Google Chrome, Safari, Opera 15+ */
}
09.10.2016, 06:36 (This post was last modified: 09.10.2016, 06:54 by buuuudzik.)
Yes, it works! You're the best. Maybe do you have some idea how to change css and interval of this page.
I've tried:
Code:
$(function(){
var black = 'rgb(0, 0, 0)' // Black
$('iframe').load(function() {
// Changing text
var iframeInnerElement = $('iframe').contents().find('#bloktext').get(0);
iframeInnerElement.innerHTML = "Erwin van der Zwart";
// Changing interval
iframeInnerElement.css('animation', przesun 4s linear infinite);
iframeInnerElement.css('-webkit-animation', przesun 4s linear infinite);
// Changing background color
var iframeInnerElement = $('iframe').contents().find('#blok').get(0);
iframeInnerElement.css('background-color', black);
});
});
When I've tried run lines for "Changing interval" the console show:
"identifier starts immediately after numeric literal"
When I've tried run lines for "Changing background color" the console show:
"iframeInnerElement.css is not a function"
Task: change which plan is shown when plan link is clicked depending on object value. For example, there are 2 plans for climate control, winter mode has heating controls, summer mode has air conditioning.
1. Create two plans: named Winter mode and Summer mode
2. Create a boolean object 1/1/1 (for which we assume that true = winter, false = summer)
3. Create a plan link element and add summer-winter to Additional classes. Plan link location does not matter
4. Add this to custom JavaScript (edit config variables as needed if plan names or object address is different):
Code:
$(function() {
// make sure we're in visualization mode
if (typeof grp === 'undefined') {
return;
}
// find plan id by plan name
function findPlanByName(name) {
var id = -1;
$.each(planStore, function(pid, plan) {
if (plan.name == name) {
id = pid;
}
});
return id;
};
// listen to changes on summer/winter object
grp.listen(toggleObject, function(obj) {
var id = findPlanByName(obj.value ? winterPlanName : summerPlanName)
, el = $(planLinkClass);
// remove old click handler
el.off('vclick');
// assign new handler
el.on('vclick', function() {
showPlan(id);
});
});
});
(07.10.2016, 17:38)admin Wrote: Try replacing Number(...) calls with parseFloat(...). Then it won't matter whether you have units/suffix set or not.
It works good So this is ready. I've checked also the possibility of using one pair (Temp_1 and Setp_1) in a few places, when you have actual temperature presented in a few places. You must add to every 2, 3, 4 etc. actual temp only 'Temp_x' and it works.
Only it not work on iPhone 5s and iPad Air2 when temperature is on the widget. On PC it working also on the widget. Do you know what could be the reason?
Do somebody know what could be the reason that on Apple devices on widget temperature is not colored but when I open the same page on the PC browser(Mozilla and also Safari) temperatures on a widget are colored?
Probably some bug in iOS where DOMSubtreeModified event is not called on hidden elements. You can try refreshing the status every second and see if it works in iOS:
10.10.2016, 13:41 (This post was last modified: 10.10.2016, 19:30 by buuuudzik.)
I've tried but unfortunately on iPhone 5s still there is no color but on PC is perfect.
I've tried to change the fill color and height of rectangle in SVG which is in <object>. This is the solution.
Code:
$(function(){
$('object').load(function() {
var svg = $('object')[0]; // Choosing svg
var svgDoc = svg.contentDocument; // Choosing content from svg
var svgItem = svgDoc.getElementById("rect4136"); // Choosing rectangle from content
svgItem.setAttribute('height', '50'); // Changing attributes e.g. height
svgItem.style.fill='black'; // Changing style e.g. fill color
});
});
I hope that it would be helpful for somebody in the future
11.10.2016, 09:59 (This post was last modified: 04.03.2018, 21:45 by buuuudzik.)
Here is some svg image and custom script which can be used for learning manipulating svg images by custom javascript. I used Inkscape for editing svg image(e.g. adding new elements).
1. Copy to "Custom javascript":
Code:
// Manipulating SVG images
$(function(){
$('.blind1 > object').load(function() {
var svg = $('.blind1 > object')[0]; // Choosing svg
var svgDoc = svg.contentDocument; // Choosing content from svg
var svgItem = svgDoc.getElementById("rect4136"); // Choosing blind from content
var svgItem1 = svgDoc.getElementById("g4136"); // Choosing window from content
var svgItem2 = svgDoc.getElementById("rect4154-4"); // Choosing light from content
position_plus = '32/1/15'; // Position
grp.listen(position_plus, function(obj, type) {
if (type == 'init') return false;
let height = Number( svgItem.getAttribute("height") ) + 10;
console.log('plus, nowa: ', height)
if (height >= 100) svgItem.setAttribute('height', '100');
else if (height < 100) svgItem.setAttribute('height', height);
// onclick blind-up
svgItem.addEventListener('click', function (event) {
}, false);
svgItem.addEventListener('click', function (event) {
svgItem.setAttribute('height', '0')
}, true);
// onclick blind-down
svgItem1.addEventListener('click', function (event) {
}, false);
svgItem1.addEventListener('click', function (event) {
svgItem.setAttribute('height', '100');
}, true);
});
});
2. Upload 'interactive.svg' to /Images/Backgrounds'.
3. Add it as local image on some plan and add to this image Additional class 'blind1'.
4. You can also add some buttons which change +/-10% height.
Currently they should be created in this way:
For +10%: '6/0/54' which send 0 and 1
For -10%: '6/0/53' which send 0 and 1