summaryrefslogtreecommitdiff
path: root/StoneIsland/plugins/cordova-plugin-dialogs/src/windows/NotificationProxy.js
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2016-11-08 12:37:03 -0500
committerJules Laplace <jules@okfoc.us>2016-11-08 12:37:03 -0500
commitef4f212fc1482136dba1e690ec589b315b4a377f (patch)
tree0b7e16d72567fafcfd3e08d7c5c591ad07a63458 /StoneIsland/plugins/cordova-plugin-dialogs/src/windows/NotificationProxy.js
parent5fa81da81260d65113f57a293b6256d334fe8e2d (diff)
build 0.7.0
Diffstat (limited to 'StoneIsland/plugins/cordova-plugin-dialogs/src/windows/NotificationProxy.js')
-rw-r--r--[-rwxr-xr-x]StoneIsland/plugins/cordova-plugin-dialogs/src/windows/NotificationProxy.js92
1 files changed, 52 insertions, 40 deletions
diff --git a/StoneIsland/plugins/cordova-plugin-dialogs/src/windows/NotificationProxy.js b/StoneIsland/plugins/cordova-plugin-dialogs/src/windows/NotificationProxy.js
index d1eb3448..2d32f836 100755..100644
--- a/StoneIsland/plugins/cordova-plugin-dialogs/src/windows/NotificationProxy.js
+++ b/StoneIsland/plugins/cordova-plugin-dialogs/src/windows/NotificationProxy.js
@@ -17,17 +17,36 @@
* specific language governing permissions and limitations
* under the License.
*
-*/
+ */
-/*global Windows:true */
+/*global Windows:true, WinJS, toStaticHTML */
var cordova = require('cordova');
+var urlutil = require('cordova/urlutil');
var isAlertShowing = false;
var alertStack = [];
+function createCSSElem(fileName) {
+ var elemId = fileName.substr(0, fileName.lastIndexOf(".")) + "-plugin-style";
+ // If the CSS element exists, don't recreate it.
+ if (document.getElementById(elemId)) {
+ return false;
+ }
+
+ // Create CSS and append it to DOM.
+ var $elem = document.createElement('link');
+ $elem.id = elemId;
+ $elem.rel = "stylesheet";
+ $elem.type = "text/css";
+ $elem.href = urlutil.makeAbsolute("/www/css/" + fileName);
+
+ document.head.appendChild($elem);
+ return true;
+}
+
// CB-8928: When toStaticHTML is undefined, prompt fails to run
-function _cleanHtml(html) { return html; }
+var _cleanHtml = function(html) { return html; };
if (typeof toStaticHTML !== 'undefined') {
_cleanHtml = toStaticHTML;
}
@@ -36,66 +55,53 @@ if (typeof toStaticHTML !== 'undefined') {
// simple html-based implementation until it is available
function createPromptDialog(title, message, buttons, defaultText, callback) {
- var isPhone = cordova.platformId == "windows" && WinJS.Utilities.isPhone;;
+ var isPhone = cordova.platformId === "windows" && WinJS.Utilities.isPhone;
+ var isWindows = !!cordova.platformId.match(/windows/);
+
+ createCSSElem("notification.css");
var dlgWrap = document.createElement("div");
- dlgWrap.style.position = "absolute";
- dlgWrap.style.width = "100%";
- dlgWrap.style.height = "100%";
- dlgWrap.style.backgroundColor = "rgba(0,0,0,0.25)";
- dlgWrap.style.zIndex = "100000";
+ dlgWrap.className = "dlgWrap";
var dlg = document.createElement("div");
- dlg.style.width = "100%";
- dlg.style.minHeight = "180px";
- dlg.style.height = "auto";
- dlg.style.overflow = "auto";
- dlg.style.backgroundColor = "white";
- dlg.style.position = "relative";
- dlg.style.lineHeight = "2";
+ dlg.className = "dlgContainer";
- if (isPhone) {
- dlg.style.padding = "0px 5%";
- } else {
- dlg.style.top = "50%"; // center vertically
- dlg.style.transform = "translateY(-50%)";
- dlg.style.padding = "0px 30%";
+ if (isWindows) {
+ dlg.className += " dlgContainer-windows";
+ } else if (isPhone) {
+ dlg.className += " dlgContainer-phone";
}
+
// dialog layout template
- dlg.innerHTML = _cleanHtml("<span id='lbl-title' style='font-size: 24pt'></span><br/>" // title
- + "<span id='lbl-message'></span><br/>" // message
- + "<input id='prompt-input' style='width: 100%'/><br/>"); // input fields
+ dlg.innerHTML = _cleanHtml("<span id='lbl-title'></span><br/>" + // title
+ "<span id='lbl-message'></span><br/>" + // message
+ "<input id='prompt-input'/><br/>"); // input fields
dlg.querySelector('#lbl-title').appendChild(document.createTextNode(title));
dlg.querySelector('#lbl-message').appendChild(document.createTextNode(message));
dlg.querySelector('#prompt-input').setAttribute('placeholder', defaultText);
+ dlg.querySelector('#prompt-input').setAttribute('value', defaultText);
function makeButtonCallback(idx) {
return function () {
- var value = promptInput = dlg.querySelector('#prompt-input').value;
+ var value = dlg.querySelector('#prompt-input').value || defaultText;
dlgWrap.parentNode.removeChild(dlgWrap);
if (callback) {
callback({ input1: value, buttonIndex: idx });
}
- }
+ };
}
function addButton(idx, label) {
var button = document.createElement('button');
- button.style.margin = "8px 0 8px 16px";
- button.style.float = "right";
- button.style.fontSize = "12pt";
+ button.className = "dlgButton";
button.tabIndex = idx;
button.onclick = makeButtonCallback(idx + 1);
- if (idx == 0) {
- button.style.color = "white";
- button.style.backgroundColor = "#464646";
- } else {
- button.style.backgroundColor = "#cccccc";
+ if (idx === 0) {
+ button.className += " dlgButtonFirst";
}
- button.style.border = "none";
button.appendChild(document.createTextNode(label));
dlg.appendChild(button);
}
@@ -109,7 +115,7 @@ function createPromptDialog(title, message, buttons, defaultText, callback) {
document.body.appendChild(dlgWrap);
// make sure input field is under focus
- dlg.querySelector('#prompt-input').focus();
+ dlg.querySelector('#prompt-input').select();
return dlgWrap;
}
@@ -134,7 +140,9 @@ module.exports = {
md.commands.append(new Windows.UI.Popups.UICommand(_buttonLabel));
md.showAsync().then(function() {
isAlertShowing = false;
- win && win();
+ if (win) {
+ win();
+ }
if (alertStack.length) {
setTimeout(alertStack.shift(), 0);
@@ -204,7 +212,9 @@ module.exports = {
md.showAsync().then(function(res) {
isAlertShowing = false;
var result = res ? buttons.indexOf(res.label) + 1 : 0;
- win && win(result);
+ if (win) {
+ win(result);
+ }
if (alertStack.length) {
setTimeout(alertStack.shift(), 0);
}
@@ -236,7 +246,9 @@ module.exports = {
} else {
snd.removeEventListener("ended", onEvent);
snd = null;
- winX && winX(); // notification.js just sends null, but this is future friendly
+ if (winX) {
+ winX(); // notification.js just sends null, but this is future friendly
+ }
}
count--;
};