source: other-projects/nz-flag-design/trunk/design-2d/Original editor.method.ac/method-draw/src/dialog.js@ 29468

Last change on this file since 29468 was 29468, checked in by sjs49, 9 years ago

Initial commit for editor.method.ac for flag design

  • Property svn:executable set to *
File size: 1.7 KB
Line 
1// This sets up alternative dialog boxes. They mostly work the same way as
2// their UI counterparts, expect instead of returning the result, a callback
3// needs to be included that returns the result as its first parameter.
4// In the future we may want to add additional types of dialog boxes, since
5// they should be easy to handle this way.
6
7(function() {
8 $('#dialog_container').draggable({cancel:'#dialog_content, #dialog_buttons *', containment: 'window'});
9 var box = $('#dialog_box'), btn_holder = $('#dialog_buttons');
10
11 var dbox = function(type, msg, callback, defText) {
12 $('#dialog_content').html('<p>'+msg.replace(/\n/g,'</p><p>')+'</p>')
13 .toggleClass('prompt',(type=='prompt'));
14 btn_holder.empty();
15
16 var ok = $('<input type="button" value="' + uiStrings.common.ok + '">').appendTo(btn_holder);
17
18 if(type != 'alert') {
19 $('<input type="button" value="' + uiStrings.common.cancel + '">')
20 .appendTo(btn_holder)
21 .on("click touchstart", function() { box.hide();callback(false)});
22 }
23
24 if(type == 'prompt') {
25 var input = $('<input type="text">').prependTo(btn_holder);
26 input.val(defText || '');
27 input.bind('keydown', 'return', function() {ok.trigger("click touchstart");});
28 }
29
30 if(type == 'process') {
31 ok.hide();
32 }
33
34 box.show();
35
36 ok.on("click touchstart", function() {
37 box.hide();
38 var resp = (type == 'prompt')?input.val():true;
39 if(callback) callback(resp);
40 }).focus();
41
42 if(type == 'prompt') input.focus();
43 }
44
45 $.alert = function(msg, cb) { dbox('alert', msg, cb);};
46 $.confirm = function(msg, cb) { dbox('confirm', msg, cb);};
47 $.process_cancel = function(msg, cb) { dbox('process', msg, cb);};
48 $.prompt = function(msg, txt, cb) { dbox('prompt', msg, cb, txt);};
49}());
Note: See TracBrowser for help on using the repository browser.