tremulous.js, zurück zur Projektbeschreibung
   1/*
   2  vim: set encoding=utf8 expandtab tabstop=2 shiftwidth=2 softtabstop=2:
   3
   4  Javascript-function for the Tremulous Player Manifest,
   5  Copyright (C) 2006, 2011 Zacharias Korsalka <mail@sacharja.at>
   6
   7  Permission is hereby granted, free of charge, to any person obtaining a copy
   8  of this software and associated documentation files (the "Software"), to deal
   9  in the Software without restriction, including without limitation the rights
  10  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11  copies of the Software, and to permit persons to whom the Software is
  12  furnished to do so, subject to the following conditions:
  13
  14  The above copyright notice and this permission notice shall be included in
  15  all copies or substantial portions of the Software.
  16
  17  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
  19  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
  22  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  23  THE SOFTWARE.
  24
  25  This file is part of the project “Tremulous Player Manifest”
  26*/
  27
  28// check for “our friend the Internet Explorer”, mind that JScript ≠ Javascript!
  29var IE = /*@cc_on!@*/false;
  30
  31// color classes (NOT definitions!) for coloring ingame-names
  32var Colors = {
  33  '0': '_000',
  34  '1': '_f00',
  35  '2': '_0f0',
  36  '3': '_ff0',
  37  '4': '_00f',
  38  '5': '_f0f',
  39  '6': '_0ff',
  40  '7': '_fff',
  41  '8': '_000',
  42  '9': '_f00'
  43};
  44
  45// maskings for HTML-specific characters
  46var Markup = {
  47  '<': '&lt;',
  48  '>': '&gt;',
  49  '&': '&amp;'
  50};
  51
  52
  53
  54function pass(){
  55  //
  56  // python has a pass-command, which sometimes does come in handy to clarify code, so I wanted it here, too.
  57  //
  58  var do_nothing = true;
  59}
  60
  61
  62
  63function get_option(the_id){
  64  //
  65  // get currently selected option of a <select>-contruct
  66  //
  67  my = document.getElementById(the_id);
  68  return(my.options[my.options.selectedIndex].value);
  69}
  70
  71
  72
  73function init(){
  74  //
  75  // to be called when body loads
  76  //
  77  
  78  // just clear that span, if it exists
  79  my = document.getElementById("turnmeoff");
  80  if(my){
  81    my.childNodes[0].nodeValue = "";
  82  }
  83  
  84  // and change that link, if IT exists
  85  my = document.getElementById("tobacklink");
  86  if(my){
  87    my.href = 'javascript:history.go(-1)';
  88  }
  89  
  90  return(0);
  91}
  92
  93
  94
  95function input_mirror(the, themode){
  96  //
  97  // modify spans meant to be mirroring form-input
  98  // themode gives control over which type of input is required
  99  //
 100  
 101  if(themode === undefined){
 102    themode = "";
 103  }
 104  
 105  var input =  document.getElementById("in_"+the);
 106  var output = document.getElementById("out_"+the);
 107  
 108  var result = "";
 109  var i = 0;
 110
 111  while(i < input.value.length){
 112    c = input.value.charAt(i);
 113    if(c in Markup){
 114      result += Markup[c];
 115    }else{
 116      result += c;
 117    }
 118    i += 1;
 119  }
 120  
 121  // e-mail-mode
 122  if(themode == "mail"){
 123    // notyet: unfinished e-mail-address; good: an address that is already correct
 124    var notyet = new RegExp('^[a-z0-9-_\\.]+@?[a-z0-9]*\\.?[a-z]?$', 'i');
 125    var good = new RegExp('^[a-z0-9-_\\.]+@[a-z0-9-_]+\\.[a-z][a-z]+$', 'i');
 126    
 127    if(result.match(notyet)){
 128      result = '<span class="grey">'+result+'</span>';
 129    }else if(result.match(good)){
 130      pass();
 131    }else{
 132      result = '<span class="faulty">'+result+'</span>';
 133    }
 134  }
 135  
 136  // website-mode
 137  if(themode == 'website'){
 138    var header = new RegExp('^http://');
 139    if(result.match(header)){
 140      result = '<span class="grey">http://</span>'+result.slice(7);
 141    }
 142  }
 143  
 144  output.innerHTML = result;
 145}
 146
 147
 148
 149function ingame_name_colors(){
 150  //
 151  // mirror input of an ingame-name, applying the respective colors defined above
 152  //
 153  
 154  var input =  document.getElementById("ign_input");
 155  var output = document.getElementById("ign_output");
 156  
 157  var result = "";
 158  
 159  var i=0;
 160  var colored = false;
 161  var color = "";
 162  var c = "";
 163  
 164  while(i < input.value.length){
 165    c = input.value.charAt(i);
 166    
 167    if(c in Markup){
 168      result += Markup[c];
 169      i += 1;
 170      continue;
 171    }
 172    
 173    if(c=='^'){
 174      c = input.value.charAt(i+1);
 175      color = "";
 176      if(c in Colors){
 177        color = Colors[c];
 178        if(colored){
 179          result += '</span>';
 180        }
 181        colored = true;
 182        result += '<span class="'+color+'">';
 183      }else{
 184        result += '^'+c;
 185      }
 186      i += 2;
 187    }else{
 188      result += c;
 189      i += 1;
 190    }
 191  }
 192  if(colored){
 193    result += '</span>';
 194  }
 195  output.innerHTML = result;
 196}
 197
 198
 199
 200function set_flag(){
 201  my = document.getElementById('flag_to_set');
 202  if(!my){
 203    return(-1);
 204  }
 205  my.setAttribute('class', get_option('flag_selector'));
 206}
 207
 208
 209
 210function set_year(){
 211  //
 212  // mirror year of main form in sign.php
 213  //
 214  my = document.getElementById('out_year');
 215  my.innerHTML = get_option('in_year');
 216}
 217
 218
 219
 220function set_gender(){
 221  //
 222  // mirror gender of main form in sign.php
 223  //
 224  var gender = '';
 225  if(get_option("gender") == 'female'){
 226    gender = '♀';
 227  }
 228  if(get_option("gender") == 'male'){
 229    gender = '♂';
 230  }
 231  my = document.getElementById('out_gender');
 232  my.innerHTML = gender;
 233}
 234
 235