Log in | Register | Lost password

Bottom
FCKeditor pagesetter plugin
  • Posted: 23.06.2007, 01:51
     
    Converted
    rank:
    12
    registered:
     March 2009
    Status:
    offline
    last visit:
    Posts:
    0
    Hi,
    I posted this on the postnuke forums but haven't gotten a reply. Pagesetter has made my website better and my life easier. I've been trying to create a plugin for the scribite FCKeditor to use pagesetter's publication finder function. I'm not a programmer by profession, though, and I've been having some trouble. I'm just not sure how to pass variables between the FCKeditor and Pagesetter.

    I was hoping, because Jorn created Pagesetter and is using FCKeditor for the cotype module, that he or someone else would be able to create such a plugin.

    As I said, I'm not a programmer, but I still gave it a shot. Here's my attempt at a plugin:

    add this statement to:
    javascript\scribite_editors\fckeditor\fckconfig.js:


    Code

    FCKConfig.Plugins.Add( 'pagesetter', 'en' ) ;



    language define:
    javascript\scribite_editors\fckeditor\editor\plugins\Pagesetter\lang


    Code

    FCKLang.InsertLinkBtn = 'Link to pagesetter article' ; //This will be the caption for your toolbar button



    create a small toolbar icon at: javascript\scribite_editors\fckeditor\editor\plugins\Pagesetter\pagesetter.gif

    and the plugin file:
    javascript\scribite_editors\fckeditor\editor\plugins\Pagesetter\fckplugin.js

    Code

    var InsertPagesetterCommand=function(){

    //create our own command, we dont want to use the FCKDialogCommand because it uses the default fck layout and not our own

    };

    InsertPagesetterCommand.prototype.Execute=function(){

    }

    InsertPagesetterCommand.GetState=function() {

    return FCK_TRISTATE_OFF; //we dont want the button to be toggled

    }

    InsertPagesetterCommand.Execute=function() {

    //open a popup window when the button is clicked

    window.open('XXXXXXX/index.php?module=pagesetter&func=pubfind&url=relative&html=a&targetID=' + XXXXXXXX, 'insertPagesetter', 'width=750,height=350,scrollbars=yes,scrolling=yes,location=no,toolbar=no');

    }

    FCKCommands.RegisterCommand('pagesetter', InsertPagesetterCommand ); //otherwise our command will not be found

    var oInsertPagesetter = new FCKToolbarButton('pagesetter', FCKLang.InsertLinkBtn);

    oInsertPagesetter.IconPath = FCKPlugins.Items['pagesetter'].Path + 'pagesetter.gif' ; //specifies the image used in the toolbar

    FCKToolbarItems.RegisterItem( 'pagesetter', oInsertPagesetter );



    The Pagesetter pubedit popup opens, but when I select a publication I get a javascript error. I can't figure out what to set the targetID to in
    index.php?module=Pagesetter&func=pubfind&url=relative&HTML=a&targetID=' + xxxxxx


    Help?!!
  • Posted: 27.06.2007, 00:09
     
    Converted
    rank:
    12
    registered:
     March 2009
    Status:
    offline
    last visit:
    Posts:
    0
    By the way, most of the above code came from the FCKeditor Wiki. A smarter programmer with some knowledge of pagesetter and a quick reveiw of this page might be able to solve this problem real quickly! :-)
  • Posted: 27.06.2007, 22:07
     
    Converted
    rank:
    12
    registered:
     March 2009
    Status:
    offline
    last visit:
    Posts:
    0
    Don't forgive to share your hack when it will be finished ;)

    Thanks
  • Posted: 28.06.2007, 02:03
     
    Converted
    rank:
    12
    registered:
     March 2009
    Status:
    offline
    last visit:
    Posts:
    0
    I'm stuck!
  • Posted: 06.07.2007, 06:40
     
    Converted
    rank:
    12
    registered:
     March 2009
    Status:
    offline
    last visit:
    Posts:
    0
    OK, I've been pulling my hair out for a few weeks now trying to figure this out. Since I'm running out of hair I'm going to ask for help again.

    Maybe if I think about this out loud someone might be able to point me in the right direction (or tell me that I'm totally misunderstanding things and should just give up).

    Here's my understanding of how these plugins function:

    1) the user clicks the editor's pagesetter icon and the plugin's script opens ...index.php?module=pagesetter&func=pubfind... in a new window. This link also passes information about the editor that is opening the window.

    2) the user finds a publication and clicks "insert". This, via the findpub.js script in pagesetter, pastes a link to the publication in the editor window.

    The thing that i'm having trouble with is I can't figure out what the ID of the editor is; what value should be passed on to the pubfind function? It doesn't seem that complicated, but I just can't figure it out and it's driving me crazy!

    Is my understanding of how this works correct?

    I've combed through all the guppy files, the FCKeditor plugins, the forums at FCKeditor, the forums here. I just don't know what else to do.

    If anyone could give me any other advice it would be very appreciated.





    edited by: toddzarwell, Jul 06, 2007 - 08:10 AM
  • Posted: 11.07.2007, 02:01
     
    Converted
    rank:
    12
    registered:
     March 2009
    Status:
    offline
    last visit:
    Posts:
    0
    OK, I got something to work, but I had to really hack up pagesetter/pnjavasctipt/pubfind.js to do it. Now none of the editors will work ... but FCKeditor will. Hopefully someone can improve upon what I've done.

    Here's what I have:

    add this statement to the bottom of javascript\scribite_editors\fckeditor\fckconfig.js:

    Code

    FCKConfig.Plugins.Add( 'pagesetter', 'en' ) ;


    Create a directory at: javascript/scribite_editors/fckeditor/editor/plugins/pagesetter

    In it, create the directory javascript/scribite_editors/fckeditor/editor/plugins/pagesetter/en, which contains the file en.js:

    Code

    FCKLang.InsertLinkBtn = 'Link to pagesetter article' ; //This will be the caption for your toolbar button

    FCKLang.InsertLinkDlgTitle = 'Pagesetter Links' ; //This will be the title of the dialog box


    In javascript/scribite_editors/fckeditor/editor/plugins/pagesetter create this plugin file: fckplugin.js :

    Code

    var InsertPagesetterCommand=function(){

    //create our own command, we dont want to use the FCKDialogCommand because it uses the default fck layout and not our own

    };

    InsertPagesetterCommand.prototype.Execute=function(){

    }

    InsertPagesetterCommand.GetState=function() {

    return FCK_TRISTATE_OFF; //we dont want the button to be toggled

    }

    InsertPagesetterCommand.Execute=function() {



    oEditor = FCK.Name;



    //open a popup window when the button is clicked



    window.open("http://www.YOURURL.com/dev/index.php?module=pagesetter&func=pubfind&url=relative&html=a&targetID="+oEditor+"&targetMode=FCK", "", "width=750,height=315,resizable");

    }

    FCKCommands.RegisterCommand('pagesetter', InsertPagesetterCommand ); //otherwise our command will not be found

    var oInsertPagesetter = new FCKToolbarButton('pagesetter', FCKLang.InsertLinkBtn);

    oInsertPagesetter.IconPath = FCKPlugins.Items['pagesetter'].Path + 'pagesetter.gif' ; //specifies the image used in the toolbar

    FCKToolbarItems.RegisterItem( 'pagesetter', oInsertPagesetter );


    Now here is where I got a little goofy and started hacking things. I wanted to create some if/then statements in pagesetter/pnjavasctipt/pubfind.js so the FCKeditor functions would be used if the FCKeditor was the active editor and use the other functions if another editor was active. I couldn't figure out how to tell the script which was the active editor, so I just hacked it so it would work with FCKeditor. I hope someone can suggest a way to make this work for any editors.

    Anyway, here's my modified pagesetter/pnjavasctipt/pubfind.js script. My hacks are identified by the "TMZ" comments.

    Code

    //=============================================================================

    // Stand alone link selector for Pagesetter

    // (C) Jorn Lind-Nielsen

    //=============================================================================



    // htmlArea 3.0 editor for access in selector window

    var currentPagesetterEditor = null;



    //=============================================================================

    // External interface functions

    //=============================================================================



    // onClick handler for "find publication" button in external program

    function pagesetterFindPub(inputID, pagesetterURL)

    {

    window.open(pagesetterURL+"&targetID="+inputID, "", "width=750,height=315,resizable");

    }





    function pagesetterFindPubHtmlArea30(editor, pagesetterURL)

    {



    // Save editor for access in selector window

    currentPagesetterEditor = editor;



    // Inform publication selector of how it should paste the resulting HTML

    pagesetterURL += "&target=htmlArea30";



    window.open(pagesetterURL, "", "width=750,height=450,resizable");

    }





    //=============================================================================

    // Paste link into parent input field

    //=============================================================================



    function pagesetterPasteLink(URLMode, HTMLMode, title, url, targetInputID, targetMode)

    {



    //TMZ added this line:

    window.opener.currentPagesetterEditor = window.opener.FCK;





    var html = url;



    if (targetMode == 'htmlArea30')

    {

    //TMZ commented out:

    //var selectedHTML = window.opener.currentPagesetterEditor.getSelectedHTML();



    //TMZ added the next "if" statement:

    if (document.all){

    selectedHTML = window.opener.FCK.EditorDocument.selection.createRange().text;

    } else {

    selectedHTML = window.opener.FCK.EditorWindow.getSelection();

    }





    if (typeof selectedHTML != "undefined" && selectedHTML != '')

    {

    title = selectedHTML;

    }

    }



    // Strip absolute part of URL if requested

    if (URLMode != "absolute")

    {

    var startPos = url.indexOf("index.php?");

    url = url.substr(startPos);

    }



    // Add <A> tag around url if requested

    if (HTMLMode == 'a')

    {

    html = "<a href=\"" + url + "\"/>" + title + "</a>";

    }

    else

    html = url;



    // Paste link data into original input/textarea element



    if (targetMode == 'htmlArea30')

    {

    // TMZ commented out the next two lines:

    // window.opener.currentPagesetterEditor.focusEditor();

    // window.opener.currentPagesetterEditor.insertHTML();



    //TMZ added these two lines:

    window.opener.currentPagesetterEditor.Focus();

    window.opener.currentPagesetterEditor.InsertHtml(html);

    }

    else

    {

    // Where to insert the calculate URL

    var targetInputElement = window.opener.document.getElementById(targetInputID);



    if (targetInputElement.tagName == 'INPUT')

    {

    // Simply overwrite value of input elements

    targetInputElement.value = html;

    }

    else if (targetInputElement.tagName == 'TEXTAREA')

    {

    // Try to paste into textarea - technique depends on browser (and Pagesetter framework)



    if (typeof document.selection != "undefined")

    {

    if (targetInputElement.style.display == 'none' && // Someone has hidden the original textarea

    typeof window.opener.editor_insertHTML != "undefined") // ... and this function is defined => guess we are using htmlArea

    {

    // IE: using htmlArea for editing

    window.opener.editor_insertHTML(targetInputID, html);

    }

    else

    {

    // IE: Move focus to textarea (which fortunately keeps its current selection) and overwrite selection

    targetInputElement.focus();

    window.opener.document.selection.createRange().text = html;

    }

    }

    else if (typeof targetInputElement.selectionStart != "undefined")

    {

    // Mozilla: Get start and end points of selection and create new value based on old value

    var startPos = targetInputElement.selectionStart;

    var endPos = targetInputElement.selectionEnd;

    targetInputElement.value = targetInputElement.value.substring(0, startPos)

    + html

    + targetInputElement.value.substring(endPos, targetInputElement.value.length);

    }

    else

    {

    // Others: just append to the current value

    targetInputElement.value += html;

    }

    }

    }



    window.close();

    }


    Oh, and don't forget to place a "pagesetter.gif" icon in javascript/scribite_editors/fckeditor/editor/plugins/pagesetter/



    edited by: toddzarwell, Jul 11, 2007 - 03:03 AM

Template courtesy of Designs By Darren.