Subversion Repositories wimsdev

Rev

Blame | 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('Italics',function(){
  35.                         this.wrapSelection('<em>','</em>');
  36.                 },{
  37.                         id: 'markdown_italics_button'
  38.                 });
  39.                
  40.                 this.toolbar.addButton('Bold',function(){
  41.                         this.wrapSelection('<strong>','</strong>');
  42.                 },{
  43.                         id: 'markdown_bold_button'
  44.                 });
  45.                
  46.                 this.toolbar.addButton('Link',function(){
  47.                         var selection = this.getSelection();
  48.                         var response = prompt('Enter Link URL','');
  49.                         if(response == null)
  50.                                 return;
  51.                         this.replaceSelection('<a href="'+response+'">' + (selection == '' ? 'Link Text' : selection) + '</a>' + (response == '' ? '' : '').replace(/^(?!(f|ht)tps?:\/\/)/,'') + '');
  52.                 },{
  53.                         id: 'markdown_link_button'
  54.                 });
  55.                
  56.                 this.toolbar.addButton('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="Image manquante"}' : selection) + '' + (response == '' ? '' : '').replace(/^(?!(f|ht)tps?:\/\/)/,'') + '');
  63.                 },{
  64.                         id: 'markdown_image_button'
  65.                 });
  66.                
  67.                 //this.toolbar.addButton('Heading',function(){
  68.                         //var selection = this.getSelection();
  69.                         //if(selection == '')
  70.                                 //selection = 'Heading';
  71.                         //var str = '';
  72.                         //(Math.max(5,selection.length)).times(function(){
  73.                                 //str += '-';
  74.                         //});
  75.                         //this.replaceSelection("\n" + selection + "\n" + str + "\n");
  76.                 //},{
  77.                         //id: 'markdown_heading_button'
  78.                 //});
  79.                
  80.                 this.toolbar.addButton('Heading',function(){
  81.                         this.wrapSelection('<h1>','</h1>');
  82.                 },{
  83.                         id: 'markdown_heading_button'
  84.                 });
  85.                
  86.                
  87.                 this.toolbar.addButton('Unordered List',function(){
  88.                         this.wrapSelection('<ul>','</ul>');
  89.                 },{
  90.                         id: 'markdown_unordered_list_button'
  91.                 });
  92.                
  93.                 this.toolbar.addButton('Ordered List',function(){
  94.                         this.wrapSelection('<li>','</li>');
  95.                 },{
  96.                         id: 'markdown_ordered_list_button'
  97.                 });
  98.                
  99.                 this.toolbar.addButton('espace',function(event){
  100.                         this.injectEachSelectedLine(function(lines,line){
  101.                                 lines.push((event.shiftKey ? line.replace(/^\> /,'') : '' + line));
  102.                                 return lines;
  103.                         });
  104.                 },{
  105.                         id: 'markdown_espace_button'
  106.                 });
  107.                 this.toolbar.addButton('title',function(){
  108.                         this.wrapSelection('\n\\title{}','');
  109.                 },{
  110.                         id: 'markdown_title_button'
  111.                 });
  112.                
  113.                
  114.                 this.toolbar.addButton('Help',function(){
  115.                         function help_url(){
  116.                                 var url="?session="+document.getElementById("help_url").innerHTML+"&lang=fr&module=adm/createxo.fr&cmd=help&special_parm=enev";
  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('auteur',function(){
  127.                         this.wrapSelection('\n\\author{}','');
  128.                 },{
  129.                         id: 'markdown_auteur_button'
  130.                 });
  131.                 this.toolbar.addButton('range',function(){
  132.                         this.wrapSelection("\n\\range{}",'');
  133.                 },{
  134.                         id: 'markdown_range_button'
  135.                 });
  136.                
  137.                
  138.                
  139.                 this.toolbar.addButton('espace2',function(){
  140.                         this.wrapSelection('','');
  141.                 },{
  142.                         id: 'markdown_espace2_button'
  143.                 });
  144.                 this.toolbar.addButton('statem',function(){
  145.                         this.wrapSelection('\n\\statement{}','');
  146.                 },{
  147.                         id: 'markdown_statem_button'
  148.                 });
  149.                 this.toolbar.addButton('hint',function(){
  150.                         this.wrapSelection('\n\\hint{}','');
  151.                 },{
  152.                         id: 'markdown_hint_button'
  153.                 });
  154.                 this.toolbar.addButton('help',function(){
  155.                         this.wrapSelection('\n\\help{}','');
  156.                 },{
  157.                         id: 'help'
  158.                 });
  159.                 this.toolbar.addButton('espace3',function(){
  160.                         this.wrapSelection('','');
  161.                 },{
  162.                         id: 'markdown_espace3_button'
  163.                 });
  164.                 this.toolbar.addButton('answer',function(){
  165.                         this.wrapSelection('\n\\answer{}{}{type=}','');
  166.                 },{
  167.                         id: 'markdown_answer_button'
  168.                 });
  169.                
  170.                
  171.                 this.toolbar.addButton('feed',function(){
  172.                         this.wrapSelection('\n\\feedback{}{}','');
  173.                 },{
  174.                         id: 'markdown_feed_button'
  175.                 });
  176.                 this.toolbar.addButton('condition',function(){
  177.                         this.wrapSelection('\n\\condition{}{}','');
  178.                 },{
  179.                         id: 'markdown_condition_button'
  180.                 });
  181.                 this.toolbar.addButton('solution',function(){
  182.                         this.wrapSelection('\n\\solution{}','');
  183.                 },{
  184.                         id: 'markdown_solution_button'
  185.                 });
  186.         }
  187. });