Subversion Repositories wimsdev

Rev

Rev 4468 | Go to most recent revision | 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 href="'+response+'">' + (selection == '' ? names["Link_Text"] : selection) + '</a>' + (response == '' ? '' : '').replace(/^(?!(f|ht)tps?:\/\/)/,'') + '');
  52.                 },{
  53.                         id: 'markdown_link_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 src="\\filedir/'+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>\n</ol>');
  95.                 },{
  96.                         id: 'markdown_ordered_list_button'
  97.                 });
  98.                
  99.                 this.toolbar.addButton(names["List_item"],function(){
  100.                         this.wrapSelection('<li> \n','\n </li>');
  101.                 },{
  102.                         id: 'markdown_ordered_list_button'
  103.                 });
  104.                
  105.                 this.toolbar.addButton('',function(event){
  106.                         this.injectEachSelectedLine(function(lines,line){
  107.                                 lines.push((event.shiftKey ? line.replace(/^\> /,'') : '' + line));
  108.                                 return lines;
  109.                         });
  110.                 },{
  111.                         id: 'markdown_espace_button'
  112.                 });
  113.         }
  114. });