Changeset 1097


Ignore:
Timestamp:
10/20/08 15:53:08 (11 years ago)
Author:
nicholasbs
Message:
  • Fixes #58 (configuration of allowed target types)
  • Fixes #1308 (remove link button doesn't work, switching target types causes JS error)
  • Clean up dialog html (remove embedded JavaScript?)
Location:
trunk/plugins/Linker
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/plugins/Linker/dialog.html

    r1078 r1097  
    44<div id="[options]" > 
    55  <fieldset> 
    6     <legend><label><input type="radio" name="[type]" id="[type]" value="url" checked="checked" onclick=" 
    7       document.getElementById('[urltable]').style.display=this.checked?'':'none'; 
    8       document.getElementById('[mailtable]').style.display=this.checked?'none':''; 
    9       document.getElementById('[anchortable]').style.display=this.checked?'none':''; 
    10     " /> <l10n>URL Link</l10n></label></legend> 
     6    <legend><label><input type="radio" name="[type]" id="[type_url]" value="url" checked="checked" /> 
     7        <l10n>URL Link</l10n> 
     8    </label></legend> 
    119    <table id="[urltable]" width="100%"> 
    1210      <tr> 
    1311        <th><label for="[href]"><l10n>URL:</l10n> </label></th> 
    14         <td><input type="text" name="[href]" style="width:100%" value="http://www.example.com/" onfocus="if (this.value == 'http://www.example.com/') this.value = '';" /></td> 
     12        <td><input type="text" name="[href]" id="[href]" style="width:100%" value="http://www.example.com/" onfocus="if (this.value == 'http://www.example.com/') this.value = '';" /></td> 
    1513      </tr> 
    16       <tr style="vertical-align: top;"> 
     14      <tr style="vertical-align: top;" id="[target_options]"> 
    1715        <th><l10n>Target:</l10n></th> 
    1816        <td> 
    19           <div><label><input type="radio" name="[target]" value="" onclick="document.getElementById('[popuptable]').style.display='none';"  checked="checked" /> <l10n>Ordinary Link</l10n></label></div> 
    20           <div><label><input type="radio" name="[target]" value="_top" onclick="document.getElementById('[popuptable]').style.display='none';"  /> <l10n>Same Window (jump out of frames)</l10n></label></div> 
    21           <div><label><input type="radio" name="[target]" value="_blank" onclick="document.getElementById('[popuptable]').style.display='none';"/> <l10n>New Window</l10n> </label></div> 
    22           <div> 
    23             <label><input type="radio" name="[target]" value="popup"    onclick="document.getElementById('[popuptable]').style.display='';" /> <l10n>Popup Window</l10n> </label> 
     17          <div id="[noTarget]"><label><input type="radio" name="[target]" id="[noTargetRadio]" value="" /> <l10n>Ordinary Link</l10n></label></div> 
     18          <div id="[sameWindow]"><label><input type="radio" name="[target]" id="[sameWindowRadio]" value="_top" /> <l10n>Same Window (jump out of frames)</l10n></label></div> 
     19          <div id="[newWindow]"><label><input type="radio" name="[target]" id="[newWindowRadio]" value="_blank" /> <l10n>New Window</l10n> </label></div> 
     20          <div id="[popupWindow]"> 
     21            <label><input type="radio" name="[target]" id="[popupWindowRadio]" value="popup" /> <l10n>Popup Window</l10n> </label> 
    2422             <div style="padding-left:10px"> 
    2523              <table id="[popuptable]"> 
     
    6159  </fieldset> 
    6260  <fieldset id="[mailtofieldset]"> 
    63     <legend><label><input type="radio" name="[type]" value="mailto" onclick=" 
    64       document.getElementById('[mailtable]').style.display=this.checked?'':'none'; 
    65       document.getElementById('[urltable]').style.display=this.checked?'none':''; 
    66       document.getElementById('[anchortable]').style.display=this.checked?'none':''; 
    67     "/> <l10n>Email Link</l10n></label></legend> 
     61    <legend><label><input type="radio" name="[type]" id="[type_mailto]" value="mailto"/> 
     62        <l10n>Email Link</l10n> 
     63    </label></legend> 
    6864    <table id="[mailtable]" width="100%"> 
    6965      <tr> 
    7066        <th><label for="[to]"><l10n>Email Address:</l10n> </label></th> 
    71         <td><input type="text" name="[to]" style="width:100%" value="alice@example.com" onfocus="if (this.value == 'alice@example.com') this.value = '';" /></td> 
     67        <td><input type="text" name="[to]" id="[to]" style="width:100%" value="alice@example.com" onfocus="if (this.value == 'alice@example.com') this.value = '';" /></td> 
    7268      </tr> 
    7369      <tr> 
     
    8379 
    8480  <fieldset id="[anchorfieldset]"> 
    85     <legend><label><input type="radio" name="[type]" value="anchor" onclick=" 
    86       document.getElementById('[urltable]').style.display=this.checked?'none':''; 
    87       document.getElementById('[mailtable]').style.display=this.checked?'none':''; 
    88       document.getElementById('[anchortable]').style.display=this.checked?'':'none'; 
    89     "/> <l10n>Anchor-Link</l10n></label></legend> 
     81    <legend><label><input type="radio" name="[type]" id="[type_anchor]" value="anchor"/> 
     82        <l10n>Anchor-Link</l10n> 
     83    </label></legend> 
    9084    <table id="[anchortable]" width="100%"> 
    9185      <tr> 
     
    10195  <div style="text-align:right"> 
    10296    <input type="button" id="[ok]"     value="_(OK)"     /> 
    103     <input type="button" id="[clear]"  value="_(Remove Link)" onclick="this.form['[href]'].value='';this.form['[to]'].value='';document.getElementById('[ok]').click();" /> 
     97    <input type="button" id="[clear]"  value="_(Remove Link)" /> 
    10498    <input type="button" id="[cancel]" value="_(Cancel)" /> 
    10599  </div> 
    106100</div> 
    107101</div> 
     102 
     103 
  • trunk/plugins/Linker/pluginMethods.js

    r1078 r1097  
    269269  var files = this.linker.files; 
    270270 
    271   var html = Linker.html; 
    272  
    273271  // Now we have everything we need, so we can build the dialog. 
    274272  var dialog = this.dialog = new Xinha.Dialog(linker.editor, Linker.html, 'Linker',{width:600,height:400}); 
     
    325323      lDialog.ddTree.style.width  = w + 'px'; 
    326324    } 
     325 
     326  // Set the onclick handlers for the link type radio buttons 
     327  self = this; 
     328  this.dialog.getElementById('type_url').onclick = function() { 
     329    self.showOptionsForType('url'); 
     330  }; 
     331  this.dialog.getElementById('type_mailto').onclick = function() { 
     332    self.showOptionsForType('mailto'); 
     333  }; 
     334  this.dialog.getElementById('type_anchor').onclick = function() { 
     335    self.showOptionsForType('anchor'); 
     336  }; 
     337 
     338  var hidePopupOptions = function() { 
     339    self.showOptionsForTarget('none') 
     340  }; 
     341  this.dialog.getElementById('noTargetRadio').onclick = hidePopupOptions; 
     342  this.dialog.getElementById('sameWindowRadio').onclick = hidePopupOptions; 
     343  this.dialog.getElementById('newWindowRadio').onclick = hidePopupOptions; 
     344  this.dialog.getElementById('popupWindowRadio').onclick = function() { 
     345    self.showOptionsForTarget('popup'); 
     346  }; 
     347 
    327348  this.ready = true; 
    328349  ddTree = null; 
     
    386407  } 
    387408 
    388   if(inputs.type=='url') 
    389   { 
    390     this.dialog.getElementById('urltable').style.display = ''; 
    391     this.dialog.getElementById('mailtable').style.display = 'none'; 
    392     this.dialog.getElementById('anchortable').style.display = 'none'; 
    393   } 
    394   else if(inputs.type=='anchor') 
    395   { 
    396     this.dialog.getElementById('urltable').style.display = 'none'; 
    397     this.dialog.getElementById('mailtable').style.display = 'none'; 
    398     this.dialog.getElementById('anchortable').style.display = ''; 
    399   } 
    400   else 
    401   { 
    402     this.dialog.getElementById('urltable').style.display = 'none'; 
    403     this.dialog.getElementById('mailtable').style.display = ''; 
    404     this.dialog.getElementById('anchortable').style.display = 'none'; 
    405   } 
    406  
    407   if(inputs.target=='popup') 
    408   { 
    409     this.dialog.getElementById('popuptable').style.display = ''; 
    410   } 
    411   else 
    412   { 
    413     this.dialog.getElementById('popuptable').style.display = 'none'; 
    414   } 
     409  this.showOptionsForType(inputs.type); 
     410  this.showOptionsForTarget(inputs.target); 
    415411   
    416412  var anchor = this.dialog.getElementById('anchor'); 
     
    467463  } 
    468464 
    469    
     465  // Disable link targets (all targets available by default) 
     466  var disabledTargets = this.linker.lConfig.disableTargetTypes;  
     467  if (typeof disabledTargets == 'undefined') 
     468  { 
     469    disabledTargets = []; 
     470  }  
     471  else if (typeof disabledTargets == 'string') 
     472  { 
     473    disabledTargets = [disabledTargets]; 
     474  } 
     475  for (var i=0; i<disabledTargets.length; i++) 
     476  { 
     477    this.dialog.getElementById(disabledTargets[i]).style.display = "none"; 
     478  } 
     479  if (disabledTargets.length == 3) // only one target option is visible 
     480  { 
     481    if (disabledTargets.contains('popupWindow')) 
     482    { 
     483      // There's no need to show anything, so hide the entire div 
     484      this.dialog.getElementById('target_options').style.display = "none"; 
     485    } 
     486    else 
     487    { 
     488      // Only popups are allowed, hide the radio button 
     489      this.dialog.getElementById('popupWindowRadio').style.display = "none"; 
     490      this.showOptionsForTarget('popup'); 
     491    } 
     492  } 
     493 
     494  var enabledTargets = new Array(); 
     495  if (!disabledTargets.contains('noTarget')) 
     496  { 
     497    enabledTargets.push('noTargetRadio'); 
     498  } 
     499  if (!disabledTargets.contains('sameWindow')) 
     500  { 
     501    enabledTargets.push('sameWindowRadio'); 
     502  } 
     503  if (!disabledTargets.contains('newWindow')) 
     504  { 
     505    enabledTargets.push('newWindowRadio'); 
     506  } 
     507  if (!disabledTargets.contains('popupWindow')) 
     508  { 
     509    enabledTargets.push('popupWindowRadio'); 
     510  } 
     511 
    470512  // if we're not editing an existing link, hide the remove link button 
    471513  if (inputs.href == 'http://www.example.com/' && inputs.to == 'alice@example.com') {  
    472514    this.dialog.getElementById('clear').style.display = "none"; 
    473515  } 
    474   else { 
    475     this.dialog.getElementById('clear').style.display = ""; 
     516  else { //  
     517    var clearBtn = this.dialog.getElementById('clear'); 
     518    clearBtn.style.display = ""; 
     519    if (ok) 
     520    { 
     521      clearBtn.onclick = function() { lDialog.removeLink(ok); }; 
     522    } 
    476523  } 
    477524  // Connect the OK and Cancel buttons 
     
    501548  this.dialog.show(inputs); 
    502549 
     550  // If we set the default radio button *before* we call dialog.show() 
     551  // it doesn' work... 
     552  var targetSelected = false; 
     553  for (var i=0; i<enabledTargets.length; i++) 
     554  { 
     555    console.log(this.dialog.getElementById(enabledTargets[i])); 
     556    console.log("is checked: " + this.dialog.getElementById(enabledTargets[i]).checked); 
     557    if (this.dialog.getElementById(enabledTargets[i]).checked == true) 
     558    { 
     559      targetSelected = true; 
     560      break; 
     561    } 
     562  } 
     563  // If no target is selected, select the first one by default 
     564  if (!targetSelected && enabledTargets.length > 0) 
     565  { 
     566    this.dialog.getElementById(enabledTargets[0]).checked = true; 
     567  } 
     568 
    503569  // Init the sizes 
    504570  this.dialog.onresize(); 
     
    510576  return this.dialog.hide(); 
    511577}; 
     578 
     579Linker.Dialog.prototype.removeLink = function(applyFunc) 
     580{ 
     581  this.dialog.getElementById('href').value = ""; 
     582  this.dialog.getElementById('to').value = ""; 
     583 
     584  return applyFunc(); 
     585}; 
     586 
     587Linker.Dialog.prototype.showOptionsForType = function(type) 
     588{ 
     589  var urlOptions = this.dialog.getElementById('urltable'); 
     590  var mailtoOptions = this.dialog.getElementById('mailtable'); 
     591  var anchorOptions = this.dialog.getElementById('anchortable'); 
     592 
     593  if (type == 'anchor') 
     594  { 
     595    anchorOptions.style.display = ''; 
     596    urlOptions.style.display = 'none'; 
     597    mailtoOptions.style.display = 'none'; 
     598  } 
     599  else if (type == 'mailto') 
     600  { 
     601    mailtoOptions.style.display = ''; 
     602    urlOptions.style.display = 'none'; 
     603    anchorOptions.style.display = 'none'; 
     604  } 
     605  else  
     606  { 
     607    urlOptions.style.display = ''; 
     608    mailtoOptions.style.display = 'none'; 
     609    anchorOptions.style.display = 'none'; 
     610  } 
     611}; 
     612 
     613Linker.Dialog.prototype.showOptionsForTarget = function(target) 
     614{ 
     615  var popupOptions = this.dialog.getElementById('popuptable'); 
     616  popupOptions.style.display = target == 'popup' ? '' : 'none'; 
     617}; 
Note: See TracChangeset for help on using the changeset viewer.