// O = Opdatering
// P = Ttv page
// P = Ttvpumpe
+// Q = Open quicklink dialog
// R = Requeue in tango
// S = Snapshot
// T = Test
var TV2Developer = {
_lastAction: null,
+
+ /* method for initialize, reading properties, adding icon at firstrun, added keyshortcuts */
init: function() {
// init
this._lastAction = this.getPref('lastaction-linktype');
+ // add shortcuts depending on platform
+ var shortcuts = document.getElementById('mainKeyset');
+ // We take this from ui.key.chromeAccess (no other way it seems, jkkn)
+ // Use 0 for disabled, 1 for Shift, 2 for Ctrl, 4 for Alt, 8 for Meta
+ // (values can be combined, e.g. 5 for Alt+Shift)
+ var altKey = []; // ALT on windows, CONTROL on mac
+ var chromeAccess =
+ Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService)
+ .getBranch('ui.key.').getIntPref('chromeAccess');
+ if (chromeAccess & 1) altKey.push('shift');
+ if (chromeAccess & 2) altKey.push('control');
+ if (chromeAccess & 4) altKey.push('alt');
+ if (chromeAccess & 8) altKey.push('meta');
+ if (altKey.length > 0) {
+ altKey = altKey.join(',');
+ this._addShortcut(shortcuts, 'tv2-key-open', altKey, '1', 'TV2Developer.handleKeyShortcut(event)');
+ this._addShortcut(shortcuts, 'tv2-key-repeat', altKey, '2', 'TV2Developer.handleButton(event)');
+ this._addShortcut(shortcuts, 'tv2-key-quick', altKey, '3', 'TV2Developer.openQuickbox(event)');
+ }
+ // first run, add icon
if (this.getPref('firstRun')) {
this.setPref('firstRun', false);
// add icon
catch(e) { }
}
},
-
+
+ /* utility function to create shortcut object */
+ _addShortcut: function(parent, id, modifiers, key, oncommand) {
+ var newKey = document.createElement('key');
+ newKey.setAttribute('id', id);
+ newKey.setAttribute('modifiers', modifiers);
+ newKey.setAttribute('key', key);
+ newKey.setAttribute('oncommand', oncommand);
+ parent.appendChild(newKey);
+ },
+
+ /* string methods for localizations */
_strs: null,
get strs() {
if (!this._strs) {
return this.strs.getString(str);
} catch(e) {
alert('Missing string: ' + str);
+ return '';
}
},
+ /* preference functions */
_prefs: null,
get prefs() {
if (!this._prefs)
}
},
+ /* popup menu utility functions */
emptyMenu: function(menu) {
var children = menu.childNodes;
- for (var i = children.length - 1; i >= 0; --i)
- {
- var index = children[i].getAttribute('tv2link');
- if (index)
- menu.removeChild(children[i]);
- }
+ for (var i = children.length - 1; i >= 0; --i) {
+ menu.removeChild(children[i]);
+ }
},
TV2Link: function(type, domain, uri, accesskey, flags) {
menu.appendChild(item);
return def;
},
-
+
+ /* Main function for adding all the links for the menu popup */
_reg_tv2: /^https?:\/\/([^/.]*)?([^/]*?)(\.(robot|opdatering2?|template)\.?)?(\.((test|snapshot)3?)\.)?tv2\.dk((\/[^#\?]*).*)?$/,
_reg_php: /^(.*\.php)/,
_reg_nodeid: /([0-9]{2,})/g,
return links;
},
-
+
+ /* fill in menu onbefore popup event */
fillMenu: function(event) {
var menu = event.target;
var links = this.getLinks();
for (var i=0; i<links.length; i++) {
defSet |= this.addMenuLink(menu, links[i], defSet);
}
+
+ // add link to quickbox
+ menu.appendChild(document.createElement('menuseparator'));
+ var item = document.createElement('menuitem');
+ item.setAttribute('label', this.getStr('quickbox.menuitem'));
+ item.setAttribute('accesskey', this.getStr('quickbox.accesskey'));
+ item.setAttribute('tooltiptext', this.getStr('quickbox.menuitem'));
+ item.setAttribute('oncommand', 'TV2Developer.openQuickbox(event)');
+ menu.appendChild(item);
},
+ /* handle a link menu item */
handleMenu: function(event) {
var t = event.target;
this.gotoLink(event, t.getAttribute('url'),
t.getAttribute('tv2flags'));
},
+ /* return link for default action */
getButtonAction: function() {
/* repeat last action or may hit a fall back link of same type */
var children = this.getLinks();
return null;
},
+ /* handle click on button, either default action or show menu */
handleButton: function(event) {
var action = this.getButtonAction();
if (action) {
}
}
},
-
+
+ /* shortcut to open menu */
handleKeyShortcut: function(event) {
document.getElementById('tv2-swap-button').open = true;
},
-
+
+ /* utility function to go to a link */
gotoLink: function(event, url, tv2linktype, tv2flags) {
if (url) {
/* handle flags */
this.clearCache();
}
}
- /* follow link */
- openUILink(url, event, false, false, false); /* allow ctrl, alt, but don't google */
+ /* follow link */
+ openUILink(url, event, false, true, false); /* allow ctrl, not alt, and don't google */
if (tv2linktype) {
this._lastAction = tv2linktype;
this.setPref('lastaction-linktype', tv2linktype);
}
},
- /* function to clear cache */
+ /* function to clear browser cache */
clearCache: function () {
var cacheService = Components.classes["@mozilla.org/network/cache-service;1"]
.getService(Components.interfaces.nsICacheService);
} catch(ex) {}
},
-}
+ /* Below is functionality for the quick link box */
+
+ _addCheckbox: function(here, id, label, accesskey) {
+ var radio = document.createElement('radio');
+ radio.setAttribute('id', id);
+ radio.setAttribute('label', label);
+ radio.setAttribute('accesskey', accesskey);
+ here.appendChild(radio);
+ },
-window.addEventListener("load", function(e) { TV2Developer.init(); }, false);
+ updateQuickbox: function() {
+ var postfix = document.getElementById('radiobox-rows');
+ var username = this.getPref('developer-initials');
+ var php4 = '';
+ // add webroot links
+ var webroot = document.createElement('row');
+ this._addCheckbox(webroot, 'postfix-live', '.tv2.dk', this.getStr('quickbox.live.accesskey'));
+ this._addCheckbox(webroot, 'postfix-test', '.'+username+'.test'+php4+'.tv2.dk', this.getStr('quickbox.test.accesskey'));
+ this._addCheckbox(webroot, 'postfix-snapshot', '.snapshot'+php4+'.tv2.dk', this.getStr('quickbox.snapshot.accesskey'));
+ postfix.appendChild(webroot);
+ // add opdatering links
+ var opdatering = document.createElement('row');
+ this._addCheckbox(opdatering, 'postfix-live-opdatering', '.opdatering.tv2.dk', this.getStr('quickbox.live-opdatering.accesskey'));
+ this._addCheckbox(opdatering, 'postfix-test-opdatering', '.'+username+'.opdatering.test'+php4+'.tv2.dk', this.getStr('quickbox.test-opdatering.accesskey'));
+ this._addCheckbox(opdatering, 'postfix-snapshot-opdatering', '.opdatering.snapshot'+php4+'.tv2.dk', this.getStr('quickbox.snapshot-opdatering.accesskey'));
+ postfix.appendChild(opdatering);
+ // add robot links
+ var robot = document.createElement('row');
+ this._addCheckbox(robot, 'postfix-live-robot', '.robot.tv2.dk', this.getStr('quickbox.live-robot.accesskey'));
+ this._addCheckbox(robot, 'postfix-test-robot', '.robot.'+username+'.test'+php4+'.tv2.dk', this.getStr('quickbox.test-robot.accesskey'));
+ this._addCheckbox(robot, 'postfix-snapshot-robot', '.robot.snapshot'+php4+'.tv2.dk', this.getStr('quickbox.snapshot-robot.accesskey'));
+ postfix.appendChild(robot);
+ // select default radio button
+ var def = document.getElementById(this.getPref('lastaction-quickbox-postfix', 'postfix-live'));
+ if (def) {
+ document.getElementById('tv2postfix').selectedItem = def;
+ }
+ document.getElementById('tv2prefix').value = this.getPref('lastaction-quickbox-prefix', '');
+ document.getElementById('php4site').checked = this.getPref('lastaction-quickbox-php4site', false);
+ },
+
+ goQuickbox: function() {
+ var prefix = document.getElementById('tv2prefix').value;
+ var postfix_obj = document.getElementById('tv2postfix').selectedItem;
+ var php4site = document.getElementById('php4site').checked;
+ var url;
+ this.setPref('lastaction-quickbox-prefix', prefix);
+ this.setPref('lastaction-quickbox-postfix', postfix_obj.id);
+ this.setPref('lastaction-quickbox-php4site', document.getElementById('php4site').checked);
+ if (postfix_obj.id.substr(0, 8)=='postfix-') {
+ if (prefix == '') {
+ prefix = 'www';
+ }
+ var postfix = postfix_obj.label;
+ if (php4site) { /* change test to test3, snapshot to snapshot3 */
+ postfix = postfix.replace(/(test|snapshot)(\.tv2\.dk)/, '$13$2');
+ }
+ url = prefix+postfix;
+ } else {
+ var id = encodeURIComponent(prefix);
+ if (postfix_obj.id == 'go-node') {
+ url = 'http://i2.opdatering.tv2.dk/tool/node/?id=' + id;
+ } else if (postfix_obj.id == 'go-content-id') {
+ url = 'http://i2.opdatering2.tv2.dk/tool/query/?id=&2=&3=&_checkbox=1&content_id='+id+'&4=&5=0&6=&action=Query&timeout=1';
+ } else if (postfix_obj.id == 'go-ttv-page') {
+ url = 'http://i2.opdatering2.tv2.dk/tool/ttv/?1=' + id + '&2=0';
+ }
+ }
+ window.close();
+ opener.openUILink(url, 'current', false, false, false); /* allow ctrl, alt, but don't google */
+ },
+
+ openQuickbox: function(event) {
+ window.openDialog('chrome://tv2developer/content/quickbox.xul','tv2quickbox','chrome,dialog,modal');
+ }
+
+}