Development

/plugins/sfI18NTranslatorPlugin/modules/sfI18NTranslator/templates/indexSuccess.js.php

You must first sign up to be able to contribute.

root/plugins/sfI18NTranslatorPlugin/modules/sfI18NTranslator/templates/indexSuccess.js.php

Revision 12488, 2.4 kB (checked in by florian.klein, 5 years ago)

Added scriptaculous include in partial

Line 
1
2 $(document).observe('dom:loaded', function(event) {
3     new SfI18NTranslator();
4 });
5
6 var SfI18NTranslator = Class.create({
7
8     bound: {},
9     element: null,
10     form: null,
11
12     initialize: function() {
13    
14         this.form = $('sfI18NTranslator-form');
15        
16         //new Draggable(this.form);
17        
18         this.initEvents();
19         this.initBindings();
20     },
21    
22     initEvents: function() {
23         this.bound = {
24             update: this.update.bindAsEventListener(this),
25             fillForm: this.fillForm.bindAsEventListener(this),
26             hover: this.hover.bindAsEventListener(this),
27             leave: this.leave.bindAsEventListener(this),
28             close: this.close.bindAsEventListener(this)
29         };
30     },
31    
32     initBindings: function() {
33         $$('.translate').each(function( el ) {
34             el.observe('click', this.bound.fillForm );
35             el.observe('mouseover', this.bound.hover );
36             el.observe('mouseout', this.bound.leave );
37         }.bind(this));
38         this.form.observe('submit', this.bound.update );
39         $('sfI18NTranslator-form-close').observe('click', this.bound.close );
40     },
41    
42     fillForm: function(event) {
43         this.element = event.element();
44        
45         $('sfI18NTranslator-source').value = this.getSource();
46         $('sfI18NTranslator-target').value = this.getTarget();
47         $('sfI18NTranslator-target').focus();
48         this.form.show();
49     },
50    
51     hover: function(event) {
52         event.element().addClassName('hover');
53     },
54    
55     leave: function(event) {
56         event.element().removeClassName('hover');
57     },
58    
59     getSource: function() {
60         return this.element.hasAttribute('name') ? this.element.readAttribute('name') : this.element.firstChild.nodeValue;
61     },
62    
63     getTarget: function() {
64         return this.element.hasAttribute('name') ? this.element.firstChild.nodeValue : '';
65     },
66        
67     update: function(event) {
68         event.stop();
69         this.form.request({
70             method: 'post',
71             onComplete: function( transport, json ) {
72                 json = json || transport.responseText.evalJSON();
73                 this.element.writeAttribute('name', json.source );
74                 this.element.firstChild.nodeValue = json.target;
75                 //new Effect.Highlight(this.element);
76             }.bind(this)
77         });
78     },
79    
80     close: function(event) {
81         event.stop();
82         this.form.hide();
83     }
84 });
85
Note: See TracBrowser for help on using the browser.