Intel XDK HTML5 + Cordova Adjust Brightness - html

I'm having trouble adjusting the brightness in Intel XDK HTML5 + Cordova. I have imported a phonegap/cordova plugin # https://github.com/fiscal-cliff/phonegap-plugin-brightness but it still will not do anything.
Any advice would be greatly apperciated!
Here is my code:
<script src="intelxdk.js"></script>
<script src="cordova.js"></script>
<script src="xhr.js"></script>
<script src="xdk/init-dev.js"></script>
<script type="application/javascript" src="lib/jquery.min.js"></script>
<script type="application/javascript" src="jqm/jquery.mobile-min.js" data-ver="0"></script>
<script type="application/javascript" src="js/app.js"></script>
<script type="application/javascript" src="js/init-app.js"></script>
<link rel="stylesheet" media="screen" type="text/css" href="css/colorpicker.css">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
<script type="text/javascript" src="js/colorpicker.js"></script>
<script type="text/javascript" src="js/eye.js"></script>
<script type="text/javascript" src="js/utils.js"></script>
<script type="text/javascript" src="js/layout.js?ver=1.0.2"></script>
<script type="application/javascript" src="sidebar/js/hammer.js"></script>
<script type="application/javascript" src="sidebar/js/jquery.hammer.js"></script>
<script type="application/javascript" src="sidebar/js/swipe-hammer.js"></script>
<script type="application/javascript" src="sidebar/js/sidebar.js"></script>
<script type="application/javascript" src="js/index_user_scripts.js"></script>
<script type="application/javascript" src="xdk/ad/jqm_subpage.js"></script>
<script type="application/javascript">
document.addEventListener('deviceready', onDeviceReady);
function onDeviceReady() {
window.brightness = cordova.require("cordova.plugin.Brightness.Brightness");
}
function setBrightness(value) {
brightness.setBrightness(value, win, fail);
alert(value);
}
function getBrightness() {
brightness.getBrightness( win, fail);
alert(brightness.getBrightness( win, fail));
}
function win(status) {
alert('Message: ' + status);
}
function fail(status) {
alert('Error: ' + status);
}
getBrightness();
</script>
<div class="upage-outer">
<div class="upage-content" id="page_54_58">
<a class="widget uib_w_4 d-margins settings-button" data-uib="jquery_mobile/button" data-ver="0" data-role="button" data-icon="gear" data-iconpos="notext" id="settings_button">Settings Button</a>
</div>
<div class="inner-element uib_w_3 uib_sidebar leftbar bar-bg thumb-bg bar-gutter" data-uib="layout/left_sidebar" data-ver="1" data-anim="{'style':'overlap', 'v':200, 'side':'left', 'dur':200}">
<div class="sidebar-content content-area vertical-col">
<div class="widget uib_w_1 no_wrap no_swipe-x with-label d-margins brightness" data-uib="jquery_mobile/slider" data-ver="0">
<label class="narrow-control label-inline"><i class="fa fa-adjust font-icons"> </i>
</label>
<div class="wide-control">
<input type="range" value="50" min="0" max="100" step="1" name="brightness" style="display:none;" onchange="setBrightness(this.value)" data-highlight="true">
</div>
</div>
<div class="table-thing with-label widget uib_w_2 d-margins screencolor" data-uib="jquery_mobile/input" data-ver="0">
<label class="narrow-control"><i class="fa fa-eyedropper font-icons"> Screen Color</i>
</label>
<input class="wide-control" type="hidden" name="screencolor" id="screencolor">
<p id="colorpickerHolder"></p>
</div>
</div>
</div>
</div>
</div>
<div class="upage vertical-col left" id="settings" data-role="page">
<div class="upage-outer">
<div class="upage-content content-area vertical-col left" id="page_69_80">
</div>
</div>
</div>

You are calling getBrightness(); before the device ready event fires. At this point the cordova plugins might not be loaded. Also, you are referencing the brightness on the window variable that is set up during the deviceready event.
The quick fix is to move your getBrightness() call up into the onDeviceReady() function.
function onDeviceReady() {
window.brightness = cordova.require("cordova.plugin.Brightness.Brightness");
getBrightness();
}
Now we are calling the method after cordova has setup the plugins. Another approach you could take is wrapping each plugin call in a deviceready handler, or scoping your functions to a function called on device ready.

Related

Confused about Jquery load

May someone tell me why does the content of q.txt not get loaded to the div with the class name "content". q.txt is a local file
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$(".content").load("q.txt");
});
</script>
<div id="content">
<div class="content">
<h2>aaaa</h2>
</div>
</div>

inline SVG but in a separate file?

I'd like to store SVG code in a separate file so I can clean up the main code.
I'm using this script in the <head>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"
integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4="
crossorigin="anonymous">
</script>
<script>
$(function(){
$("icon").load("icon.xml");
});
</script>
and I'm calling the file like this:
<div class="logo">
<div id="icon"></div>
</div>
but nothing appears. This method is working for me for referencing as a separate html for nav links. Does this method not support other file types?
Due to typos, the SVG cannot be displayed. Here is the fix:
<script src="https://code.jquery.com/jquery-3.6.0.min.js"
integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4="
crossorigin="anonymous"></script>
<script>
$(function(){
$("#icon").load("icon.xml");
});
</script>
<div class="logo">
<div id="icon"></div>
</div>

Date Format in a text box, it is not appearing upon clicking

Upon clicking on the text box, which is supposed to be showing a date picker for me to choose the date, but it is not showing at all, I wanted it to be shown upon clicking on it.
<div class="row">
<div class='col-sm-6'>
<input type='text' class="form-control" id='datetimepicker4' />
</div>
<script type="text/javascript">
$(function () {
$('#datetimepicker4').datetimepicker();
});
</script>
</div>
It seems that you haven't used script links for JQuery and/or datetimepicker.
You can try this:
$(function() {
$('#datetimepicker4').datetimepicker();
});
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/css/bootstrap-datetimepicker.min.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.6/moment.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/js/bootstrap-datetimepicker.min.js"></script>
<div class="container">
<div class="row">
<div class="col-sm-6">
<input type='text' class="form-control" id='datetimepicker4' />
</div>
</div>
</div>
As we discussed remove the script tag completely from HTML window, and remove tag except the actual JS from JS window.
Your Code pen's code should look like this:

Bootstrap timepicker not appearing

I have the following piece of code in my front end. I couldn't get the timepicker to show up. Any help please?
<!DOCTYPE HTML>
<html>
<head>
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-timepicker/0.5.2/js/bootstrap-timepicker.js"></script>
<link type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-timepicker/0.5.2/css/bootstrap-timepicker.min.css" />
<script type="text/javascript">
$(() => {
$('#timepicker1').timepicker();
});
</script>
</head>
<body>
<div class="input-group bootstrap-timepicker timepicker">
<input id="timepicker1" type="text" class="form-control input-small">
<span class="input-group-addon"><i class="glyphicon glyphicon-time"></i></span>
</div>
</body>
<html>
I have all the required source files in my the correct path as mentioned in the code above. Also, I am not seeing any errors in the browser logs. Please help me fix this.
Thank you all
EDIT: I have now used the direct cdn links for all the source files as provided in jsfiddle.
To use the time picker on bootstrap. You must use the datetimepicker component. And use the format property to allow only hours and minutes to be captured
<!DOCTYPE HTML>
<html>
<head>
<link href="bootstrap-3.3.7/css/bootstrap.css" rel="stylesheet">
<link href="bootstrap-3.3.7/css/bootstrap-datetimepicker.min.css" rel="stylesheet">
<script src="bootstrap-3.3.7/js/jquery-1.11.3.min.js"></script>
<script src="bootstrap-3.3.7/js/moment.js"></script>
<script src="bootstrap-3.3.7/js/bootstrap.js"></script>
<script src="bootstrap-3.3.7/js/bootstrap-datetimepicker.min.js"</script>
<script src="bootstrap-3.3.7/js/transition.js"></script>
<script src="bootstrap-3.3.7/js/collapse.js"></script>
</head>
<body>
<div class="input-group bootstrap-timepicker timepicker">
<input id="timepicker1" type="text" class="form-control input-small">
<span class="input-group-addon"><i class="glyphicon glyphicon-time"></i></span>
</div>
<script type="text/javascript">
$(function () {
$('#timepicker1').datetimepicker({
format: 'HH:mm'
});
});
</script>
</body>
<html>
rel="stylesheet" was missing in one of the css tags. That was the issue.

beforeActivate not firing jeasyui

I've read through many of these questions and they are answered the same. I've tried it but can't get it to work. I've gotten the code very small. What am I doing wrong? The tabs work fine, but no event getting fired.
<html>
<head>
<link rel="stylesheet" type="text/css" href="http://www.jeasyui.com/easyui/themes/default/easyui.css">
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
<script type="text/javascript" src="http://www.jeasyui.com/easyui/jquery.easyui.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#tabs').tabs({
beforeActivate: function(event,ui) {
alert("Tabs Changed");
}
});
});
</script>
</head>
<body>
<div class="easyui-tabs" id="tabs">
<div Title="Home" >
Home
</div>
<div Title="Admin">
Admin
</div>
</div>
</body>
</html>
thanks,
dave