b2evolution PHP Cross Reference Blogging Systems

Source: /rsc/js/admin.js - 139 lines - 4162 bytes - Summary - Text - Print

Description: General functions for the backoffice. b2evolution - http://b2evolution.net/

   1  /**
   2   * General functions for the backoffice.
   3   * b2evolution - http://b2evolution.net/
   4   * @version $Id: admin.js 5563 2014-01-06 10:21:07Z attila $
   5   */
   6  
   7  
   8  /**
   9   * Set the action attribute on a form, including a Safari fix.
  10   *
  11   * This is so complicated, because the form also can have a (hidden) action value.
  12   *
  13   * @return boolean
  14   */
  15  function set_new_form_action( form, newaction )
  16  {
  17      // Stupid thing: having a field called action !
  18      var saved_action = form.attributes.getNamedItem('action').value;
  19      form.attributes.getNamedItem('action').value = newaction;
  20  
  21      // requested host+directory, used for Opera workaround below
  22      var reqdir = location.href.replace(/(\/)[^\/]*$/, "$1");
  23  
  24      // FIX for Safari (2.0.2, OS X 10.4.3) - (Konqueror does not fail here)
  25      if( form.attributes.getNamedItem('action').value != newaction
  26          && form.attributes.getNamedItem('action').value != reqdir+newaction /* Opera 9.25: action holds the complete URL, not just the given filename */
  27      )
  28      { // Setting form.action failed! (This is the case for Safari)
  29          // NOTE: checking "form.action == saved_action" (or through document.getElementById()) does not work - Safari uses the input element then
  30          { // _Setting_ form.action however sets the form's action attribute (not the input element) on Safari
  31              form.action = newaction;
  32          }
  33  
  34          if( form.attributes.getNamedItem('action').value != newaction )
  35          { // Still old value, did not work.
  36              alert('set_new_form_action: Cannot set new form action (Safari workaround).');
  37              return false;
  38          }
  39      }
  40      // END FIX for Safari
  41  
  42      return true;
  43  }
  44  
  45  
  46  /**
  47   * Open the item in a preview window (a new window with target 'b2evo_preview'), by changing
  48   * the form's action attribute and target temporarily.
  49   *
  50   * fp> This is gonna die...
  51   */
  52  function b2edit_open_preview( form, newaction )
  53  {
  54      if( form.target == 'b2evo_preview' )
  55      { // A double-click on the Preview button
  56          return false;
  57      }
  58  
  59      var saved_action = form.attributes.getNamedItem('action').value;
  60      if( ! set_new_form_action(form, newaction) )
  61      {
  62          alert( "Preview not supported. Sorry. (Could not set form.action for preview)" );
  63          return false;
  64      }
  65  
  66      form.target = 'b2evo_preview';
  67      preview_window = window.open( '', 'b2evo_preview' );
  68      preview_window.focus();
  69      // submit after target window is created.
  70      form.submit();
  71      form.attributes.getNamedItem('action').value = saved_action;
  72      form.target = '_self';
  73      return false;
  74  }
  75  
  76  
  77  /**
  78   * Submits the form after setting its action attribute to "newaction" and the blog value to "blog" (if given).
  79   *
  80   * This is used to switch to another blog or tab, but "keep" the input in the form.
  81   */
  82  function b2edit_reload( form, newaction, blog, params )
  83  {
  84      // Set the new form action URL:
  85      if( ! set_new_form_action(form, newaction) )
  86      {
  87          return false;
  88      }
  89  
  90      var hidden_action_set = false;
  91  
  92      // Set the new form "action" HIDDEN value:
  93      if( form.elements.namedItem("actionArray[update]") )
  94      {
  95          jQuery(form).append('<input type="hidden" name="action" value="edit_switchtab" />');
  96          hidden_action_set = true;
  97      }
  98      else if( form.elements.namedItem("actionArray[create]") )
  99      {
 100          jQuery(form).append('<input type="hidden" name="action" value="new_switchtab" />');
 101          hidden_action_set = true;
 102      }
 103      else
 104      {
 105          jQuery(form).append('<input type="hidden" name="action" value="switchtab" />');
 106          hidden_action_set = true;
 107      }
 108  
 109      if( hidden_action_set && ( typeof params != 'undefined' ) )
 110      {
 111          for( param in params )
 112          {
 113              jQuery(form).append('<input type="hidden" name="' + param + '" value="' + params[param] + '" />');
 114          }
 115      }
 116  
 117      // Set the blog we are switching to:
 118      if( typeof blog != 'undefined' )
 119      {
 120          if( blog == null )
 121          { // Set to an empty string, otherwise POST param value will be 'null' in IE and it cause issues
 122              blog = '';
 123          }
 124          form.elements.blog.value = blog;
 125      }
 126  
 127      // form.action.value = 'reload';
 128      // form.post_title.value = 'demo';
 129      // alert( form.action.value + ' ' + form.post_title.value );
 130  
 131      // disable bozo validator if active:
 132      // TODO: dh> this seems to actually delete any events attached to beforeunload, which can cause problems if e.g. a plugin hooks this event
 133      window.onbeforeunload = null;
 134  
 135      // Submit the form:
 136      form.submit();
 137  
 138      return false;
 139  }

title

Description

title

Description

title

Description

title

title

Body