The problem can be solved using additional technique like narrative js
http://www.neilmix.com/narrativejs/doc/ (or its successor strands
http://www.xucia.com/strands-doc/index.html)
my function for File Chooser dialog (using NJS) follows:
function chooseFile(options)
{
var filename = null;
var notifier = new EventNotifier();
var defaults =
{
dir : getCurrentDir(),
title : 'Select file',
selectButtonText : 'Save',
callback : function() {},
//test : function() {return true;},
manual: false
};
// set default values
options = $.extend(defaults, options);
// get files
var files = enumerateDirectory(options.dir, options.test);
// prepare dialog html
var html = '<div class="dialog filechooser" id="dialog" title="' +
options.title + '">';
if (options.manual)
html += 'File name: <input type="text" name="val" id="val"
/><br /
>';
else
html += '<input type="hidden" name="val" id="val" />';
html += '<ul class="options">';
for (var i = 0; i < files.length; ++i)
html += '<li><a href="#">' + files[i] + '</a></li>';
html += '</ul>';
html += '</div>';
// callback to handle dialog closing
var cb_close = function()
{
var d = $('#dialog');
filename = null;
if (d)
{
if (d.attr('_submitted'))
filename = d.find('#val').attr('value');
d.dialog('destroy').remove();
}
notifier();
}
// buttons callbacks
var cb_save = function(dialog)
{
if (!$('#dialog #val').attr('value'))
return true;
$('#dialog').attr('_submitted', 'true');
$('#dialog').dialog('close');
return false;
}
var cb_cancel = function(dialog)
{
$('#dialog a').removeClass('selected');
$('#dialog #val').attr('value', '');
$('#dialog').dialog('close');
return false;
}
var buttons = {
'Cancel': cb_cancel
};
buttons[options.selectButtonText] = cb_save;
// create dialog
$(html).dialog({modal: true, close: cb_close, buttons: buttons,
width: 400, height: 400, autoOpen: false});
// set anchors clicks
$('#dialog ul li a').click( function(){
$('#dialog #val').attr('value', $(this).text());
$('#dialog a').removeClass('selected');
$(this).addClass('selected');
return false;
});
// show dialog
$('#dialog').dialog('open');
notifier.wait->();
return filename;
}
The function should be called from the NJS code like
var file = chooseFile->(options)
and both files should either be included using NJS compiler (slow) or
pre-compiled for production development. see docs for details
the slow and easy inclusion is
<!-- Narrative JS library -->
<script src="js/njs/njs_compile.js" type="text/javascript">//
TODO:
implement building system with njs pre-compiling</script>
<script type="text/javascript">NjsCompiler.load("js/
filechooser.njs");</script>
<script type="text/javascript">NjsCompiler.load("js/
menu_actions.njs");</script>
The last file here uses the filechooser
Gene
On Dec 16 2008, 11:16 pm, Carl Von Stetten <[email protected]>
wrote:
> I'm trying to replace the standard browser confirm() function with a
> custom one based on ui.dialog. Here is the function:
>
> function confirm(msg) {
> var response = false;
> // Create the confirm dialog box and open it
> $("#confirm_dialog")
> .html('<p>'+msg+'</p>')
> .dialog({
> modal: true,
> title: "Confirmation Required",
> closeOnEscape: false,
> open: function() {
>
> $(document).unbind('keydown.dialog-overlay');
> },
> buttons: {
> "OK": function() {
> $(this).dialog("close");
> $(this).dialog("destroy");
> response=true;
> },
> "Cancel": function() {
> $(this).dialog("close");
> $(this).dialog("destroy");
> response=false;
> }
> }
> });
> return response;
>
> }
>
> As you can see, the intent is that if the OK button is clicked, the
> function returns true, and if Cancel is clicked, the function returns
> false. However, this is not working. The value of response is not
> being changed by the ui.dialog buttons callbacks. What am I doing
> wrong?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"jQuery UI" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/jquery-ui?hl=en
-~----------~----~----~----~------~----~------~--~---