home *** CD-ROM | disk | FTP | other *** search
- const FILE_VERSION = 5;
- var table, tree, STRINGS, hideTree, updateElement;
- var filterText = "";
- function init() {
- STRINGS = document.getElementById("strings");
- var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefService);
- prefs = prefs.getBranch("extensions.googleredesigned.");
- if (prefs.getIntPref("fileVersion") != FILE_VERSION) {
- openDialog("chrome://googleredesigned/content/repair.xul", "googleredesignedRepair", "chrome,dialog,modal,center,resizable=no", {});
- prefs.setIntPref("fileVersion", FILE_VERSION);
- }
- if (location.href.indexOf("sidebar=1") > -1) {
- var sidebarStyle = document.createProcessingInstruction("xml-stylesheet", "href=\"chrome://googleredesigned/skin/sidebar.css\" type=\"text/css\"");
- document.insertBefore(sidebarStyle, document.documentElement);
- }
- if (googleredesignedCommon.hasSSSFix) {
- document.getElementById("manage-info").style.display = "none";
- }
- tree = document.getElementById("styles");
- hideTree = document.getElementById("hide-tree");
- updateElement = document.getElementById("update");
- loadTable();
- }
- function loadTable() {
- var topVisibleRow = null;
- if (table) {
- topVisibleRow = getTopVisibleRow();
- }
- table = [];
- var enumerator = GoogleRedesignedStyle.prototype.ds.getNode(GoogleRedesignedStyle.prototype.containerURI).getChildren();
- var atLeastOne = enumerator.hasMoreElements();
- while (enumerator.hasMoreElements()) {
- var node = enumerator.getNext();
- var style = new GoogleRedesignedStyle(node);
- if (filterText == "" ||
- style.description.toLowerCase().indexOf(filterText) >= 0) {
- table.push(style);
- }
- }
- sort();
- if (topVisibleRow) {
- setTopVisibleRow(topVisibleRow);
- }
- hideTree.selectedIndex = atLeastOne ? 0 : 1;
- updateElement.disabled = !atLeastOne;
- changeSelection();
- }
- function treeView(table) {
- this.rowCount = table.length;
- this.getCellText = function (row, col) {return table[row][col.id];};
- this.getCellValue = function (row, col) {return table[row][col.id];};
- this.setCellValue = function (row, col, value) {table[row].enabledString = value;GoogleRedesignedStyle.prototype.ds.save();loadTable();};
- this.setTree = function (treebox) {this.treebox = treebox;};
- this.isEditable = function (row, col) {return col.editable;};
- this.isContainer = function (row) {return false;};
- this.isSeparator = function (row) {return false;};
- this.isSorted = function () {return false;};
- this.getLevel = function (row) {return 0;};
- this.getImageSrc = function (row, col) {return null;};
- this.getRowProperties = function (row, props) {};
- this.getCellProperties = function (row, col, props) {};
- this.getColumnProperties = function (colid, col, props) {};
- this.cycleHeader = function (col, elem) {};
- this.performActionOnRow = function (action, row) {switch (action) {case "open":if (row == -1) {openAdd();} else {googleredesignedCommon.openEdit(table[row]);}break;default:alert("Unrecognized action " + action + " on row " + row + ".");}};
- this.performAction = function (action) {switch (action) {case "delete":var styles = getSelectedStyles();var prompt, parms, title;if (styles.length == 1) {parms = [styles[0].description];title = STRINGS.getString("deleteStyleTitle");prompt = STRINGS.getFormattedString("deleteStyle", parms);} else {parms = [styles.length];title = STRINGS.getString("deleteStylesTitle");prompt = STRINGS.getFormattedString("deleteStyles", parms);}var prompts = Components.classes['@mozilla.org/embedcomp/prompt-service;1'].getService(Components.interfaces.nsIPromptService);if (prompts.confirmEx(window, title, prompt, prompts.BUTTON_POS_0 * prompts.BUTTON_TITLE_IS_STRING + prompts.BUTTON_POS_1 * prompts.BUTTON_TITLE_CANCEL, STRINGS.getString("deleteStyleOK"), null, null, null, {})) {return;}for (var i = 0; i < styles.length; i++) {if (styles[i].enabled) {styles[i].unregister();}GoogleRedesignedStyle.prototype.ds.deleteRecursive(styles[i].node);}GoogleRedesignedStyle.prototype.ds.save();loadTable();break;default:alert("Unrecognized action " + action + ".");}};
- }
- function load() {
- document.getElementById("hidesbicon").addEventListener("command", function (event) {var sss = Components.classes['@mozilla.org/content/style-sheet-service;1'].getService(Components.interfaces.nsIStyleSheetService);var ios = Components.classes['@mozilla.org/network/io-service;1'].getService(Components.interfaces.nsIIOService);var css = "@namespace url(http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul);#googleredesigned-panel,#googleredesigned-panel-prism {display: none !important;}";var uri = ios.newURI("data:text/css," + css, null, null);if (!sss.sheetRegistered(uri, sss.USER_SHEET)) {sss.loadAndRegisterSheet(uri, sss.USER_SHEET);var grprefsinstance = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);var grsbiconhide = grprefsinstance.getBoolPref("extensions.googleredesigned.sbiconhide");grprefsinstance.setBoolPref("extensions.googleredesigned.sbiconhide", true);} else {sss.unregisterSheet(uri, sss.USER_SHEET);var grprefsinstance = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);var grsbiconhide = grprefsinstance.getBoolPref("extensions.googleredesigned.sbiconhide");grprefsinstance.setBoolPref("extensions.googleredesigned.sbiconhide", false);}}, false);
- document.getElementById("toolsmnicon").addEventListener("command", function (event) {var sss = Components.classes['@mozilla.org/content/style-sheet-service;1'].getService(Components.interfaces.nsIStyleSheetService);var ios = Components.classes['@mozilla.org/network/io-service;1'].getService(Components.interfaces.nsIIOService);var css = "@namespace url(http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul);#googleredesigned-tools-menu {display: -moz-box !important;}";var uri = ios.newURI("data:text/css," + css, null, null);if(!sss.sheetRegistered(uri, sss.USER_SHEET)) {sss.loadAndRegisterSheet(uri, sss.USER_SHEET);var grprefsinstance = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);var grsbiconhide = grprefsinstance.getBoolPref("extensions.googleredesigned.toolsmnhide");grprefsinstance.setBoolPref("extensions.googleredesigned.toolsmnhide", false);} else {sss.unregisterSheet(uri, sss.USER_SHEET);var grprefsinstance = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);var grsbiconhide = grprefsinstance.getBoolPref("extensions.googleredesigned.toolsmnhide");grprefsinstance.setBoolPref("extensions.googleredesigned.toolsmnhide", true);}}, false);
- document.getElementById("turnoffau").addEventListener("command", function (event) {var grprefsinstance = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);var grautoupdateon = grprefsinstance.getBoolPref("extensions.googleredesigned.autoupdateon");if (grautoupdateon) {grprefsinstance.setBoolPref("extensions.googleredesigned.autoupdateon", false);} else {grprefsinstance.setBoolPref("extensions.googleredesigned.autoupdateon", true);}}, false);
- }
- function sort(column) {
- var columnName;
- var order = tree.getAttribute("sortDirection") == "ascending" ? 1 : -1;
- if (column) {
- columnName = column.id;
- if (tree.getAttribute("sortResource") == columnName) {
- order *= -1;
- }
- } else {
- columnName = tree.getAttribute("sortResource");
- }
- function columnSort(a, b) {
- if (prepareForComparison(a[columnName]) > prepareForComparison(b[columnName])) {
- return 1 * order;
- }
- if (prepareForComparison(a[columnName]) < prepareForComparison(b[columnName])) {
- return -1 * order;
- }
- if (columnName != "description") {
- if (prepareForComparison(a.description) > prepareForComparison(b.description)) {
- return 1;
- }
- if (prepareForComparison(a.description) < prepareForComparison(b.description)) {
- return -1;
- }
- }
- return 0;
- }
- table.sort(columnSort);
- tree.setAttribute("sortDirection", order == 1 ? "ascending" : "descending");
- tree.setAttribute("sortResource", columnName);
- tree.view = new treeView(table);
- var cols = tree.getElementsByTagName("treecol");
- for (var i = 0; i < cols.length; i++) {
- cols[i].removeAttribute("sortDirection");
- }
- document.getElementById(columnName).setAttribute("sortDirection", order == 1 ? "ascending" : "descending");
- }
- function prepareForComparison(o) {
- if (typeof o == "string") {
- return o.toLowerCase();
- }
- return o;
- }
- function getSelectedIndices() {
- var indices = [];
- var rangeCount = tree.view.selection.getRangeCount();
- for (var i = 0; i < rangeCount; i++) {
- var start = {};
- var end = {};
- tree.view.selection.getRangeAt(i, start, end);
- for (var c = start.value; c <= end.value; c++) {
- indices.push(c);
- }
- }
- return indices;
- }
- function getSelectedStyles() {
- var indices = getSelectedIndices();
- var styles = [];
- for (var i = 0; i < indices.length; i++) {
- styles.push(table[indices[i]]);
- }
- return styles;
- }
- function getTopVisibleRow() {
- return tree.treeBoxObject.getFirstVisibleRow();
- }
- function setTopVisibleRow(topVisibleRow) {
- return tree.treeBoxObject.scrollToRow(topVisibleRow);
- }
- function openAdd() {
- openDialog("chrome://googleredesigned/content/edit.xul", googleredesignedCommon.getRandomDialogName("googleredesignedEdit"), googleredesignedCommon.editDialogOptions);
- }
- function handleEditButtonClick() {
- tree.view.performActionOnRow("open", getSelectedIndices()[0]);
- }
- function handleDeleteButtonClick() {
- tree.view.performAction("delete");
- }
- function findUpdateButtonClick() {
- openDialog("chrome://googleredesigned/content/update.xul", "googleredesignedUpdate", "chrome,resizable,dialog=no,centerscreen");
- }
- function styleListKeyPress(aEvent) {
- if (aEvent.keyCode == 46) {
- tree.view.performAction("delete");
- }
- }
- function changeSelection() {
- var edit = document.getElementById("edit");
- var deleteB = document.getElementById("delete");
- var selectedStyleCount = getSelectedStyles().length;
- switch (selectedStyleCount) {
- case 0:
- edit.disabled = true;
- deleteB.disabled = true;
- break;
- case 1:
- edit.disabled = false;
- deleteB.disabled = false;
- break;
- default:
- edit.disabled = true;
- deleteB.disabled = false;
- break;
- }
- }
- function handleStyleListDoubleClick(event) {
- var row = {}, col = {}, obj = {};
- tree.treeBoxObject.getCellAt(event.clientX, event.clientY, row, col, obj);
- tree.view.performActionOnRow("open", row.value);
- }
- function inputFilter(event) {
- var value = event.target.value.toLowerCase();
- setFilter(value);
- document.getElementById("clearFilter").disabled = value.length == 0;
- }
- function clearFilter() {
- document.getElementById("clearFilter").disabled = true;
- var filterElement = document.getElementById("filter");
- filterElement.focus();
- filterElement.value = "";
- setFilter("");
- }
- function setFilter(text) {
- filterText = text;
- loadTable();
- }
- var listObserver = {onDragStart: function (event, transferData, action) {var row = {}, col = {}, obj = {};tree.treeBoxObject.getCellAt(event.clientX, event.clientY, row, col, obj);transferData.data = new TransferData;transferData.data.addDataForFlavour("text/unicode", "chrome://googleredesigned/content/edit.xul?uri=" + encodeURIComponent(table[row.value].uri));}};
-