+++ /dev/null
-// TV 2 Developer Plugin
-// Javascript Implementation
-// @author Kristian Kræmmer Nielsen <jkkn@tv2.dk>
-//
-// Keyboard shortcuts
-// . = Prompttest
-// 2 = Back from i2
-// 7 = Lookup R7 video clip
-// A = Template
-// B = Robot
-// C = Gitweb
-// D = Dynamic version
-// E = Node info
-// F = Tango interface
-// G = Look in tango
-// H = View source in Gitweb
-// I = I2 tree
-// K = Lookup content
-// L = Live
-// N = Node lookup
-// O = Opdatering
-// P = Ttv page
-// P = Ttvpumpe
-// Q = Open quicklink dialog
-// R = Requeue in tango
-// S = Snapshot
-// T = Test
-// T = tv2.dk
-// U = Node query tool
-// V = W3C markup validator
-// W = Webroot
-// X = Examine database queries
-// Y = Flush cache
-
-var TV2Developer = {
-
- _lastAction: null,
- _useStatusBarIconInstead: false,
-
- /* toggle between statusbar/toolbar mode */
- updateStatusBarMode: function() {
- var enabled = this._useStatusBarIconInstead = TV2Util.getPref('useStatusBarMode');
-
- var statusbutton = document.getElementById('tv2developer_statusbutton');
- var swapbutton = document.getElementById('tv2-swap-button');
- var popupmenu = document.getElementById('tv2developer-popupmenu');
-
- statusbutton.hidden = !enabled;
- swapbutton.hidden = enabled;
-
- if (enabled) {
- statusbutton.appendChild(popupmenu);
- } else {
- swapbutton.appendChild(popupmenu);
- }
- },
-
- /* method for initialize, reading properties, adding icon at firstrun, added keyshortcuts */
- init: function() {
- // init
- this._lastAction = TV2Util.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', 'VK_F1', 'TV2Developer.handleKeyShortcut(event)');
- this._addShortcut(shortcuts, 'tv2-key-repeat', altKey, '2', 'VK_F2', 'TV2Developer.handleButton(event)');
- this._addShortcut(shortcuts, 'tv2-key-quick', altKey, '3', 'VK_F3', 'TV2Developer.openQuickbox(event)');
- this._addShortcut(shortcuts, 'tv2-key-quick-go', altKey, '4', 'VK_F4', 'TV2Developer.openQuickbox(event, true)');
- }
-
- // first run, add icon
- if (TV2Util.getPref('firstRun')) {
- TV2Util.setPref('firstRun', false);
- // add icon
- try {
- var firefoxnav = document.getElementById('nav-bar');
- var curSet = firefoxnav.currentSet;
- if (curSet.indexOf('tv2-swap-button') == -1)
- {
- var set;
- // Place the button after the urlbar
- if (curSet.indexOf('urlbar-container') != -1)
- set = curSet.replace(/urlbar-container/, 'urlbar-container,tv2-swap-button');
- else // otherwise at the end
- set = firefoxnav.currentSet + ',tv2-swap-button';
- firefoxnav.setAttribute('currentset', set);
- firefoxnav.currentSet = set;
- document.persist('nav-bar', 'currentset');
- // If you don't do the following call, funny things happen
- try {
- BrowserToolboxCustomizeDone(true);
- }
- catch (e) { }
- }
- }
- catch(e) { }
- }
-
- // initializes the statusbar icon by observe optional preference changes
- TV2Util.prefs.addObserver('useStatusBarMode', {
- observe: function(subject, topic, data) {
- if (topic == 'nsPref:changed') {
- TV2Developer.updateStatusBarMode();
- }
- }}, false);
- TV2Developer.updateStatusBarMode();
- },
-
- /* utility function to create shortcut object */
- _addShortcut: function(parent, id, modifiers, key, fkeycode, 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);
- // also add F-key shortcut
- newKey = document.createElement('key');
- newKey.setAttribute('id', id+'-fkey');
- newKey.setAttribute('modifiers', 'accel');
- newKey.setAttribute('keycode', fkeycode);
- newKey.setAttribute('oncommand', oncommand);
- parent.appendChild(newKey);
- },
-
- /* popup menu utility functions */
- emptyMenu: function(menu) {
- var children = menu.childNodes;
- for (var i = children.length - 1; i >= 0; --i) {
- menu.removeChild(children[i]);
- }
- },
-
- TV2Link: function(type, domain, uri, accesskey, flags) {
- this.type = type;
- // Postfix label with up to 25 chars of uri
- this.label = domain;
- if (uri.length > 25) {
- this.label += uri.substr(0, 23) + '\u2026';
- } else {
- this.label += uri;
- }
- this.url = 'http://' + domain + uri;
- if (accesskey) this.accesskey = accesskey;
- this.disabled = false;
- this.flags = (flags ? flags : '');
- },
-
- TV2LinkSplit: function () {
- this.type = 'split';
- },
-
- TV2LinkWithLabel: function(type, label, url, accesskey, flags, disabled) {
- this.type = type;
- this.label = label;
- this.url = url;
- if (accesskey) this.accesskey = accesskey;
- this.disabled = typeof(disabled)!='undefined' ? disabled : false;
- this.flags = (flags ? flags : '');
- },
-
- addMenuLink: function(menu, tv2link, defSet) {
- var def = false;
- var item;
- if (tv2link.type == 'split') {
- item = document.createElement('menuseparator');
- } else {
- item = document.createElement('menuitem');
- item.setAttribute('label', tv2link.label);
- if (tv2link.accesskey)
- item.setAttribute('accesskey', tv2link.accesskey);
- item.setAttribute('url', tv2link.url);
- item.setAttribute('tooltiptext', tv2link.label);
- item.setAttribute('disabled', tv2link.disabled);
- item.setAttribute('tv2flags', tv2link.flags);
- if (!defSet && tv2link.type == this._lastAction) {
- item.setAttribute('style', 'font-weight: bold');
- def = true;
- }
- }
- item.setAttribute('tv2link', tv2link.type);
- menu.appendChild(item);
- return def;
- },
-
- _isPhp4: function(site) {
- if (!site) site = 'www';
- return ((','+TV2Util.getPref('php4sites')+',').indexOf(','+site+',') != -1);
- },
-
- /* Main function for adding all the links for the menu popup */
- _reg_tv2: /^https?:\/\/([^/.]*)?([^/]*?)(\.(robot|opdatering|template)\.?)?(\.(php4|php5)\.?)?(\.((test3?|snapshot3?|stage))\.)?tv2\.dk((\/[^#\?]*).*)?$/,
- _reg_branchuser: /^\.(([^.]*?)\.)?([^.]*)/,
- _reg_php: /^(.*\.php)/,
- _reg_nodeid: /([0-9]{2,})/g,
- _reg_i2files: /\/([0-9]+)-/,
- _reg_r7program: /-([0-9]+)\//,
- _reg_fromgitweb: /^https?:\/\/flimmer\.tv2\.dk\/git\/\?p=([^/]+)\.tv2\.dk\.git.*(?:f=(webroot|robot|opdatering|template)([^;&]*))/,
- _reg_fromi2if: /^\/(tango\/(entry|requeue|dynamic)|tool\/pdo_log\/frameset)\.php.*?(\?|&)url=([^&]+)/,
- _reg_cutdomain: /^(.*)\.tv2\.dk$/,
- getLinks: function() {
- var links = new Array();
- var currentURL = getBrowser().currentURI.spec;
- var encodedURL = encodeURIComponent(currentURL);
- var initials = TV2Util.getPref('developer-initials');
-
- /* Check if we are on the Gitweb site */
- var fromgitweb = this._reg_fromgitweb.exec(currentURL);
-
- // Adding links as appropiate if tv2.dk site
- var tv2 = this._reg_tv2.exec(currentURL);
-
- if (tv2 && !fromgitweb) {
- var skip_treenodes = false;
- var tv2_sitename = tv2[1];
- var tv2_branchuser = tv2[2];
- var tv2_sitetype = tv2[4];
- var tv2_apptype = tv2[6]; // php4 or php5
- var tv2_testsite = tv2[8];
- var tv2_testtype = tv2[9]; /* no 3 */
- var tv2_uri = tv2[10];
- var tv2_uriOnly = tv2[11]; // no parameters, anchers
-
- // Strip -dyn and -static
- if (tv2_sitename) tv2_sitename = tv2_sitename.replace(/-(dyn|static)$/, '');
-
- // convert old URLs (.test3 / .snapshot3)
- if (tv2_testsite == 'test3') {
- tv2_testsite = 'test';
- tv2_apptype = 'php4';
- } else if (tv2_testsite == 'snapshot3') {
- tv2_testsite = 'snapshot';
- tv2_apptype = 'php4';
- }
-
- var tv2_user;
- var tv2_branch;
- // In stage and snapshot and test - split username and branch
- if (tv2_testsite == 'snapshot' || tv2_testsite == 'stage' || tv2_testsite == 'test' && tv2_branchuser) {
- if (tv2_testsite == 'test') { // if only one - this is the username
- var bc = this._reg_branchuser.exec(tv2_branchuser);
- if (bc) {
- tv2_branch = bc[2];
- tv2_user = bc[3];
- }
- } else { // we do not have usernames on snapshot/stage, so this is the branch
- tv2_branch = tv2_branchuser.replace(/^\./, '');
- }
- }
-
- // php4 site
- var php4 = this._isPhp4(tv2_sitename);
- if (!tv2_apptype) {
- tv2_apptype = php4 ? 'php4' : 'php5';
- }
-
- // Handle sites with aliases (e.g. ol2008.tv2.dk is ol.tv2.dk on live... )
- var git_sitename;
- var live_sitename = (tv2_sitename ? tv2_sitename : 'www');
-
- var docWin = getBrowser().contentWindow;
- if (docWin.wrappedJSObject) {
- var docObj = docWin.wrappedJSObject;
- if (docObj.TV2_PROJECTNAME) {
- var nodomain = this._reg_cutdomain.exec(docObj.TV2_PROJECTNAME);
- if (nodomain) {
- git_sitename = nodomain[1];
- }
- }
- if (docObj.TV2_LIVESITE) {
- var nodomain = this._reg_cutdomain.exec(docObj.TV2_LIVESITE);
- if (nodomain) {
- live_sitename = nodomain[1];
- }
- }
- }
-
- // Find live, test, stage and snapshot url for current site
- var liveurl;
- var live_sitename_complete = ((live_sitename=='www') ? '' : live_sitename+'.') + 'tv2.dk';
- if (!git_sitename) {
- git_sitename = tv2_sitename ? tv2_sitename : 'www';
- }
-
- // Construct corresponding live URL
- if (tv2_testsite) { // test, snapshot or stage
- if (tv2_sitetype) { /* opdatering, ... */
- liveurl = tv2_sitename+'.'+tv2_sitetype+'.tv2.dk';
- } else {
- liveurl = live_sitename_complete;
- }
- }
-
- var testprompturl = git_sitename+(tv2_branch?'.'+tv2_branch:'')+'.?'+(tv2_sitetype?'.'+tv2_sitetype:'')+'.'+tv2_apptype+'.test'+'.tv2.dk';
- var testurl = git_sitename+(tv2_branch?'.'+tv2_branch:'')+'.'+initials+(tv2_sitetype?'.'+tv2_sitetype:'')+'.'+tv2_apptype+'.test'+'.tv2.dk';
- var snapshoturl = git_sitename+(tv2_branch?'.'+tv2_branch:'')+(tv2_sitetype?'.'+tv2_sitetype:'')+'.'+tv2_apptype+'.snapshot'+'.tv2.dk';
- var stageurl = git_sitename+(tv2_branch?'.'+tv2_branch:'')+(tv2_sitetype?'.'+tv2_sitetype:'')+'.'+tv2_apptype+'.stage'+'.tv2.dk';
-
- // Add the two urls we are not at
- if (!tv2_testsite) { // always add swaps to stage, snapshot and the test site
- links.push(new this.TV2Link('test_live_swap', testurl, tv2_uri, TV2Util.getStr('test.accesskey')));
- links.push(new this.TV2Link('snapshot_live_swap', snapshoturl, tv2_uri, TV2Util.getStr('snapshot.accesskey')));
- links.push(new this.TV2Link('stage_live_swap', stageurl, tv2_uri, TV2Util.getStr('stage.accesskey')));
- links.push(new this.TV2Link('testprompt_swap', testprompturl, tv2_uri, TV2Util.getStr('testprompt.accesskey'), 'promptInitials'));
- } else if (tv2_testtype == 'snapshot') {
- links.push(new this.TV2Link('snapshot_live_swap', liveurl, tv2_uri, TV2Util.getStr('live.accesskey')));
- links.push(new this.TV2Link('snapshot_stage_swap', stageurl, tv2_uri, TV2Util.getStr('stage.accesskey')));
- links.push(new this.TV2Link('test_snapshot_swap', testurl, tv2_uri, TV2Util.getStr('test.accesskey')));
- links.push(new this.TV2Link('testprompt_swap', testprompturl, tv2_uri, TV2Util.getStr('testprompt.accesskey'), 'promptInitials'));
- } else if (tv2_testtype == 'stage') {
- links.push(new this.TV2Link('stage_live_swap', liveurl, tv2_uri, TV2Util.getStr('live.accesskey')));
- links.push(new this.TV2Link('snapshot_stage_swap', snapshoturl, tv2_uri, TV2Util.getStr('stage.accesskey')));
- links.push(new this.TV2Link('test_stage_swap', testurl, tv2_uri, TV2Util.getStr('test.accesskey')));
- links.push(new this.TV2Link('testprompt_swap', testprompturl, tv2_uri, TV2Util.getStr('testprompt.accesskey'), 'promptInitials'));
- } else { // must be test
- links.push(new this.TV2Link('test_live_swap', liveurl, tv2_uri, TV2Util.getStr('live.accesskey')));
- links.push(new this.TV2Link('test_snapshot_swap', snapshoturl, tv2_uri, TV2Util.getStr('snapshot.accesskey')));
- links.push(new this.TV2Link('test_stage_swap', stageurl, tv2_uri, TV2Util.getStr('stage.accesskey')));
- if (tv2_user != initials) {
- links.push(new this.TV2Link('test_swap', testurl, tv2_uri, TV2Util.getStr('test.accesskey')));
- }
- links.push(new this.TV2Link('testprompt_swap', testprompturl, tv2_uri, TV2Util.getStr('testprompt.accesskey'), 'promptInitials'));
- }
-
- links.push(new this.TV2LinkSplit());
-
- // Add link to .opdatering, .template, .robot
- var _prefix = (tv2_testsite ? git_sitename : live_sitename) + (tv2_branch?'.'+tv2_branch:'') + (tv2_user ? '.' + tv2_user : '');
- var _postfix = (tv2_testsite ? '.'+tv2_apptype+'.'+tv2_testsite : '') + '.tv2.dk';
- var opdatering = _prefix + '.opdatering' + _postfix;
- //var template = _prefix + '.template' + _postfix;
- var robot = _prefix + '.robot' + _postfix;
- var normal = (tv2_testsite ? _prefix + '.' + tv2_apptype + '.' + tv2_testsite + '.tv2.dk'
- : live_sitename_complete);
- links.push(new this.TV2Link('opdatering_swap', (tv2_sitetype!='opdatering')?opdatering:normal, '/',
- (tv2_sitetype!='opdatering') ? TV2Util.getStr('opdatering.accesskey') : TV2Util.getStr('webroot.accesskey')));
- /*links.push(new this.TV2Link('template_swap', (tv2_sitetype!='template')?template:normal, '/',
- (tv2_sitetype!='template') ? TV2Util.getStr('template.accesskey') : TV2Util.getStr('webroot.accesskey'))); */
- links.push(new this.TV2Link('robot_swap', (tv2_sitetype!='robot')?robot:normal, '/',
- (tv2_sitetype!='robot') ? TV2Util.getStr('robot.accesskey') : TV2Util.getStr('webroot.accesskey')));
-
- links.push(new this.TV2LinkSplit());
-
- // Add the GitWeb link, inspired by ViewCVS link, inspired by Adrian Bak (ADBA)
- var gitweb = 'http://flimmer.i.tv2.dk/git/?p='
- + git_sitename + '.tv2.dk.git;hb=HEAD;f=' + (tv2_sitetype?tv2_sitetype:'webroot');
- var php = this._reg_php.exec(tv2_uriOnly);
- if (php) {
- gitweb += php[1];
- } else if(tv2_uriOnly.substr(-1) == '/') {
- // we add 'index.php' and say that's it! :-)
- gitweb += tv2_uriOnly + 'index.php';
- } else {
- gitweb += tv2_uriOnly;
- }
- var gitweb_source = gitweb + ';a=blob';
- gitweb += ';a=history';
- // we set a nice type so we can swap between using the button (test<>gitweb, live<>gitweb,...)
- var gitweb_type;
- if (!tv2_testsite) {
- gitweb_type = 'gitweb_live';
- } else if (tv2_testtype == 'snapshot') {
- gitweb_type = 'gitweb_snapshot';
- } else if (tv2_testtype == 'stage') {
- gitweb_type = 'gitweb_stage';
- } else {
- gitweb_type = 'gitweb_test';
- }
- links.push(new this.TV2LinkWithLabel(gitweb_type, TV2Util.getStr('lookupInGitWebSource'), gitweb_source,
- TV2Util.getStr('lookupInGitWebSource.accesskey')));
- links.push(new this.TV2LinkWithLabel(gitweb_type, TV2Util.getStr('lookupInGitWeb'), gitweb,
- TV2Util.getStr('lookupInGitWeb.accesskey')));
-
- // Update and I2 base URL
- var updatepostfix = (tv2_user ? '.' + tv2_user : '')
- + '.opdatering'
- + (tv2_testtype ? '.php5.' + tv2_testtype : '') + '.tv2.dk'
- var i2link = 'http://i2' + updatepostfix;
-
- // Check if we are on an Tango or I2 interface, then we can extract the URL again
- var onI2interface;
- var onI2interface_url;
- if (tv2_sitetype == 'opdatering' && tv2_sitename == 'i2') {
- var tangoif = this._reg_fromi2if.exec(tv2_uri);
- if (tangoif) {
- onI2interface = tangoif[1];
- onI2interface_url = decodeURIComponent(tangoif[4]);
- }
- }
-
- // Add Tango lookup link
- var i2tango = i2link + '/tango/entry.php?url=';
- var tango = encodedURL;
- var docWin = getBrowser().contentWindow;
- if (docWin.wrappedJSObject && docWin.wrappedJSObject.Tango_URL) {
- tango = encodeURIComponent(docWin.wrappedJSObject.Tango_URL);
- links.push(new this.TV2LinkWithLabel('tango/dynamic', TV2Util.getStr('viewDynamicVersion'),
- i2link + '/tango/dynamic.php?url='+tango+'&referer='+encodedURL,
- TV2Util.getStr('viewDynamicVersion.accesskey'),
- 'flushCache'));
- }
- if (onI2interface != 'tango/entry' && onI2interface != 'tango/requeue') {
- links.push(new this.TV2LinkWithLabel('tango/entry', TV2Util.getStr('lookupInTango'),
- i2link + '/tango/entry.php?url=' + tango, TV2Util.getStr('lookupInTango.accesskey')));
- links.push(new this.TV2LinkWithLabel('tango/requeue', TV2Util.getStr('requeueInTango'),
- i2link + '/tango/requeue.php?url=' + tango, TV2Util.getStr('requeueInTango.accesskey')));
- }
-
- // Add run pdo_log link
- if ((onI2interface != 'tool/pdo_log/frameset') &&
- ((!tv2_testsite && !php4) || // only php5 live sites
- (tv2_testsite && tv2_apptype != 'php4'))) { /* not supported on php4 sites */
- links.push(new this.TV2LinkWithLabel('tool/pdo_log/frameset', TV2Util.getStr('performDbPdoLog'),
- i2link + '/tool/pdo_log/frameset.php?url='+tango+'&autostop=1&prefix='+initials,
- TV2Util.getStr('performDbPdoLog.accesskey'),
- 'flushCache'));
- }
-
-// if (TV2Util.getPref('enable-secret', false)) {
-// }
-
- if (onI2interface_url) {
- /* link entered in I2 interface */
- links.push(new this.TV2LinkSplit());
- /* tango/entry, tango/requeue, tango/dynamic, tool/pdo_log */
- links.push(new this.TV2LinkWithLabel(onI2interface, onI2interface_url, onI2interface_url, TV2Util.getStr('backI2.accesskey')));
- }
-
- // Some special cases for some sites
- if (tv2_sitename == 'ttv') {
- links.push(new this.TV2LinkSplit());
- var ttv_page = /side=([0-9]+)/.exec(tv2_uri);
- var ttvpumpelink = 'ttvpumpe'+updatepostfix;
- if (ttv_page) {
- skip_treenodes = true;
- links.push(new this.TV2LinkWithLabel('ttvpage', TV2Util.getStr('lookupTTVPage') + ' ' + ttv_page[1],
- 'http://' + ttvpumpelink + '/?channel=TV+2&page=' + ttv_page[1] + '#' + ttv_page[1], /* hardcoded to TV 2 TTV */
- TV2Util.getStr('lookupTTVPage.accesskey')));
- }
- /*links.push(new this.TV2Link('ttvpumpe', ttvpumpelink, '/', TV2Util.getStr('ttvpumpe.accesskey')));*/
- links.push(new this.TV2Link('ttvpumpe', 'ttvpumpe.opdatering.tv2.dk', '/', TV2Util.getStr('ttvpumpe.accesskey')));
- }
-
- // I2-Files and I2-Images
- if (tv2_sitename == 'i2-files' || tv2_sitename == 'i2-images' || tv2_sitename == 'i2') {
- var contentId = this._reg_i2files.exec(tv2_uriOnly);
- if (contentId) {
- var typeId;
- var typeName;
- skip_treenodes = true;
- if (tv2_sitename == 'i2-files') {
- typeId = 74; // I2_File (and subtypes)
- typeName = 'I2_File';
- } else {
- if (tv2_uriOnly.substr(0,2)=='/s') {
- typeId = 8; typeName = 'I2_Image_Selection';
- } else {
- typeId = 7; typeName = ' I2_Image';
- }
- }
- links.push(new this.TV2LinkSplit());
- links.push(new this.TV2LinkWithLabel('i2files', TV2Util.getStr('lookupContent') + ' ' + contentId[1] + ', ' +
- TV2Util.getStr('lookupContent.type') + ' ' + typeName,
- i2link +
- '/tool/query/?id=&_checkbox=1&2=&3='+typeId+'&content_id='+contentId[1]+'&4=&5=0&6=&action=Query&timeout=1',
- TV2Util.getStr('lookupContent.accesskey')
- ));
- }
- }
-
- // Sputnik R7 program links
- if (tv2_sitename == 'sputnik') {
- var programId = this._reg_r7program.exec(tv2_uriOnly);
- if (programId) {
- skip_treenodes = true;
- links.push(new this.TV2LinkSplit());
- links.push(new this.TV2LinkWithLabel('r7program', TV2Util.getStr('lookupR7Program') + ' ' + programId[1],
- i2link +
- '/tool/r7/?1='+programId[1],
- TV2Util.getStr('lookupR7Program.accesskey')
- ));
- }
- }
-
- // Try to extract node id and add links to the node tool
- if (!skip_treenodes) {
- var i2node = i2link + '/tool/node/?id=';
- var nodeids;
- var first = true;
- while ((nodeids = this._reg_nodeid.exec(tv2_uri)) != null) {
- if (first) {
- links.push(new this.TV2LinkSplit());
- first = false;
- }
- links.push(new this.TV2LinkWithLabel('node', TV2Util.getStr('lookupTreeNode') + ' ' + nodeids[1],
- i2node + nodeids[1],
- TV2Util.getStr('lookupTreeNode.accesskey')
- ));
- }
- }
-
- } else {
-
- /* Add links to the site if viewing info at GitWeb site */
- if (fromgitweb) {
- var tv2_sitename = fromgitweb[1];
- var tv2_sitetype = fromgitweb[2];
- var tv2_uri = fromgitweb[3];
-
- // cut off 'index.php'
- if (tv2_uri.substr(-10) == '/index.php') {
- tv2_uri = tv2_uri.substr(0, tv2_uri.length-9);
- }
-
- // php4 sites
- var php4 = this._isPhp4(tv2_sitename);
- var appType = php4 ? 'php4.' : 'php5.';
-
- var live_sitename = (tv2_sitetype=='webroot' && tv2_sitename=='www') ? '': (tv2_sitename+'.');
- var type = (tv2_sitetype=='webroot')? '' : tv2_sitetype+'.';
-
- links.push(new this.TV2Link('gitweb_live', live_sitename + type + 'tv2.dk', tv2_uri, TV2Util.getStr('live.accesskey')));
- links.push(new this.TV2Link('gitweb_test', tv2_sitename + '.' + initials + '.' + type + appType + 'test' + '.tv2.dk', tv2_uri, TV2Util.getStr('test.accesskey')));
- links.push(new this.TV2Link('gitweb_snapshot', tv2_sitename + '.' + type + appType + 'snapshot' + '.tv2.dk', tv2_uri, TV2Util.getStr('snapshot.accesskey')));
- links.push(new this.TV2Link('gitweb_stage', tv2_sitename + '.' + type + appType + 'stage' + '.tv2.dk', tv2_uri, TV2Util.getStr('stage.accesskey')));
- links.push(new this.TV2Link('gitweb_testprompt', tv2_sitename + '.?.' + type + appType + 'test' + '.tv2.dk', tv2_uri, TV2Util.getStr('testprompt.accesskey'), 'promptInitials'));
-
- } else {
- links.push(new this.TV2LinkWithLabel('disabled', TV2Util.getStr('notTV2Site'), null, '', null, true));
- links.push(new this.TV2LinkSplit());
- links.push(new this.TV2Link('tv2dk', 'tv2.dk', '/', TV2Util.getStr('tv2dk.accesskey')));
- }
- }
-
- // Utility links
- links.push(new this.TV2LinkSplit());
- links.push(new this.TV2LinkWithLabel('link_tree', TV2Util.getStr('i2Tree'), 'http://i2.opdatering.tv2.dk/tree/', TV2Util.getStr('i2Tree.accesskey')));
- links.push(new this.TV2LinkWithLabel('node', TV2Util.getStr('nodeInformationTool'), 'http://i2.opdatering.tv2.dk/tool/node/', TV2Util.getStr('nodeInformationTool.accesskey')));
- links.push(new this.TV2LinkWithLabel('link_query', TV2Util.getStr('nodeQueryTool'), 'http://i2.opdatering.tv2.dk/tool/query/', TV2Util.getStr('nodeQueryTool.accesskey')));
- links.push(new this.TV2LinkWithLabel('tango/entry', TV2Util.getStr('tangoInterface'), 'http://i2.opdatering.tv2.dk/tango/', TV2Util.getStr('tangoInterface.accesskey')));
- links.push(new this.TV2LinkWithLabel('w3c', TV2Util.getStr('w3c'),
- 'http://validator.jkkn.net/check?uri=' + encodedURL, TV2Util.getStr('w3c.accesskey')));
- links.push(new this.TV2LinkWithLabel('flushcache', TV2Util.getStr('flushCache'),
- '-', TV2Util.getStr('flushCache.accesskey'), 'flushCache'));
-
- return links;
-
- },
-
- /* fill in menu onbefore popup event */
- fillMenu: function(event) {
- var menu = event.target;
- var links = this.getLinks();
- this.emptyMenu(menu);
-
- var defSet = false;
- 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', TV2Util.getStr('quickbox.menuitem'));
- item.setAttribute('accesskey', TV2Util.getStr('quickbox.accesskey'));
- item.setAttribute('tooltiptext', TV2Util.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('tv2link'),
- 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();
- for (var i = 0; i < children.length; i++) {
- if (children[i].type == this._lastAction) {
- return children[i];
- }
- }
- return null;
- },
-
- /* handle click on button, either default action or show menu */
- handleButton: function(event) {
- var action = this.getButtonAction();
- if (action) {
- this.gotoLink(event, action.url, action.type, action.flags);
- } else {
- event.target.open = true;
- }
- },
-
- setStatusText: function(text) {
- var statusTextFld = document.getElementById("statusbar-display");
- if (statusTextFld && statusTextFld.label != text) {
- statusTextFld.label = text;
- }
- },
-
- handleStatusText: function(event) {
- var id = event.target.getAttribute('id');
- if (id == 'tv2-swap-button') {
- var action = this.getButtonAction();
- var button = document.getElementById('tv2-swap-button');
- if (action) {
- button.setAttribute('tooltiptext', action.label);
- this.setStatusText(action.url);
- } else {
- button.removeAttribute('tooltiptext');
- }
- } else {
- var url = event.target.getAttribute('url');
- if (url) {
- this.setStatusText(url);
- }
- }
- },
-
- /* shortcut to open menu */
- handleKeyShortcut: function(event) {
- if (!this._useStatusBarIconInstead) { // normal icon dropdown
- document.getElementById('tv2-swap-button').open = true;
- } else { // status bar icon
- var popupmenu = document.getElementById('tv2developer-popupmenu');
- popupmenu.showPopup();
- }
- },
-
- /* utility function to go to a link */
- gotoLink: function(event, url, tv2linktype, tv2flags) {
- if (url) {
- /* handle flags */
- if (tv2flags) {
- if (tv2flags.indexOf('promptInitials') != -1) {
- var initials = prompt(TV2Util.getStr('enterInitials'), TV2Util.getPref('alternativ-initials', ''));
- if (initials == '' || initials == null) {
- return; // cancelled
- }
- TV2Util.setPref('alternativ-initials', initials);
- url = url.replace('?', initials);
- }
- if (tv2flags.indexOf('flushCache') != -1) {
- this.clearCache();
- }
- }
- /* follow link */
- if (url != '-') {
- openUILink(url, event, false, true, false); /* allow ctrl, not alt, and don't google */
- }
- if (tv2linktype) {
- this._lastAction = tv2linktype;
- TV2Util.setPref('lastaction-linktype', tv2linktype);
- }
- }
- },
-
- /* function to clear browser cache */
- clearCache: function () {
- var cacheService = Components.classes["@mozilla.org/network/cache-service;1"]
- .getService(Components.interfaces.nsICacheService);
- try {
- cacheService.evictEntries(Components.interfaces.nsICache.STORE_ANYWHERE);
- } catch(ex) {}
- },
-
- openQuickbox: function(event, autogo) {
- var startUrl = '';
- var urlbar = document.getElementById('urlbar');
- if (typeof(autogo)=='undefined') autogo = false;
- if (urlbar) {
- startUrl = urlbar.value;
- }
- window.openDialog('chrome://tv2developer/content/quickbox.xul','tv2quickbox','modal,centerscreen,chrome,resizable=no,title=no', startUrl, autogo);
- },
-
- /* Options */
- openOptionsDialog: function(event) {
- var instantApply = getBoolPref("browser.preferences.instantApply", false);
- var features = "chrome,titlebar,toolbar,centerscreen" + (instantApply ? ",dialog=no" : ",modal");
- window.openDialog('chrome://tv2developer/content/options.xul', 'tv2options', features);
- }
-
-
-}