includes/clientside/static/editor.js
changeset 1227 bdac73ed481e
parent 1102 faef5e62e1e0
child 1291 a971f6efcb7b
equal deleted inserted replaced
1226:de56132c008d 1227:bdac73ed481e
     7 var editor_save_lock = false;
     7 var editor_save_lock = false;
     8 var editor_wikitext_transform_enable = true;
     8 var editor_wikitext_transform_enable = true;
     9 
     9 
    10 window.ajaxEditor = function(revid)
    10 window.ajaxEditor = function(revid)
    11 {
    11 {
    12   if ( KILL_SWITCH )
    12 	if ( KILL_SWITCH )
    13     return true;
    13 		return true;
    14   if ( editor_open )
    14 	if ( editor_open )
    15     return true;
    15 		return true;
    16   load_component(['l10n', 'template-compiler', 'messagebox', 'fadefilter', 'flyin', 'toolbar']);
    16 	load_component(['l10n', 'template-compiler', 'messagebox', 'fadefilter', 'flyin', 'toolbar']);
    17   selectButtonMinor('edit');
    17 	selectButtonMinor('edit');
    18   selectButtonMajor('article');
    18 	selectButtonMajor('article');
    19   setAjaxLoading();
    19 	setAjaxLoading();
    20   
    20 	
    21   var rev_id_uri = ( revid ) ? '&revid=' + revid : '';
    21 	var rev_id_uri = ( revid ) ? '&revid=' + revid : '';
    22   ajaxGet(stdAjaxPrefix + '&_mode=getsource' + rev_id_uri, function(ajax)
    22 	ajaxGet(stdAjaxPrefix + '&_mode=getsource' + rev_id_uri, function(ajax)
    23     {
    23 		{
    24       if ( ajax.readyState == 4 && ajax.status == 200 )
    24 			if ( ajax.readyState == 4 && ajax.status == 200 )
    25       {
    25 			{
    26         unsetAjaxLoading();
    26 				unsetAjaxLoading();
    27         
    27 				
    28         var response = String(ajax.responseText + '');
    28 				var response = String(ajax.responseText + '');
    29         if ( !check_json_response(response) )
    29 				if ( !check_json_response(response) )
    30         {
    30 				{
    31           handle_invalid_json(response);
    31 					handle_invalid_json(response);
    32           return false;
    32 					return false;
    33         }
    33 				}
    34         
    34 				
    35         response = parseJSON(response);
    35 				response = parseJSON(response);
    36         if ( response.mode == 'error' )
    36 				if ( response.mode == 'error' )
    37         {
    37 				{
    38           unselectAllButtonsMinor();
    38 					unselectAllButtonsMinor();
    39           new MessageBox(MB_OK | MB_ICONSTOP, $lang.get('editor_err_server'), response.error);
    39 					new MessageBox(MB_OK | MB_ICONSTOP, $lang.get('editor_err_server'), response.error);
    40           return false;
    40 					return false;
    41         }
    41 				}
    42         
    42 				
    43         if ( !response.auth_view_source )
    43 				if ( !response.auth_view_source )
    44         {
    44 				{
    45           unselectAllButtonsMinor();
    45 					unselectAllButtonsMinor();
    46           new MessageBox(MB_OK | MB_ICONSTOP, $lang.get('editor_err_access_denied_title'), $lang.get('editor_err_access_denied_body'));
    46 					new MessageBox(MB_OK | MB_ICONSTOP, $lang.get('editor_err_access_denied_title'), $lang.get('editor_err_access_denied_body'));
    47           return false;
    47 					return false;
    48         }
    48 				}
    49         
    49 				
    50         // do we need to enter a captcha before saving the page?
    50 				// do we need to enter a captcha before saving the page?
    51         var captcha_hash = ( response.require_captcha ) ? response.captcha_id : false;
    51 				var captcha_hash = ( response.require_captcha ) ? response.captcha_id : false;
    52         
    52 				
    53         ajaxBuildEditor((!response.auth_edit), response.time, response.allow_wysiwyg, captcha_hash, response.revid, response.undo_info, response);
    53 				ajaxBuildEditor((!response.auth_edit), response.time, response.allow_wysiwyg, captcha_hash, response.revid, response.undo_info, response);
    54       }
    54 			}
    55     });
    55 		});
    56 }
    56 }
    57 
    57 
    58 window.ajaxBuildEditor = function(readonly, timestamp, allow_wysiwyg, captcha_hash, revid, undo_info, response)
    58 window.ajaxBuildEditor = function(readonly, timestamp, allow_wysiwyg, captcha_hash, revid, undo_info, response)
    59 {
    59 {
    60   // Set flags
    60 	// Set flags
    61   // We don't want the fancy confirmation framework to trigger if the user is only viewing the page source
    61 	// We don't want the fancy confirmation framework to trigger if the user is only viewing the page source
    62   if ( !readonly )
    62 	if ( !readonly )
    63   {
    63 	{
    64     editor_open = true;
    64 		editor_open = true;
    65     disableUnload();
    65 		disableUnload();
    66   }
    66 	}
    67   
    67 	
    68   // Destroy existing contents of page container
    68 	// Destroy existing contents of page container
    69   if ( editor_use_modal_window )
    69 	if ( editor_use_modal_window )
    70   {
    70 	{
    71     darken(true, 70, 'enano_editor_darkener');
    71 		darken(true, 70, 'enano_editor_darkener');
    72     // Build a div with 80% width, centered, and 10px from the top of the window
    72 		// Build a div with 80% width, centered, and 10px from the top of the window
    73     var edcon = document.createElement('div');
    73 		var edcon = document.createElement('div');
    74     edcon.style.position = 'absolute';
    74 		edcon.style.position = 'absolute';
    75     edcon.style.backgroundColor = '#FFFFFF';
    75 		edcon.style.backgroundColor = '#FFFFFF';
    76     edcon.style.padding = '10px';
    76 		edcon.style.padding = '10px';
    77     edcon.style.width = '80%';
    77 		edcon.style.width = '80%';
    78     edcon.style.zIndex = getHighestZ() + 1;
    78 		edcon.style.zIndex = getHighestZ() + 1;
    79     edcon.id = 'ajaxEditContainerModal';
    79 		edcon.id = 'ajaxEditContainerModal';
    80     
    80 		
    81     // Positioning
    81 		// Positioning
    82     var top = getScrollOffset() + 10;
    82 		var top = getScrollOffset() + 10;
    83     var left = ( getWidth() / 10 ) - 10; // 10% of window width on either side - 10px for padding = perfect centering effect
    83 		var left = ( getWidth() / 10 ) - 10; // 10% of window width on either side - 10px for padding = perfect centering effect
    84     edcon.style.top = String(top) + 'px';
    84 		edcon.style.top = String(top) + 'px';
    85     edcon.style.left = String(left) + 'px';
    85 		edcon.style.left = String(left) + 'px';
    86     var body = document.getElementsByTagName('body')[0];
    86 		var body = document.getElementsByTagName('body')[0];
    87     
    87 		
    88     // Set opacity to 0
    88 		// Set opacity to 0
    89     domObjChangeOpac(0, edcon);
    89 		domObjChangeOpac(0, edcon);
    90     body.appendChild(edcon);
    90 		body.appendChild(edcon);
    91   }
    91 	}
    92   else
    92 	else
    93   {
    93 	{
    94     var edcon = document.getElementById('ajaxEditContainer');
    94 		var edcon = document.getElementById('ajaxEditContainer');
    95     for ( var i = edcon.childNodes.length - 1; i >= 0; i-- )
    95 		for ( var i = edcon.childNodes.length - 1; i >= 0; i-- )
    96     {
    96 		{
    97       edcon.removeChild(edcon.childNodes[i]);
    97 			edcon.removeChild(edcon.childNodes[i]);
    98     }
    98 		}
    99   }
    99 	}
   100   
   100 	
   101   var content = response.src;
   101 	var content = response.src;
   102   
   102 	
   103   //
   103 	//
   104   // BUILD EDITOR
   104 	// BUILD EDITOR
   105   //
   105 	//
   106   
   106 	
   107   var heading = document.createElement('h3');
   107 	var heading = document.createElement('h3');
   108   heading.style.cssFloat = 'left';
   108 	heading.style.cssFloat = 'left';
   109   heading.style.styleFloat = 'left';
   109 	heading.style.styleFloat = 'left';
   110   heading.style.marginTop = '0px';
   110 	heading.style.marginTop = '0px';
   111   heading.style.marginBottom = '0px';
   111 	heading.style.marginBottom = '0px';
   112   heading.appendChild(document.createTextNode($lang.get('editor_msg_editor_heading')));
   112 	heading.appendChild(document.createTextNode($lang.get('editor_msg_editor_heading')));
   113   
   113 	
   114   // Plaintext/wikitext toggler
   114 	// Plaintext/wikitext toggler
   115   // Only build the editor if using TinyMCE is allowed. THIS IS WEAK
   115 	// Only build the editor if using TinyMCE is allowed. THIS IS WEAK
   116   // AND CANNOT BE MADE ANY STRONGER.
   116 	// AND CANNOT BE MADE ANY STRONGER.
   117   
   117 	
   118   if ( allow_wysiwyg )
   118 	if ( allow_wysiwyg )
   119   {
   119 	{
   120     var toggler = document.createElement('p');
   120 		var toggler = document.createElement('p');
   121     toggler.style.marginLeft = '0';
   121 		toggler.style.marginLeft = '0';
   122     toggler.style.textAlign = 'right';
   122 		toggler.style.textAlign = 'right';
   123     
   123 		
   124     var span_wiki = document.createElement('span');
   124 		var span_wiki = document.createElement('span');
   125     var span_mce  = document.createElement('span');
   125 		var span_mce  = document.createElement('span');
   126     span_wiki.id  = 'enano_edit_btn_pt';
   126 		span_wiki.id  = 'enano_edit_btn_pt';
   127     span_mce.id   = 'enano_edit_btn_mce';
   127 		span_mce.id   = 'enano_edit_btn_mce';
   128     
   128 		
   129     // to-wikitext button
   129 		// to-wikitext button
   130     var a = document.createElement('a');
   130 		var a = document.createElement('a');
   131     a.href = '#';
   131 		a.href = '#';
   132     a.className = 'abutton image abutton_green';
   132 		a.className = 'abutton image abutton_green';
   133     a.appendChild(gen_sprite(scriptPath + '/images/editor/sprite.png', 16, 16, 0, 96));
   133 		a.appendChild(gen_sprite(scriptPath + '/images/editor/sprite.png', 16, 16, 0, 96));
   134     a.appendChild(document.createTextNode(' ' + $lang.get('editor_btn_wikitext')));
   134 		a.appendChild(document.createTextNode(' ' + $lang.get('editor_btn_wikitext')));
   135     span_wiki.appendChild(a);
   135 		span_wiki.appendChild(a);
   136     toggler.appendChild(span_wiki);
   136 		toggler.appendChild(span_wiki);
   137     
   137 		
   138     // to-HTML button
   138 		// to-HTML button
   139     var a = document.createElement('a');
   139 		var a = document.createElement('a');
   140     a.href = '#';
   140 		a.href = '#';
   141     a.className = 'abutton image abutton_blue';
   141 		a.className = 'abutton image abutton_blue';
   142     a.appendChild(gen_sprite(scriptPath + '/images/editor/sprite.png', 16, 16, 0, 112));
   142 		a.appendChild(gen_sprite(scriptPath + '/images/editor/sprite.png', 16, 16, 0, 112));
   143     a.appendChild(document.createTextNode(' ' + $lang.get('editor_btn_graphical')));
   143 		a.appendChild(document.createTextNode(' ' + $lang.get('editor_btn_graphical')));
   144     span_mce.appendChild(a);
   144 		span_mce.appendChild(a);
   145     toggler.appendChild(span_mce);
   145 		toggler.appendChild(span_mce);
   146     
   146 		
   147     if ( response.page_format == 'xhtml' )
   147 		if ( response.page_format == 'xhtml' )
   148     {
   148 		{
   149       // Current selection is TinyMCE - make span_wiki have the link and span_mce be plaintext
   149 			// Current selection is TinyMCE - make span_wiki have the link and span_mce be plaintext
   150       span_mce.style.display = 'none';
   150 			span_mce.style.display = 'none';
   151     }
   151 		}
   152     else
   152 		else
   153     {
   153 		{
   154       // Current selection is wikitext - set span_wiki to plaintext and span_mce to link
   154 			// Current selection is wikitext - set span_wiki to plaintext and span_mce to link
   155       span_wiki.style.display = 'none';
   155 			span_wiki.style.display = 'none';
   156     }
   156 		}
   157   }
   157 	}
   158   
   158 	
   159   // Form (to allow submits from MCE to trigger a real save)
   159 	// Form (to allow submits from MCE to trigger a real save)
   160   var form = document.createElement('form');
   160 	var form = document.createElement('form');
   161   form.action = 'javascript:void(0);';
   161 	form.action = 'javascript:void(0);';
   162   form.onsubmit = function()
   162 	form.onsubmit = function()
   163   {
   163 	{
   164     ajaxEditorSave();
   164 		ajaxEditorSave();
   165     return false;
   165 		return false;
   166   }
   166 	}
   167   
   167 	
   168   // Draft notice
   168 	// Draft notice
   169   if ( response.have_draft && !readonly )
   169 	if ( response.have_draft && !readonly )
   170   {
   170 	{
   171     var dn = document.createElement('div');
   171 		var dn = document.createElement('div');
   172     dn.className = 'warning-box';
   172 		dn.className = 'warning-box';
   173     dn.id = 'ajax_edit_draft_notice';
   173 		dn.id = 'ajax_edit_draft_notice';
   174     dn.innerHTML = '<b>' + $lang.get('editor_msg_have_draft_title') + '</b><br />';
   174 		dn.innerHTML = '<b>' + $lang.get('editor_msg_have_draft_title') + '</b><br />';
   175     dn.innerHTML += $lang.get('editor_msg_have_draft_body', { author: response.draft_author, time: response.draft_time });
   175 		dn.innerHTML += $lang.get('editor_msg_have_draft_body', { author: response.draft_author, time: response.draft_time });
   176   }
   176 	}
   177   
   177 	
   178   // Old-revision notice
   178 	// Old-revision notice
   179   if ( revid > 0 )
   179 	if ( revid > 0 )
   180   {
   180 	{
   181     var oldrev_box = document.createElement('div');
   181 		var oldrev_box = document.createElement('div');
   182     oldrev_box.className = 'usermessage';
   182 		oldrev_box.className = 'usermessage';
   183     oldrev_box.appendChild(document.createTextNode($lang.get('editor_msg_editing_old_revision')));
   183 		oldrev_box.appendChild(document.createTextNode($lang.get('editor_msg_editing_old_revision')));
   184   }
   184 	}
   185   
   185 	
   186   // Preview holder
   186 	// Preview holder
   187   var preview_anchor = document.createElement('a');
   187 	var preview_anchor = document.createElement('a');
   188   preview_anchor.name = 'ajax_preview';
   188 	preview_anchor.name = 'ajax_preview';
   189   preview_anchor.id = 'ajax_preview';
   189 	preview_anchor.id = 'ajax_preview';
   190   var preview_container = document.createElement('div');
   190 	var preview_container = document.createElement('div');
   191   preview_container.id = 'enano_editor_preview';
   191 	preview_container.id = 'enano_editor_preview';
   192   preview_container.style.clear = 'left';
   192 	preview_container.style.clear = 'left';
   193   
   193 	
   194   // Textarea containing the content
   194 	// Textarea containing the content
   195   var ta_wrapper = document.createElement('div');
   195 	var ta_wrapper = document.createElement('div');
   196   ta_wrapper.style.margin = '10px 0';
   196 	ta_wrapper.style.margin = '10px 0';
   197   // ta_wrapper.style.clear = 'both';
   197 	// ta_wrapper.style.clear = 'both';
   198   var textarea = document.createElement('textarea');
   198 	var textarea = document.createElement('textarea');
   199   ta_wrapper.appendChild(textarea);
   199 	ta_wrapper.appendChild(textarea);
   200   
   200 	
   201   textarea.id = 'ajaxEditArea';
   201 	textarea.id = 'ajaxEditArea';
   202   textarea.rows = '20';
   202 	textarea.rows = '20';
   203   textarea.cols = '60';
   203 	textarea.cols = '60';
   204   textarea.style.width = '98.7%';
   204 	textarea.style.width = '98.7%';
   205   
   205 	
   206   // Revision metadata controls
   206 	// Revision metadata controls
   207   var tblholder = document.createElement('div');
   207 	var tblholder = document.createElement('div');
   208   tblholder.className = 'tblholder';
   208 	tblholder.className = 'tblholder';
   209   var metatable = document.createElement('table');
   209 	var metatable = document.createElement('table');
   210   metatable.setAttribute('border', '0');
   210 	metatable.setAttribute('border', '0');
   211   metatable.setAttribute('cellspacing', '1');
   211 	metatable.setAttribute('cellspacing', '1');
   212   metatable.setAttribute('cellpadding', '4');
   212 	metatable.setAttribute('cellpadding', '4');
   213   
   213 	
   214   if ( readonly )
   214 	if ( readonly )
   215   {
   215 	{
   216     // Close Viewer button
   216 		// Close Viewer button
   217     var toolbar = '';
   217 		var toolbar = '';
   218     var head = new templateParser(response.toolbar_templates.toolbar_start);
   218 		var head = new templateParser(response.toolbar_templates.toolbar_start);
   219     var button = new templateParser(response.toolbar_templates.toolbar_button);
   219 		var button = new templateParser(response.toolbar_templates.toolbar_button);
   220     var tail = new templateParser(response.toolbar_templates.toolbar_end);
   220 		var tail = new templateParser(response.toolbar_templates.toolbar_end);
   221     
   221 		
   222     toolbar += head.run();
   222 		toolbar += head.run();
   223     
   223 		
   224     button.assign_bool({
   224 		button.assign_bool({
   225         show_title: true
   225 				show_title: true
   226       });
   226 			});
   227     
   227 		
   228     // Button: close
   228 		// Button: close
   229     button.assign_vars({
   229 		button.assign_vars({
   230         TITLE: $lang.get('editor_btn_closeviewer'),
   230 				TITLE: $lang.get('editor_btn_closeviewer'),
   231         IMAGE: editor_img_path + '/discard.gif',
   231 				IMAGE: editor_img_path + '/discard.gif',
   232         SPRITE: gen_sprite_html(editor_img_path + '/sprite.png', 16, 16, 0, 16),
   232 				SPRITE: gen_sprite_html(editor_img_path + '/sprite.png', 16, 16, 0, 16),
   233         FLAGS: 'href="#" onclick="ajaxReset(true); return false;"'
   233 				FLAGS: 'href="#" onclick="ajaxReset(true); return false;"'
   234       });
   234 			});
   235     toolbar += button.run();
   235 		toolbar += button.run();
   236     toolbar += tail.run();
   236 		toolbar += tail.run();
   237   }
   237 	}
   238   else
   238 	else
   239   {
   239 	{
   240     // First row: edit summary
   240 		// First row: edit summary
   241     var tr1 = document.createElement('tr');
   241 		var tr1 = document.createElement('tr');
   242     var td1_1 = document.createElement('td');
   242 		var td1_1 = document.createElement('td');
   243     var td1_2 = document.createElement('td');
   243 		var td1_2 = document.createElement('td');
   244     td1_1.className = 'row2';
   244 		td1_1.className = 'row2';
   245     td1_2.className = 'row1';
   245 		td1_2.className = 'row1';
   246     td1_2.style.width = '70%';
   246 		td1_2.style.width = '70%';
   247     td1_1.appendChild(document.createTextNode($lang.get('editor_lbl_edit_summary')));
   247 		td1_1.appendChild(document.createTextNode($lang.get('editor_lbl_edit_summary')));
   248     td1_1.appendChild(document.createElement('br'));
   248 		td1_1.appendChild(document.createElement('br'));
   249     var small = document.createElement('small');
   249 		var small = document.createElement('small');
   250     small.appendChild(document.createTextNode($lang.get('editor_lbl_edit_summary_explain')));
   250 		small.appendChild(document.createTextNode($lang.get('editor_lbl_edit_summary_explain')));
   251     td1_1.appendChild(small);
   251 		td1_1.appendChild(small);
   252     
   252 		
   253     var field_es = document.createElement('input');
   253 		var field_es = document.createElement('input');
   254     field_es.id = 'enano_editor_field_summary';
   254 		field_es.id = 'enano_editor_field_summary';
   255     field_es.type = 'text';
   255 		field_es.type = 'text';
   256     field_es.size = '40';
   256 		field_es.size = '40';
   257     field_es.style.width = '96%';
   257 		field_es.style.width = '96%';
   258     
   258 		
   259     if ( revid > 0 )
   259 		if ( revid > 0 )
   260     {
   260 		{
   261       undo_info.last_rev_id = revid;
   261 			undo_info.last_rev_id = revid;
   262       field_es.value = $lang.get('editor_reversion_edit_summary', undo_info);
   262 			field_es.value = $lang.get('editor_reversion_edit_summary', undo_info);
   263     }
   263 		}
   264     
   264 		
   265     td1_2.appendChild(field_es);
   265 		td1_2.appendChild(field_es);
   266     
   266 		
   267     tr1.appendChild(td1_1);
   267 		tr1.appendChild(td1_1);
   268     tr1.appendChild(td1_2);
   268 		tr1.appendChild(td1_2);
   269     
   269 		
   270     // Second row: minor edit
   270 		// Second row: minor edit
   271     var tr2 = document.createElement('tr');
   271 		var tr2 = document.createElement('tr');
   272     var td2_1 = document.createElement('td');
   272 		var td2_1 = document.createElement('td');
   273     var td2_2 = document.createElement('td');
   273 		var td2_2 = document.createElement('td');
   274     td2_1.className = 'row2';
   274 		td2_1.className = 'row2';
   275     td2_2.className = 'row1';
   275 		td2_2.className = 'row1';
   276     td2_1.appendChild(document.createTextNode($lang.get('editor_lbl_minor_edit')));
   276 		td2_1.appendChild(document.createTextNode($lang.get('editor_lbl_minor_edit')));
   277     td2_1.appendChild(document.createElement('br'));
   277 		td2_1.appendChild(document.createElement('br'));
   278     var small = document.createElement('small');
   278 		var small = document.createElement('small');
   279     small.appendChild(document.createTextNode($lang.get('editor_lbl_minor_edit_explain')));
   279 		small.appendChild(document.createTextNode($lang.get('editor_lbl_minor_edit_explain')));
   280     td2_1.appendChild(small);
   280 		td2_1.appendChild(small);
   281     
   281 		
   282     var label = document.createElement('label');
   282 		var label = document.createElement('label');
   283     var field_mi = document.createElement('input');
   283 		var field_mi = document.createElement('input');
   284     field_mi.id = 'enano_editor_field_minor';
   284 		field_mi.id = 'enano_editor_field_minor';
   285     field_mi.type = 'checkbox';
   285 		field_mi.type = 'checkbox';
   286     label.appendChild(field_mi);
   286 		label.appendChild(field_mi);
   287     label.appendChild(document.createTextNode(' '));
   287 		label.appendChild(document.createTextNode(' '));
   288     label.appendChild(document.createTextNode($lang.get('editor_lbl_minor_edit_field')));
   288 		label.appendChild(document.createTextNode($lang.get('editor_lbl_minor_edit_field')));
   289     td2_2.appendChild(label);
   289 		td2_2.appendChild(label);
   290     
   290 		
   291     tr2.appendChild(td2_1);
   291 		tr2.appendChild(td2_1);
   292     tr2.appendChild(td2_2);
   292 		tr2.appendChild(td2_2);
   293     
   293 		
   294     if ( captcha_hash )
   294 		if ( captcha_hash )
   295     {
   295 		{
   296       // generate captcha field (effectively third row)
   296 			// generate captcha field (effectively third row)
   297       var tr4 = document.createElement('tr');
   297 			var tr4 = document.createElement('tr');
   298       var td4_1 = document.createElement('td');
   298 			var td4_1 = document.createElement('td');
   299       var td4_2 = document.createElement('td');
   299 			var td4_2 = document.createElement('td');
   300       td4_1.className = 'row2';
   300 			td4_1.className = 'row2';
   301       td4_2.className = 'row1';
   301 			td4_2.className = 'row1';
   302       
   302 			
   303       td4_1.appendChild(document.createTextNode($lang.get('editor_lbl_field_captcha')));
   303 			td4_1.appendChild(document.createTextNode($lang.get('editor_lbl_field_captcha')));
   304       td4_1.appendChild(document.createElement('br'));
   304 			td4_1.appendChild(document.createElement('br'));
   305       var small2 = document.createElement('small');
   305 			var small2 = document.createElement('small');
   306       small2.appendChild(document.createTextNode($lang.get('editor_msg_captcha_pleaseenter')));
   306 			small2.appendChild(document.createTextNode($lang.get('editor_msg_captcha_pleaseenter')));
   307       small2.appendChild(document.createElement('br'));
   307 			small2.appendChild(document.createElement('br'));
   308       small2.appendChild(document.createElement('br'));
   308 			small2.appendChild(document.createElement('br'));
   309       small2.appendChild(document.createTextNode($lang.get('editor_msg_captcha_blind')));
   309 			small2.appendChild(document.createTextNode($lang.get('editor_msg_captcha_blind')));
   310       td4_1.appendChild(small2);
   310 			td4_1.appendChild(small2);
   311       
   311 			
   312       var img = document.createElement('img');
   312 			var img = document.createElement('img');
   313       img.src = makeUrlNS('Special', 'Captcha/' + captcha_hash);
   313 			img.src = makeUrlNS('Special', 'Captcha/' + captcha_hash);
   314       img.setAttribute('enano:captcha_hash', captcha_hash);
   314 			img.setAttribute('enano:captcha_hash', captcha_hash);
   315       img.id = 'enano_editor_captcha_img';
   315 			img.id = 'enano_editor_captcha_img';
   316       img.onclick = function()
   316 			img.onclick = function()
   317       {
   317 			{
   318         this.src = makeUrlNS('Special', 'Captcha/' + this.getAttribute('enano:captcha_hash') + '/' + Math.floor(Math.random() * 100000));
   318 				this.src = makeUrlNS('Special', 'Captcha/' + this.getAttribute('enano:captcha_hash') + '/' + Math.floor(Math.random() * 100000));
   319       }
   319 			}
   320       img.style.cursor = 'pointer';
   320 			img.style.cursor = 'pointer';
   321       td4_2.appendChild(img);
   321 			td4_2.appendChild(img);
   322       td4_2.appendChild(document.createElement('br'));
   322 			td4_2.appendChild(document.createElement('br'));
   323       td4_2.appendChild(document.createTextNode($lang.get('editor_lbl_field_captcha_code') + ' '));
   323 			td4_2.appendChild(document.createTextNode($lang.get('editor_lbl_field_captcha_code') + ' '));
   324       var input = document.createElement('input');
   324 			var input = document.createElement('input');
   325       input.type = 'text';
   325 			input.type = 'text';
   326       input.id = 'enano_editor_field_captcha';
   326 			input.id = 'enano_editor_field_captcha';
   327       input.setAttribute('enano:captcha_hash', captcha_hash);
   327 			input.setAttribute('enano:captcha_hash', captcha_hash);
   328       input.size = '9';
   328 			input.size = '9';
   329       td4_2.appendChild(input);
   329 			td4_2.appendChild(input);
   330       
   330 			
   331       tr4.appendChild(td4_1);
   331 			tr4.appendChild(td4_1);
   332       tr4.appendChild(td4_2);
   332 			tr4.appendChild(td4_2);
   333     }
   333 		}
   334     
   334 		
   335     // Third row: controls
   335 		// Third row: controls
   336     
   336 		
   337     var toolbar = '';
   337 		var toolbar = '';
   338     var head = new templateParser(response.toolbar_templates.toolbar_start);
   338 		var head = new templateParser(response.toolbar_templates.toolbar_start);
   339     var button = new templateParser(response.toolbar_templates.toolbar_button);
   339 		var button = new templateParser(response.toolbar_templates.toolbar_button);
   340     var label = new templateParser(response.toolbar_templates.toolbar_label);
   340 		var label = new templateParser(response.toolbar_templates.toolbar_label);
   341     var tail = new templateParser(response.toolbar_templates.toolbar_end);
   341 		var tail = new templateParser(response.toolbar_templates.toolbar_end);
   342     
   342 		
   343     button.assign_bool({
   343 		button.assign_bool({
   344         show_title: true
   344 				show_title: true
   345       });
   345 			});
   346     
   346 		
   347     toolbar += head.run();
   347 		toolbar += head.run();
   348     
   348 		
   349     // Button: Save
   349 		// Button: Save
   350     button.assign_vars({
   350 		button.assign_vars({
   351         TITLE: $lang.get('editor_btn_save'),
   351 				TITLE: $lang.get('editor_btn_save'),
   352         IMAGE: editor_img_path + '/save.gif',
   352 				IMAGE: editor_img_path + '/save.gif',
   353         SPRITE: gen_sprite_html(editor_img_path + '/sprite.png', 16, 16, 0, 64),
   353 				SPRITE: gen_sprite_html(editor_img_path + '/sprite.png', 16, 16, 0, 64),
   354         FLAGS: 'href="#" onclick="ajaxEditorSave(); return false;"'
   354 				FLAGS: 'href="#" onclick="ajaxEditorSave(); return false;"'
   355       });
   355 			});
   356     toolbar += button.run();
   356 		toolbar += button.run();
   357     
   357 		
   358     // Button: preview
   358 		// Button: preview
   359     button.assign_vars({
   359 		button.assign_vars({
   360         TITLE: $lang.get('editor_btn_preview'),
   360 				TITLE: $lang.get('editor_btn_preview'),
   361         IMAGE: editor_img_path + '/preview.gif',
   361 				IMAGE: editor_img_path + '/preview.gif',
   362         SPRITE: gen_sprite_html(editor_img_path + '/sprite.png', 16, 16, 0, 32),
   362 				SPRITE: gen_sprite_html(editor_img_path + '/sprite.png', 16, 16, 0, 32),
   363         FLAGS: 'href="#" onclick="ajaxEditorGenPreview(); return false;"'
   363 				FLAGS: 'href="#" onclick="ajaxEditorGenPreview(); return false;"'
   364       });
   364 			});
   365     toolbar += button.run();
   365 		toolbar += button.run();
   366     
   366 		
   367     // Button: revert
   367 		// Button: revert
   368     button.assign_vars({
   368 		button.assign_vars({
   369         TITLE: $lang.get('editor_btn_revert'),
   369 				TITLE: $lang.get('editor_btn_revert'),
   370           IMAGE: editor_img_path + '/revert.gif',
   370 					IMAGE: editor_img_path + '/revert.gif',
   371           SPRITE: gen_sprite_html(editor_img_path + '/sprite.png', 16, 16, 0, 48),
   371 					SPRITE: gen_sprite_html(editor_img_path + '/sprite.png', 16, 16, 0, 48),
   372         FLAGS: 'href="#" onclick="ajaxEditorRevertToLatest(); return false;"'
   372 				FLAGS: 'href="#" onclick="ajaxEditorRevertToLatest(); return false;"'
   373       });
   373 			});
   374     toolbar += button.run();
   374 		toolbar += button.run();
   375     
   375 		
   376     // Button: diff
   376 		// Button: diff
   377     button.assign_vars({
   377 		button.assign_vars({
   378         TITLE: $lang.get('editor_btn_diff'),
   378 				TITLE: $lang.get('editor_btn_diff'),
   379         IMAGE: editor_img_path + '/diff.gif',
   379 				IMAGE: editor_img_path + '/diff.gif',
   380         SPRITE: gen_sprite_html(editor_img_path + '/sprite.png', 16, 16, 0, 0),
   380 				SPRITE: gen_sprite_html(editor_img_path + '/sprite.png', 16, 16, 0, 0),
   381         FLAGS: 'href="#" onclick="ajaxEditorShowDiffs(); return false;"'
   381 				FLAGS: 'href="#" onclick="ajaxEditorShowDiffs(); return false;"'
   382       });
   382 			});
   383     toolbar += button.run();
   383 		toolbar += button.run();
   384     
   384 		
   385     // Button: cancel
   385 		// Button: cancel
   386     button.assign_vars({
   386 		button.assign_vars({
   387         TITLE: $lang.get('editor_btn_cancel'),
   387 				TITLE: $lang.get('editor_btn_cancel'),
   388         IMAGE: editor_img_path + '/discard.gif',
   388 				IMAGE: editor_img_path + '/discard.gif',
   389         SPRITE: gen_sprite_html(editor_img_path + '/sprite.png', 16, 16, 0, 16),
   389 				SPRITE: gen_sprite_html(editor_img_path + '/sprite.png', 16, 16, 0, 16),
   390         FLAGS: 'href="#" onclick="ajaxEditorCancel(); return false;"'
   390 				FLAGS: 'href="#" onclick="ajaxEditorCancel(); return false;"'
   391       });
   391 			});
   392     toolbar += button.run();
   392 		toolbar += button.run();
   393     
   393 		
   394     // Separator
   394 		// Separator
   395     label.assign_vars({
   395 		label.assign_vars({
   396         TITLE: ' '
   396 				TITLE: ' '
   397       });
   397 			});
   398     toolbar += label.run();
   398 		toolbar += label.run();
   399     
   399 		
   400     // Button: Save draft
   400 		// Button: Save draft
   401     button.assign_vars({
   401 		button.assign_vars({
   402         TITLE: $lang.get('editor_btn_savedraft'),
   402 				TITLE: $lang.get('editor_btn_savedraft'),
   403         IMAGE: editor_img_path + '/savedraft.gif',
   403 				IMAGE: editor_img_path + '/savedraft.gif',
   404         SPRITE: false,
   404 				SPRITE: false,
   405         FLAGS: 'href="#" onclick="ajaxPerformAutosave(); return false;" id="ajax_edit_savedraft_btn"'
   405 				FLAGS: 'href="#" onclick="ajaxPerformAutosave(); return false;" id="ajax_edit_savedraft_btn"'
   406       });
   406 			});
   407     toolbar += button.run();
   407 		toolbar += button.run();
   408     
   408 		
   409     toolbar += tail.run();
   409 		toolbar += tail.run();
   410     
   410 		
   411     metatable.appendChild(tr1);
   411 		metatable.appendChild(tr1);
   412     metatable.appendChild(tr2);
   412 		metatable.appendChild(tr2);
   413     if ( captcha_hash )
   413 		if ( captcha_hash )
   414     {
   414 		{
   415       metatable.appendChild(tr4);
   415 			metatable.appendChild(tr4);
   416     }
   416 		}
   417     // metatable.appendChild(tr3);
   417 		// metatable.appendChild(tr3);
   418   }
   418 	}
   419   tblholder.appendChild(metatable);
   419 	tblholder.appendChild(metatable);
   420   
   420 	
   421   // Edit disclaimer/notice
   421 	// Edit disclaimer/notice
   422   if ( response.edit_notice )
   422 	if ( response.edit_notice )
   423   {
   423 	{
   424     var en_div = document.createElement('div');
   424 		var en_div = document.createElement('div');
   425     en_div.innerHTML = response.edit_notice;
   425 		en_div.innerHTML = response.edit_notice;
   426     en_div.className = 'usermessage';
   426 		en_div.className = 'usermessage';
   427     en_div.style.margin = '10px 0 0 0';
   427 		en_div.style.margin = '10px 0 0 0';
   428   }
   428 	}
   429   
   429 	
   430   // Put it all together...
   430 	// Put it all together...
   431   form.appendChild(heading);
   431 	form.appendChild(heading);
   432   if ( allow_wysiwyg )
   432 	if ( allow_wysiwyg )
   433     form.appendChild(toggler);
   433 		form.appendChild(toggler);
   434   
   434 	
   435   if ( dn )
   435 	if ( dn )
   436     form.appendChild(dn);
   436 		form.appendChild(dn);
   437   
   437 	
   438   if ( oldrev_box )
   438 	if ( oldrev_box )
   439     form.appendChild(oldrev_box);
   439 		form.appendChild(oldrev_box);
   440   
   440 	
   441   form.appendChild(preview_anchor);
   441 	form.appendChild(preview_anchor);
   442   form.appendChild(preview_container);
   442 	form.appendChild(preview_container);
   443   form.appendChild(ta_wrapper);
   443 	form.appendChild(ta_wrapper);
   444   if ( !readonly )
   444 	if ( !readonly )
   445     form.appendChild(tblholder);
   445 		form.appendChild(tblholder);
   446   form.innerHTML += '<div style="margin: 10px 0 0 0;">' + toolbar + '</div>';
   446 	form.innerHTML += '<div style="margin: 10px 0 0 0;">' + toolbar + '</div>';
   447   edcon.appendChild(form);
   447 	edcon.appendChild(form);
   448   
   448 	
   449   if ( response.edit_notice && !readonly )
   449 	if ( response.edit_notice && !readonly )
   450   {
   450 	{
   451     edcon.appendChild(en_div);
   451 		edcon.appendChild(en_div);
   452   }
   452 	}
   453   
   453 	
   454   // more textarea attribs/init
   454 	// more textarea attribs/init
   455   var textarea = document.getElementById('ajaxEditArea');
   455 	var textarea = document.getElementById('ajaxEditArea');
   456   textarea.as_last_save = 0;
   456 	textarea.as_last_save = 0;
   457   textarea.content_orig = content;
   457 	textarea.content_orig = content;
   458   textarea.used_draft = false;
   458 	textarea.used_draft = false;
   459   textarea.onkeyup = function()
   459 	textarea.onkeyup = function()
   460   {
   460 	{
   461     if ( this.needReset )
   461 		if ( this.needReset )
   462     {
   462 		{
   463       var img = $dynano('ajax_edit_savedraft_btn').object.getElementsByTagName('img')[0];
   463 			var img = $dynano('ajax_edit_savedraft_btn').object.getElementsByTagName('img')[0];
   464       var lbl = $dynano('ajax_edit_savedraft_btn').object.getElementsByTagName('span')[0];
   464 			var lbl = $dynano('ajax_edit_savedraft_btn').object.getElementsByTagName('span')[0];
   465       img.src = editor_img_path + '/savedraft.gif';
   465 			img.src = editor_img_path + '/savedraft.gif';
   466       lbl.innerHTML = $lang.get('editor_btn_savedraft');
   466 			lbl.innerHTML = $lang.get('editor_btn_savedraft');
   467     }
   467 		}
   468     if ( window.AutosaveTimeoutObj )
   468 		if ( window.AutosaveTimeoutObj )
   469       clearTimeout(window.AutosaveTimeoutObj);
   469 			clearTimeout(window.AutosaveTimeoutObj);
   470     window.AutosaveTimeoutObj = setTimeout('ajaxAutosaveDraft();', ( AUTOSAVE_TIMEOUT * 1000 ));
   470 		window.AutosaveTimeoutObj = setTimeout('ajaxAutosaveDraft();', ( AUTOSAVE_TIMEOUT * 1000 ));
   471   }
   471 	}
   472   
   472 	
   473   if ( readonly )
   473 	if ( readonly )
   474   {
   474 	{
   475     textarea.className = 'mce_readonly';
   475 		textarea.className = 'mce_readonly';
   476     textarea.setAttribute('readonly', 'readonly');
   476 		textarea.setAttribute('readonly', 'readonly');
   477   }
   477 	}
   478   
   478 	
   479   $dynano('ajaxEditArea').object.focus();
   479 	$dynano('ajaxEditArea').object.focus();
   480   $dynano('ajaxEditArea').object._edTimestamp = timestamp;
   480 	$dynano('ajaxEditArea').object._edTimestamp = timestamp;
   481   $dynano('ajaxEditArea').setContent(content);
   481 	$dynano('ajaxEditArea').setContent(content);
   482   
   482 	
   483   // If the editor preference is tinymce, switch the editor to TinyMCE now
   483 	// If the editor preference is tinymce, switch the editor to TinyMCE now
   484   if ( response.page_format == 'xhtml' && allow_wysiwyg )
   484 	if ( response.page_format == 'xhtml' && allow_wysiwyg )
   485   {
   485 	{
   486     $dynano('ajaxEditArea').switchToMCE(false);
   486 		$dynano('ajaxEditArea').switchToMCE(false);
   487   }
   487 	}
   488   
   488 	
   489   if ( allow_wysiwyg )
   489 	if ( allow_wysiwyg )
   490   {
   490 	{
   491     var a = document.getElementById('enano_edit_btn_pt').getElementsByTagName('a')[0];
   491 		var a = document.getElementById('enano_edit_btn_pt').getElementsByTagName('a')[0];
   492     a.onclick = function() {
   492 		a.onclick = function() {
   493       ajaxSetEditorPlain();
   493 			ajaxSetEditorPlain();
   494       return false;
   494 			return false;
   495     };
   495 		};
   496     var a = document.getElementById('enano_edit_btn_mce').getElementsByTagName('a')[0];
   496 		var a = document.getElementById('enano_edit_btn_mce').getElementsByTagName('a')[0];
   497     a.onclick = function() {
   497 		a.onclick = function() {
   498       ajaxSetEditorMCE();
   498 			ajaxSetEditorMCE();
   499       return false;
   499 			return false;
   500     };
   500 		};
   501   }
   501 	}
   502   
   502 	
   503   // if we're using the modal window, fade it in
   503 	// if we're using the modal window, fade it in
   504   if ( editor_use_modal_window )
   504 	if ( editor_use_modal_window )
   505   {
   505 	{
   506     domOpacity(edcon, 0, 100, 500);
   506 		domOpacity(edcon, 0, 100, 500);
   507   }
   507 	}
   508   
   508 	
   509   // Autosave every 5 minutes           (m  *  s  *  ms)
   509 	// Autosave every 5 minutes           (m  *  s  *  ms)
   510   setInterval('ajaxPerformAutosave();', ( 5 * 60 * 1000 ));
   510 	setInterval('ajaxPerformAutosave();', ( 5 * 60 * 1000 ));
   511 }
   511 }
   512 
   512 
   513 window.ajaxEditorDestroyModalWindow = function()
   513 window.ajaxEditorDestroyModalWindow = function()
   514 {
   514 {
   515   if ( editor_use_modal_window )
   515 	if ( editor_use_modal_window )
   516   {
   516 	{
   517     var edcon = document.getElementById('ajaxEditContainerModal');
   517 		var edcon = document.getElementById('ajaxEditContainerModal');
   518     var body = document.getElementsByTagName('body')[0];
   518 		var body = document.getElementsByTagName('body')[0];
   519     if ( edcon )
   519 		if ( edcon )
   520     {
   520 		{
   521       body.removeChild(edcon);
   521 			body.removeChild(edcon);
   522       enlighten(true, 'enano_editor_darkener');
   522 			enlighten(true, 'enano_editor_darkener');
   523     }
   523 		}
   524   }
   524 	}
   525 }
   525 }
   526 
   526 
   527 window.ajaxEditorSave = function(is_draft, text_override)
   527 window.ajaxEditorSave = function(is_draft, text_override)
   528 {
   528 {
   529   if ( !is_draft )
   529 	if ( !is_draft )
   530   {
   530 	{
   531     ajaxSetEditorLoading();
   531 		ajaxSetEditorLoading();
   532   }
   532 	}
   533   if ( is_draft && editor_save_lock )
   533 	if ( is_draft && editor_save_lock )
   534     return false;
   534 		return false;
   535   else
   535 	else
   536     editor_save_lock = true;
   536 		editor_save_lock = true;
   537   
   537 	
   538   var ta_content = ( text_override ) ? text_override : $dynano('ajaxEditArea').getContent();
   538 	var ta_content = ( text_override ) ? text_override : $dynano('ajaxEditArea').getContent();
   539   
   539 	
   540   if ( !is_draft && ( ta_content == '' || ta_content == '<p></p>' || ta_content == '<p>&nbsp;</p>' ) )
   540 	if ( !is_draft && ( ta_content == '' || ta_content == '<p></p>' || ta_content == '<p>&nbsp;</p>' ) )
   541   {
   541 	{
   542     new MessageBox(MB_OK|MB_ICONSTOP, $lang.get('editor_err_no_text_title'), $lang.get('editor_err_no_text_body'));
   542 		new MessageBox(MB_OK|MB_ICONSTOP, $lang.get('editor_err_no_text_title'), $lang.get('editor_err_no_text_body'));
   543     ajaxUnSetEditorLoading();
   543 		ajaxUnSetEditorLoading();
   544     return false;
   544 		return false;
   545   }
   545 	}
   546   
   546 	
   547   if ( is_draft )
   547 	if ( is_draft )
   548   {
   548 	{
   549     // ajaxSetEditorLoading();
   549 		// ajaxSetEditorLoading();
   550     var img = $dynano('ajax_edit_savedraft_btn').object.getElementsByTagName('img')[0];
   550 		var img = $dynano('ajax_edit_savedraft_btn').object.getElementsByTagName('img')[0];
   551     var lbl = $dynano('ajax_edit_savedraft_btn').object.getElementsByTagName('span')[0];
   551 		var lbl = $dynano('ajax_edit_savedraft_btn').object.getElementsByTagName('span')[0];
   552     img.src = cdnPath + '/images/loading.gif';
   552 		img.src = cdnPath + '/images/loading.gif';
   553     var d = new Date();
   553 		var d = new Date();
   554     var m = String(d.getMinutes());
   554 		var m = String(d.getMinutes());
   555     if ( m.length < 2 )
   555 		if ( m.length < 2 )
   556       m = '0' + m;
   556 			m = '0' + m;
   557     var time = d.getHours() + ':' + m;
   557 		var time = d.getHours() + ':' + m;
   558     lbl.innerHTML = $lang.get('editor_msg_draft_saving');
   558 		lbl.innerHTML = $lang.get('editor_msg_draft_saving');
   559   }
   559 	}
   560   
   560 	
   561   var edit_summ = $dynano('enano_editor_field_summary').object.value;
   561 	var edit_summ = $dynano('enano_editor_field_summary').object.value;
   562   if ( !edit_summ )
   562 	if ( !edit_summ )
   563     edit_summ = '';
   563 		edit_summ = '';
   564   var is_minor = ( $dynano('enano_editor_field_minor').object.checked ) ? 1 : 0;
   564 	var is_minor = ( $dynano('enano_editor_field_minor').object.checked ) ? 1 : 0;
   565   var timestamp = $dynano('ajaxEditArea').object._edTimestamp;
   565 	var timestamp = $dynano('ajaxEditArea').object._edTimestamp;
   566   var used_draft = $dynano('ajaxEditArea').object.used_draft;
   566 	var used_draft = $dynano('ajaxEditArea').object.used_draft;
   567   
   567 	
   568   var json_packet = {
   568 	var json_packet = {
   569     src: ta_content,
   569 		src: ta_content,
   570     summary: edit_summ,
   570 		summary: edit_summ,
   571     minor_edit: is_minor,
   571 		minor_edit: is_minor,
   572     time: timestamp,
   572 		time: timestamp,
   573     draft: ( is_draft == true ),
   573 		draft: ( is_draft == true ),
   574     format: ( $dynano('ajaxEditArea').isMCE() ) ? 'xhtml' : 'wikitext',
   574 		format: ( $dynano('ajaxEditArea').isMCE() ) ? 'xhtml' : 'wikitext',
   575     used_draft: used_draft
   575 		used_draft: used_draft
   576   };
   576 	};
   577   
   577 	
   578   // Do we need to add captcha info?
   578 	// Do we need to add captcha info?
   579   if ( document.getElementById('enano_editor_field_captcha') && !is_draft )
   579 	if ( document.getElementById('enano_editor_field_captcha') && !is_draft )
   580   {
   580 	{
   581     var captcha_field = document.getElementById('enano_editor_field_captcha');
   581 		var captcha_field = document.getElementById('enano_editor_field_captcha');
   582     if ( captcha_field.value == '' )
   582 		if ( captcha_field.value == '' )
   583     {
   583 		{
   584       new MessageBox(MB_OK|MB_ICONSTOP, $lang.get('editor_err_need_captcha_title'), $lang.get('editor_err_need_captcha_body'));
   584 			new MessageBox(MB_OK|MB_ICONSTOP, $lang.get('editor_err_need_captcha_title'), $lang.get('editor_err_need_captcha_body'));
   585       ajaxUnSetEditorLoading();
   585 			ajaxUnSetEditorLoading();
   586       return false;
   586 			return false;
   587     }
   587 		}
   588     json_packet.captcha_code = captcha_field.value;
   588 		json_packet.captcha_code = captcha_field.value;
   589     json_packet.captcha_id = captcha_field.getAttribute('enano:captcha_hash');
   589 		json_packet.captcha_id = captcha_field.getAttribute('enano:captcha_hash');
   590   }
   590 	}
   591   
   591 	
   592   json_packet = ajaxEscape(toJSONString(json_packet));
   592 	json_packet = ajaxEscape(toJSONString(json_packet));
   593   ajaxPost(stdAjaxPrefix + '&_mode=savepage_json', 'r=' + json_packet, function(ajax)
   593 	ajaxPost(stdAjaxPrefix + '&_mode=savepage_json', 'r=' + json_packet, function(ajax)
   594     {
   594 		{
   595       if ( ajax.readyState == 4 && ajax.status == 200 )
   595 			if ( ajax.readyState == 4 && ajax.status == 200 )
   596       {
   596 			{
   597         ajaxUnSetEditorLoading();
   597 				ajaxUnSetEditorLoading();
   598         var response = String(ajax.responseText + '');
   598 				var response = String(ajax.responseText + '');
   599         if ( !check_json_response(response) )
   599 				if ( !check_json_response(response) )
   600         {
   600 				{
   601           handle_invalid_json(response);
   601 					handle_invalid_json(response);
   602           return false;
   602 					return false;
   603         }
   603 				}
   604         
   604 				
   605         response = parseJSON(response);
   605 				response = parseJSON(response);
   606         // This will only be used if there was a lower-level error.
   606 				// This will only be used if there was a lower-level error.
   607         if ( response.mode == 'error' )
   607 				if ( response.mode == 'error' )
   608         {
   608 				{
   609           editor_save_lock = false;
   609 					editor_save_lock = false;
   610           new MessageBox(MB_OK | MB_ICONSTOP, $lang.get('editor_err_server'), response.error);
   610 					new MessageBox(MB_OK | MB_ICONSTOP, $lang.get('editor_err_server'), response.error);
   611           return false;
   611 					return false;
   612         }
   612 				}
   613         // This will be used if the PageProcessor generated errors (usually security/permissions related)
   613 				// This will be used if the PageProcessor generated errors (usually security/permissions related)
   614         if ( response.mode == 'errors' )
   614 				if ( response.mode == 'errors' )
   615         {
   615 				{
   616           editor_save_lock = false;
   616 					editor_save_lock = false;
   617           // This will be true if the user entered a captcha code incorrectly, thus
   617 					// This will be true if the user entered a captcha code incorrectly, thus
   618           // invalidating the code and requiring a new image to be generated.
   618 					// invalidating the code and requiring a new image to be generated.
   619           if ( response.new_captcha )
   619 					if ( response.new_captcha )
   620           {
   620 					{
   621             // Generate the new captcha field
   621 						// Generate the new captcha field
   622             var img = document.getElementById('enano_editor_captcha_img');
   622 						var img = document.getElementById('enano_editor_captcha_img');
   623             var input = document.getElementById('enano_editor_field_captcha');
   623 						var input = document.getElementById('enano_editor_field_captcha');
   624             if ( img && input )
   624 						if ( img && input )
   625             {
   625 						{
   626               img._captchaHash = response.new_captcha;
   626 							img._captchaHash = response.new_captcha;
   627               input._captchaHash = response.new_captcha;
   627 							input._captchaHash = response.new_captcha;
   628               img.src = makeUrlNS('Special', 'Captcha/' + response.new_captcha);
   628 							img.src = makeUrlNS('Special', 'Captcha/' + response.new_captcha);
   629               input.value = '';
   629 							input.value = '';
   630             }
   630 						}
   631           }
   631 					}
   632           var errors = '<ul><li>' + implode('</li><li>', response.errors) + '</li></ul>';
   632 					var errors = '<ul><li>' + implode('</li><li>', response.errors) + '</li></ul>';
   633           new MessageBox(MB_OK | MB_ICONSTOP, $lang.get('editor_err_save_title'), $lang.get('editor_err_save_body') + errors);
   633 					new MessageBox(MB_OK | MB_ICONSTOP, $lang.get('editor_err_save_title'), $lang.get('editor_err_save_body') + errors);
   634           return false;
   634 					return false;
   635         }
   635 				}
   636         // If someone else got to the page first, warn the user
   636 				// If someone else got to the page first, warn the user
   637         if ( response.mode == 'obsolete' )
   637 				if ( response.mode == 'obsolete' )
   638         {
   638 				{
   639           editor_save_lock = false;
   639 					editor_save_lock = false;
   640           // Update the local timestamp to allow override
   640 					// Update the local timestamp to allow override
   641           $dynano('ajaxEditArea').object._edTimestamp = response.time;
   641 					$dynano('ajaxEditArea').object._edTimestamp = response.time;
   642           new MessageBox(MB_OK | MB_ICONEXCLAMATION, $lang.get('editor_err_obsolete_title'), $lang.get('editor_err_obsolete_body', { author: response.author, timestamp: response.date_string, page_url: makeUrl(title, false, true) }));
   642 					new MessageBox(MB_OK | MB_ICONEXCLAMATION, $lang.get('editor_err_obsolete_title'), $lang.get('editor_err_obsolete_body', { author: response.author, timestamp: response.date_string, page_url: makeUrl(title, false, true) }));
   643           return false;
   643 					return false;
   644         }
   644 				}
   645         if ( response.mode == 'success' )
   645 				if ( response.mode == 'success' )
   646         {
   646 				{
   647           if ( response.is_draft )
   647 					if ( response.is_draft )
   648           {
   648 					{
   649             document.getElementById('ajaxEditArea').used_draft = true;
   649 						document.getElementById('ajaxEditArea').used_draft = true;
   650             document.getElementById('ajaxEditArea').needReset = true;
   650 						document.getElementById('ajaxEditArea').needReset = true;
   651             var img = $dynano('ajax_edit_savedraft_btn').object.getElementsByTagName('img')[0];
   651 						var img = $dynano('ajax_edit_savedraft_btn').object.getElementsByTagName('img')[0];
   652             var lbl = $dynano('ajax_edit_savedraft_btn').object.getElementsByTagName('span')[0];
   652 						var lbl = $dynano('ajax_edit_savedraft_btn').object.getElementsByTagName('span')[0];
   653             if ( response.is_draft == 'delete' )
   653 						if ( response.is_draft == 'delete' )
   654             {
   654 						{
   655               img.src = scriptPath + '/images/editor/savedraft.gif';
   655 							img.src = scriptPath + '/images/editor/savedraft.gif';
   656               lbl.innerHTML = $lang.get('editor_btn_savedraft');
   656 							lbl.innerHTML = $lang.get('editor_btn_savedraft');
   657               
   657 							
   658               var dn = $dynano('ajax_edit_draft_notice').object;
   658 							var dn = $dynano('ajax_edit_draft_notice').object;
   659               if ( dn )
   659 							if ( dn )
   660               {
   660 							{
   661                 dn.parentNode.removeChild(dn);
   661 								dn.parentNode.removeChild(dn);
   662               }
   662 							}
   663             }
   663 						}
   664             else
   664 						else
   665             {
   665 						{
   666               img.src = scriptPath + '/images/mini-info.png';
   666 							img.src = scriptPath + '/images/mini-info.png';
   667               var d = new Date();
   667 							var d = new Date();
   668               var m = String(d.getMinutes());
   668 							var m = String(d.getMinutes());
   669               if ( m.length < 2 )
   669 							if ( m.length < 2 )
   670                 m = '0' + m;
   670 								m = '0' + m;
   671               var time = d.getHours() + ':' + m;
   671 							var time = d.getHours() + ':' + m;
   672               lbl.innerHTML = $lang.get('editor_msg_draft_saved', { time: time });
   672 							lbl.innerHTML = $lang.get('editor_msg_draft_saved', { time: time });
   673             }
   673 						}
   674             editor_save_lock = false;
   674 						editor_save_lock = false;
   675           }
   675 					}
   676           else
   676 					else
   677           {
   677 					{
   678             // The save was successful; reset flags and make another request for the new page content
   678 						// The save was successful; reset flags and make another request for the new page content
   679             setAjaxLoading();
   679 						setAjaxLoading();
   680             editor_open = false;
   680 						editor_open = false;
   681             editor_save_lock = false;
   681 						editor_save_lock = false;
   682             enableUnload();
   682 						enableUnload();
   683             $dynano('ajaxEditArea').destroyMCE(false);
   683 						$dynano('ajaxEditArea').destroyMCE(false);
   684             changeOpac(0, 'ajaxEditContainer');
   684 						changeOpac(0, 'ajaxEditContainer');
   685             ajaxGet(stdAjaxPrefix + '&_mode=getpage&noheaders', function(ajax)
   685 						ajaxGet(stdAjaxPrefix + '&_mode=getpage&noheaders', function(ajax)
   686               {
   686 							{
   687                 if ( ajax.readyState == 4 && ajax.status == 200 )
   687 								if ( ajax.readyState == 4 && ajax.status == 200 )
   688                 {
   688 								{
   689                   unsetAjaxLoading();
   689 									unsetAjaxLoading();
   690                   selectButtonMajor('article');
   690 									selectButtonMajor('article');
   691                   unselectAllButtonsMinor();
   691 									unselectAllButtonsMinor();
   692                   
   692 									
   693                   ajaxEditorDestroyModalWindow();
   693 									ajaxEditorDestroyModalWindow();
   694                   document.getElementById('ajaxEditContainer').innerHTML = '<div class="usermessage">' + $lang.get('editor_msg_saved') + '</div>' + ajax.responseText;
   694 									document.getElementById('ajaxEditContainer').innerHTML = '<div class="usermessage">' + $lang.get('editor_msg_saved') + '</div>' + ajax.responseText;
   695                   // if we're on a userpage, call the onload function to rebuild the tabs
   695 									// if we're on a userpage, call the onload function to rebuild the tabs
   696                   if ( typeof(userpage_onload) == 'function' )
   696 									if ( typeof(userpage_onload) == 'function' )
   697                   {
   697 									{
   698                     window.userpage_blocks = [];
   698 										window.userpage_blocks = [];
   699                     userpage_onload();
   699 										userpage_onload();
   700                   }
   700 									}
   701                   opacity('ajaxEditContainer', 0, 100, 1000);
   701 									opacity('ajaxEditContainer', 0, 100, 1000);
   702                 }
   702 								}
   703               });
   703 							});
   704           }
   704 					}
   705         }
   705 				}
   706       }
   706 			}
   707     }, true);
   707 		}, true);
   708 }
   708 }
   709 
   709 
   710 // Delete the draft (this is a massive server-side hack)
   710 // Delete the draft (this is a massive server-side hack)
   711 window.ajaxEditorDeleteDraft = function()
   711 window.ajaxEditorDeleteDraft = function()
   712 {
   712 {
   713   miniPromptMessage({
   713 	miniPromptMessage({
   714       title: $lang.get('editor_msg_confirm_delete_draft_title'),
   714 			title: $lang.get('editor_msg_confirm_delete_draft_title'),
   715       message: $lang.get('editor_msg_confirm_delete_draft_body'),
   715 			message: $lang.get('editor_msg_confirm_delete_draft_body'),
   716       buttons: [
   716 			buttons: [
   717           {
   717 					{
   718             text: $lang.get('editor_btn_delete_draft'),
   718 						text: $lang.get('editor_btn_delete_draft'),
   719             color: 'red',
   719 						color: 'red',
   720             style: {
   720 						style: {
   721               fontWeight: 'bold'
   721 							fontWeight: 'bold'
   722             },
   722 						},
   723             onclick: function() {
   723 						onclick: function() {
   724               ajaxEditorDeleteDraftReal();
   724 							ajaxEditorDeleteDraftReal();
   725               miniPromptDestroy(this);
   725 							miniPromptDestroy(this);
   726             }
   726 						}
   727           },
   727 					},
   728           {
   728 					{
   729             text: $lang.get('etc_cancel'),
   729 						text: $lang.get('etc_cancel'),
   730             onclick: function() {
   730 						onclick: function() {
   731               miniPromptDestroy(this);
   731 							miniPromptDestroy(this);
   732             }
   732 						}
   733           }
   733 					}
   734         ]
   734 				]
   735     });
   735 		});
   736 }
   736 }
   737 
   737 
   738 window.ajaxEditorDeleteDraftReal = function()
   738 window.ajaxEditorDeleteDraftReal = function()
   739 {
   739 {
   740   return ajaxEditorSave(true, -1);
   740 	return ajaxEditorSave(true, -1);
   741 }
   741 }
   742 
   742 
   743 window.ajaxEditorGenPreview = function()
   743 window.ajaxEditorGenPreview = function()
   744 {
   744 {
   745   ajaxSetEditorLoading();
   745 	ajaxSetEditorLoading();
   746   var ta_content = $dynano('ajaxEditArea').getContent();
   746 	var ta_content = $dynano('ajaxEditArea').getContent();
   747   ta_content = ajaxEscape(ta_content);
   747 	ta_content = ajaxEscape(ta_content);
   748   if ( $dynano('enano_editor_preview').object.innerHTML != '' )
   748 	if ( $dynano('enano_editor_preview').object.innerHTML != '' )
   749   {
   749 	{
   750     opacity('enano_editor_preview', 100, 0, 500);
   750 		opacity('enano_editor_preview', 100, 0, 500);
   751   }
   751 	}
   752   ajaxPost(stdAjaxPrefix + '&_mode=preview', 'text=' + ta_content, function(ajax)
   752 	ajaxPost(stdAjaxPrefix + '&_mode=preview', 'text=' + ta_content, function(ajax)
   753     {
   753 		{
   754       if ( ajax.readyState == 4 && ajax.status == 200 )
   754 			if ( ajax.readyState == 4 && ajax.status == 200 )
   755       {
   755 			{
   756         ajaxUnSetEditorLoading();
   756 				ajaxUnSetEditorLoading();
   757         changeOpac(0, 'enano_editor_preview');
   757 				changeOpac(0, 'enano_editor_preview');
   758         $dynano('enano_editor_preview').object.innerHTML = ajax.responseText;
   758 				$dynano('enano_editor_preview').object.innerHTML = ajax.responseText;
   759         window.location.hash = '#ajax_preview';
   759 				window.location.hash = '#ajax_preview';
   760         opacity('enano_editor_preview', 0, 100, 500);
   760 				opacity('enano_editor_preview', 0, 100, 500);
   761       }
   761 			}
   762     }, true);
   762 		}, true);
   763 }
   763 }
   764 
   764 
   765 window.ajaxEditorRevertToLatest = function()
   765 window.ajaxEditorRevertToLatest = function()
   766 {
   766 {
   767   miniPromptMessage({
   767 	miniPromptMessage({
   768       title: $lang.get('editor_msg_revert_confirm_title'),
   768 			title: $lang.get('editor_msg_revert_confirm_title'),
   769       message: $lang.get('editor_msg_revert_confirm_body'),
   769 			message: $lang.get('editor_msg_revert_confirm_body'),
   770       buttons: [
   770 			buttons: [
   771         {
   771 				{
   772           text: $lang.get('editor_btn_revert_confirm'),
   772 					text: $lang.get('editor_btn_revert_confirm'),
   773           color: 'red',
   773 					color: 'red',
   774           sprite: [ editor_img_path + '/sprite.png', 16, 16, 0, 48 ],
   774 					sprite: [ editor_img_path + '/sprite.png', 16, 16, 0, 48 ],
   775           style: {
   775 					style: {
   776             fontWeight: 'bold'
   776 						fontWeight: 'bold'
   777           },
   777 					},
   778           onclick: function()
   778 					onclick: function()
   779           {
   779 					{
   780             ajaxEditorRevertToLatestReal();
   780 						ajaxEditorRevertToLatestReal();
   781             miniPromptDestroy(this);
   781 						miniPromptDestroy(this);
   782             return false;
   782 						return false;
   783           }
   783 					}
   784         },
   784 				},
   785         {
   785 				{
   786           text: $lang.get('etc_cancel'),
   786 					text: $lang.get('etc_cancel'),
   787           onclick: function()
   787 					onclick: function()
   788           {
   788 					{
   789             miniPromptDestroy(this);
   789 						miniPromptDestroy(this);
   790             return false;
   790 						return false;
   791           }
   791 					}
   792         }
   792 				}
   793       ]
   793 			]
   794     });
   794 		});
   795 }
   795 }
   796 
   796 
   797 window.ajaxEditorRevertToLatestReal = function()
   797 window.ajaxEditorRevertToLatestReal = function()
   798 {
   798 {
   799   ajaxSetEditorLoading();
   799 	ajaxSetEditorLoading();
   800   ajaxGet(stdAjaxPrefix + '&_mode=getsource', function(ajax)
   800 	ajaxGet(stdAjaxPrefix + '&_mode=getsource', function(ajax)
   801     {
   801 		{
   802       if ( ajax.readyState == 4 && ajax.status == 200 )
   802 			if ( ajax.readyState == 4 && ajax.status == 200 )
   803       {
   803 			{
   804         ajaxUnSetEditorLoading();
   804 				ajaxUnSetEditorLoading();
   805         
   805 				
   806         var response = String(ajax.responseText + '');
   806 				var response = String(ajax.responseText + '');
   807         if ( !check_json_response(response) )
   807 				if ( !check_json_response(response) )
   808         {
   808 				{
   809           handle_invalid_json(response);
   809 					handle_invalid_json(response);
   810           return false;
   810 					return false;
   811         }
   811 				}
   812         
   812 				
   813         response = parseJSON(response);
   813 				response = parseJSON(response);
   814         if ( response.mode == 'error' )
   814 				if ( response.mode == 'error' )
   815         {
   815 				{
   816           unselectAllButtonsMinor();
   816 					unselectAllButtonsMinor();
   817           new MessageBox(MB_OK | MB_ICONSTOP, $lang.get('editor_err_server'), response.error);
   817 					new MessageBox(MB_OK | MB_ICONSTOP, $lang.get('editor_err_server'), response.error);
   818           return false;
   818 					return false;
   819         }
   819 				}
   820         
   820 				
   821         if ( !response.auth_view_source )
   821 				if ( !response.auth_view_source )
   822         {
   822 				{
   823           unselectAllButtonsMinor();
   823 					unselectAllButtonsMinor();
   824           new MessageBox(MB_OK | MB_ICONSTOP, $lang.get('editor_err_access_denied_title'), $lang.get('editor_err_access_denied_body'));
   824 					new MessageBox(MB_OK | MB_ICONSTOP, $lang.get('editor_err_access_denied_title'), $lang.get('editor_err_access_denied_body'));
   825           return false;
   825 					return false;
   826         }
   826 				}
   827         
   827 				
   828         setTimeout(function()
   828 				setTimeout(function()
   829           {
   829 					{
   830             editor_convert_if_needed(response.page_format);
   830 						editor_convert_if_needed(response.page_format);
   831             $dynano('ajaxEditArea').setContent(response.src);
   831 						$dynano('ajaxEditArea').setContent(response.src);
   832           }, aclDisableTransitionFX ? 10 : 750);
   832 					}, aclDisableTransitionFX ? 10 : 750);
   833       }
   833 			}
   834     }, true);
   834 		}, true);
   835 }
   835 }
   836 
   836 
   837 window.ajaxEditorShowDiffs = function()
   837 window.ajaxEditorShowDiffs = function()
   838 {
   838 {
   839   ajaxSetEditorLoading();
   839 	ajaxSetEditorLoading();
   840   var ta_content = $dynano('ajaxEditArea').getContent();
   840 	var ta_content = $dynano('ajaxEditArea').getContent();
   841   ta_content = ajaxEscape(ta_content);
   841 	ta_content = ajaxEscape(ta_content);
   842   if ( $dynano('enano_editor_preview').object.innerHTML != '' )
   842 	if ( $dynano('enano_editor_preview').object.innerHTML != '' )
   843   {
   843 	{
   844     opacity('enano_editor_preview', 100, 0, 500);
   844 		opacity('enano_editor_preview', 100, 0, 500);
   845   }
   845 	}
   846   ajaxPost(stdAjaxPrefix + '&_mode=diff_cur', 'text=' + ta_content, function(ajax)
   846 	ajaxPost(stdAjaxPrefix + '&_mode=diff_cur', 'text=' + ta_content, function(ajax)
   847     {
   847 		{
   848       if ( ajax.readyState == 4 && ajax.status == 200 )
   848 			if ( ajax.readyState == 4 && ajax.status == 200 )
   849       {
   849 			{
   850         ajaxUnSetEditorLoading();
   850 				ajaxUnSetEditorLoading();
   851         changeOpac(0, 'enano_editor_preview');
   851 				changeOpac(0, 'enano_editor_preview');
   852         $dynano('enano_editor_preview').object.innerHTML = ajax.responseText;
   852 				$dynano('enano_editor_preview').object.innerHTML = ajax.responseText;
   853         window.location.hash = '#ajax_preview';
   853 				window.location.hash = '#ajax_preview';
   854         opacity('enano_editor_preview', 0, 100, 500);
   854 				opacity('enano_editor_preview', 0, 100, 500);
   855       }
   855 			}
   856     }, true);
   856 		}, true);
   857 }
   857 }
   858 
   858 
   859 window.ajaxEditorCancel = function()
   859 window.ajaxEditorCancel = function()
   860 {
   860 {
   861   miniPromptMessage({
   861 	miniPromptMessage({
   862       title: $lang.get('editor_msg_cancel_confirm_title'),
   862 			title: $lang.get('editor_msg_cancel_confirm_title'),
   863       message: $lang.get('editor_msg_cancel_confirm_body'),
   863 			message: $lang.get('editor_msg_cancel_confirm_body'),
   864       buttons: [
   864 			buttons: [
   865         {
   865 				{
   866           text: $lang.get('editor_btn_cancel_confirm'),
   866 					text: $lang.get('editor_btn_cancel_confirm'),
   867           color: 'red',
   867 					color: 'red',
   868           sprite: [ editor_img_path + '/sprite.png', 16, 16, 0, 16 ],
   868 					sprite: [ editor_img_path + '/sprite.png', 16, 16, 0, 16 ],
   869           style: {
   869 					style: {
   870             fontWeight: 'bold'
   870 						fontWeight: 'bold'
   871           },
   871 					},
   872           onclick: function()
   872 					onclick: function()
   873           {
   873 					{
   874             setAjaxLoading();
   874 						setAjaxLoading();
   875             ajaxEditorDestroyModalWindow();
   875 						ajaxEditorDestroyModalWindow();
   876             editor_open = false;
   876 						editor_open = false;
   877             enableUnload();
   877 						enableUnload();
   878             $dynano('ajaxEditArea').destroyMCE(false);
   878 						$dynano('ajaxEditArea').destroyMCE(false);
   879             ajaxReset();
   879 						ajaxReset();
   880             miniPromptDestroy(this);
   880 						miniPromptDestroy(this);
   881             return false;
   881 						return false;
   882           }
   882 					}
   883         },
   883 				},
   884         {
   884 				{
   885           text: $lang.get('editor_btn_cancel_cancel'),
   885 					text: $lang.get('editor_btn_cancel_cancel'),
   886           onclick: function()
   886 					onclick: function()
   887           {
   887 					{
   888             miniPromptDestroy(this);
   888 						miniPromptDestroy(this);
   889             return false;
   889 						return false;
   890           }
   890 					}
   891         }
   891 				}
   892       ]
   892 			]
   893     });
   893 		});
   894 }
   894 }
   895 
   895 
   896 window.ajaxSetEditorMCE = function(confirmed)
   896 window.ajaxSetEditorMCE = function(confirmed)
   897 {
   897 {
   898   if ( editor_loading )
   898 	if ( editor_loading )
   899     return false;
   899 		return false;
   900   
   900 	
   901   if ( !confirmed )
   901 	if ( !confirmed )
   902   {
   902 	{
   903     miniPromptMessage({
   903 		miniPromptMessage({
   904         title: $lang.get('editor_msg_convert_confirm_title'),
   904 				title: $lang.get('editor_msg_convert_confirm_title'),
   905         message: $lang.get('editor_msg_convert_confirm_body'),
   905 				message: $lang.get('editor_msg_convert_confirm_body'),
   906         buttons: [
   906 				buttons: [
   907           {
   907 					{
   908             color: 'blue',
   908 						color: 'blue',
   909             text: $lang.get('editor_btn_graphical'),
   909 						text: $lang.get('editor_btn_graphical'),
   910             style: {
   910 						style: {
   911               fontWeight: 'bold'
   911 							fontWeight: 'bold'
   912             },
   912 						},
   913             sprite: [ editor_img_path + '/sprite.png', 16, 16, 0, 112 ],
   913 						sprite: [ editor_img_path + '/sprite.png', 16, 16, 0, 112 ],
   914             onclick: function()
   914 						onclick: function()
   915             {
   915 						{
   916               ajaxSetEditorMCE(true);
   916 							ajaxSetEditorMCE(true);
   917               miniPromptDestroy(this);
   917 							miniPromptDestroy(this);
   918               return false;
   918 							return false;
   919             }
   919 						}
   920           },
   920 					},
   921           {
   921 					{
   922             text: $lang.get('etc_cancel'),
   922 						text: $lang.get('etc_cancel'),
   923             onclick: function()
   923 						onclick: function()
   924             {
   924 						{
   925               miniPromptDestroy(this);
   925 							miniPromptDestroy(this);
   926               return false;
   926 							return false;
   927             }
   927 						}
   928           }
   928 					}
   929         ]
   929 				]
   930       });
   930 			});
   931     return false;
   931 		return false;
   932   }
   932 	}
   933   
   933 	
   934   // Clear out existing buttons
   934 	// Clear out existing buttons
   935   var span_wiki = $dynano('enano_edit_btn_pt').object;
   935 	var span_wiki = $dynano('enano_edit_btn_pt').object;
   936   var span_mce  = $dynano('enano_edit_btn_mce').object;
   936 	var span_mce  = $dynano('enano_edit_btn_mce').object;
   937   span_wiki.style.display = 'inline';
   937 	span_wiki.style.display = 'inline';
   938   span_mce.style.display = 'none';
   938 	span_mce.style.display = 'none';
   939   
   939 	
   940   // Swap editor
   940 	// Swap editor
   941   $dynano('ajaxEditArea').switchToMCE(true);
   941 	$dynano('ajaxEditArea').switchToMCE(true);
   942 }
   942 }
   943 
   943 
   944 window.ajaxSetEditorPlain = function(confirmed)
   944 window.ajaxSetEditorPlain = function(confirmed)
   945 {
   945 {
   946   if ( editor_loading )
   946 	if ( editor_loading )
   947     return false;
   947 		return false;
   948   
   948 	
   949   if ( !confirmed )
   949 	if ( !confirmed )
   950   {
   950 	{
   951     miniPromptMessage({
   951 		miniPromptMessage({
   952         title: $lang.get('editor_msg_convert_confirm_title'),
   952 				title: $lang.get('editor_msg_convert_confirm_title'),
   953         message: $lang.get('editor_msg_convert_confirm_body'),
   953 				message: $lang.get('editor_msg_convert_confirm_body'),
   954         buttons: [
   954 				buttons: [
   955           {
   955 					{
   956             color: 'green',
   956 						color: 'green',
   957             text: $lang.get('editor_btn_wikitext'),
   957 						text: $lang.get('editor_btn_wikitext'),
   958             style: {
   958 						style: {
   959               fontWeight: 'bold'
   959 							fontWeight: 'bold'
   960             },
   960 						},
   961             sprite: [ editor_img_path + '/sprite.png', 16, 16, 0, 96 ],
   961 						sprite: [ editor_img_path + '/sprite.png', 16, 16, 0, 96 ],
   962             onclick: function()
   962 						onclick: function()
   963             {
   963 						{
   964               ajaxSetEditorPlain(true);
   964 							ajaxSetEditorPlain(true);
   965               miniPromptDestroy(this);
   965 							miniPromptDestroy(this);
   966               return false;
   966 							return false;
   967             }
   967 						}
   968           },
   968 					},
   969           {
   969 					{
   970             text: $lang.get('etc_cancel'),
   970 						text: $lang.get('etc_cancel'),
   971             onclick: function()
   971 						onclick: function()
   972             {
   972 						{
   973               miniPromptDestroy(this);
   973 							miniPromptDestroy(this);
   974               return false;
   974 							return false;
   975             }
   975 						}
   976           }
   976 					}
   977         ]
   977 				]
   978       });
   978 			});
   979     return false;
   979 		return false;
   980   }
   980 	}
   981   
   981 	
   982   // Clear out existing buttons
   982 	// Clear out existing buttons
   983   var span_wiki = $dynano('enano_edit_btn_pt').object;
   983 	var span_wiki = $dynano('enano_edit_btn_pt').object;
   984   var span_mce  = $dynano('enano_edit_btn_mce').object;
   984 	var span_mce  = $dynano('enano_edit_btn_mce').object;
   985   span_wiki.style.display = 'none';
   985 	span_wiki.style.display = 'none';
   986   span_mce.style.display = 'inline';
   986 	span_mce.style.display = 'inline';
   987   
   987 	
   988   // Swap editor
   988 	// Swap editor
   989   $dynano('ajaxEditArea').destroyMCE(true);
   989 	$dynano('ajaxEditArea').destroyMCE(true);
   990 }
   990 }
   991 
   991 
   992 var editor_loading = false;
   992 var editor_loading = false;
   993 
   993 
   994 window.ajaxSetEditorLoading = function()
   994 window.ajaxSetEditorLoading = function()
   995 {
   995 {
   996   var ed = false;
   996 	var ed = false;
   997   if ( window.tinyMCE )
   997 	if ( window.tinyMCE )
   998   {
   998 	{
   999     ed = tinyMCE.get('ajaxEditArea');
   999 		ed = tinyMCE.get('ajaxEditArea');
  1000   }
  1000 	}
  1001   editor_loading = true;
  1001 	editor_loading = true;
  1002   if ( ed )
  1002 	if ( ed )
  1003   {
  1003 	{
  1004     ed.setProgressState(1);
  1004 		ed.setProgressState(1);
  1005   }
  1005 	}
  1006   else
  1006 	else
  1007   {
  1007 	{
  1008     ed = document.getElementById('ajaxEditArea');
  1008 		ed = document.getElementById('ajaxEditArea');
  1009     var blackout = document.createElement('div');
  1009 		var blackout = document.createElement('div');
  1010     blackout.style.position = 'absolute';
  1010 		blackout.style.position = 'absolute';
  1011     blackout.style.top = $dynano('ajaxEditArea').Top() + 'px';
  1011 		blackout.style.top = $dynano('ajaxEditArea').Top() + 'px';
  1012     blackout.style.left = $dynano('ajaxEditArea').Left() + 'px';
  1012 		blackout.style.left = $dynano('ajaxEditArea').Left() + 'px';
  1013     blackout.style.width = $dynano('ajaxEditArea').Width() + 'px';
  1013 		blackout.style.width = $dynano('ajaxEditArea').Width() + 'px';
  1014     blackout.style.height = $dynano('ajaxEditArea').Height() + 'px';
  1014 		blackout.style.height = $dynano('ajaxEditArea').Height() + 'px';
  1015     blackout.style.backgroundColor = '#FFFFFF';
  1015 		blackout.style.backgroundColor = '#FFFFFF';
  1016     domObjChangeOpac(60, blackout);
  1016 		domObjChangeOpac(60, blackout);
  1017     blackout.style.backgroundImage = 'url(' + scriptPath + '/includes/clientside/tinymce/themes/advanced/skins/default/img/progress.gif)';
  1017 		blackout.style.backgroundImage = 'url(' + scriptPath + '/includes/clientside/tinymce/themes/advanced/skins/default/img/progress.gif)';
  1018     blackout.style.backgroundPosition = 'center center';
  1018 		blackout.style.backgroundPosition = 'center center';
  1019     blackout.style.backgroundRepeat = 'no-repeat';
  1019 		blackout.style.backgroundRepeat = 'no-repeat';
  1020     blackout.id = 'enano_editor_blackout';
  1020 		blackout.id = 'enano_editor_blackout';
  1021     blackout.style.zIndex = getHighestZ() + 2;
  1021 		blackout.style.zIndex = getHighestZ() + 2;
  1022     
  1022 		
  1023     var body = document.getElementsByTagName('body')[0];
  1023 		var body = document.getElementsByTagName('body')[0];
  1024     body.appendChild(blackout);
  1024 		body.appendChild(blackout);
  1025   }
  1025 	}
  1026 }
  1026 }
  1027 
  1027 
  1028 window.ajaxUnSetEditorLoading = function()
  1028 window.ajaxUnSetEditorLoading = function()
  1029 {
  1029 {
  1030   editor_loading = false;
  1030 	editor_loading = false;
  1031   var ed = false;
  1031 	var ed = false;
  1032   if ( window.tinyMCE )
  1032 	if ( window.tinyMCE )
  1033   {
  1033 	{
  1034     ed = tinyMCE.get('ajaxEditArea');
  1034 		ed = tinyMCE.get('ajaxEditArea');
  1035   }
  1035 	}
  1036   if ( ed )
  1036 	if ( ed )
  1037   {
  1037 	{
  1038     ed.setProgressState(0);
  1038 		ed.setProgressState(0);
  1039   }
  1039 	}
  1040   else
  1040 	else
  1041   {
  1041 	{
  1042     var blackout = document.getElementById('enano_editor_blackout');
  1042 		var blackout = document.getElementById('enano_editor_blackout');
  1043     var body = document.getElementsByTagName('body')[0];
  1043 		var body = document.getElementsByTagName('body')[0];
  1044     if ( !blackout )
  1044 		if ( !blackout )
  1045       return false;
  1045 			return false;
  1046     body.removeChild(blackout);
  1046 		body.removeChild(blackout);
  1047   }
  1047 	}
  1048 }
  1048 }
  1049 
  1049 
  1050 window.ajaxAutosaveDraft = function()
  1050 window.ajaxAutosaveDraft = function()
  1051 {
  1051 {
  1052   var aed = document.getElementById('ajaxEditArea');
  1052 	var aed = document.getElementById('ajaxEditArea');
  1053   if ( !aed )
  1053 	if ( !aed )
  1054     return false;
  1054 		return false;
  1055   var last_save = aed.as_last_save;
  1055 	var last_save = aed.as_last_save;
  1056   var now = unix_time();
  1056 	var now = unix_time();
  1057   if ( ( last_save + 120 ) < now && aed.value != aed.content_orig )
  1057 	if ( ( last_save + 120 ) < now && aed.value != aed.content_orig )
  1058   {
  1058 	{
  1059     ajaxPerformAutosave();
  1059 		ajaxPerformAutosave();
  1060   }
  1060 	}
  1061 }
  1061 }
  1062 
  1062 
  1063 window.ajaxPerformAutosave = function()
  1063 window.ajaxPerformAutosave = function()
  1064 {
  1064 {
  1065   var aed = document.getElementById('ajaxEditArea');
  1065 	var aed = document.getElementById('ajaxEditArea');
  1066   if ( !aed )
  1066 	if ( !aed )
  1067     return false;
  1067 		return false;
  1068   var now = unix_time();
  1068 	var now = unix_time();
  1069   aed.as_last_save = now;
  1069 	aed.as_last_save = now;
  1070   
  1070 	
  1071   var ta_content = $dynano('ajaxEditArea').getContent();
  1071 	var ta_content = $dynano('ajaxEditArea').getContent();
  1072   
  1072 	
  1073   if ( ta_content == '' || ta_content == '<p></p>' || ta_content == '<p>&nbsp;</p>' )
  1073 	if ( ta_content == '' || ta_content == '<p></p>' || ta_content == '<p>&nbsp;</p>' )
  1074   {
  1074 	{
  1075     return false;
  1075 		return false;
  1076   }
  1076 	}
  1077   
  1077 	
  1078   ajaxEditorSave(true);
  1078 	ajaxEditorSave(true);
  1079 }
  1079 }
  1080 
  1080 
  1081 window.ajaxEditorUseDraft = function()
  1081 window.ajaxEditorUseDraft = function()
  1082 {
  1082 {
  1083   var aed = document.getElementById('ajaxEditArea');
  1083 	var aed = document.getElementById('ajaxEditArea');
  1084   if ( !aed )
  1084 	if ( !aed )
  1085     return false;
  1085 		return false;
  1086   ajaxSetEditorLoading();
  1086 	ajaxSetEditorLoading();
  1087   ajaxGet(stdAjaxPrefix + '&_mode=getsource&get_draft=1', function(ajax)
  1087 	ajaxGet(stdAjaxPrefix + '&_mode=getsource&get_draft=1', function(ajax)
  1088     {
  1088 		{
  1089       if ( ajax.readyState == 4 && ajax.status == 200 )
  1089 			if ( ajax.readyState == 4 && ajax.status == 200 )
  1090       {
  1090 			{
  1091         ajaxUnSetEditorLoading();
  1091 				ajaxUnSetEditorLoading();
  1092         
  1092 				
  1093         var response = String(ajax.responseText + '');
  1093 				var response = String(ajax.responseText + '');
  1094         if ( !check_json_response(response) )
  1094 				if ( !check_json_response(response) )
  1095         {
  1095 				{
  1096           handle_invalid_json(response);
  1096 					handle_invalid_json(response);
  1097           return false;
  1097 					return false;
  1098         }
  1098 				}
  1099         
  1099 				
  1100         response = parseJSON(response);
  1100 				response = parseJSON(response);
  1101         if ( response.mode == 'error' )
  1101 				if ( response.mode == 'error' )
  1102         {
  1102 				{
  1103           unselectAllButtonsMinor();
  1103 					unselectAllButtonsMinor();
  1104           new MessageBox(MB_OK | MB_ICONSTOP, $lang.get('editor_err_server'), response.error);
  1104 					new MessageBox(MB_OK | MB_ICONSTOP, $lang.get('editor_err_server'), response.error);
  1105           return false;
  1105 					return false;
  1106         }
  1106 				}
  1107         
  1107 				
  1108         editor_convert_if_needed(response.page_format);
  1108 				editor_convert_if_needed(response.page_format);
  1109         
  1109 				
  1110         $dynano('ajaxEditArea').setContent(response.src);
  1110 				$dynano('ajaxEditArea').setContent(response.src);
  1111         $dynano('ajaxEditArea').object.used_draft = true;
  1111 				$dynano('ajaxEditArea').object.used_draft = true;
  1112         
  1112 				
  1113         var es = document.getElementById('enano_editor_field_summary');
  1113 				var es = document.getElementById('enano_editor_field_summary');
  1114         if ( es.value == '' )
  1114 				if ( es.value == '' )
  1115         {
  1115 				{
  1116           es.value = response.edit_summary;
  1116 					es.value = response.edit_summary;
  1117         }
  1117 				}
  1118         
  1118 				
  1119         var dn = $dynano('ajax_edit_draft_notice').object;
  1119 				var dn = $dynano('ajax_edit_draft_notice').object;
  1120         dn.parentNode.removeChild(dn);
  1120 				dn.parentNode.removeChild(dn);
  1121       }
  1121 			}
  1122     }, true);
  1122 		}, true);
  1123 }
  1123 }
  1124 
  1124 
  1125 window.editor_convert_if_needed = function(targetformat, noticetitle, noticebody)
  1125 window.editor_convert_if_needed = function(targetformat, noticetitle, noticebody)
  1126 {
  1126 {
  1127   // Do we need to change the format?
  1127 	// Do we need to change the format?
  1128   var need_to_mce = ( targetformat == 'xhtml' && !$dynano('ajaxEditArea').isMCE() );
  1128 	var need_to_mce = ( targetformat == 'xhtml' && !$dynano('ajaxEditArea').isMCE() );
  1129   var need_to_wkt = ( targetformat == 'wikitext' && $dynano('ajaxEditArea').isMCE() );
  1129 	var need_to_wkt = ( targetformat == 'wikitext' && $dynano('ajaxEditArea').isMCE() );
  1130   if ( need_to_mce )
  1130 	if ( need_to_mce )
  1131   {
  1131 	{
  1132     $dynano('ajaxEditArea').setContent('');
  1132 		$dynano('ajaxEditArea').setContent('');
  1133     $dynano('ajaxEditArea').switchToMCE(false);
  1133 		$dynano('ajaxEditArea').switchToMCE(false);
  1134     
  1134 		
  1135     // Clear out existing buttons
  1135 		// Clear out existing buttons
  1136     var span_wiki = $dynano('enano_edit_btn_pt').object;
  1136 		var span_wiki = $dynano('enano_edit_btn_pt').object;
  1137     var span_mce  = $dynano('enano_edit_btn_mce').object;
  1137 		var span_mce  = $dynano('enano_edit_btn_mce').object;
  1138     span_wiki.style.display = 'inline';
  1138 		span_wiki.style.display = 'inline';
  1139     span_mce.style.display = 'none';
  1139 		span_mce.style.display = 'none';
  1140   }
  1140 	}
  1141   else if ( need_to_wkt )
  1141 	else if ( need_to_wkt )
  1142   {
  1142 	{
  1143     $dynano('ajaxEditArea').setContent('');
  1143 		$dynano('ajaxEditArea').setContent('');
  1144     $dynano('ajaxEditArea').destroyMCE(false);
  1144 		$dynano('ajaxEditArea').destroyMCE(false);
  1145     
  1145 		
  1146     // Clear out existing buttons
  1146 		// Clear out existing buttons
  1147     var span_wiki = $dynano('enano_edit_btn_pt').object;
  1147 		var span_wiki = $dynano('enano_edit_btn_pt').object;
  1148     var span_mce  = $dynano('enano_edit_btn_mce').object;
  1148 		var span_mce  = $dynano('enano_edit_btn_mce').object;
  1149     span_wiki.style.display = 'none';
  1149 		span_wiki.style.display = 'none';
  1150     span_mce.style.display = 'inline';
  1150 		span_mce.style.display = 'inline';
  1151   }
  1151 	}
  1152   if ( need_to_mce || need_to_wkt )
  1152 	if ( need_to_mce || need_to_wkt )
  1153   {
  1153 	{
  1154     // explain the conversion
  1154 		// explain the conversion
  1155     if ( !noticetitle )
  1155 		if ( !noticetitle )
  1156       noticetitle = 'editor_msg_convert_draft_load_title';
  1156 			noticetitle = 'editor_msg_convert_draft_load_title';
  1157     if ( !noticebody )
  1157 		if ( !noticebody )
  1158       noticebody = 'editor_msg_convert_draft_load_body';
  1158 			noticebody = 'editor_msg_convert_draft_load_body';
  1159     
  1159 		
  1160     miniPromptMessage({
  1160 		miniPromptMessage({
  1161         title: $lang.get(noticetitle),
  1161 				title: $lang.get(noticetitle),
  1162         message: $lang.get(noticebody),
  1162 				message: $lang.get(noticebody),
  1163         buttons: [
  1163 				buttons: [
  1164           {
  1164 					{
  1165             text: $lang.get('etc_ok'),
  1165 						text: $lang.get('etc_ok'),
  1166             onclick: function()
  1166 						onclick: function()
  1167             {
  1167 						{
  1168               miniPromptDestroy(this);
  1168 							miniPromptDestroy(this);
  1169               return false;
  1169 							return false;
  1170             }
  1170 						}
  1171           }
  1171 					}
  1172         ]
  1172 				]
  1173       });
  1173 			});
  1174   }
  1174 	}
  1175 }
  1175 }