root/branches/jf.hovinne/0.3-002/wymeditor/wymeditor.js

Revision 46, 2.2 kB (checked in by jf.hovinne, 4 years ago)

Minor bug fix (msie).

Line 
1/* WYMeditor - http://www.wymeditor.org/ */
2
3//Wymeditor object
4function Wymeditor(elem,index,options) {
5
6        var _html=null;
7        var _editor=null;
8        var _wymeditor=this;
9
10        this.version = "0.3-alpha-002";
11        this.element = elem;
12
13        this.init = function() {
14
15                this.html(elem.val());
16                elem.hide();
17                elem.after(options.htmlToInsert);
18                wym_instances[index]=this;
19               
20                var div_editor=elem.next();
21                this.editor(div_editor);
22                this.element=elem;
23
24                $(div_editor).load(options.pageToLoad,null,function(){
25
26                        var iframe=$(div_editor).find(options.iframeClass).get(0);
27                        var elem=$(div_editor).prev();
28                        var wymeditor=_wymeditor;
29
30                        $(div_editor).find(options.execClass).click(function(){
31
32                                wymeditor.execCommand(iframe,$(this).name());
33                        });
34
35                        $(div_editor).find(options.toggleClass).toggle(function(){
36
37                                var html=wymeditor.iframeHtml(iframe);
38                                wymeditor.html(html)
39                                $(elem).val(html);
40
41                                $(elem).toggle();
42
43                                },function(){
44
45                                var html=$(elem).val();
46                                wymeditor.html(html);
47                                wymeditor.iframeHtml(iframe,html);
48
49                                $(elem).toggle();
50                        });
51                });
52        }
53
54        this.init();
55}
56
57//Set or Get html property
58Wymeditor.prototype.html = function(s) {
59        if(s)this._html=s;
60        else return(this._html);
61}
62
63//Set or Get iframe innerHTML
64Wymeditor.prototype.iframeHtml = function(iframe,s) {
65        if(s) {
66                if(jQuery.browser.mozilla) iframe.contentDocument.body.innerHTML=s;
67                else if(jQuery.browser.msie) iframe.contentWindow.document.body.innerHTML=s;
68        }
69        else {
70                var html="";
71                if(jQuery.browser.mozilla) html=iframe.contentDocument.body.innerHTML;
72                else if(jQuery.browser.msie) html=iframe.contentWindow.document.body.innerHTML;
73                return(html);
74        }
75}
76
77//Exec command (bold,italic,...)
78Wymeditor.prototype.execCommand = function(iframe,cmd) {
79        if(jQuery.browser.mozilla) iframe.contentDocument.execCommand(cmd,'',null);
80        else if(jQuery.browser.msie) iframe.contentWindow.document.execCommand(cmd);
81}
82
83//Set or Get editor property
84Wymeditor.prototype.editor = function(o) {
85        if(o)this._editor=o;
86        else return(this._editor);
87}
88
89//Little hack to set iframe(s) content
90var wym_instances=new Array();
91var wym_counter=-1;
92
93function wym_instance()
94{
95        wym_counter++;
96        return(wym_instances[wym_counter]);
97}
Note: See TracBrowser for help on using the browser.