root/trunk/EmoticonButton/mt-static/plugins/EmoticonButton/js/emoticon.js @ 644

Revision 644, 6.4 kB (checked in by fumiakiy, 19 months ago)

Fixed the bug that disabled other buttons when the plugin was installed.

Line 
1App.singletonConstructor =
2MT.App = new Class( MT.App, {
3    initEditor: function() {
4        if ( this.constructor.Editor && DOM.getElement( "editor-content" ) ) {
5           
6            var mode = DOM.getElement( "convert_breaks" );
7            DOM.addEventListener( mode, "change", this.getIndirectEventListener( "setTextareaMode" ) );
8       
9            /* special case */
10            window.cur_text_format = mode.value;
11       
12            this.editorMode = ( mode.value == "richtext" ) ? "iframe" : "textarea";
13           
14            this.editor = this.addComponent( new MT.App.Editor.Emoticon( "editor-content", this.editorMode ) );
15            this.editor.textarea.setTextMode( mode.value );
16            this.editor.emoticon = this.addComponent( new MT.App.Emoticon( "emoticon", "emoticon" ) );
17       
18            this.editorInput = {
19                content: DOM.getElement( "editor-input-content" ),
20                extended: DOM.getElement( "editor-input-extended" )
21            };
22       
23            if ( this.editorInput.content.value )
24                this.editor.setHTML( this.editorInput.content.value );
25        }
26    }
27});
28
29MT.App.Emoticon = new Class( Transient, {
30
31    initObject: function( element, templateName ) {
32        arguments.callee.applySuper( this, arguments );
33        this.templateName = templateName;
34       
35        this.contentElement = DOM.getElement( this.element.id + '-content' );
36        if( !this.contentElement )
37            this.contentElement = this.element;
38        this.icons = this.populateIcons();
39    },
40
41    open: function() {
42        arguments.callee.applySuper( this, arguments );
43        this.render();
44        this.reflow();
45    },
46
47    render: function() {
48        this.contentElement.innerHTML = Template.process( "emoticons", { "icons": this.icons } ); 
49    },
50
51    eventClick: function( event ) {
52        var name = event.target.id;
53        name = name.replace(/emoticon\-icon\-(\w+)/, '$1');
54        if (!name)
55            return;
56        var ancestor = DOM.getFirstAncestorByClassName( event.target, "emoticon-icon", true );
57        if ( ancestor )
58            DOM._rCN( ancestor, "hover-over" );
59        if ( event.shiftKey )
60            app.editor.toolbar.insertEmoticon({ 'name': name });
61        else
62            this.close( { 'name': name } );
63    },
64
65    eventMouseOver: function( event ) {
66        var ancestor = DOM.getFirstAncestorByClassName( event.target, "emoticon-icon", true );
67        if ( !ancestor )
68            return;
69        DOM._aCN( ancestor, "hover-over" );
70    },
71
72    eventMouseOut: function( event ) {
73        var ancestor = DOM.getFirstAncestorByClassName( event.target, "emoticon-icon", true );
74        if ( !ancestor )
75            return;
76        DOM._rCN( ancestor, "hover-over" );
77    },
78
79    populateIcons: function() {
80        return [
81            'sun','cloud','rain','snow','thunder','typhoon','mist','sprinkle','aries','taurus',
82            'gemini','cancer','leo','virgo','libra','scorpius','sagittarius','capricornus','aquarius','pisces',
83            'sports','baseball','golf','tennis','soccer','ski','basketball','motorsports','pocketbell','train',
84            'subway','bullettrain','car','rvcar','bus','ship','airplane','house','building','postoffice',
85            'hospital','bank','atm','hotel','24hours','gasstation','parking','signaler','toilet','restaurant',
86            'cafe','bar','beer','fastfood','boutique','hairsalon','karaoke','movie','upwardright','carouselpony',
87            'music','art','drama','event','ticket','smoking','nosmoking','camera','bag','book',
88            'ribbon','present','birthday','telephone','mobilephone','memo','tv','game','cd','heart',
89            'spade','diamond','club','eye','ear','rock','scissors','paper','downwardright','upwardleft',
90            'foot','shoe','eyeglass','wheelchair','newmoon','moon1','moon2','moon3','fullmoon','dog',
91            'cat','yacht','xmas','downwardleft','phoneto','mailto','faxto','info01','info02','mail',
92            'by-d','d-point','yen','free','id','key','enter','clear','search','new',
93            'flag','freedial','sharp','mobaq','one','two','three','four','five','six',
94            'seven','eight','nine','zero','ok','heart01','heart02','heart03','heart04','happy01',
95            'angry','despair','sad','wobbly','up','note','spa','cute','kissmark','shine',
96            'flair','annoy','punch','bomb','notes','down','sleepy','sign01','sign02','sign03',
97            'impact','sweat01','sweat02','dash','sign04','sign05','slate','pouch','pen','shadow',
98            'chair','night','soon','on','end','clock','appli01','appli02','t-shirt','moneybag',
99            'rouge','denim','snowboard','bell','door','dollar','pc','loveletter','wrench','pencil',
100            'crown','ring','sandclock','bicycle','japanesetea','watch','think','confident','coldsweats01','coldsweats02',
101            'pout','gawk','lovely','good','bleah','wink','happy02','bearing','catface','crying',
102            'weep','ng','clip','copyright','tm','run','secret','recycle','r-mark','danger',
103            'ban','empty','pass','full','leftright','updown','school','wave','fuji','clover',
104            'cherry','tulip','banana','apple','bud','maple','cherryblossom','riceball','cake','bottle',
105            'noodle','bread','snail','chick','penguin','fish','delicious','smile','horse','pig',
106            'wine','shock'
107        ];
108    }
109} );
110
111MT.App.Editor.Emoticon = new Class( MT.App.Editor, {
112
113} );
114
115MT.App.Editor.Emoticon.Textarea = new Class( MT.App.Editor.Textarea, {
116
117} );
118
119MT.App.Editor.Emoticon.Iframe = new Class( MT.App.Editor.Iframe, {
120
121} );
122
123MT.App.Editor.Emoticon.Toolbar = new Class( MT.App.Editor.Toolbar, {
124       
125    insertEmoticon: function( data ) {
126        if (!data) return;
127        var name = data['name'];
128        if (!name) return;
129        this.editor.insertHTML('<img class="emoticon ' + name + '" src="' + StaticURI + 'plugins/EmoticonButton/images/emoticons/' + name + '.gif" alt="' + name + '" style="border:0;" />');
130    },
131
132    eventClick: function( event ) {
133        var command = this.getMouseEventCommand( event );
134        if ( !command )
135            return event.stop();
136
137        switch( command ) {
138
139            case "openEmoticonPallet":
140                this.editor.emoticon.open( null, this._gIM('insertEmoticon'), event.commandElement );
141                break;
142
143            default:
144                return arguments.callee.applySuper( this, arguments );
145       
146        }
147
148        return event.stop();
149    }
150});
Note: See TracBrowser for help on using the browser.