﻿ <!-- New Editor - Begin -->
//************ImageUpload*************************
var secureURL = '' ;
var navURL = '' ;

var rootEditor = "../Editor/"
   
function myImageUpload(editor)
{
  var imageFileName = null;
  var imageFileTitle = null;


  function postback(doc,popup_iframe)
  {
    if(doc != null) // Upload clicked
    {
      if(doc.getElementById("path").value != "")
      {
        var frm = doc.getElementById("fraExecute");

        function onLoad()
        {
          setTimeout(function()
                    {
                     if(frm.detachEvent)
                        frm.detachEvent("onload", onLoad);
                     else
                     if(frm.removeEventListener)
                        frm.removeEventListener("load", onLoad, true);

                     imageFileName = frm.contentWindow.imageFileName;
                     imageFileTitle = frm.contentWindow.imageFileTitle;

                     if(imageFileName == null)
                        alert(frm.contentWindow.imageSaved);

                     popup_iframe.contentWindow.document.getElementById("cancel").onclick();  // emulate Cancel pressed
                    },0);
        }

        if(frm.attachEvent)
           frm.attachEvent("onload", onLoad);
        else
        if(frm.addEventListener)
           frm.addEventListener("load", onLoad, true);

        try{doc.getElementById("frmFile").submit();}
        catch(e)
        {
          alert(e.message);

          if(frm.detachEvent)
             frm.detachEvent("onload", onLoad);
          else
          if(frm.removeEventListener)
             frm.removeEventListener("load", onLoad, true);

         popup_iframe.contentWindow.document.getElementById("cancel").onclick();
        }
        return false;
      }
    }
    else  // Cancel clicked or emulated
    {
      if(imageFileName != null)
      {
        editor.focusEditor();
        editor.InsertHTML("<img src=\""+ "" + imageFileName+"\" alt=\""+imageFileTitle+"\" title=\""+imageFileTitle+"\" />");
        //editor.InsertHTML("<img src=\""+ navURL+imageFileName+"\" alt=\""+imageFileTitle+"\" title=\""+imageFileTitle+"\" />");
        
      }
    }
  }

  function init(doc,popup_iframe)
  {
    if(doc != null)
    {
        doc.getElementById("title").value = "";
        if(document.all)
        {
          popup_iframe.style.display = "none";
          doc.getElementById("path").click();
          popup_iframe.style.display = "";
          if(doc.getElementById("path").value == "")
            popup_iframe.contentWindow.document.getElementById("cancel").onclick();
        }
    }
  }

  editor.customPopup("popup_image_upload","image-upload", rootEditor + "__cs_myImageUpload.aspx",postback,init, false, false);
}

//**************UploadDocument********************
function myDocumentUpload(editor)
{
  var documentFileName = null;
  var documentFileTitle = null;

  function postback(doc,popup_iframe)
  {
    if(doc != null) // Upload clicked
    {
      if(doc.getElementById("path").value != "")
      {
        var frm = doc.getElementById("fraExecute");

        function onLoad()
        {
          setTimeout(function()
                    {
                     if(frm.detachEvent)
                        frm.detachEvent("onload", onLoad);
                     else
                     if(frm.removeEventListener)
                        frm.removeEventListener("load", onLoad, true);

                     documentFileName = frm.contentWindow.documentFileName;
                     documentFileTitle = frm.contentWindow.documentFileTitle;

                     if(documentFileName == null)
                        alert(frm.contentWindow.documentSaved);

                     popup_iframe.contentWindow.document.getElementById("cancel").onclick();  // emulate Cancel pressed
                    },0);
        }

        if(frm.attachEvent)
           frm.attachEvent("onload", onLoad);
        else
        if(frm.addEventListener)
           frm.addEventListener("load", onLoad, true);

        try{doc.getElementById("frmFile").submit();}
        catch(e)
        {
          alert(e.message);

          if(frm.detachEvent)
             frm.detachEvent("onload", onLoad);
          else
          if(frm.removeEventListener)
             frm.removeEventListener("load", onLoad, true);

         popup_iframe.contentWindow.document.getElementById("cancel").onclick();
        }
        return false;
      }
    }
    else  // Cancel clicked or emulated
    {
      if(documentFileName != null)
      {
        editor.focusEditor();

        if(editor.TextSelected())
        {
          editor.SurroundHTML("<a href=\""+navURL+documentFileName+"\" title=\""+documentFileTitle+"\" />","</a>");
        }
        else
        {
          var linkText = (documentFileTitle && documentFileTitle.length > 0)?documentFileTitle:"New document's link";
          editor.InsertHTML("<a href=\""+navURL+documentFileName+"\" title=\""+documentFileTitle+"\" />"+linkText+"</a>");
        }
      }
    }
  }

  function init(doc,popup_iframe)
  {
    if(doc != null)
    {
        doc.getElementById("title").value = "";
    }
  }

  editor.customPopup("popup_document_upload","document-upload", rootEditor + "__cs_myDocumentUpload.aspx",postback,init, false, false);
}


//*************************** Upload SWF *******************************************
function mySwfUpload(editor)
{
  var documentFileName = null;
  var documentFileTitle = null;

  function postback(doc,popup_iframe)
  {
    if(doc != null) // Upload clicked
    {
      if(doc.getElementById("path").value != "")
      {
        var frm = doc.getElementById("fraExecute");

        function onLoad()
        {
          setTimeout(function()
                    {
                     if(frm.detachEvent)
                        frm.detachEvent("onload", onLoad);
                     else
                     if(frm.removeEventListener)
                        frm.removeEventListener("load", onLoad, true);

                     documentFileName = frm.contentWindow.documentFileName;
                     documentFileTitle = frm.contentWindow.documentFileTitle;

                     if(documentFileName == null)
                        alert(frm.contentWindow.documentSaved);

                     popup_iframe.contentWindow.document.getElementById("cancel").onclick();  // emulate Cancel pressed
                    },0);
        }

        if(frm.attachEvent)
           frm.attachEvent("onload", onLoad);
        else
        if(frm.addEventListener)
           frm.addEventListener("load", onLoad, true);

        try{doc.getElementById("frmFile").submit();}
        catch(e)
        {
          alert(e.message);

          if(frm.detachEvent)
             frm.detachEvent("onload", onLoad);
          else
          if(frm.removeEventListener)
             frm.removeEventListener("load", onLoad, true);

         popup_iframe.contentWindow.document.getElementById("cancel").onclick();
        }
        return false;
      }
    }
    else  // Cancel clicked or emulated
    {
      if(documentFileName != null)
      {
        editor.focusEditor();

        if(editor.TextSelected())
        {
          var strSwf1= "<embed wmode=\"transparent\" src="+navURL+documentFileName+" width="+ "100" +" height=" + "100" + " quality=\"low\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" >";
          editor.InsertHTML(strSwf1);
        }
        else
        {
          var strSwf= "<embed wmode=\"transparent\" src="+navURL+documentFileName+" width="+ "100" +" height=" + "100" + " quality=\"low\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" >";
          editor.InsertHTML(strSwf);
        }
      }
    }
  }

  function init(doc,popup_iframe)
  {
    if(doc != null)
    {
        doc.getElementById("title").value = "";
    }
  }

  editor.customPopup("popup_document_upload","document-upload", rootEditor + "__cs_mySwfUpload.aspx",postback,init, false, false);
}

//End DOCUMENT UPLOAD

//*************FieldSet

// on custom button click
function myFieldsetInsert(editor)
{
  var element;
  var id = "__myTempId__"; // temporary id for new element

  // insert our new element into Editor's content (Editor's content is saved automaticaly on success)
  if(editor.InsertHTML("<fieldset id='"+id+"' style='width:300px; height:50px;'><legend>title</legend>text</fieldset>"))
  {
     // get just inserted element
     element = editor.getDocument().getElementById(id);

     // remove temporary id
     element.id=null;
     element.removeAttribute("id");

     // work with custom popup window
     myFieldsetPopup(editor,element,false);
  }
}

// on custom menu item ("Fieldset properties") click
function myFieldsetEdit(editor,element)
{
  // save Editor's content before edititing this element properties
  editor.SaveContent();

  // work with custom popup window
  myFieldsetPopup(editor,element,true);
}

// on custom menu item ("Remove Fieldset") click
function myRemoveFieldset(editor,element)
{
  // delete it
  editor.DeleteNode(element); // it saves Editor content before deleting
}

// custom menu items are available always
function myFieldsetEditCheck  (editor,element) {return true;}
function myRemoveFieldsetCheck(editor,element) {return true;}

// working with Fieldset popup
function myFieldsetPopup(editor, element, isEdit)
{
  function postback(doc,popup_iframe) //on OK and Cancell buttons click
  {
    if(doc != null) // OK clicked
    {
      // get fields values from popup
      var width   = doc.getElementById("widthField"  ).value;
      var height  = doc.getElementById("heightField" ).value;
      var padding = doc.getElementById("paddingField").value;
      var margin  = doc.getElementById("marginField" ).value;

      // check input fields and highlight them on error
      if((isNaN(width  ) && width  .length > 0) || width   < 0) {setSelectionRange(doc.getElementById("widthField"  )); /* don't close popup */ return false;}
      if((isNaN(height ) && height .length > 0) || height  < 0) {setSelectionRange(doc.getElementById("heightField" )); /* don't close popup */ return false;}
      if((isNaN(padding) && padding.length > 0) || padding < 0) {setSelectionRange(doc.getElementById("paddingField")); /* don't close popup */ return false;}
      if((isNaN(margin ) && margin .length > 0) || margin  < 0) {setSelectionRange(doc.getElementById("marginField" )); /* don't close popup */ return false;}
       
      // update properties of the element
      element.style.width   = (!isNaN(width  ) && width  .length > 0)?(width  +"px"):"";
      element.style.height  = (!isNaN(height ) && height .length > 0)?(height +"px"):"";
      element.style.padding = (!isNaN(padding) && padding.length > 0)?(padding+"px"):"";
      element.style.margin  = (!isNaN(margin ) && margin .length > 0)?(margin +"px"):"";
    }
    else // Cancel Clicked
    {
      // restore saved Editor's content (after success InsertHtml)
      editor.RestoreContent();
    }
    return true; // close popup
  }

  function init(doc,popup_iframe)  // on Popup window content init
  {
    if(doc != null)
    {
      // init popup's fields
      doc.getElementById("widthField"  ).value = (element.style.width  )?parseInt(element.style.width  ):"";
      doc.getElementById("heightField" ).value = (element.style.height )?parseInt(element.style.height ):"";
      doc.getElementById("paddingField").value = (element.style.padding)?parseInt(element.style.padding):"";
      doc.getElementById("marginField" ).value = (element.style.margin )?parseInt(element.style.margin ):"";
    }
  }

  // open custom popup window
  editor.customPopup("popup_fieldset","fieldset","Editor/__cs_fieldset.aspx",postback,init, false, isEdit);
}

// selecting <input> value 
function setSelectionRange(input)
{
  input.focus();
  if (input.setSelectionRange) {
    input.setSelectionRange(0, input.value.length);
  }
  else if (input.createTextRange) {
    var range = input.createTextRange();
    range.collapse(true);
    range.moveEnd  ('character', input.value.length);
    range.moveStart('character', 0);
    range.select();
  }
}
<!-- New Editor - End -->
