Subversion Repositories wimsdev

Rev

Rev 5759 | 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 target=\"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 src="\\filedir/'+response+'"' + (selection == '' ? ' alt="'+names["image_alt"]+'"/>' : selection) + '' + (response == '' ? '' : '').replace(/^(?!(f|ht)tps?:\/\/)/,'') + '');
  75.                 },{
  76.                         id: 'markdown_image_button'
  77.                 });
  78.  
  79.                 this.toolbar.addButton(names["Heading"],function(){
  80.                         this.wrapSelection('\n<h2 class="wims_docu">','</h2>');
  81.                 },{
  82.                         id: 'markdown_heading_button'
  83.                 });
  84.  
  85.                 this.toolbar.addButton(names["Unordered_List"],function(){
  86.                         this.wrapSelection('\n<ul>\n <li>','\n </li>\n</ul>');
  87.                 },{
  88.                         id: 'markdown_unordered_list_button'
  89.                 });
  90.  
  91.                 this.toolbar.addButton(names["Ordered_List"],function(){
  92.                         this.wrapSelection('\n<ol>\n <li>','\n </li>\n</ol>');
  93.                 },{
  94.                         id: 'markdown_ordered_list_button'
  95.                 });
  96.  
  97.                 this.toolbar.addButton(names["List_item"],function(){
  98.                         this.wrapSelection('<li>\n','\n </li>');
  99.                 },{
  100.                         id: 'markdown_ordered_list_button'
  101.                 });
  102.  
  103.                 this.toolbar.addButton(names["wims_link"],function(){
  104.                  var selection = this.getSelection();
  105.                         var response = prompt(names["Enter_link_name"],'');
  106.                         if(response == '' ) return; if(response == null ) return;
  107.                         this.replaceSelection(' \\link{'+response+'} ');
  108.                 },{
  109.                         id: 'markdown_link_internal_button'
  110.                 });
  111.                 this.toolbar.addButton(names["wims_fold"],function(){
  112.                  var selection = this.getSelection();
  113.                         var response = prompt(names["Enter_fold_name"],'');
  114.                         if(response == '') return; if(response == null) return;
  115.                         this.replaceSelection(' \\fold{'+response+'} ');
  116.                 },{
  117.                         id: 'markdown_link_internal_button'
  118.                 });
  119.  
  120.                 this.toolbar.addButton(names["wims_href"],function(){
  121.                  var selection = this.getSelection();
  122.                         var response = prompt(names["Enter_href_name"],'');
  123.                         var response2 = prompt(names["Enter_href_name2"],'');
  124.                         if(response == '' ) return; if(response == null) return;
  125.                         this.replaceSelection(' \\href{'+response+'}{'+response2+'} ');
  126.                 },{
  127.                         id: 'markdown_link_internal_button'
  128.                 });
  129.         }
  130. });
  131.