2 * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 // TODO: remove when added to public cordova repository -> begin
18 var plugin_name = 'cordova-plugin-dialogs.tizen.Notification';
20 cordova.define(plugin_name, function(require, exports, module) {
21 // TODO: remove -> end
23 var _document = document || {};
25 var playback = (function() {
28 var soundPathArray = ['/usr/share/feedback/sound/operation/operation.wav', '/usr/share/feedback/sound/operation/home.wav', '/usr/share/feedback/sound/operation/back.wav'];
29 var soundPathCount = 0;
32 console.log('Success to get the notification sound: ' + v);
33 soundElement = new Audio(v);
34 soundElement.addEventListener('ended', function() {
42 console.error('Failed to get the notification sound: ' + e);
45 function recursiveFailCallback(e) {
47 console.warn("Retry with another path");
49 if(soundPathCount >= soundPathArray.length){
50 console.error('Failed to get the notification sound: There is no available sound file path');
54 tizen.filesystem.resolve(soundPathArray[soundPathCount++], function(file) {
56 }, recursiveFailCallback, 'r');
60 if ('tv' === tizen.systeminfo.getCapability('http://tizen.org/feature/profile').toLowerCase()) {
61 tizen.filesystem.resolve(soundPathArray[soundPathCount++], function(file) {
63 }, recursiveFailCallback, 'r');
65 tizen.systemsetting.getProperty('NOTIFICATION_EMAIL', win, fail);
68 function beep(times) {
80 var popup = (function () {
81 var boxId = 'cordova-modal-box';
82 var overlayId = 'cordova-modal-overlay';
83 var popupId = 'cordova-modal-popup';
84 var buttonIdPrefix = 'cordova-modal-popup-button-';
85 var inputId = 'cordova-modal-popup-input';
92 var tizenHwKeyListener = null;
94 function isPopupVisible() {
96 return box.style.display === 'block';
102 function tizenHwKeyFunc(evt) {
103 if (evt.keyName === "back") {
104 evt.stopImmediatePropagation();
105 if (dismissCallback) {
111 function showPopup() {
112 box.style.display = 'block';
115 function hidePopup() {
116 box.style.display = 'none';
119 function createCloseCallback(callback, id, prompt) {
123 text = d.getElementById(inputId).value;
126 if (tizenHwKeyListener) {
127 window.removeEventListener('tizenhwkey', tizenHwKeyListener, true);
128 tizenHwKeyListener = null;
136 function hasCssClass(name) {
137 for (var i = 0; i < d.styleSheets.length; ++i) {
138 for (var j = 0; j < d.styleSheets[i].rules.length; ++j) {
139 if (name === d.styleSheets[i].rules[j].selectorText) {
147 function createStyleSheet() {
149 var style = document.createElement('style');
150 d.head.appendChild(style);
156 var hasOverlay = hasCssClass('.cordova-ui-popupwindow-overlay');
157 var hasPopup = hasCssClass('.cordova-ui-popupwindow');
162 sheet.insertRule('.cordova-ui-popupwindow-overlay {' +
163 'background: #000000;' +
179 sheet.insertRule('.cordova-ui-popupwindow {' +
183 'margin-right: -50%;' +
184 'transform: translate(-50%, -50%);' +
185 '-webkit-transform: translate(-50%, -50%);' +
186 'z-index: 1201 !important;' +
188 'background: #2a2d30;' +
192 sheet.insertRule('.cordova-ui-popupwindow .popup-title {' +
195 'font-size: 1.0909090909090908rem;' +
196 'background: #5093b6;' +
198 sheet.insertRule('.cordova-ui-popupwindow .popup-title p {' +
199 'margin: 0rem 0rem;' +
200 'padding: 0.5909090909090909rem 0.5rem;' +
202 sheet.insertRule('.cordova-ui-popupwindow .popup-text {' +
205 'font-size: 1.0909090909090908rem;' +
206 'background: #2a2d30;' +
208 sheet.insertRule('.cordova-ui-popupwindow .popup-text p {' +
209 'text-align: left;' +
212 sheet.insertRule('.cordova-ui-popupwindow .popup-input {' +
214 'padding-bottom: 0.4rem;' +
215 'text-align: center;' +
217 sheet.insertRule('.cordova-ui-popupwindow .popup-input input {' +
221 'line-height: 1.2;' +
222 'font-weight: normal;' +
223 'border: 1px solid #555;' +
224 'border-radius: 5px;' +
225 '-webkit-border-radius: 5px;' +
227 sheet.insertRule('.cordova-ui-popupwindow .popup-button-bg {' +
228 'font-size: 1.4545454545454546rem;' +
229 'background: #2a2d30;' +
231 'padding-top: 0.5rem;' +
232 'padding-bottom: 0.5rem;' +
233 'vertical-align: middle;' +
234 'text-align: right;' +
236 sheet.insertRule('.cordova-ui-popupwindow .popup-button-bg input {' +
237 'border: 1px solid #555;' +
238 'border-radius: 5px;' +
239 '-webkit-border-radius: 5px;' +
240 'text-align: center;' +
241 'display: inline-block;' +
242 'background: #444;' +
244 'font-size: 0.8em;' +
245 'text-decoration: none;' +
246 'margin: 1px 1px 1px 3px;' +
251 function initHtml() {
252 var touchMoveDisable = function(e) {
253 e.preventDefault(); // disable the touch-move of the background
256 box = d.createElement('div');
259 overlay = box.appendChild(d.createElement('div'));
260 overlay.id = overlayId;
261 overlay.className = 'cordova-ui-popupwindow-overlay';
262 overlay.addEventListener('click', function() {
263 if (dismissCallback) {
267 overlay.addEventListener('touchmove', touchMoveDisable);
269 popup = box.appendChild(d.createElement('div'));
271 popup.className = 'cordova-ui-popupwindow';
272 popup.addEventListener('touchmove', touchMoveDisable);
276 d.getElementsByTagName('body')[0].appendChild(box);
286 function show(options) {
287 if (isPopupVisible()) {
288 console.warn('Popup is already shown, ignoring.');
294 options = options || {};
296 // prepare contents of the popup
298 html += '<div class="popup-title"><p>' + (options.title || 'Title') + '</p></div>';
299 html += '<div class="popup-text"><p>' + (options.message || 'Message') + '</p></div>';
300 if (options.prompt) {
301 html += '<div class="popup-input"><input id="' + inputId + '" type="text" value="' + options.promptDefaultText + '" /></div>';
303 var buttons = options.buttons || ['Button'];
304 html += '<div class="popup-button-bg">';
305 for (var i = 0; i < buttons.length; ++i) {
306 html += '<input id="' + buttonIdPrefix + (i + 1)
307 + '" type="button" value="' + buttons[i] + '" />';
311 popup.innerHTML = html;
314 var callback = options.callback || function(){};
315 dismissCallback = createCloseCallback(callback, 0, options.prompt);
317 for (var i = 0; i < buttons.length; ++i) {
318 var e = d.getElementById(buttonIdPrefix + (i + 1));
319 e.addEventListener('click', createCloseCallback(callback, i + 1, options.prompt), false);
322 if (!tizenHwKeyListener) {
323 tizenHwKeyListener = tizenHwKeyFunc;
324 window.addEventListener('tizenhwkey', tizenHwKeyListener, true);
337 alert: function(successCallback, errorCallback, args) {
340 callback: successCallback,
345 confirm: function(successCallback, errorCallback, args) {
348 callback: successCallback,
353 prompt: function(successCallback, errorCallback, args) {
356 callback: function(idx, text) {
357 successCallback({buttonIndex: idx, input1: text});
362 promptDefaultText: args[3]
365 beep: function(successCallback, errorCallback, args) {
366 playback.beep(args[0]);
370 require("cordova/exec/proxy").add("Notification", exports);
372 console.log('Loaded cordova.dialog API');
374 // TODO: remove when added to public cordova repository -> begin
376 // TODO: remove -> end