/// chrome://wikilocaledit/content/config.js
/// Serve configuration dialog.
// Requires:
// * content/fileIO.js
// * content/locale.js
// * content/permissions.js
// Used by windows:
// * content/config.xul
// Uses:
// * wikiLocalEdit.pages.fresh()
/// 2012-11-30 [email protected]
/// Fingerprint: #0#0#
/// <nowiki>
/*jshint curly:true, eqeqeq:true, strict:true, undef:true, white:false */
/*global document, KeyEvent, window */
/*jslint plusplus: true, white: true */
/*globals KeyEvent: true, document: true, window: true */
( function ( w ) {
"use strict";
var CNF, PREFS;
if ( ! w.wikiLocalEdit ) {
w.wikiLocalEdit = { };
}
w.wikiLocalEdit.self = "PerfektesChaos/[email protected]";
if ( ! w.wikiLocalEdit.cnf ) {
w.wikiLocalEdit.cnf = { };
}
CNF = w.wikiLocalEdit.cnf;
PREFS = w.wikiLocalEdit.prefs;
CNF.onLoad = function() {
CNF.checkLead = document.getElementById( "leading_default" );
CNF.basedir = document.getElementById( "basedir_default" );
CNF.textbox = document.getElementById( "userpage_textbox" );
CNF.listbox = document.getElementById( "userpages_list" );
CNF.buttAdd = document.getElementById( "buttonAdd" );
CNF.buttRemove = document.getElementById( "buttonRemove" );
CNF.buttClear = document.getElementById( "buttonRemoveAll" );
CNF.getVersion();
CNF.checkLead.checked = PREFS.getLeading();
CNF.setBasedir();
CNF.userlist = PREFS.getUserlist();
CNF.setListbox();
CNF.userpageSelected();
w.sizeToContent();
}; // .cnf.onLoad()
CNF.getVersion = function() {
var display, em, s;
if ( "@mozilla.org/extensions/manager;1" in w.Components.classes ) {
em = w.Components.classes[ "@mozilla.org/extensions/manager;1" ]
.getService( w.Components.interfaces.nsIExtensionManager );
if ( "getItemForID" in em ) {
s = em.getItemForID( w.wikiLocalEdit.self ).version;
if ( s ) {
display =
document.getElementById( "WikiLocalEditVersion" );
if ( s && display ) {
display.value = s;
}
}
}
}
}; // .cnf.getVersion()
CNF.updateLeading = function() {
PREFS.setLeading( CNF.checkLead.checked );
}; // .cnf.updateLeading()
CNF.updateBasedir = function() {
PREFS.fetchBasedir();
CNF.setBasedir();
}; // .cnf.updateBasedir()
CNF.setBasedir = function() {
CNF.basedir.value = PREFS.getDirBase();
}; // .cnf.updateBasedir()
CNF.setListbox = function() {
var i, n,
l = true;
while ( CNF.listbox.getRowCount() ) {
CNF.listbox.removeItemAt( 0 );
} // while not empty
if ( this.userlist ) {
n = this.userlist.length;
for ( i = 0; i < n; i++ ) {
this.listbox.ensureElementIsVisible(
this.listbox.appendItem( this.userlist[ i ] ) );
} // for i
l = false;
}
CNF.buttRemove.disabled = true;
CNF.buttClear.disabled = l;
}; // .cnf.setListbox()
CNF.userpageInput = function() {
var s = CNF.textbox.value,
s2 = s.trim();
if ( s2 !== s ) {
s = s2;
CNF.textbox.value = s;
}
CNF.buttAdd.disabled = ( s ? false : true );
}; // .cnf.userpageInput()
CNF.userpageKeypress = function( event ) {
if ( event ) {
if ( event.type === "keypress" ) {
if ( event.keyCode === KeyEvent.DOM_VK_RETURN ) {
event.preventDefault();
CNF.addUserpage();
} else {
CNF.userpageInput();
}
}
}
}; // .cnf.userpageKeypress()
CNF.addUserpage = function() {
// Uses:
// > .reUserURL
// > .locale.userpageAlert
var i, n,
l = false,
s = CNF.textbox.value;
if ( w.wikiLocalEdit.reUserURL.test( s ) ) {
l = true;
if ( CNF.userlist ) {
n = this.userlist.length;
for ( i = 0; i < n; i++ ) {
if ( CNF.userlist[ i ] === s ) {
l = false;
break;
}
} // for i
if ( l ) {
CNF.userlist.push( s );
CNF.userlist.sort();
}
} else {
CNF.userlist = [ s ];
}
CNF.textbox.value = "";
} else {
w.alert( w.wikiLocalEdit.locale.userpageAlert + "\n" + s );
}
if ( l ) {
CNF.setListbox();
}
CNF.buttAdd.disabled = true;
}; // .cnf.addUserpage()
CNF.userpageSelected = function() {
CNF.buttRemove.disabled = ( CNF.listbox.selectedIndex < 0 );
}; // .cnf.userpageSelected()
CNF.removeUserpage = function() {
var i = CNF.listbox.selectedIndex,
n;
if ( i >= 0 ) {
CNF.listbox.removeItemAt( i );
if ( i ) {
n = CNF.listbox.getRowCount();
if ( i === n ) {
CNF.userlist.pop();
} else {
CNF.userlist = CNF.userlist.slice( 0, i )
.concat( CNF.userlist.slice( i + 1 ) );
}
} else {
CNF.userlist.shift();
if ( ! CNF.userlist.length ) {
CNF.userlist = false;
CNF.buttClear.disabled = true;
}
}
}
CNF.buttRemove.disabled = true;
}; // .cnf.removeUserpage()
CNF.removeAllUserpages = function() {
CNF.userlist = false;
CNF.setListbox();
}; // .cnf.removeAllUserpages()
CNF.doOK = function () {
// Uses:
// > .pages.fresh()
var i, n,
s = "";
if ( CNF.userlist ) {
n = CNF.userlist.length;
for ( i = 0; i < n; i++ ) {
if ( i ) {
s = s + " ";
}
s = s + CNF.userlist[ i ];
} // for i
}
PREFS.setUserpages( s );
if ( typeof w.wikiLocalEdit.pages.fresh === "function" ) {
w.wikiLocalEdit.pages.fresh();
}
w.close();
return true;
}; // .cnf.doOK()
} ( window ) );
/// EOF </nowiki> content/config.js