Autore Topic: Creare Editor WYSiWYG per Firefox  (Letto 4380 volte)

0 Utenti e 1 Visitatore stanno visualizzando questo topic.

Offline Batman05

  • Post: 8
Creare Editor WYSiWYG per Firefox
« il: 24 Agosto 2005 16:46:12 »
Carissimi sono un neofita di firefox  :D ...  e quindi ho un'informazione da chiedervi:
Sto realizzando un editor wysiwyg il problema è che con internet explorer funziona alla grande perchè ho utilizzato un'area contenitore testo con attributo "content editable".. :x mentre con firefox non viene riconosciuto questo attributo.
Come posso fare allora per visualizzare in un area le immagini, i link, le tabelle ecc.ecc. richieste dall'utente in fase di editazione?  Tenete presente che mi è stato vietato di  utilizzare l'Iframe. Debbo per caso creare un object?? E se si come ??? Non esiste un attributo simile a "content editable" per firefox ?
Vi sarei veramente molto grato se quanto prima mi aiutaste a risolvere l'arcano.

P.S. Ho utilizzato istruzioni javascript compatibili per IE e per Mozilla.

Ciao e a presto.  :wink: [/i]

Offline Strahd

  • Post: 56
Creare Editor WYSiWYG per Firefox
« Risposta #1 il: 25 Agosto 2005 17:11:07 »
ehm... si può vedere l'esempio?

Offline lucasali

  • Moderatore
  • Post: 7493
Creare Editor WYSiWYG per Firefox
« Risposta #2 il: 25 Agosto 2005 17:25:46 »
sposto nella sezione più adatta
come ti ha già chiesto Strahd potresti mandarci il link (o il codice) della pagina in questione?

ciao. Luca

Offline jooliaan

  • Lazy Old Man
  • Post: 8532
    • BlogZilla
Creare Editor WYSiWYG per Firefox
« Risposta #3 il: 25 Agosto 2005 19:03:05 »
Vedi un  po' se questo t'è d'aiuto. E' il JS usato dall'editor WYSIWYG di blogger.com (che funziona perfettamente con Mozilla, Firefox, Opera ed IE:

Codice: [Seleziona]
function surroundFrameSelection(frame, tagName) {
  var win = frame.contentWindow;
  surroundSelection(win, tagName);
}

function surroundSelection(win, tagName) {
  if (Detect.IE()) {
    surroundSelection_IE(win.document, tagName);
  } else {
    var doc = (win.contentDocument) ? win.contentDocument : document;
    var el = doc.createElement(tagName);
    surroundSelection_DOM(win, el);
  }
}

function insertNodeAtSelection(win, tag, fragment) {
  if (Detect.IE()) {
    var doc = win.document;
    var range = doc.selection.createRange();
    insertNodeAtSelection_IE(doc, tag, fragment.innerHTML);
  } else {
    var doc = (win.contentDocument) ? win.contentDocument : document;
    var el = doc.createElement(tag);
    insertNodeAtSelection_DOM(win, el, fragment);
  }
}

function insertNodeAtSelection_IE(doc, tag, html) {
  try {
    var range = doc.selection.createRange();
    var startTag = '<' + tag + '>';
    var endTag = '</' + tag + '>';
    var replaceString = startTag + html + endTag;
   
    var isCollapsed = range.text == '';
    range.pasteHTML(replaceString);
   
    if (!isCollapsed) {
      // move selection to html contained within the surrounding node
      range.moveToElementText(range.parentElement().childNodes[0]);
      range.select();
    }
  } catch(e) {
    RichEdit.addDebugMsg('insertNodeAtSelection_IE() failed for "' + tag + '"');
  }
}

function surroundSelection_IE(doc, tag) {
  try {
    var range = doc.selection.createRange();
    var html = range.htmlText;
   
    // get rid of beginning newline
    if (html.substring(0,2) == '\r\n') html = html.substring(2, html.length);
   
    // resolve IE's special DIV cases
    html = replaceEmptyDIVsWithBRs(html);
   
    insertNodeAtSelection_IE(doc, tag, html);
  } catch(e) {
    RichEdit.addDebugMsg('surroundSelection_IE() failed for "' + tag + '"');
  }
}

function surroundSelection_DOM(win, tag) {
  try {
    var sel = win.getSelection();  
    var range = sel.getRangeAt(0);
    insertNodeAtSelection_DOM(win, tag, range.cloneContents());
  } catch(e) {
    RichEdit.addDebugMsg('surroundSelection_DOM() failed for "' + tag + '"');
  }
}


/*
 * This function was taken from The Mozilla Organization's Midas demo. It has
 * been modified.  In the future we may instead be able to use the
 * surroundContents() method of the range object, but a bug exists as of
 * 7/6/2004 that prohibits our use of it in Mozilla.
 * (http://bugzilla.mozilla.org/show_bug.cgi?id=135928)
 */
function insertNodeAtSelection_DOM(win, insertNode, html)
{
  // get current selection
  var sel = win.getSelection();  
 
  // get the first range of the selection
  // (there's almost always only one range)
  var range = sel.getRangeAt(0);
 
  // insert specified HTML into the node passed by argument
  insertNode.appendChild(html);  
 
  // deselect everything
  sel.removeAllRanges();
 
  // remove content of current selection from document
  range.deleteContents();
 
  // get location of current selection
  var container = range.startContainer;
  var pos = range.startOffset;
 
  // make a new range for the new selection
  range=document.createRange();
 
  var afterNode;
 
  if (container.nodeType==3 && insertNode.nodeType==3) {
   
    // if we insert text in a textnode, do optimized insertion
    container.insertData(pos, insertNode.nodeValue);
   
  } else {
   
   
    if (container.nodeType==3) {
     
      // when inserting into a textnode
      // we create 2 new textnodes
      // and put the insertNode in between
     
      var textNode = container;
      container = textNode.parentNode;
      var text = textNode.nodeValue;
     
      // text before the split
      var textBefore = text.substr(0,pos);
      // text after the split
      var textAfter = text.substr(pos);
     
      var beforeNode = document.createTextNode(textBefore);
      var afterNode = document.createTextNode(textAfter);
     
      // insert the 3 new nodes before the old one
      container.insertBefore(afterNode, textNode);
      container.insertBefore(insertNode, afterNode);
      container.insertBefore(beforeNode, insertNode);
     
      // remove the old node
      container.removeChild(textNode);
     
    } else {
     
      // else simply insert the node
      afterNode = container.childNodes[pos];
      container.insertBefore(insertNode, afterNode);
    }
  }
 
  // select the modified html
  range.setEnd(insertNode, insertNode.childNodes.length);
  range.setStart(insertNode, insertNode);
  sel.addRange(range);
};




/*
 * getRangeAsDocumentFragment()
 *
 * Returns an HTML Document fragment representing the contents of the
 * supplied selection range.
 */
function getRangeAsDocumentFragment(range) {
  try {
    if (Detect.IE()) {
      var el = document.createElement('span');
      el.innerHTML = range.htmlText;
      return el;
    } else {
      return range.cloneContents();
    }
  } catch(e) {
    RichEdit.addDebugMsg('--getRangeAsDocumentFragment() failed');
    return null;
  }
}



Codice: [Seleziona]
BACKSPACE = null;
DELETE = null;
RETURN = null;
TAB = null;
CTRL_SHFT_A = null;
CTRL_SHFT_B = null;
CTRL_SHFT_T = null;
CTRL_SHFT_L = null;
CTRL_SHFT_P = null;
CTRL_SHFT_S = null;
CTRL_SHFT_D = null;
CTRL_SHFT_U = null;
CTRL_SHFT_Z = null;
CTRL_B = null;
CTRL_D = null;
CTRL_I = null;
CTRL_L = null;
CTRL_P = null;
CTRL_S = null;
CTRL_Y = null;
CTRL_Z = null;

IE_KEYSET = (Detect.IE() || Detect.SAFARI());

function setKeysetByEvent(e) {
 
  // IE delivers a different keyset per key event type.  Additionally,
  // 'keydown' is different than 'keypress' but only in terms of the
  // ctrl + shift combination.  Ugh.  Safari is more consistent.  Gecko is
  // right on.
  IE_CTRL_SHIFT_KEYSET = IE_KEYSET;  
  if (Detect.IE() && e && e.type == "keydown") IE_CTRL_SHIFT_KEYSET = false;
 
  BACKSPACE = (getKey(e) == 8);
  DELETE = (getKey(e) == 46);
  RETURN = (getKey(e) == 13);
  TAB = (getKey(e) == 9);
 
  CTRL_SHFT_A = (IE_CTRL_SHIFT_KEYSET) ?
    isKeyPressedWithCtrlShift(1, e) : isKeyPressedWithCtrlShift(65, e);

  CTRL_SHFT_B = (IE_CTRL_SHIFT_KEYSET) ?
    isKeyPressedWithCtrlShift(2, e) : isKeyPressedWithCtrlShift(66, e);
 
  CTRL_SHFT_D = (IE_CTRL_SHIFT_KEYSET) ?
    isKeyPressedWithCtrlShift(4, e) : isKeyPressedWithCtrlShift(68, e);
 
  CTRL_SHFT_L = (IE_CTRL_SHIFT_KEYSET) ?
    isKeyPressedWithCtrlShift(12, e) : isKeyPressedWithCtrlShift(76, e);
 
  CTRL_SHFT_P = (IE_CTRL_SHIFT_KEYSET) ?
    isKeyPressedWithCtrlShift(16, e) : isKeyPressedWithCtrlShift(80, e);
 
  CTRL_SHFT_S = (IE_CTRL_SHIFT_KEYSET) ?
    isKeyPressedWithCtrlShift(19, e) : isKeyPressedWithCtrlShift(83, e);

  CTRL_SHFT_T = (IE_CTRL_SHIFT_KEYSET) ?
    isKeyPressedWithCtrlShift(20, e) : isKeyPressedWithCtrlShift(84, e);
 
  CTRL_SHFT_U = (IE_CTRL_SHIFT_KEYSET) ?
    isKeyPressedWithCtrlShift(21, e) : isKeyPressedWithCtrlShift(85, e);
 
  CTRL_SHFT_Z = (IE_CTRL_SHIFT_KEYSET) ?
    isKeyPressedWithCtrlShift(26, e) : isKeyPressedWithCtrlShift(90, e);
 
  CTRL_B = (IE_KEYSET) ?
    isKeyPressedWithCtrl(66, e) : isKeyPressedWithCtrl(98, e);
 
  CTRL_D = (IE_KEYSET) ?
    isKeyPressedWithCtrl(68, e) : isKeyPressedWithCtrl(100, e);
 
  CTRL_I = (IE_KEYSET) ?
    isKeyPressedWithCtrl(73, e) : isKeyPressedWithCtrl(105, e);
 
  CTRL_L = (IE_KEYSET) ?
    isKeyPressedWithCtrl(76, e) : isKeyPressedWithCtrl(108, e);
 
  CTRL_P = (IE_KEYSET) ?
    isKeyPressedWithCtrl(80, e) : isKeyPressedWithCtrl(112, e);
 
  CTRL_S = (IE_KEYSET) ?
    isKeyPressedWithCtrl(83, e) : isKeyPressedWithCtrl(115, e);
 
  CTRL_Y = (IE_KEYSET) ?
    isKeyPressedWithCtrl(89, e) : isKeyPressedWithCtrl(121, e);
 
  CTRL_Z = (IE_KEYSET) ?
    isKeyPressedWithCtrl(90, e) : isKeyPressedWithCtrl(122, e);

}



/**
* isCtrlShiftKeyPressed()
 *
 * Determine by char index whether a certain key's been pressed in conjunction
 * with the CTRL and SHIFT keys.
 */
function isKeyPressedWithCtrlShift(num, e) {
  var key = getKeyAfterCtrlAndShift(e);
  if (key) return (key == num);
  return false;
}

function isKeyPressedWithCtrl(num, e) {
  var key = getKeyAfterCtrl(e);
  if (key) return (key == num);
  return false;
}

function isKeyPressedWithShift(num, e) {
  var key = getKeyAfterShift(e);
  if (key) return (key == num);
  return false;
}



// The following functions help manage some differing browser event models and  
// key detection.
function getKeyAfterCtrl(e) {
  if (isCtrlKeyPressed(e)) { return getKey(e); }
  return false;  
}

function getKeyAfterShift(e) {
  if (isShiftKeyPressed(e)) { return getKey(e); }
  return false;  
}

function getKeyAfterCtrlAndShift(e) {
  if (isCtrlKeyPressed(e) && isShiftKeyPressed(e)) { return getKey(e); }
  return false;  
}

function isCtrlKeyPressed(e) {
  return getEvent(e).ctrlKey;
}

function isShiftKeyPressed(e) {
  return getEvent(e).shiftKey;
}

function isAltKeyPressed(e) {
  return getEvent(e).altKey;
}

function getKey(e) {
  var key = getEvent(e).keyCode;
  if (!key) key = getEvent(e).charCode;
  return key;
}

function getEventSource(evt) {
  if (Detect.IE()) {
    return evt.srcElement;
  } else {
    return evt.target;
  }
}

function getEvent(e) {
  return (!e) ? event : e;
}


Codice: [Seleziona]
/**
 * Using a factory class to avoid namespace collisions
 * of common ID names for different purposes
 */
function Preview() {}
function Posting() {}
function HtmlSource() {}

// Common IDs, class names, and other constants
HtmlSource.TEXTAREA = "textarea";

Preview.ID = "preview";
Preview.TEXTAREA = HtmlSource.TEXTAREA;
Preview.PREVIEW_BUTTON = "formatbar_PreviewAction";
Preview.HTML_PREVIEW_BUTTON = "htmlbar_PreviewAction";

Posting.PUBLISH_BUTTON = "publishPost";
Posting.DRAFT_BUTTON = "saveDraft";
Posting.OPTIONS = "postoptions";
Posting.TITLE = "f-title";
Posting.URL = "f-address";


Codice: [Seleziona]
/** -------------------------------------------------------
 * Author: Chris Wetherell
 * Inline Preview ("Toggle")
 *
 * A series of functions that will toggle a simply styled
 * preview of the post that could be generated by the form, if
 * submitted.
 *
 * Warning: Written on the highways between L.A. and Tuscon.
 *
 * Warning: Updated on the highways between New Mexico and Texas.
 *
 * Typical usage:
 * On an HTML element: onclick="toggle();"
  ------------------------------------------------------- */


  /**
   * toggle()
   *
   * A series of functions that will toggle a simply styled
   * preview of the post that could be generated by the form, if
   * submitted.
   *
   * Typical usage:
   * On an HTML element: onclick="toggle();"
   */
  function toggle(e)
  {
    if (!document.getElementById) {
      alert("This feature is not supported by your browser.");
      return;
    }
    if (RichEdit.PREVIEW_IS_HIDDEN) {
      showPreview();
    } else {
      hidePreview();      
    }
   
    togglePostOptions();
  }



  /**
   * PreviewElements()
   *
   * An object which stores the various elements needed to be adjusted to
   * display a preview of the post.
   */
  var PreviewElements = function() {}
 
  function setPreviewElements() {
   
    PreviewElements.f = d(RichEdit.frameId);
    PreviewElements.t = getElement(Preview.TEXTAREA);
    PreviewElements.p = getElement("previewbody");
    PreviewElements.s = d("SubmitTwo");
    PreviewElements.k = d("key_commands");
    PreviewElements.ed = d("editarea");
    PreviewElements.title = d(Posting.TITLE);
    PreviewElements.address = d(Posting.URL);
    PreviewElements.h1 = dE(getElement(Preview.ID),"h1")[0];
    PreviewElements.b = (RichEdit.mode == RichEdit.DESIGN_MODE) ?
      d(Preview.PREVIEW_BUTTON) : d(Preview.HTML_PREVIEW_BUTTON);
   
  }




  /**
   * showPreview()
   *
   * Displays a preview of the post and hides form elements.
   */
  function showPreview() {
   
    setPreviewElements();
   
    // get the post body
    var strBody;
    if (RichEdit.mode == RichEdit.DESIGN_MODE) {
      strBody = getDesignModeHtml();
      if (Detect.IE()) strBody = RemoveLinksWithinTags(strBody);
    }      
    if (RichEdit.mode == RichEdit.HTML_MODE) {
      strBody = PreviewElements.t.value;
     
      // Safari bug - if textarea has focus and
      // then disappears subsequent key capture fails
      if (PreviewElements.t.style.display!="none" && Detect.SAFARI()) {
        PreviewElements.t.blur();
      }
    }
   
    // hide the edit area
    if (RichEdit.mode == RichEdit.DESIGN_MODE) {
      hideElement(PreviewElements.f);
    } else {
      hideElement(PreviewElements.t);
    }
   
    // change the preview label
    if (PreviewElements.b) PreviewElements.b.innerHTML = "Hide Preview";
   
    // ------------------------------------------
    // Transform the post body for inline viewing
    // ------------------------------------------
   
    // Replace text line breaks with HTML link breaks
    strBody = strBody.replace(/\n/g,"<br />");
   
    // Make images with relative links appear in Preview
    var blogURL = d("blogURL").value;
    strBody = strBody.replace(/<img src=\"\//g,
                              "<img src=\"" + blogURL);
   
    // Make all preview links open in a new window
    var anchors = PreviewElements.p.getElementsByTagName('A');
    for (a = 0; a < anchors.length ; a++) {
      anchors[a].setAttribute('target', '_new');
    }
   
    // ------------------------------------------
    // Set the preview area
    // ------------------------------------------
   
    showElement(PreviewElements.p);
    hideElement(PreviewElements.k);
   
    // Add the post title, and if the URL field exists and
    // has content, then make the title a hyperlink.
    if (PreviewElements.title) {
      if (PreviewElements.title.value.length > 0) {
        showElement(PreviewElements.h1);
      } else {
        hideElement(PreviewElements.h1);
      }
      setPreviewTitle(getTitle());
    }
   
    // Make extra save buttons at the bottom of large posts.
    if (strBody.length>1600) {
      PreviewElements.s.innerHTML = d('postButtons').innerHTML;
    } else {
      PreviewElements.s.innerHTML = '';
    }
   
    // Copy and paste the post text from the form to the preview area
    PreviewElements.p.innerHTML = strBody;
   
    // Clean-up post body if it came from the WYSIWYG iframe
    if (RichEdit.ENABLE_IFRAME) {
      PreviewElements.p.innerHTML
        = convertAllFontsToSpans(cleanHTML(PreviewElements.p.innerHTML));
    }
   
    setFormatBarElements('none');
   
    RichEdit.PREVIEW_IS_HIDDEN = false;
   
    // To restore the editing area via key commands, Moz needs the focus
    // to be transferred from the invisible editor to a visible element
    if (Detect.MOZILLA()) PreviewElements.title.focus();
   
  }




  /**
   * hidePreview()
   *
   * Hides a preview of the post and displays the form elements.
   */
  function hidePreview() {
   
    setPreviewElements();
   
    // ------------------------------------------
    // Restore the editing area
    // ------------------------------------------
   
    if (RichEdit.mode == RichEdit.DESIGN_MODE) {
      showElement(PreviewElements.f);
    } else {
      showElement(PreviewElements.t);
    }
    showElement(PreviewElements.k);
    hideElement(PreviewElements.p);
    hideElement(PreviewElements.s);
    hideElement(PreviewElements.h1);
   
    setFormatBarElements('block');
   
    if (PreviewElements.b) PreviewElements.b.innerHTML = "Preview";
   
    RichEdit.PREVIEW_IS_HIDDEN = true;
   
    // Moz needs to be reminded to have the iframe editable after
    // a display change is made
    if (RichEdit.ENABLE_IFRAME
        && RichEdit.mode == RichEdit.DESIGN_MODE) {
      RichEdit.frameDoc.designMode = "On";
    }    
  }




  /**
   * togglePostOptions()
   *
   * Shows (or hides) the post options bar.
   */
  function togglePostOptions() {
    toggleDisplay(d(Posting.OPTIONS));
  }




  /**
   * setFormatBarElements()
   *
   * Shows (or hides) the glyphs and icons with the formatting bar.
   */
  function setFormatBarElements(display) {
    var bar = RichEdit.formatbar;
    var bar_SPANs = dE(bar, 'span');
    for (x = 0; x < bar_SPANs.length; x++) {
      var span = bar_SPANs[x];
      if (span.id != Preview.PREVIEW_BUTTON) {
        span.style.display = display;
      }
    }
    var bar_SELECTs = dE(bar, 'select');
    for (x = 0; x < bar_SELECTs.length; x++) {
      bar_SELECTs[x].style.display = display;
    }
    var bar_DIVs = dE(bar, 'div');
    for (x = 0; x < bar_DIVs.length; x++) {
      var div = bar_DIVs[x];
      if (div.className != "clear") {
        div.style.display = display;
      }
    }
  }



  /**
   * setPreviewTitle()
   *
   * Sets the title text of the post's preview
   *
   * Typical usage:
   * setPreviewTitle(getTitle());
   */
  function setPreviewTitle(s)
  {
    try {
      var h1 = dE(d(Preview.ID),"h1")[0];
      if (h1.style.display=="block") {
        h1.innerHTML=s;
      }
    } catch(e) {}
  }


  /**
   * getTitle()
   *
   * Returns the value of the title field except in the
   * case where there's a non-empty URL field where this
   * instead returns the title value wrapped in a hyperlink.
   *
   * Typical usage:
   * setPreviewTitle(getTitle());
   */
  function getTitle()
  {

    var title = d(Posting.TITLE);
    var address = d(Posting.URL);

    if (title) {
      var sTitle = title.value;
      if (address  && address.value.length>0) {
        sTitle = "<a target=\"new\" href=\""
                  +address.value
                  +"\">"
                  +sTitle
                  +"</a>";
      }
    }

    return sTitle;
  }




Codice: [Seleziona]
// Copyright 2004 Google, Inc.

// A script that provides provides storage for a single string, backed by
// cookies.  
//
// The maximum string size is specified by:
// backupCookieMaxLen * backupCookieMaxNum.
//
// backupCookieMaxLen should not exceed 4KB due to browser limitations.
// backupCookieMaxNum should be set conservatively to avoid running into
// domain specific cookie limits.
//
// Be sure to include JsConstants before including this file as it includes
// translated messages for this feature.

var backupCookieMaxLen = 640;
var backupCookieMaxNum = 5;
var backupCookieTime = 1800000; // 30 minutes
var backupCookieBaseName = "autoSaveCookie";
var backupBlogIDCookieBaseName = "backupBlogId";
var backupInterval = 2000; // in milliseconds
var backupLargerThan = 9;  // num of chars, important for IE
var backupLimit = 12000;    // character length, for strict web servers
var backupTimer;

function setBackupCookie(num, data, exp) {
  document.cookie = backupCookieBaseName + num + "=" + data +
                    "; expires=" + exp +
                    "; path=/";
  document.cookie = backupBlogIDCookieBaseName + "=" +
                    document.stuffform.blogID.value +
                    "; expires=" + exp +
                    "; path=/";
}

// Start auto-save and generate its UI
function startAutoSave() {
 
  // add the HTML element for recovery
  setAutoSaveHtml();
 
  // Start auto-save and backup the post every x milliseconds
  backupTimer = setInterval('backupPost();', backupInterval);
}

function setAutoSaveHtml() {
  var div = document.createElement('div');
  div.id = 'recover';
  var span = document.createElement('span');
  span.innerHTML = recover_post_label;
  span.onclick = function() {
    if (confirm(recover_post_confirm)) {
      setPost(loadBackupData());
    }
  }
  div.appendChild(span);
  d('richbars').appendChild(div);
}

function backupPost() {
  var post = getPost();
  // Don't auto-save very small posts. This could be delayed, unintended input.
  if (post.length <= backupLargerThan) return;
  // Prevent large content from surpassing content length limits on web servers
  if (post.length >= backupLimit) {
    post = post.substring(0, backupLimit);
  }
  clearBackupData();
  setBackupData(post);
}

// Get the post body.
function getPost() {
  if (RichEdit.mode == RichEdit.DESIGN_MODE) {
    if (Detect.IE()) {
      return RemoveLinksWithinTags(getDesignModeHtml());
    } else {  
      return getDesignModeHtml();
    }
  }      
  if (RichEdit.mode == RichEdit.HTML_MODE) {
    return getElement(Preview.TEXTAREA).value;
  }
}

// Set the editor text.
function setPost(data) {  
  if (RichEdit) {
    getElement(Preview.TEXTAREA).value = data;
  }
  if (RichEdit.mode == RichEdit.DESIGN_MODE) {
    RichEdit.ShowRichEditor();
  }    
}

// Store a string.
function setBackupData(unescapedData) {
  var cookieIdx = 0;
  var cookieNum = 0;

  var data = escape(unescapedData);

  while ((cookieIdx < data.length) && (cookieNum < backupCookieMaxNum)) {
    var cookieData = data.substring(cookieIdx, cookieIdx + backupCookieMaxLen);

    var date = new Date();
    date.setTime(date.getTime() + backupCookieTime);
    var cookieExp = date.toGMTString();
    setBackupCookie(cookieNum, cookieData, cookieExp);

    cookieIdx += backupCookieMaxLen;
    cookieNum++;
  }
}

// Clear the stored string.
function clearBackupData() {
  var date = new Date();
  date.setTime(0);
  var pastExp = date.toGMTString();
 
  for (var i = 0; i < backupCookieMaxNum; i++) {
    setBackupCookie(i, "", pastExp);
  }
}

// Load the stored string.
function loadBackupData() {
  var curCookie = document.cookie;
  var numParts = 0;
  var parts = new Array(backupCookieMaxLen);
  var cookieParts = curCookie.split("; ");  
  var blogHasCookie = false;

  for (var i = 0; i < cookieParts.length; i++) {
    keyvalue = cookieParts[i].split("=");
    key = keyvalue[0];
    value = keyvalue[1];
   
    // Is this cookie for this blog?
    if (key == backupBlogIDCookieBaseName) {
      if (value == document.stuffform.blogID.value) {
        blogHasCookie = true;
      }
    }

    if (key.substr(0, backupCookieBaseName.length) == backupCookieBaseName) {
      var whichPart = key.substr(backupCookieBaseName.length,
                                 key.length - backupCookieBaseName.length);
      if (whichPart < backupCookieMaxNum) {
        parts[whichPart] = value;
        numParts++;
      }
    }
  }

  // Stop if cookie is empty or is not recoverable for this blog
  if (numParts == 0 || !blogHasCookie) {
    return "";
  }

  var data = "";

  for (var i = 0; i < numParts; i++) {
    if (parts[i] != null) {
      data = data + parts[i];
    } else {
      return "";
    }
  }

  return unescape(data);
}


Ciao :)

0 Utenti e 1 Visitatore stanno visualizzando questo topic.