21
21
22
22
var modulemapper = require ( 'cordova/modulemapper' ) ;
23
23
24
-
25
24
var origOpenFunc = modulemapper . getOriginalSymbol ( window , 'window.open' ) ;
26
25
26
+ function _empty ( ) { }
27
27
28
- function _empty ( ) { }
29
-
30
-
31
- function modal ( message , callback , title , buttonLabels , domObjects ) {
28
+ function modal ( message , callback , title , buttonLabels , domObjects ) {
32
29
var mainWindow = window ;
33
30
var modalWindow = origOpenFunc ( ) ;
34
31
var modalDocument = modalWindow . document ;
@@ -61,78 +58,78 @@ function modal(message, callback, title, buttonLabels, domObjects) {
61
58
box . appendChild ( menu ) ;
62
59
for ( var index = 0 ; index < buttonLabels . length ; index ++ ) {
63
60
// TODO: last button listens to the cancel key
64
- addButton ( buttonLabels [ index ] , ( index + 1 ) , ( index === 0 ) ) ;
61
+ addButton ( buttonLabels [ index ] , ( index + 1 ) , ( index === 0 ) ) ;
65
62
}
66
63
modalDocument . body . appendChild ( box ) ;
67
64
68
- function addButton ( label , index , recommended ) {
65
+ function addButton ( label , index , recommended ) {
69
66
var thisButtonCallback = makeCallbackButton ( index + 1 ) ;
70
67
var button = modalDocument . createElement ( 'button' ) ;
71
68
button . appendChild ( modalDocument . createTextNode ( label ) ) ;
72
69
button . addEventListener ( 'click' , thisButtonCallback , false ) ;
73
70
if ( recommended ) {
74
71
// TODO: default one listens to Enter key
75
- button . classList . add ( 'recommend' ) ;
72
+ button . classList . add ( 'recommend' ) ;
76
73
}
77
74
menu . appendChild ( button ) ;
78
75
}
79
76
80
77
// TODO: onUnload listens to the cancel key
81
- function onUnload ( ) {
78
+ function onUnload ( ) {
82
79
var result = 0 ;
83
80
if ( modalDocument . getElementById ( 'prompt-input' ) ) {
84
81
result = {
85
82
input1 : '' ,
86
83
buttonIndex : 0
87
84
} ;
88
85
}
89
- mainWindow . setTimeout ( function ( ) {
86
+ mainWindow . setTimeout ( function ( ) {
90
87
callback ( result ) ;
91
88
} , 10 ) ;
92
89
}
93
90
modalWindow . addEventListener ( 'unload' , onUnload , false ) ;
94
91
95
92
// call callback and destroy modal
96
- function makeCallbackButton ( labelIndex ) {
97
- return function ( ) {
98
- if ( modalWindow ) {
99
- modalWindow . removeEventListener ( 'unload' , onUnload , false ) ;
100
- modalWindow . close ( ) ;
101
- }
93
+ function makeCallbackButton ( labelIndex ) {
94
+ return function ( ) {
95
+ if ( modalWindow ) {
96
+ modalWindow . removeEventListener ( 'unload' , onUnload , false ) ;
97
+ modalWindow . close ( ) ;
98
+ }
102
99
// checking if prompt
103
- var promptInput = modalDocument . getElementById ( 'prompt-input' ) ;
104
- var response ;
105
- if ( promptInput ) {
106
- response = {
107
- input1 : promptInput . value ,
108
- buttonIndex : labelIndex
109
- } ;
110
- }
111
- response = response || labelIndex ;
112
- callback ( response ) ;
100
+ var promptInput = modalDocument . getElementById ( 'prompt-input' ) ;
101
+ var response ;
102
+ if ( promptInput ) {
103
+ response = {
104
+ input1 : promptInput . value ,
105
+ buttonIndex : labelIndex
106
+ } ;
107
+ }
108
+ response = response || labelIndex ;
109
+ callback ( response ) ;
113
110
} ;
114
111
}
115
112
}
116
113
117
114
var Notification = {
118
- vibrate : function ( milliseconds ) {
115
+ vibrate : function ( milliseconds ) {
119
116
navigator . vibrate ( milliseconds ) ;
120
117
} ,
121
- alert : function ( successCallback , errorCallback , args ) {
118
+ alert : function ( successCallback , errorCallback , args ) {
122
119
var message = args [ 0 ] ;
123
120
var title = args [ 1 ] ;
124
121
var _buttonLabels = [ args [ 2 ] ] ;
125
122
var _callback = ( successCallback || _empty ) ;
126
123
modal ( message , _callback , title , _buttonLabels ) ;
127
124
} ,
128
- confirm : function ( successCallback , errorCallback , args ) {
125
+ confirm : function ( successCallback , errorCallback , args ) {
129
126
var message = args [ 0 ] ;
130
127
var title = args [ 1 ] ;
131
128
var buttonLabels = args [ 2 ] ;
132
129
var _callback = ( successCallback || _empty ) ;
133
130
modal ( message , _callback , title , buttonLabels ) ;
134
131
} ,
135
- prompt : function ( successCallback , errorCallback , args ) {
132
+ prompt : function ( successCallback , errorCallback , args ) {
136
133
var message = args [ 0 ] ;
137
134
var title = args [ 1 ] ;
138
135
var buttonLabels = args [ 2 ] ;
@@ -150,6 +147,5 @@ var Notification = {
150
147
}
151
148
} ;
152
149
153
-
154
150
module . exports = Notification ;
155
151
require ( 'cordova/exec/proxy' ) . add ( 'Notification' , Notification ) ;
0 commit comments