~automne-team/automne/4.2

« back to all changes in this revision

Viewing changes to automne/fckeditor/automnePlugin/polymod/fckpolymod.js

  • Committer: sebastien
  • Date: 2008-11-26 17:12:36 UTC
  • Revision ID: sebastien_sebastien-20081126171236-16r3kxfuz2kmq2qe
Tags: V4_0_0a0
4.0.0a0 :
Initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* vim: set expandtab tabstop=4 shiftwidth=4: */
 
2
// +----------------------------------------------------------------------+
 
3
// | Automne (TM)                                                         |
 
4
// +----------------------------------------------------------------------+
 
5
// | Copyright (c) 2000-2004 WS Interactive                               |
 
6
// | Copyright (c) 2000-2004 Antoine Pouch                                |
 
7
// +----------------------------------------------------------------------+
 
8
// | This source file is subject to version 2.0 of the GPL license,       |
 
9
// | or (at your discretion) to version 3.0 of the PHP license.           |
 
10
// | The first is bundled with this package in the file LICENSE-GPL, and  |
 
11
// | is available at through the world-wide-web at                        |
 
12
// | http://www.gnu.org/copyleft/gpl.html.                                |
 
13
// | The later is bundled with this package in the file LICENSE-PHP, and  |
 
14
// | is available at through the world-wide-web at                        |
 
15
// | http://www.php.net/license/3_0.txt.                                  |
 
16
// +----------------------------------------------------------------------+
 
17
// | Author: Frederico Caldeira Knabben (fredck@fckeditor.net)            |
 
18
// | Author: S�bastien Pauchet <sebastien.pauchet@ws-interactive.fr>      |    
 
19
// +----------------------------------------------------------------------+
 
20
//
 
21
// $Id: fckpolymod.js,v 1.1.1.1 2008/11/26 17:12:14 sebastien Exp $
 
22
 
 
23
/**
 
24
  * Javascript plugin for FCKeditor
 
25
  * Create Automne medias items insertions
 
26
  *
 
27
  * @package CMS
 
28
  * @subpackage admin
 
29
  * @author Frederico Caldeira Knabben (fredck@fckeditor.net)
 
30
  * @author S�bastien Pauchet <sebastien.pauchet@ws-interactive.fr>
 
31
  */
 
32
 
 
33
var oEditor = window.parent.InnerDialogLoaded() ;
 
34
var FCK         = oEditor.FCK ;
 
35
var FCKLang     = oEditor.FCKLang ;
 
36
 
 
37
// oSpan: The selected span in the editor if any.
 
38
var oSpan;
 
39
// oID: The span id in the editor if any
 
40
var oID = '';
 
41
// oContent: The selected text content in the editor if any
 
42
var oContent = '';
 
43
 
 
44
//Initialization Code
 
45
window.onload = function()
 
46
{
 
47
        // Translate the dialog box texts.
 
48
        oEditor.FCKLanguageManager.TranslatePage(document) ;
 
49
        // Load the selected span informations (if any).
 
50
        LoadSelection() ;
 
51
        //load iframe with span infos
 
52
        GetE('plugin').src = GetE('iframeURL').value + '?id=' + oID + '&content=' + escape(oContent);
 
53
        // Show the initial dialog content.
 
54
        GetE('divInfo').style.display = '' ;
 
55
        // Activate the "OK" button.
 
56
        window.parent.SetOkButton( true ) ;
 
57
}
 
58
//load current selected span if any and all span infos
 
59
function LoadSelection()
 
60
{
 
61
        oSpan = FCK.Selection.MoveToAncestorNode( 'SPAN' ) ;
 
62
        if ( oSpan && oSpan.className == 'polymod'){
 
63
                FCK.Selection.SelectNode( oSpan ) ;
 
64
                oID = oSpan.id;
 
65
                //oContent = oSpan.textContent;
 
66
                if (typeof oSpan.innerText != 'undefined') { //IE
 
67
                        oContent = oSpan.innerText;
 
68
                } else if (typeof oSpan.textContent != 'undefined') { //GECKO
 
69
                        oContent = oSpan.textContent;
 
70
                }
 
71
        } else {
 
72
                if (FCK.EditorWindow.getSelection) { //GECKO
 
73
                        oContent = FCK.EditorWindow.getSelection();
 
74
                } else { //IE
 
75
                        var oRange = FCK.EditorDocument.selection.createRange() ;
 
76
                        oContent = oRange.text;
 
77
                }
 
78
        }
 
79
        return;
 
80
}
 
81
//The OK button was hit.
 
82
function Ok()
 
83
{
 
84
        if (GetE('codeToPaste').value == '') {
 
85
                alert(FCKLang['DlgPolymodNoPage']);
 
86
        } else {
 
87
                var codeToPaste = htmlDecode(GetE('codeToPaste').value);
 
88
                //remove old selection code
 
89
                FCK.Selection.Delete();
 
90
                //then paste the new one
 
91
                FCK.InsertHtml(codeToPaste);
 
92
                //try to exec JS if any
 
93
                /*var re = /(?:<script([^>]*)?>)((\n|\r|.)*?)(?:<\/script>)/ig;
 
94
                while(match = re.exec(codeToPaste)){
 
95
                        if(match[2] && match[2].length > 0){
 
96
                                eval(match[2]);
 
97
                        }
 
98
                }*/
 
99
                //then close windows
 
100
                window.parent.Cancel() ;
 
101
        }
 
102
}
 
103
function htmlDecode(value){
 
104
        return !value ? value : String(value).replace(/&amp;/g, "&").replace(/&gt;/g, ">").replace(/&lt;/g, "<").replace(/&quot;/g, '"');
 
105
}