06.10.2016, 10:04
Is it possible to do the moving text with the last alerts which appeared in the last 5 minutes and its timestamp?
Custom JavaScript examples
|
06.10.2016, 10:04
Is it possible to do the moving text with the last alerts which appeared in the last 5 minutes and its timestamp?
(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() 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: 123456789101112131415161718 // 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);
} else {
$(".Temp_" + i).css("color", defaultcolor);
}
}
}
}
07.10.2016, 17:38
Try replacing Number(...) calls with parseFloat(...). Then it won't matter whether you have units/suffix set or not.
(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 ![]() 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, 16:35
Does anybody know how can I find and edit via custom javascript text which is in the page which is in the iframe?
I've tried: document.getElementById("iframe1").contentWindow.document.getElementById("text") but it not works ![]()
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: 12345678 $(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: Code: 123 <div id="blok">
<p id="bloktext">tekst</p>
</div>Now you can do whatever with the element (: BR, Erwin
I've added the additional class to the iframe: ''komunikat1".
My iframe has following structure: Code: 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 -- Create HTML content
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Darmowy Kurs CSS</title>
<style>
#blok {
position:relative;
width:660px;
height:80px;
line-height:80px;
margin:0 auto;
<!-- border:3px solid #DDD;
border-color: #787878;
border-radius: 10px; -->
font-family:sans-serif;
font-size:50px;
font-weight:bold;
color: white;
background-color:]] .. color .. [[;
overflow:hidden;
}
#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+ */
}
#blok > p:hover {
animation-play-state:paused;
-webkit-animation-play-state:paused;
}
/* ------------ANIMACJA-PRZESUN------------ */
@keyframes przesun
{
0% { transform:translateX(0); padding-left:110%; }
100% { transform:translateX(-100%); padding-left:110%; }
}
@-webkit-keyframes przesun /* dla Google Chrome, Safari, Opera 15+ */
{
0% { -webkit-transform:translateX(0); padding-left:110%; }
100% { -webkit-transform:translateX(-100%); padding-left:110%; }
}
</style>
</head>
<body>
<div id="blok">
<p>tekst</p>
</div>
</body>
</html>]]But unfortunately console in Mozilla show: "myiframe is undefined" I've also tried run this function after the document is ready Code: 1234567 $(function(){
$( document ).ready(function() {
var myiframe = document.getElementsByClassName("komunikat1")[0];
var myiframeelement = myiframe.contentWindow.document.getElementById('blok')
console.log(myiframeelement)
});
});but unfortunately the result is the same. I've tried but I have this(something but probably not exactly "blok"):
08.10.2016, 22:48
(This post was last modified: 09.10.2016, 05:18 by Erwin van der Zwart.)
Hi Buuuudzik,
The problem is that the iframe is not fully loaded when grabbing the element. I changed the code to solve this. See previous post, i have updated the article (; BR, Erwin van der Zwart
Yes, it works!
![]() I've tried: Code: 12345678910111213141516171819 $(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"
09.10.2016, 07:39
(This post was last modified: 09.10.2016, 07:46 by Erwin van der Zwart.)
Hi Buuuudzik,
Change your css with Jquery like this: Code: 123456789 // Change text opacity
$(iframeInnerElement).css('opacity', '0.2');
// Change text color
$(iframeInnerElement).css('color', 'rgb(0, 0, 0)');
// Change duration
var textspeed = 4;
$(iframeInnerElement).css('animationDuration', textspeed + 's');BR, Erwin van der Zwart
It works
![]() ![]()
09.10.2016, 15:42
Hi Buuudzik,
To be honest, i can't do anything with LM, but i can do magic with homeLYnk and spaceLYnk (: BR, Erwin van der Zwart
09.10.2016, 17:44
What kind of javascript function you are using for sleep function like os.sleep() in LUA?
10.10.2016, 09:21
(This post was last modified: 10.10.2016, 09:21 by Erwin van der Zwart.)
Hi Buuuudzik,
Try this: Code: 123456789 // Sleep time expects milliseconds
function sleep (time) {
return new Promise((resolve) => setTimeout(resolve, time));
}
// Usage:
sleep(500).then(() => {
// Do something after the sleep
});BR, Erwin
10.10.2016, 09:24
Use built-in setTimeout, just keep in mind that it's async, so it will not further block execution unlike Lua os.sleep.
Code: 123 setTimeout(function() {
console.log('hello')
}, 1000); // time in in milliseconds
10.10.2016, 09:32
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: 12345678910111213141516171819202122232425262728293031323334353637 $(function() {
// make sure we're in visualization mode
if (typeof grp === 'undefined') {
return;
}
// config
var winterPlanName = 'Winter mode'
, summerPlanName = 'Summer mode'
, toggleObject = '1/1/1' // true = winter, false = summer
, planLinkClass = '.summer-winter';
// 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);
});
});
});
10.10.2016, 13:17
(07.10.2016, 19:41)buuuudzik Wrote:(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. 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?
10.10.2016, 13:34
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:
Code: 123 // Initial execution
CheckSetpointandValue();
setInterval(CheckSetpointandValue, 1000);
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: 1234567891011121314 $(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 ![]()
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: 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 // 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);
if (height > 50) {
svgItem.style.fill='black';
svgItem2.style.opacity= '0';
} else {
svgItem.style.fill='red';
svgItem2.style.opacity= '80';
};
}, true);
position_minus = '32/1/16';
grp.listen(position_minus, function(obj, type) {
if (type == 'init') return false;
let height = Number( svgItem.getAttribute("height") ) - 10;
console.log('minus, nowa: ', height)
if (height <= 0) svgItem.setAttribute('height', '0');
else if (height > 0) svgItem.setAttribute('height', height);
if (height > 50) {
svgItem.style.fill='black';
svgItem2.style.opacity= '0';
} else {
svgItem.style.fill='red';
svgItem2.style.opacity= '80';
};
}, true);
// 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 5. Try manipulating this svg ![]() |
« Next Oldest | Next Newest »
|