/** * gollum.dialog.js * * Used for dialogs. Duh. * */ (function($) { var Dialog = { debugOn: false, markupCreated: false, markup: '', attachEvents: function( evtOK ) { $('#gollum-dialog-action-ok').click(function( e ) { Dialog.eventOK( e, evtOK ); }); $('#gollum-dialog-action-cancel').click( Dialog.eventCancel ); $('#gollum-dialog-dialog input[type="text"]').keydown(function( e ) { if ( e.keyCode == 13 ) { Dialog.eventOK( e, evtOK ); } }); }, detachEvents: function() { $('#gollum-dialog-action-ok').unbind('click'); $('#gollum-dialog-action-cancel').unbind('click'); }, createFieldMarkup: function( fieldArray ) { var fieldMarkup = '
'; return fieldMarkup; }, createFieldText: function( fieldAttributes ) { var html = ''; if ( fieldAttributes.name ) { html += ''; } html += ''; } if( fieldAttributes.context ){ html += '' + fieldAttributes.context + ''; } return html; }, createMarkup: function( title, body ) { Dialog.markupCreated = true; if ($.facebox) { return '' + argObject.body + '
'; } // alright, build out fields if ( argObject.fields && typeof argObject.fields == 'object' ) { body += Dialog.createFieldMarkup( argObject.fields ); } if ( argObject.title && typeof argObject.title == 'string' ) { title = argObject.title; } if ( Dialog.markupCreated ) { if ($.facebox) { $(document).trigger('close.facebox'); } else { $('#gollum-dialog-dialog').remove(); } } Dialog.markup = Dialog.createMarkup( title, body ); if ($.facebox) { $(document).bind('reveal.facebox', function() { if ( argObject.OK && typeof argObject.OK == 'function' ) { Dialog.attachEvents( argObject.OK ); $($('#facebox input[type="text"]').get(0)).focus(); } }); } else { $('body').append( Dialog.markup ); if ( argObject.OK && typeof argObject.OK == 'function' ) { Dialog.attachEvents( argObject.OK ); } } Dialog.show(); }, show: function() { if ( !Dialog.markupCreated ) { debug('Dialog: No markup to show. Please use init first.'); } else { debug('Showing dialog'); if ($.facebox) { $.facebox( Dialog.markup ); } else { if ( $.browser.msie ) { $('#gollum-dialog.dialog').addClass('active'); Dialog.position(); $('select').css('visibility', 'hidden'); } else { $('#gollum-dialog.dialog').css('display', 'none'); $('#gollum-dialog-dialog').animate({ opacity: 0 }, { duration: 0, complete: function() { $('#gollum-dialog-dialog').css('display', 'block'); Dialog.position(); // position this thing $('#gollum-dialog-dialog').animate({ opacity: 1 }, { duration: 500 }); $($('#gollum-dialog-dialog input[type="text"]').get(0)).focus(); } }); } } } }, position: function() { var dialogHeight = $('#gollum-dialog-dialog-inner').height(); $('#gollum-dialog-dialog-inner') .css('height', dialogHeight + 'px') .css('margin-top', -1 * parseInt( dialogHeight / 2 )); } }; if ($.facebox) { $(document).bind('reveal.facebox', function() { $('#facebox img.close_image').remove(); }); } var debug = function(m) { if ( Dialog.debugOn && typeof console != 'undefined' ) { console.log( m ); } }; $.GollumDialog = Dialog; })(jQuery);