Index: modules/block/block.admin.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/block/block.admin.inc,v retrieving revision 1.11 diff -u -r1.11 block.admin.inc --- modules/block/block.admin.inc 14 Nov 2007 09:49:30 -0000 1.11 +++ modules/block/block.admin.inc 18 Nov 2007 20:53:29 -0000 @@ -74,7 +74,7 @@ if ($throttle) { $form[$key]['throttle'] = array('#type' => 'checkbox', '#default_value' => isset($block['throttle']) ? $block['throttle'] : FALSE); } - $form[$key]['configure'] = array('#value' => l(t('configure'), 'admin/build/block/configure/'. $block['module'] .'/'. $block['delta'])); + $form[$key]['configure'] = array('#value' => l(t('configure'), 'admin/build/block/configure/'. $block['module'] .'/'. $block['delta'], array( 'popup' => true ))); if ($block['module'] == 'block') { $form[$key]['delete'] = array('#value' => l(t('delete'), 'admin/build/block/delete/'. $block['delta'])); } Index: modules/block/block.js =================================================================== RCS file: /cvs/drupal/drupal/modules/block/block.js,v retrieving revision 1.1 diff -u -r1.1 block.js --- modules/block/block.js 14 Nov 2007 09:49:30 -0000 1.1 +++ modules/block/block.js 18 Nov 2007 20:53:29 -0000 @@ -17,6 +17,7 @@ // A custom message for the blocks page specifically. Drupal.theme.tableDragChangedWarning = function () { + Drupal.markPageUnsaved(); //add warning popup to all links return '
' + Drupal.theme('tableDragChangedMarker') + ' ' + Drupal.t("The changes to these blocks will not be saved until the Save blocks button is clicked.") + '
'; }; Index: misc/drupal.js =================================================================== RCS file: /cvs/drupal/drupal/misc/drupal.js,v retrieving revision 1.40 diff -u -r1.40 drupal.js --- misc/drupal.js 5 Oct 2007 09:35:08 -0000 1.40 +++ misc/drupal.js 18 Nov 2007 20:53:28 -0000 @@ -273,3 +273,15 @@ return '' + Drupal.checkPlain(str) + ''; } }; + +/* + * Called when there is unsaved data on the page + * Warn users when the click links that they could lose their changes + */ +Drupal.markPageUnsaved = function() { +// console.log( "Marking page unsaved" ); + dialog = new Drupal.dialog(); + $('a[href!=#]').addClass('unsaved-warning'); + $('a[href!=#]').click( function(){ return dialog.open_unsaved(this); } ); +}; + Index: includes/common.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/common.inc,v retrieving revision 1.715 diff -u -r1.715 common.inc --- includes/common.inc 16 Nov 2007 15:35:24 -0000 1.715 +++ includes/common.inc 18 Nov 2007 20:53:28 -0000 @@ -1411,6 +1411,12 @@ $options['attributes']['title'] = strip_tags($options['attributes']['title']); } + if( isset($options['popup']) ) { + drupal_add_js('misc/dialogs.js'); + $options['attributes']['popup'] = $options['popup']; + } + + return ''. ($options['html'] ? $text : check_plain($text)) .''; } Index: modules/system/system.css =================================================================== RCS file: /cvs/drupal/drupal/modules/system/system.css,v retrieving revision 1.40 diff -u -r1.40 system.css --- modules/system/system.css 16 Nov 2007 13:16:50 -0000 1.40 +++ modules/system/system.css 18 Nov 2007 20:53:29 -0000 @@ -537,3 +537,58 @@ span.password-confirm span { font-weight: normal; } + +/* +** Popup Dialog box styles +*/ + +#dialog-overlay { + position: fixed; + width: 100%; + height: 100%; +/* opacity: 0.4; */ + background: black; + z-index: 9; +} + +#dialog-overlay .loading { + background: black url(../../misc/loading.gif) no-repeat; +} + +#dialog { + border: 1px solid black; + background: white; + position: absolute; + opacity: 1.0; + z-index: 10; + color: black; + padding: 0.5em; +} + +#dialog-title { + background: #222; + color: white; + padding: 0.2em; + margin: 0.2em; +} + +#dialog-title div.title { + float:left; +} + +#dialog-title #dialog-close { + float:right; +} +#dialog-title #dialog-close a { + color: red; +} +#dialog-title div.clear { + clear:both; +} + +#dialog input { + margin: 0.1em; +} + + + Index: modules/system/system.module =================================================================== RCS file: /cvs/drupal/drupal/modules/system/system.module,v retrieving revision 1.551 diff -u -r1.551 system.module --- modules/system/system.module 11 Nov 2007 08:48:22 -0000 1.551 +++ modules/system/system.module 18 Nov 2007 20:53:31 -0000 @@ -451,10 +451,40 @@ 'access callback' => TRUE, 'type' => MENU_CALLBACK, 'file' => 'system.admin.inc', - ); + ); + + // Used for dialog popups + $items['admin/get-path'] = array( + 'page callback' => 'admin_get', + 'access arguments' => array('access administration pages'), + 'type' => MENU_CALLBACK, + ); + return $items; } + +/* + * Return the content of a path as html, without the page's theming wrapper + * Used by dialogs.js for a popup with the content of a link + */ +function admin_get() { + global $base_url; + $path = $_GET['path']; + $path = substr( $path, strlen($base_url) + 1 ); + $content = menu_execute_active_handler( $path ); + $output = '
'. drupal_get_title() .'
'; + + if( $content == MENU_NOT_FOUND ) { + $output .= "Path not found: $path"; + } + else { + $output .= $content; + } + print $output; +} + + function system_init() { // Use the administrative theme if the user is looking at a page in the admin/* path. if (arg(0) == 'admin' || (variable_get('node_admin_theme', '0') && arg(0) == 'node' && (arg(1) == 'add' || arg(2) == 'edit'))) { @@ -1698,3 +1728,6 @@ $image = theme('image', $image_path, t('Powered by Drupal, an open source content management system'), t('Powered by Drupal, an open source content management system')); return l($image, 'http://drupal.org', array('html' => TRUE, 'absolute' => TRUE, 'external' => TRUE)); } + + + Index: misc/dialogs.js =================================================================== RCS file: misc/dialogs.js diff -N misc/dialogs.js --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ misc/dialogs.js 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,143 @@ +// $Id $ + +console = {}; +console.log = function() {}; + + +Drupal.behaviors.dialog = function(context) { + dialog = new Drupal.dialog(); + $('a[popup]', context).click( function(){ return dialog.open_path(this, 800); } ); +}; + +Drupal.dialog = function() { + this.dialog_width = 480; +}; + + +Drupal.dialog.prototype.add_overlay = function() { + var overlay = $('
'); + overlay.css( 'opacity', '0.4' ); // for ie + $('body').prepend( overlay ); + return overlay; +}; + +Drupal.dialog.prototype.open = function( title, body, buttons, width, overlay ) { + if( width ) + this.dialog_width = width; + + if( !overlay ) { + overlay = this.add_overlay(); + } + + // center on the screen, add in offsets if the window has been scrolled + var left = ( overlay.width() / 2 ) - ( this.dialog_width / 2 ) + f_scrollLeft(); + var top = 20 + f_scrollTop(); + + + var dialog = '
'; + dialog += '
'+ + '
' + title +'
'+ + ' '+ + '
'+ + '
'; + dialog += '
' + body +'
'; + dialog += '
'; + + for ( id in buttons) { + button = buttons[id]; + dialog += ''; + } + + dialog += '
'; // end buttons + dialog += '
'; // close dialog + overlay.before( dialog ); + + // Adding button functions + for ( id in buttons) { + func = buttons[id].func; + $('#'+id).click( func ); + } + $('#dialog-close').click( this.close ); + return false; +}; + + +Drupal.dialog.prototype.open_unsaved = function( a ) { + body = Drupal.t("There are unsaved changes on this page. If you click away from this page, you will lose those changes."); + buttons = { + 'dialog_save': { title: Drupal.t('Save Changes'), func: function(){$('#edit-submit').click()} }, + 'dialog_submit': { title: Drupal.t('Discard Changes and Continue'), func: function(){window.location = a.href} }, + 'dialog_cancel': { title: Drupal.t('Cancel'), func: this.close } + }; + + this.open( "Warning - Please Confirm", body, buttons ); + return false; +}; + +Drupal.dialog.prototype.open_path = function( a, width, height ) { + if( $(a).is('.unsaved-warning') ) { + return false; // don't do popup on unsaved-warning links + } + var url = a.href; + var popup = this; + // let the user know something is happening + $('body').css("cursor", "wait"); + var overlay = this.add_overlay(); + + // loaded the link's path into the dialog, instead going to new page + $.get("http://localhost/d6/admin/get?path="+url, function(data) { + title = $(data).eq(0).html(); + body = $(data).slice(1).html(); + popup.open( title, body, null, 600, overlay ); + $('body').css("cursor", "auto"); + }); + return false; +} + +Drupal.dialog.prototype.close = function() { + $('#dialog').remove(); + $('#dialog-overlay').remove(); +}; + +/** + * + * Utility functions taken from http://www.softcomplex.com/docs/get_window_size_and_scrollbar_position.html + * + */ + +function f_clientWidth() { + return f_filterResults ( + window.innerWidth ? window.innerWidth : 0, + document.documentElement ? document.documentElement.clientWidth : 0, + document.body ? document.body.clientWidth : 0 + ); +} +function f_clientHeight() { + return f_filterResults ( + window.innerHeight ? window.innerHeight : 0, + document.documentElement ? document.documentElement.clientHeight : 0, + document.body ? document.body.clientHeight : 0 + ); +} +function f_scrollLeft() { + return f_filterResults ( + window.pageXOffset ? window.pageXOffset : 0, + document.documentElement ? document.documentElement.scrollLeft : 0, + document.body ? document.body.scrollLeft : 0 + ); +} +function f_scrollTop() { + return f_filterResults ( + window.pageYOffset ? window.pageYOffset : 0, + document.documentElement ? document.documentElement.scrollTop : 0, + document.body ? document.body.scrollTop : 0 + ); +} +function f_filterResults(n_win, n_docel, n_body) { + var n_result = n_win ? n_win : 0; + if (n_docel && (!n_result || (n_result > n_docel))) + n_result = n_docel; + return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result; +}