2121
2222var modulemapper = require ( 'cordova/modulemapper' ) ;
2323
24-
2524var origOpenFunc = modulemapper . getOriginalSymbol ( window , 'window.open' ) ;
2625
26+ function _empty ( ) { }
2727
28- function _empty ( ) { }
29-
30-
31- function modal ( message , callback , title , buttonLabels , domObjects ) {
28+ function modal ( message , callback , title , buttonLabels , domObjects ) {
3229 var mainWindow = window ;
3330 var modalWindow = origOpenFunc ( ) ;
3431 var modalDocument = modalWindow . document ;
@@ -61,78 +58,78 @@ function modal(message, callback, title, buttonLabels, domObjects) {
6158 box . appendChild ( menu ) ;
6259 for ( var index = 0 ; index < buttonLabels . length ; index ++ ) {
6360 // TODO: last button listens to the cancel key
64- addButton ( buttonLabels [ index ] , ( index + 1 ) , ( index === 0 ) ) ;
61+ addButton ( buttonLabels [ index ] , ( index + 1 ) , ( index === 0 ) ) ;
6562 }
6663 modalDocument . body . appendChild ( box ) ;
6764
68- function addButton ( label , index , recommended ) {
65+ function addButton ( label , index , recommended ) {
6966 var thisButtonCallback = makeCallbackButton ( index + 1 ) ;
7067 var button = modalDocument . createElement ( 'button' ) ;
7168 button . appendChild ( modalDocument . createTextNode ( label ) ) ;
7269 button . addEventListener ( 'click' , thisButtonCallback , false ) ;
7370 if ( recommended ) {
7471 // TODO: default one listens to Enter key
75- button . classList . add ( 'recommend' ) ;
72+ button . classList . add ( 'recommend' ) ;
7673 }
7774 menu . appendChild ( button ) ;
7875 }
7976
8077 // TODO: onUnload listens to the cancel key
81- function onUnload ( ) {
78+ function onUnload ( ) {
8279 var result = 0 ;
8380 if ( modalDocument . getElementById ( 'prompt-input' ) ) {
8481 result = {
8582 input1 : '' ,
8683 buttonIndex : 0
8784 } ;
8885 }
89- mainWindow . setTimeout ( function ( ) {
86+ mainWindow . setTimeout ( function ( ) {
9087 callback ( result ) ;
9188 } , 10 ) ;
9289 }
9390 modalWindow . addEventListener ( 'unload' , onUnload , false ) ;
9491
9592 // 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+ }
10299 // 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 ) ;
113110 } ;
114111 }
115112}
116113
117114var Notification = {
118- vibrate : function ( milliseconds ) {
115+ vibrate : function ( milliseconds ) {
119116 navigator . vibrate ( milliseconds ) ;
120117 } ,
121- alert : function ( successCallback , errorCallback , args ) {
118+ alert : function ( successCallback , errorCallback , args ) {
122119 var message = args [ 0 ] ;
123120 var title = args [ 1 ] ;
124121 var _buttonLabels = [ args [ 2 ] ] ;
125122 var _callback = ( successCallback || _empty ) ;
126123 modal ( message , _callback , title , _buttonLabels ) ;
127124 } ,
128- confirm : function ( successCallback , errorCallback , args ) {
125+ confirm : function ( successCallback , errorCallback , args ) {
129126 var message = args [ 0 ] ;
130127 var title = args [ 1 ] ;
131128 var buttonLabels = args [ 2 ] ;
132129 var _callback = ( successCallback || _empty ) ;
133130 modal ( message , _callback , title , buttonLabels ) ;
134131 } ,
135- prompt : function ( successCallback , errorCallback , args ) {
132+ prompt : function ( successCallback , errorCallback , args ) {
136133 var message = args [ 0 ] ;
137134 var title = args [ 1 ] ;
138135 var buttonLabels = args [ 2 ] ;
@@ -150,6 +147,5 @@ var Notification = {
150147 }
151148} ;
152149
153-
154150module . exports = Notification ;
155151require ( 'cordova/exec/proxy' ) . add ( 'Notification' , Notification ) ;
0 commit comments