~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to www/media/browser/editor.js

  • Committer: wagrant
  • Date: 2008-07-14 02:33:23 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:856
editor.js: Prompt before allowing users to navigate away from a
           modified file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
    data = editbox.getCode();
16
16
    /* Do NOT refresh the page contents (causes problems for editarea and is
17
17
     * unnecessary). */
18
 
    if (current_file.svnstatus != "revision" ||
19
 
        confirm("You are currently viewing an older version of this file. " +
20
 
                "Saving will overwrite the current version. " +
21
 
                "Are you sure you want to continue?"))
22
 
    {
23
 
        do_action("putfile", filename,
24
 
                  {"path":".", "data":data, "overwrite":"true"},
25
 
                  "multipart/form-data", true);
26
 
        disable_save_if_safe();
27
 
    }
 
18
    do_action("putfile", filename,
 
19
              {"path":".", "data":data, "overwrite":"true"},
 
20
              "multipart/form-data", true);
 
21
    disable_save_if_safe();
28
22
}
29
23
 
30
24
function save_file_as(default_filename)
80
74
    editbox.edit(editbox.getCode(), select.value);
81
75
}
82
76
 
83
 
function initialise_codepress()
84
 
{
85
 
    editbox.addChangeHandler(edit_text);
86
 
    editbox.addSaveHandler(function() {document.getElementById("save_button").click()});
87
 
     
88
 
    /* We can only safely disable the save button on the first load.
89
 
     * Syntax highlighting changes will also get this function called.
90
 
     * We unfortunately need the change handler added each time.
91
 
     */
92
 
    if (!initialise_codepress.already)
93
 
    {
94
 
        disable_save_if_safe();
95
 
        initialise_codepress.already = true;
96
 
    }
97
 
}
98
 
 
99
77
/** Presents the text editor.
100
78
 */
101
79
function handle_text(path, text, handler_type)
120
98
    language = language ? language : "text";
121
99
    document.getElementById("highlighting_select").value = language;
122
100
 
123
 
    txt_elem.className = "codepress autocomplete-off " + language;
 
101
    txt_elem.className = "codepress " + language;
124
102
    txt_elem.setAttribute("onchange", "edit_text()");
125
103
    /* TODO: Make CSS height: 100% work */
126
104
    txt_elem.setAttribute("rows", "35");
132
110
     * can set a callback so we know when to enable the save button.
133
111
     * We also take this opportunity to disable the save button, if
134
112
     * the browser is likely to reenable it as needed. */
135
 
    editbox.onload = initialise_codepress
 
113
    editbox.onload = function() {editbox.addChangeHandler(edit_text);
 
114
                                 disable_save_if_safe(); };
136
115
}
137
116
 
138
117
function language_from_mime(mime)
142
121
            'text/css': 'css',
143
122
            'text/plain': 'text',
144
123
            'text/html': 'html',
145
 
            'application/xml': 'html',
146
124
            'application/xhtml+xml': 'html'}[mime];
147
125
}