plugin.js
88 lines
| 1 | /** |
| 2 | * plugin.js (edited for WP) |
| 3 | * |
| 4 | * Copyright, Moxiecode Systems AB |
| 5 | * Released under LGPL License. |
| 6 | * |
| 7 | * License: http://www.tinymce.com/license |
| 8 | * Contributing: http://www.tinymce.com/contributing |
| 9 | */ |
| 10 | |
| 11 | /*global tinymce:true */ |
| 12 | |
| 13 | tinymce.PluginManager.add('emoticons', function(editor, url) { |
| 14 | var emoticons = [{ |
| 15 | smile: ':-)', |
| 16 | razz: ':-P', |
| 17 | cool: '8-)', |
| 18 | wink: ';-)', |
| 19 | biggrin: ':-D' |
| 20 | }, |
| 21 | { |
| 22 | twisted: ':twisted:', |
| 23 | mrgreen: ':mrgreen:', |
| 24 | lol: ':lol:', |
| 25 | rolleyes: ':roll:', |
| 26 | confused: ':-?' |
| 27 | }, |
| 28 | { |
| 29 | cry: ':cry:', |
| 30 | surprised: ':-o', |
| 31 | evil: ':evil:', |
| 32 | neutral: ':-|', |
| 33 | redface: ':oops:' |
| 34 | }, |
| 35 | { |
| 36 | mad: ':-x', |
| 37 | eek: '8-O', |
| 38 | sad: ':-(', |
| 39 | arrow: ':arrow:', |
| 40 | idea: ':idea:' |
| 41 | }]; |
| 42 | |
| 43 | function getHtml() { |
| 44 | var emoticonsHtml; |
| 45 | |
| 46 | emoticonsHtml = '<table role="list" class="mce-grid">'; |
| 47 | |
| 48 | tinymce.each(emoticons, function( row ) { |
| 49 | emoticonsHtml += '<tr>'; |
| 50 | |
| 51 | tinymce.each( row, function( icon, name ) { |
| 52 | var emoticonUrl = url + '/img/icon_' + name + '.gif'; |
| 53 | |
| 54 | emoticonsHtml += '<td><a href="#" data-mce-alt="' + icon + '" tabindex="-1" ' + |
| 55 | 'role="option" aria-label="' + icon + '"><img src="' + |
| 56 | emoticonUrl + '" style="width: 15px; height: 15px; padding: 3px;" role="presentation" alt="' + icon + '" /></a></td>'; |
| 57 | }); |
| 58 | |
| 59 | emoticonsHtml += '</tr>'; |
| 60 | }); |
| 61 | |
| 62 | emoticonsHtml += '</table>'; |
| 63 | |
| 64 | return emoticonsHtml; |
| 65 | } |
| 66 | |
| 67 | editor.addButton('emoticons', { |
| 68 | type: 'panelbutton', |
| 69 | panel: { |
| 70 | role: 'application', |
| 71 | autohide: true, |
| 72 | html: getHtml, |
| 73 | onclick: function(e) { |
| 74 | var linkElm = editor.dom.getParent( e.target, 'a' ); |
| 75 | |
| 76 | if ( linkElm ) { |
| 77 | editor.insertContent( |
| 78 | ' ' + linkElm.getAttribute('data-mce-alt') + ' ' |
| 79 | ); |
| 80 | |
| 81 | this.hide(); |
| 82 | } |
| 83 | } |
| 84 | }, |
| 85 | tooltip: 'Emoticons' |
| 86 | }); |
| 87 | }); |
| 88 |