Annotation of kupu/common/kupustart.js, revision 1.1
1.1 ! dwinter 1: /*****************************************************************************
! 2: *
! 3: * Copyright (c) 2003-2005 Kupu Contributors. All rights reserved.
! 4: *
! 5: * This software is distributed under the terms of the Kupu
! 6: * License. See LICENSE.txt for license text. For a list of Kupu
! 7: * Contributors see CREDITS.txt.
! 8: *
! 9: *****************************************************************************/
! 10:
! 11: // $Id$
! 12:
! 13: function startKupu() {
! 14: // first let's load the message catalog
! 15: // if there's no global 'i18n_message_catalog' variable available, don't
! 16: // try to load any translations
! 17: if (window.i18n_message_catalog) {
! 18: var request = new XMLHttpRequest();
! 19: // sync request, scary...
! 20: request.open('GET', 'kupu-pox.cgi', false);
! 21: request.send('');
! 22: if (request.status != '200') {
! 23: alert('Error loading translation (status ' + status +
! 24: '), falling back to english');
! 25: } else {
! 26: // load successful, continue
! 27: var dom = request.responseXML;
! 28: window.i18n_message_catalog.initialize(dom);
! 29: };
! 30: };
! 31:
! 32: // initialize the editor, initKupu groks 1 arg, a reference to the iframe
! 33: var frame = getFromSelector('kupu-editor');
! 34: var kupu = initKupu(frame);
! 35:
! 36: // this makes the editor's content_changed attribute set according to changes
! 37: // in a textarea or input (registering onchange, see saveOnPart() for more
! 38: // details)
! 39: kupu.registerContentChanger(getFromSelector('kupu-editor-textarea'));
! 40:
! 41: // let's register saveOnPart(), to ask the user if he wants to save when
! 42: // leaving after editing
! 43: if (kupu.getBrowserName() == 'IE') {
! 44: // IE supports onbeforeunload, so let's use that
! 45: addEventHandler(window, 'beforeunload', saveOnPart);
! 46: } else {
! 47: // some versions of Mozilla support onbeforeunload (starting with 1.7)
! 48: // so let's try to register and if it fails fall back on onunload
! 49: var re = /rv:([0-9\.]+)/
! 50: var match = re.exec(navigator.userAgent)
! 51: if (match[1] && parseFloat(match[1]) > 1.6) {
! 52: addEventHandler(window, 'beforeunload', saveOnPart);
! 53: } else {
! 54: addEventHandler(window, 'unload', saveOnPart);
! 55: };
! 56: };
! 57:
! 58: // and now we can initialize...
! 59: kupu.initialize();
! 60:
! 61: return kupu;
! 62: };
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>