Rev 5759 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
3619 | bpr | 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 | }); |
||
7850 | bpr | 39 | |
3619 | bpr | 40 | this.toolbar.addButton(names["Bold"],function(){ |
41 | this.wrapSelection('<strong>','</strong>'); |
||
42 | },{ |
||
43 | id: 'markdown_bold_button' |
||
44 | }); |
||
7850 | bpr | 45 | |
3619 | bpr | 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; |
||
4533 | bpr | 51 | this.replaceSelection('\n<a target=\"wims_external\" href="'+response+'">' + (selection == '' ? names["Link_Text"] : selection) + '</a>' + (response == '' ? '' : '').replace(/^(?!(f|ht)tps?:\/\/)/,'') + ''); |
3619 | bpr | 52 | },{ |
4575 | bpr | 53 | id: 'markdown_link_external_button' |
3619 | bpr | 54 | }); |
7850 | bpr | 55 | |
3619 | bpr | 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 | });*/ |
||
7850 | bpr | 66 | |
3619 | bpr | 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; |
||
5759 | bpr | 74 | this.replaceSelection('<img src="\\filedir/'+response+'"' + (selection == '' ? ' alt="'+names["image_alt"]+'"/>' : selection) + '' + (response == '' ? '' : '').replace(/^(?!(f|ht)tps?:\/\/)/,'') + ''); |
3619 | bpr | 75 | },{ |
76 | id: 'markdown_image_button' |
||
77 | }); |
||
7850 | bpr | 78 | |
3619 | bpr | 79 | this.toolbar.addButton(names["Heading"],function(){ |
7850 | bpr | 80 | this.wrapSelection('\n<h2 class="wims_docu">','</h2>'); |
3619 | bpr | 81 | },{ |
82 | id: 'markdown_heading_button' |
||
83 | }); |
||
7850 | bpr | 84 | |
3619 | bpr | 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 | }); |
||
7850 | bpr | 90 | |
3619 | bpr | 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 | }); |
||
7850 | bpr | 96 | |
3619 | bpr | 97 | this.toolbar.addButton(names["List_item"],function(){ |
4468 | bpr | 98 | this.wrapSelection('<li>\n','\n </li>'); |
3619 | bpr | 99 | },{ |
100 | id: 'markdown_ordered_list_button' |
||
101 | }); |
||
7850 | bpr | 102 | |
4468 | bpr | 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 | },{ |
||
4575 | bpr | 109 | id: 'markdown_link_internal_button' |
4468 | bpr | 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 | },{ |
||
4575 | bpr | 117 | id: 'markdown_link_internal_button' |
4468 | bpr | 118 | }); |
7850 | bpr | 119 | |
4468 | bpr | 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 | },{ |
||
4575 | bpr | 127 | id: 'markdown_link_internal_button' |
4468 | bpr | 128 | }); |
3619 | bpr | 129 | } |
7850 | bpr | 130 | }); |