Changeset 45

Show
Ignore:
Timestamp:
11/03/06 17:11:55 (4 years ago)
Author:
jf.hovinne
Message:

Created Wymeditor object.

Location:
branches/jf.hovinne/0.3
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • branches/jf.hovinne/0.3/index.html

    r43 r45  
    44<title>WYMeditor</title> 
    55<style type="text/css"> 
    6         .wymeditor_iframe { width: 600px; } 
    7         .wymeditor_menu ul { padding:0; margin: 0; } 
    8         .wymeditor_menu li { list-style: none; float: left; margin-right: 0.7em; } 
    9         .wymeditor_content { clear: both; } 
     6        .wym_iframe { width: 75%; } 
     7        .wym_menu ul { padding:0; margin: 0; } 
     8        .wym_menu li { list-style: none; float: left; margin-right: 0.7em; } 
     9        .wym_content { clear: both; } 
    1010</style> 
    1111<script type="text/javascript" src="wymeditor/jquery.js"></script> 
    1212<script type="text/javascript" src="wymeditor/wymeditor.js"></script> 
     13<script type="text/javascript"> 
     14$(function() { 
     15 
     16        //create wymeditor instance(s) 
     17        //we replace each matched element by a Wymeditor instance 
     18        //this code is customizable 
     19 
     20        var elements=$(".wymeditor"); 
     21        var options = { 
     22                htmlToInsert: "<div class='wymeditor'></div>", 
     23                pageToLoad: "wymeditor/wymeditor.html", 
     24                iframeClass: ".wym_iframe", 
     25                execClass: ".wym_exec", 
     26                toggleClass: ".wym_toggle" 
     27        } 
     28 
     29        $(elements).each(function(i) { 
     30                var wymeditor=new Wymeditor($(this),i,options); 
     31        }); 
     32 
     33}); 
     34</script> 
    1335</head> 
    1436 
    1537<body> 
    1638<textarea id="txt1" rows="8" cols="40" class="wymeditor">&lt;p&gt;First textarea !&lt;/p&gt;</textarea><br/> 
    17 <textarea id="txt2" rows="8" cols="40" class="wymeditor">&lt;p&gt;Second textarea&lt;/p&gt;</textarea> 
     39<textarea id="txt2" rows="8" cols="40" class="wymeditor">&lt;p&gt;Second textarea&lt;/p&gt;</textarea><br /> 
     40<input type="text" id="txt3" class="wymeditor" value="&lt;p&gt;First input text&lt;/p&gt;" /> 
    1841</body> 
    1942 
  • branches/jf.hovinne/0.3/wymeditor/iframe.html

    r43 r45  
    99function init() 
    1010{ 
    11         document.body.innerHTML=window.parent.wymeditor_iframeGetContent(); 
     11        document.body.innerHTML=window.parent.wym_instance().html(); 
    1212        document.designMode="on"; 
    1313        if(window.parent.jQuery.browser.mozilla) document.execCommand("styleWithCSS",'',false); 
     
    1515</script> 
    1616</head> 
    17 <body class="wymeditor_iframe_body" contentEditable="true" onload="init()"></body> 
     17<body contentEditable="true" onload="init()"></body> 
    1818</html> 
  • branches/jf.hovinne/0.3/wymeditor/wymeditor.html

    r42 r45  
    1 <div class="wymeditor_menu"> 
    2         <ul> 
    3         <li><a href="#" onClick="wymeditor_execCom(this,'Bold')">Strong</a></li> 
    4         <li><a href="#" onClick="wymeditor_execCom(this,'Italic')">Emphasis</a></li> 
    5         <li><a href="#" onClick="wymeditor_execCom(this,'Superscript')">Superscript</a></li> 
    6         <li><a href="#" onClick="wymeditor_execCom(this,'Subscript')">Subscript</a></li> 
    7         <li><a href="#" onClick="wymeditor_execCom(this,'InsertOrderedList')">Ordered List</a></li> 
    8         <li><a href="#" onClick="wymeditor_execCom(this,'InsertUnorderedList')">Unordered List</a></li> 
    9         <li><a href="#" onClick="wymeditor_execCom(this,'Undo')">Undo</a></li> 
    10         <li><a href="#" onClick="wymeditor_execCom(this,'Redo')">Redo</a></li> 
     1<div class="wym_menu"> 
     2        <ul class="wym_execs"> 
     3                <li><a href="#" class="wym_exec" name="Bold">Strong</a></li> 
     4                <li><a href="#" class="wym_exec" name="Italic">Emphasis</a></li> 
     5                <li><a href="#" class="wym_exec" name="Superscript">Superscript</a></li> 
     6                <li><a href="#" class="wym_exec" name="Subscript">Subscript</a></li> 
     7                <li><a href="#" class="wym_exec" name="InsertOrderedList">Ordered List</a></li> 
     8                <li><a href="#" class="wym_exec" name="InsertUnorderedList">Unordered List</a></li> 
     9                <li><a href="#" class="wym_exec" name="Undo">Undo</a></li> 
     10                <li><a href="#" class="wym_exec" name="Redo">Redo</a></li> 
     11                <li><a href="#" class="wym_toggle">Toggle</a></li> 
    1112        </ul> 
    1213</div> 
    13 <div class="wymeditor_content"> 
    14         <iframe src="wymeditor/iframe.html" class="wymeditor_iframe"></iframe> 
     14<div class="wym_content"> 
     15        <iframe src="wymeditor/iframe.html" class="wym_iframe"></iframe> 
    1516</div> 
    16 <div class="wymeditor_submit"> 
    17         <ul> 
    18         <li><a href="#" onClick="wymeditor_submit(this)">Submit</a></li> 
    19         </ul> 
    20 </div> 
  • branches/jf.hovinne/0.3/wymeditor/wymeditor.js

    r44 r45  
    11/* WYMeditor - http://www.wymeditor.org/ */ 
    22 
    3 var wymeditor_content=new Array(); 
    4 var wymeditor_counter=-1; 
     3//Wymeditor object 
     4function Wymeditor(elem,index,options) { 
    55 
    6 function wymeditor_iframeGetContent() 
    7 { 
    8         wymeditor_counter++; 
    9         return(wymeditor_content[wymeditor_counter]); 
     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(); 
    1055} 
    1156 
    12 function wymeditor_execCom(elem,cmd,opt) 
    13 { 
    14         var div_editor=$(elem).ancestors("div.wymeditor"); 
    15         var iframe=$(div_editor).find("iframe.wymeditor_iframe").get(0); 
    16         if(jQuery.browser.mozilla) iframe.contentDocument.execCommand(cmd,'',opt); 
     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.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.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); 
    1780        else if(jQuery.browser.msie) iframe.contentWindow.document.execCommand(cmd); 
    1881} 
    1982 
    20 function wymeditor_submit(elem) 
    21 { 
    22         var div_editor=$(elem).ancestors("div.wymeditor"); 
    23         var iframe=$(div_editor).find("iframe.wymeditor_iframe").get(0); 
    24         var wymeditor_area=$(div_editor).prev(); 
    25          
    26         if(jQuery.browser.mozilla) $(wymeditor_area).val(iframe.contentDocument.body.innerHTML); 
    27         else if(jQuery.browser.msie) $(wymeditor_area).val(iframe.contentWindow.document.body.innerHTML); 
    28          
    29         $(wymeditor_area).show(); 
     83//Set or Get editor property 
     84Wymeditor.prototype.editor = function(o) { 
     85        if(o)this._editor=o; 
     86        else return(this._editor); 
    3087} 
    3188 
     89//Little hack to set iframe(s) content 
     90var wym_instances=new Array(); 
     91var wym_counter=-1; 
    3292 
    33 jQuery.wymeditor = { 
    34  
    35         build : function(options) { 
    36  
    37                 var settings = { 
    38                         appendCode: "<div class='wymeditor'></div>", 
    39                         loadPage: "wymeditor/wymeditor.html" 
    40                 }; 
    41  
    42                 if(options) jQuery.extend(settings,options); 
    43  
    44                 return this.each(function(i){ 
    45  
    46                         $(this).after(settings.appendCode); 
    47                         wymeditor_content[i]=$(this).val(); 
    48                  
    49                         var div_editor=$(this).next(); 
    50                         $(div_editor).load(settings.loadPage); 
    51                 }); 
    52         } 
    53  
    54 }; 
    55  
    56 jQuery.fn.wymeditor = jQuery.wymeditor.build; 
    57  
    58  
    59  
    60 $(function() { 
    61  
    62         //hide textareas 
    63         var wymeditor_area=$("textarea.wymeditor"); 
    64         $(wymeditor_area).hide(); 
    65         $(wymeditor_area).wymeditor();  //create wymeditor instance(s) 
    66  
    67 }); 
    68  
    69  
    70  
     93function wym_instance() 
     94{ 
     95        wym_counter++; 
     96        return(wym_instances[wym_counter]); 
     97}