source: trunk/plugins/SaveSubmit/save-submit.js @ 999

Last change on this file since 999 was 999, checked in by ray, 11 years ago

#1195 Allow to specify an external url to load a plugin from

  • Property svn:keywords set to LastChangedDate LastChangedRevision LastChangedBy HeadURL Id
File size: 4.9 KB
Line 
1/*------------------------------------------*\
2SaveSubmit for Xinha
3____________________
4
5See README.txt for information
6
7\*------------------------------------------*/
8
9function SaveSubmit(editor) {
10        this.editor = editor;
11        this.changed = false;
12        var self = this;
13        var cfg = editor.config;
14        this.textarea = this.editor._textArea;
15
16        this.image_changed = Xinha.getPluginDir("SaveSubmit")+"/img/ed_save_red.gif";
17        this.image_unchanged = Xinha.getPluginDir("SaveSubmit")+"/img/ed_save_green.gif";
18        cfg.registerButton({
19        id       : "savesubmit",
20        tooltip  : self._lc("Save"),
21        image    : this.image_unchanged,
22        textMode : false,
23        action   :  function() {
24                        self.save();
25                }
26        });
27        cfg.addToolbarElement("savesubmit", "popupeditor", -1);
28}
29
30SaveSubmit.prototype._lc = function(string) {
31    return Xinha._lc(string, 'SaveSubmit');
32}
33
34SaveSubmit._pluginInfo = {
35  name          : "SaveSubmit",
36  version       : "1.0",
37  developer     : "Raimund Meyer",
38  developer_url : "http://rheinauf.de",
39  c_owner       : "Raimund Meyer",
40  sponsor       : "",
41  sponsor_url   : "",
42  license       : "htmlArea"
43}
44
45SaveSubmit.prototype.onGenerateOnce = function() {
46        this.initial_html = this.editor.getInnerHTML();
47}
48
49SaveSubmit.prototype.onKeyPress = function(ev) {
50        if ( ev.ctrlKey && this.editor.getKey(ev) == 's') {
51                        this.save(this.editor);
52                        Xinha._stopEvent(ev);
53                        return true;
54        }
55        else {
56                if (!this.changed) {
57                        if (this.getChanged()) this.setChanged();
58                        return false;
59                }
60        }
61}
62SaveSubmit.prototype.onExecCommand = function (cmd) {
63        if (this.changed && cmd == 'undo') {
64                if (this.initial_html == this.editor.getInnerHTML()) this.setUnChanged();
65                return false;
66        }
67}
68SaveSubmit.prototype.onUpdateToolbar = function () {
69        if (!this.changed) {
70                if (this.getChanged()) this.setChanged();
71                return false;
72        }       
73}
74SaveSubmit.prototype.getChanged = function() {
75        if (this.initial_html === null) this.initial_html = this.editor.getInnerHTML();
76        if (this.initial_html != this.editor.getInnerHTML() && this.changed == false) {
77                this.changed = true;
78                return true;
79        }
80        else return false;
81}
82SaveSubmit.prototype.setChanged = function() {
83        this.editor._toolbarObjects.savesubmit.swapImage(this.image_changed);
84        this.editor.updateToolbar();
85}
86SaveSubmit.prototype.setUnChanged = function() {
87        this.changed = false;
88        this.editor._toolbarObjects.savesubmit.swapImage(this.image_unchanged);
89}
90SaveSubmit.prototype.changedReset = function() {
91        this.initial_html = null;
92        this.setUnChanged();
93}
94
95SaveSubmit.prototype.save =  function() {
96        this.buildMessage();
97        var editor = this.editor;
98        var self =this;
99        var form = editor._textArea.form;
100        form.onsubmit();
101
102        var name, value, content ='';
103       
104        for (var i=0;i<form.elements.length;i++)
105        {
106                if (( form.elements[i].type == 'checkbox' || form.elements[i].type == 'radio' ) && !form.elements[i].checked ) continue;
107
108                content += ((i>0) ? '&' : '') + form.elements[i].name + '=' + encodeURIComponent(form.elements[i].value);
109        }
110
111        Xinha._postback(editor._textArea.form.action, content, function(getback) {
112
113                if (getback) {
114                        self.setMessage(getback);
115                        //self.setMessage(self._lc("Ready"));
116                        self.changedReset();
117                }
118                removeMessage = function() { self.removeMessage()} ;
119                window.setTimeout("removeMessage()",1000);
120        });
121}
122
123SaveSubmit.prototype.setMessage = function(string) {
124  var textarea = this.textarea;
125  if ( !document.getElementById("message_sub_" + textarea.id)) { return ; }
126  var elt = document.getElementById("message_sub_" + textarea.id);
127  elt.innerHTML = Xinha._lc(string, 'SaveSubmit');
128}
129
130SaveSubmit.prototype.removeMessage = function() {
131  var textarea = this.textarea;
132  if (!document.getElementById("message_" + textarea.id)) { return ; }
133  document.body.removeChild(document.getElementById("message_" + textarea.id));
134}
135
136//ripped mokhet's loading message function
137SaveSubmit.prototype.buildMessage   = function() {
138
139        var textarea = this.textarea;
140        var htmlarea = this.editor._htmlArea;
141        var loading_message = document.createElement("div");
142        loading_message.id = "message_" + textarea.id;
143        loading_message.className = "loading";
144        loading_message.style.width    = htmlarea.offsetWidth +'px' ;//(this.editor._iframe.offsetWidth != 0) ? this.editor._iframe.offsetWidth +'px' : this.editor._initial_ta_size.w;
145
146        loading_message.style.left     = Xinha.findPosX(htmlarea) +  'px';
147        loading_message.style.top      = (Xinha.findPosY(htmlarea) + parseInt(htmlarea.offsetHeight) / 2) - 50 +  'px';
148
149        var loading_main = document.createElement("div");
150        loading_main.className = "loading_main";
151        loading_main.id = "loading_main_" + textarea.id;
152        loading_main.appendChild(document.createTextNode(this._lc("Saving...")));
153
154        var loading_sub = document.createElement("div");
155        loading_sub.className = "loading_sub";
156        loading_sub.id = "message_sub_" + textarea.id;
157        loading_sub.appendChild(document.createTextNode(this._lc("in progress")));
158        loading_message.appendChild(loading_main);
159        loading_message.appendChild(loading_sub);
160        document.body.appendChild(loading_message);
161}
Note: See TracBrowser for help on using the repository browser.