Subversion Repositories wimsdev

Rev

Rev 4575 | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. /**
  2.  * @author Ryan Johnson <ryan@livepipe.net>
  3.  * @copyright 2007 LivePipe LLC
  4.  * @package Control.TextArea.ToolBar.Markdown
  5.  * @license MIT
  6.  * @url http://livepipe.net/projects/control_textarea/
  7.  * @version 1.0.1
  8.  */
  9.  
  10. Control.TextArea.ToolBar.Markdown = Class.create();
  11. Object.extend(Control.TextArea.ToolBar.Markdown.prototype,{
  12.         textarea: false,
  13.         toolbar: false,
  14.         options: {},
  15.         initialize: function(textarea,options){
  16.                 this.textarea = new Control.TextArea(textarea);
  17.                 this.toolbar = new Control.TextArea.ToolBar(this.textarea);
  18.                 this.converter = (typeof(Showdown) != 'undefined') ? new Showdown.converter : false;
  19.                 this.options = {
  20.                         preview: false,
  21.                         afterPreview: Prototype.emptyFunction
  22.                 };
  23.                 Object.extend(this.options,options || {});
  24.                 if(this.options.preview){
  25.                         this.textarea.observe('change',function(textarea){
  26.                                 if(this.converter){
  27.                                         $(this.options.preview).update(this.converter.makeHtml(textarea.getValue()));
  28.                                         this.options.afterPreview();
  29.                                 }
  30.                         }.bind(this));
  31.                 }
  32.  
  33.                 //buttons
  34.                 this.toolbar.addButton(names["Italics"],function(){
  35.                         this.wrapSelection('<em>','</em>');
  36.                 },{
  37.                         id: 'markdown_italics_button'
  38.                 });
  39.                
  40.                 this.toolbar.addButton(names["Bold"],function(){
  41.                         this.wrapSelection('<strong>','</strong>');
  42.                 },{
  43.                         id: 'markdown_bold_button'
  44.                 });
  45.                
  46.                 this.toolbar.addButton(names["Link"],function(){
  47.                         var selection = this.getSelection();
  48.                         var response = prompt(names["Enter_Link_URL"],'http://');
  49.                         if(response == null)
  50.                                 return;
  51.                         this.replaceSelection('\n<a class=\"wims_external\" href="'+response+'">' + (selection == '' ? names["Link_Text"] : selection) + '</a>' + (response == '' ? '' : '').replace(/^(?!(f|ht)tps?:\/\/)/,'') + '');
  52.                 },{
  53.                         id: 'markdown_link_external_button'
  54.                 });
  55.                
  56.                 /*this.toolbar.addButton(names["Image"],function(){
  57.                         var selection = this.getSelection();
  58.                         afficherHud('hud_video_intro');
  59.                         var response=null;
  60.                         if(response == null)
  61.                                 return;
  62.                         this.replaceSelection('\\img{'+response+'}' + (selection == '' ? '{alt="'+names["image_alt"]+'"}' : selection) + '' + (response == '' ? '' : '').replace(/^(?!(f|ht)tps?:\/\/)/,'') + '');
  63.                 },{
  64.                         id: 'markdown_image_button'
  65.                 });*/
  66.                
  67.                 this.toolbar.addButton(names["Image"],function(){
  68.                         var selection = this.getSelection();
  69.                         //afficherHud('hud_video_intro');
  70.                         var response = prompt(names["Enter_img_URL"],'test.jpg');
  71.  
  72.                         //if(response == null)
  73.                                 //return;
  74.                         this.replaceSelection('\\img{'+response+'}' + (selection == '' ? '{alt="'+names["image_alt"]+'"}' : selection) + '' + (response == '' ? '' : '').replace(/^(?!(f|ht)tps?:\/\/)/,'') + '');
  75.                 },{
  76.                         id: 'markdown_image_button'
  77.                 });
  78.                
  79.  
  80.                 this.toolbar.addButton(names["Heading"],function(){
  81.                         this.wrapSelection('\n<h1>','</h1>');
  82.                 },{
  83.                         id: 'markdown_heading_button'
  84.                 });
  85.                
  86.                
  87.                 this.toolbar.addButton(names["Unordered_List"],function(){
  88.                         this.wrapSelection('\n<ul>\n <li>','\n </li>\n</ul>');
  89.                 },{
  90.                         id: 'markdown_unordered_list_button'
  91.                 });
  92.                
  93.                 this.toolbar.addButton(names["Ordered_List"],function(){
  94.                         this.wrapSelection('\n<ol>\n <li>','\n </li></ol>');
  95.                 },{
  96.                         id: 'markdown_ordered_list_button'
  97.                 });
  98.                
  99.                 this.toolbar.addButton('',function(event){
  100.                         this.injectEachSelectedLine(function(lines,line){
  101.                                 lines.push((event.shiftKey ? line.replace(/^\> /,'') : '' + line));
  102.                                 return lines;
  103.                         });
  104.                 },{
  105.                         class: 'markdown_espace_button'
  106.                 });
  107.                 this.toolbar.addButton(names["title"],function(){
  108.                         this.wrapSelection('\n\\title{ ','}');
  109.                 },{
  110.                         id: 'markdown_title_button'
  111.                 });
  112.                
  113.                
  114.                 this.toolbar.addButton(names["User_guide"],function(){
  115.                         function help_url(){
  116.                                 var url="?session="+document.getElementById("session_wims").innerHTML+"&lang="+version+"&module=adm/createxo&cmd=help&special_parm=JS_editor";
  117.  
  118.                                 return url;
  119.                                 }
  120.                         var help_url=help_url();
  121.  
  122.                         window.open(help_url);
  123.                 },{
  124.                         id: 'markdown_help_button'
  125.                 });
  126.                 this.toolbar.addButton(names["author"],function(){
  127.                         this.wrapSelection('\n\\author{ ','}');
  128.                 },{
  129.                         id: 'markdown_auteur_button'
  130.                 });
  131.                 this.toolbar.addButton(names["email"],function(){
  132.                         this.wrapSelection('\n\\email{',' }');
  133.                 },{
  134.                         id: 'markdown_email_button'
  135.                 });
  136.                
  137.                
  138.                
  139.                 this.toolbar.addButton('',function(){
  140.                         this.wrapSelection('','');
  141.                 },{
  142.                         class: 'markdown_espace_button'
  143.                 });
  144.                 this.toolbar.addButton(names["statement"],function(){
  145.                         this.wrapSelection('\n\\statement{\n','\n}');
  146.                 },{
  147.                         id: 'markdown_statem_button'
  148.                 });
  149.                 this.toolbar.addButton(names["hint"],function(){
  150.                         this.wrapSelection('\n\\hint{\n','\n}');
  151.                 },{
  152.                         id: 'markdown_hint_button'
  153.                 });
  154.                 this.toolbar.addButton(names["help"],function(){
  155.                         this.wrapSelection('\n\\help{\n','\n}');
  156.                 },{
  157.                         id: 'help'
  158.                 });
  159.                 this.toolbar.addButton('',function(){
  160.                         this.wrapSelection('','');
  161.                 },{
  162.                         class: 'markdown_espace_button'
  163.                 });
  164.                 this.toolbar.addButton(names["answer"],function(){
  165.                         this.wrapSelection('\n\\answer{ }{ }{type= ','}{option= }{weight= }\n');
  166.                 },{
  167.                         id: 'markdown_answer_button'
  168.                 });
  169.                
  170.                 this.toolbar.addButton(names["feedback"],function(){
  171.                         this.wrapSelection('\n\\feedback{ }{\n','\n}');
  172.                 },{
  173.                         id: 'markdown_feed_button'
  174.                 });
  175.                 this.toolbar.addButton(names["condition"],function(){
  176.                         this.wrapSelection('\n\\condition{ ',' }{ }');
  177.                 },{
  178.                         id: 'markdown_condition_button'
  179.                 });
  180.                 this.toolbar.addButton(names["solution"],function(){
  181.                         this.wrapSelection('\n\\solution{\n','\n}');
  182.                 },{
  183.                         id: 'markdown_solution_button'
  184.                 });
  185.         }
  186. });