Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load actual colors #2

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
145 changes: 145 additions & 0 deletions config.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@

<!DOCTYPE html>
<html>
<head>
<title>Configurable</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.css" />
<script src="https://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="https://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js"></script>
</head>
<body>
<div data-role="page" id="main">
<div data-role="header" class="jqm-header">
<h1>Configuration</h1>
</div>

<div data-role="content">

<div data-role="fieldcontain">
<label for="color_select">Word Color:</label>
<select name="color_select" id="color_select" data-role="text-box">
<option value="1">Light Blue</option>
<option value="2">Dark Blue</option>
<option value="3">Oxford Blue</option>
<option value="4">White</option>
<option value="5">Light Gray</option>
<option value="6">Black</option>
<option value="7">Yellow</option>
<option value="8">Orange</option>
<option value="9">Light Red</option>
<option value="10">Dark Red</option>
<option value="11">Bright Green</option>
<option value="12">Light Green</option>
<option value="13">Dark Green</option>
<option value="14">Vivid Violet</option>
<option value="15">Light Purple</option>
<option value="16">Dark Purple</option>

</select>
</div>

<div data-role="fieldcontain">
<label for="color2_select">Numbers Color:</label>
<select name="color2_select" id="color2_select" data-role="text-box">
<option value="1">Light Blue</option>
<option value="2">Dark Blue</option>
<option value="3">Oxford Blue</option>
<option value="4">White</option>
<option value="5">Light Gray</option>
<option value="6">Black</option>
<option value="7">Yellow</option>
<option value="8">Orange</option>
<option value="9">Light Red</option>
<option value="10">Dark Red</option>
<option value="11">Bright Green</option>
<option value="12">Light Green</option>
<option value="13">Dark Green</option>
<option value="14">Vivid Violet</option>
<option value="15">Light Purple</option>
<option value="16">Dark Purple</option>
</select>
</div>


<div data-role="fieldcontain">
<label for="color1_select">Background Color:</label>
<select name="color1_select" id="color1_select" data-role="text-box">
<option value="1">Light Blue</option>
<option value="2">Dark Blue</option>
<option value="3">Oxford Blue</option>
<option value="4">White</option>
<option value="5">Light Gray</option>
<option value="6">Black</option>
<option value="7">Yellow</option>
<option value="8">Orange</option>
<option value="9">Light Red</option>
<option value="10">Dark Red</option>
<option value="11">Bright Green</option>
<option value="12">Light Green</option>
<option value="13">Dark Green</option>
<option value="14">Vivid Violet</option>
<option value="15">Light Purple</option>
<option value="16">Dark Purple</option>
</select>
</div>

</div>

<div class="ui-body ui-body-b">
<fieldset class="ui-grid-a">
<div class="ui-block-a"><button type="submit" data-theme="d" id="b-cancel">Cancel</button></div>
<div class="ui-block-b"><button type="submit" data-theme="a" id="b-submit">Submit</button></div>
</fieldset>
</div>
</div>
</div>
</div>
<script>
function selectElement(select, variable) {
var color = getURLVariable(variable);
$(select).val(color);
$(select).selectmenu('refresh', true);
}

function getURLVariable(name) {
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS = "[\\?&]"+name+"=([^&#]*)",
regex = new RegExp(regexS),
results = regex.exec(window.location.href);
if (results == null) return "";
else return results[1];
}

function saveOptions() {
var options = {
'color': $("#color_select").val(),'color1': $("#color1_select").val(),'color2': $("#color2_select").val(),
}
return options;
}

$(function() {
// select options from request variables
selectElement("#color_select", "color");
selectElement("#color1_select", "color1");
selectElement("#color2_select", "color2");

$("#b-cancel").click(function() {
console.log("Cancel");
document.location = "pebblejs://close";
});

$("#b-submit").click(function() {
console.log("Submit");

var location = "pebblejs://close#" + encodeURIComponent(JSON.stringify(saveOptions()));
console.log("Warping to: " + location);
console.log(location);
document.location = location;
});

});
</script>
</body>
</html>
19 changes: 16 additions & 3 deletions src/pebble-js-app.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
var url = 'https://rawgit.com/chrira/BlueFuturistic/load-actual-colors/config.html';

Pebble.addEventListener("ready",
function(e) {
console.log("PebbleKit JS ready!");
Expand All @@ -6,8 +8,14 @@ Pebble.addEventListener("ready",

Pebble.addEventListener("showConfiguration",
function(e) {
//Load the remote config page
Pebble.openURL("http://paliantech.com/pebble/BFconfig3G.html");
// load color configuration from local storage
var color = localStorage.getItem('KEY_COLOR');
var color1 = localStorage.getItem('KEY_COLORS');
var color2 = localStorage.getItem('KEY_COLOR1');
console.log("Got colors from local storage: KEY_COLOR: " + color + ", KEY_COLORS: " + color1 + ", KEY_COLOR1: " + color2);

//Load the remote config page and give color variables to select actual options
Pebble.openURL(url + "?color=" + color + "&color1=" + color1 + "&color2=" + color2);
}
);

Expand All @@ -17,6 +25,11 @@ Pebble.addEventListener("webviewclosed",
var configuration = JSON.parse(decodeURIComponent(e.response));
console.log("Configuration window returned: " + JSON.stringify(configuration));

// save color configuration to local storage
localStorage.setItem('KEY_COLOR', configuration.color);
localStorage.setItem('KEY_COLORS', configuration.color1);
localStorage.setItem('KEY_COLOR1', configuration.color2);

//Send to Pebble, persist there
Pebble.sendAppMessage(
{"KEY_COLOR": configuration.color , "KEY_COLORS": configuration.color1, "KEY_COLOR1": configuration.color2},
Expand All @@ -28,4 +41,4 @@ Pebble.addEventListener("webviewclosed",
}
);
}
);
);