[ Index ]
 

Code source de XOOPS 2.0.17.1

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/htdocs/include/ -> xoops.js (source)

   1  
   2  if ( typeof window.$ != 'function' ) {
   3  function $() {
   4    var elements = new Array();
   5  
   6    for (var i = 0; i < arguments.length; i++) {
   7      var element = arguments[i];
   8      if (typeof element == 'string')
   9        element = document.getElementById(element);
  10  
  11      if (arguments.length == 1)
  12        return element;
  13  
  14      elements.push(element);
  15    }
  16  
  17    return elements;
  18  }
  19  }
  20  
  21      
  22  function xoopsGetElementById(id){
  23      return $(id);
  24  }
  25  
  26  function xoopsSetElementProp(name, prop, val) {
  27      var elt=xoopsGetElementById(name);
  28      if (elt) elt[prop]=val;
  29  }
  30  
  31  function xoopsSetElementStyle(name, prop, val) {
  32      var elt=xoopsGetElementById(name);
  33      if (elt && elt.style) elt.style[prop]=val;
  34  }
  35  
  36  function xoopsGetFormElement(fname, ctlname) {
  37      var frm=document.forms[fname];
  38      return frm?frm.elements[ctlname]:null;
  39  }
  40  
  41  function justReturn() {
  42      return;
  43  }
  44  
  45  function openWithSelfMain(url,name,width,height,returnwindow) {
  46      var options = "width=" + width + ",height=" + height + ",toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no";
  47  
  48      var new_window = window.open(url, name, options);
  49      window.self.name = "main";
  50      new_window.focus();
  51      if (returnwindow != null) {
  52         return new_window;
  53      }
  54  }
  55  
  56  function setElementColor(id, color){
  57      xoopsGetElementById(id).style.color = "#" + color;
  58  }
  59  
  60  function setElementFont(id, font){
  61      xoopsGetElementById(id).style.fontFamily = font;
  62  }
  63  
  64  function setElementSize(id, size){
  65      xoopsGetElementById(id).style.fontSize = size;
  66  }
  67  
  68  function changeDisplay(id){
  69      var elestyle = xoopsGetElementById(id).style;
  70      if (elestyle.display == "") {
  71          elestyle.display = "none";
  72      } else {
  73          elestyle.display = "block";
  74      }
  75  }
  76  
  77  function setVisible(id){
  78      xoopsGetElementById(id).style.visibility = "visible";
  79  }
  80  
  81  function setHidden(id){
  82      xoopsGetElementById(id).style.visibility = "hidden";
  83  }
  84  
  85  function makeBold(id){
  86      var eleStyle = xoopsGetElementById(id).style;
  87      if (eleStyle.fontWeight != "bold" && eleStyle.fontWeight != "700") {
  88          eleStyle.fontWeight = "bold";
  89      } else {
  90          eleStyle.fontWeight = "normal";
  91      }
  92  }
  93  
  94  function makeItalic(id){
  95      var eleStyle = xoopsGetElementById(id).style;
  96      if (eleStyle.fontStyle != "italic") {
  97          eleStyle.fontStyle = "italic";
  98      } else {
  99          eleStyle.fontStyle = "normal";
 100      }
 101  }
 102  
 103  function makeUnderline(id){
 104      var eleStyle = xoopsGetElementById(id).style;
 105      if (eleStyle.textDecoration != "underline") {
 106          eleStyle.textDecoration = "underline";
 107      } else {
 108          eleStyle.textDecoration = "none";
 109      }
 110  }
 111  
 112  function makeLineThrough(id){
 113      var eleStyle = xoopsGetElementById(id).style;
 114      if (eleStyle.textDecoration != "line-through") {
 115          eleStyle.textDecoration = "line-through";
 116      } else {
 117          eleStyle.textDecoration = "none";
 118      }
 119  }
 120  
 121  function appendSelectOption(selectMenuId, optionName, optionValue){
 122      var selectMenu = xoopsGetElementById(selectMenuId);
 123      var newoption = new Option(optionName, optionValue);
 124      selectMenu.options[selectMenu.length] = newoption;
 125      selectMenu.options[selectMenu.length].selected = true;
 126  }
 127  
 128  function disableElement(target){
 129      var targetDom = xoopsGetElementById(target);
 130      if (targetDom.disabled != true) {
 131          targetDom.disabled = true;
 132      } else {
 133          targetDom.disabled = false;
 134      }
 135  }
 136  
 137  function xoopsCheckAll( form, switchId ) {
 138      var eltForm = $(form);
 139      var eltSwitch = $(switchId);
 140      // You MUST NOT specify names, it's just kept for BC with the old lame crappy code

 141      if ( !eltForm && document.forms[form] )        eltForm = document.forms[form];
 142      if ( !eltSwitch && eltForm.elements[switchId] )    eltSwitch=eltForm.elements[switchId];
 143      
 144      var i;
 145      for (i=0;i!=eltForm.elements.length;i++) {
 146          if ( eltForm.elements[i] != eltSwitch && eltForm.elements[i].type == 'checkbox' ) {
 147              eltForm.elements[i].checked = eltSwitch.checked;
 148          }
 149      }
 150  }
 151      
 152  
 153  function xoopsCheckGroup( form, switchId, groupName ) {
 154      var eltForm = $(form);
 155      var eltSwitch = $(switchId);
 156      // You MUST NOT specify names, it's just kept for BC with the old lame crappy code

 157      if ( !eltForm && document.forms[form] )        eltForm = document.forms[form];
 158      if ( !eltSwitch && eltForm.elements[switchId] )    eltSwitch=eltForm.elements[switchId];
 159  
 160      var i;
 161      for (i=0;i!=eltForm.elements.length;i++) {
 162          var e=eltForm.elements[i];
 163          if ( (e.type == 'checkbox') && ( e.name == groupName ) ) {
 164              e.checked = eltSwitch.checked;
 165              e.click(); e.click();  // Click to activate subgroups twice so we don't reverse effect

 166          }
 167      }
 168  }
 169  
 170  function xoopsCheckAllElements(elementIds, switchId) {
 171      var switch_cbox = xoopsGetElementById(switchId);
 172      for (var i = 0; i < elementIds.length; i++) {
 173          var e = xoopsGetElementById(elementIds[i]);
 174          if ((e.name != switch_cbox.name) && (e.type == 'checkbox')) {
 175              e.checked = switch_cbox.checked;
 176          }
 177      }
 178  }
 179  
 180  function xoopsSavePosition(id)
 181  {
 182      var textareaDom = xoopsGetElementById(id);
 183      if (textareaDom.createTextRange) {
 184          textareaDom.caretPos = document.selection.createRange().duplicate();
 185      }
 186  }
 187  
 188  function xoopsInsertText(domobj, text)
 189  {
 190      if (domobj.createTextRange && domobj.caretPos){
 191            var caretPos = domobj.caretPos;
 192          caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) 
 193  == ' ' ? text + ' ' : text;  
 194      } else if (domobj.getSelection && domobj.caretPos){
 195          var caretPos = domobj.caretPos;
 196          caretPos.text = caretPos.text.charat(caretPos.text.length - 1)  
 197  == ' ' ? text + ' ' : text;
 198      } else {
 199          domobj.value = domobj.value + text;
 200        }
 201  }
 202  
 203  function xoopsCodeSmilie(id, smilieCode) {
 204      var revisedMessage;
 205      var textareaDom = xoopsGetElementById(id);
 206      xoopsInsertText(textareaDom, smilieCode);
 207      textareaDom.focus();
 208      return;
 209  }
 210  
 211  function showImgSelected(imgId, selectId, imgDir, extra, xoopsUrl) {
 212      if (xoopsUrl == null) {
 213          xoopsUrl = "./";
 214      }
 215      imgDom = xoopsGetElementById(imgId);
 216      selectDom = xoopsGetElementById(selectId);
 217      imgDom.src = xoopsUrl + "/"+ imgDir + "/" + selectDom.options[selectDom.selectedIndex].value + extra;
 218  }
 219  
 220  function xoopsCodeUrl(id, enterUrlPhrase, enterWebsitePhrase){
 221      if (enterUrlPhrase == null) {
 222          enterUrlPhrase = "Enter the URL of the link you want to add:";
 223      }
 224      var text = prompt(enterUrlPhrase, "");
 225      var domobj = xoopsGetElementById(id);
 226      if ( text != null && text != "" ) {
 227          if (enterWebsitePhrase == null) {
 228              enterWebsitePhrase = "Enter the web site title:";
 229          }
 230          var text2 = prompt(enterWebsitePhrase, "");
 231          if ( text2 != null ) {
 232              if ( text2 == "" ) {
 233                  var result = "[url=" + text + "]" + text + "[/url]";
 234              } else {
 235                  var pos = text2.indexOf(unescape('%00'));
 236                  if(0 < pos){
 237                      text2 = text2.substr(0,pos);
 238                  }
 239                  var result = "[url=" + text + "]" + text2 + "[/url]";
 240              }
 241              xoopsInsertText(domobj, result);
 242          }
 243      }
 244      domobj.focus();
 245  }
 246  
 247  function xoopsCodeImg(id, enterImgUrlPhrase, enterImgPosPhrase, imgPosRorLPhrase, errorImgPosPhrase){
 248      if (enterImgUrlPhrase == null) {
 249          enterImgUrlPhrase = "Enter the URL of the image you want to add:";
 250      }
 251      var text = prompt(enterImgUrlPhrase, "");
 252      var domobj = xoopsGetElementById(id);
 253      if ( text != null && text != "" ) {
 254          if (enterImgPosPhrase == null) {
 255              enterImgPosPhrase = "Now, enter the position of the image.";
 256          }
 257          if (imgPosRorLPhrase == null) {
 258              imgPosRorLPhrase = "'R' or 'r' for right, 'L' or 'l' for left, or leave it blank.";
 259          }
 260          if (errorImgPosPhrase == null) {
 261              errorImgPosPhrase = "ERROR! Enter the position of the image:";
 262          }
 263          var text2 = prompt(enterImgPosPhrase + "\n" + imgPosRorLPhrase, "");
 264          while ( ( text2 != "" ) && ( text2 != "r" ) && ( text2 != "R" ) && ( text2 != "l" ) && ( text2 != "L" ) && ( text2 != null ) ) {
 265              text2 = prompt(errorImgPosPhrase + "\n" + imgPosRorLPhrase,"");
 266          }
 267          if ( text2 == "l" || text2 == "L" ) {
 268              text2 = " align=left";
 269          } else if ( text2 == "r" || text2 == "R" ) {
 270              text2 = " align=right";
 271          } else {
 272              text2 = "";
 273          }
 274          var result = "[img" + text2 + "]" + text + "[/img]";
 275          xoopsInsertText(domobj, result);
 276      }
 277      domobj.focus();
 278  }
 279  
 280  function xoopsCodeEmail(id, enterEmailPhrase){
 281      if (enterEmailPhrase == null) {
 282          enterEmailPhrase = "Enter the email address you want to add:";
 283      }
 284      var text = prompt(enterEmailPhrase, "");
 285      var domobj = xoopsGetElementById(id);
 286      if ( text != null && text != "" ) {
 287          var result = "[email]" + text + "[/email]";
 288          xoopsInsertText(domobj, result);
 289      }
 290      domobj.focus();
 291  }
 292  
 293  function xoopsCodeQuote(id, enterQuotePhrase){
 294      if (enterQuotePhrase == null) {
 295          enterQuotePhrase = "Enter the text that you want to be quoted:";
 296      }
 297      var text = prompt(enterQuotePhrase, "");
 298      var domobj = xoopsGetElementById(id);
 299      if ( text != null && text != "" ) {
 300          var pos = text.indexOf(unescape('%00'));
 301          if(0 < pos){
 302              text = text.substr(0,pos);
 303          }
 304          var result = "[quote]" + text + "[/quote]";
 305          xoopsInsertText(domobj, result);
 306      }
 307      domobj.focus();
 308  }
 309  
 310  function xoopsCodeCode(id, enterCodePhrase){
 311      if (enterCodePhrase == null) {
 312          enterCodePhrase = "Enter the codes that you want to add.";
 313      }
 314      var text = prompt(enterCodePhrase, "");
 315      var domobj = xoopsGetElementById(id);
 316      if ( text != null && text != "" ) {
 317          var result = "[code]" + text + "[/code]";
 318          xoopsInsertText(domobj, result);
 319      }
 320      domobj.focus();
 321  }
 322  
 323  function xoopsCodeText(id, hiddentext, enterTextboxPhrase){
 324      var textareaDom = xoopsGetElementById(id);
 325      var textDom = xoopsGetElementById(id + "Addtext");
 326      var fontDom = xoopsGetElementById(id + "Font");
 327      var colorDom = xoopsGetElementById(id + "Color");
 328      var sizeDom = xoopsGetElementById(id + "Size");
 329      var xoopsHiddenTextDomStyle = xoopsGetElementById(hiddentext).style;
 330      var textDomValue = textDom.value;
 331      var fontDomValue = fontDom.options[fontDom.options.selectedIndex].value;
 332      var colorDomValue = colorDom.options[colorDom.options.selectedIndex].value;
 333      var sizeDomValue = sizeDom.options[sizeDom.options.selectedIndex].value;
 334      if ( textDomValue == "" ) {
 335          if (enterTextboxPhrase == null) {
 336              enterTextboxPhrase = "Please input text into the textbox.";
 337          }
 338          alert(enterTextboxPhrase);
 339          textDom.focus();
 340      } else {
 341          if ( fontDomValue != "FONT") {
 342              textDomValue = "[font=" + fontDomValue + "]" + textDomValue + "[/font]";
 343              fontDom.options[0].selected = true;
 344          }
 345          if ( colorDomValue != "COLOR") {
 346              textDomValue = "[color=" + colorDomValue + "]" + textDomValue + "[/color]";
 347              colorDom.options[0].selected = true;
 348          }
 349          if ( sizeDomValue != "SIZE") {
 350              textDomValue = "[size=" + sizeDomValue + "]" + textDomValue + "[/size]";
 351              sizeDom.options[0].selected = true;
 352          }
 353          if (xoopsHiddenTextDomStyle.fontWeight == "bold" || xoopsHiddenTextDomStyle.fontWeight == "700") {
 354              textDomValue = "[b]" + textDomValue + "[/b]";
 355              xoopsHiddenTextDomStyle.fontWeight = "normal";
 356          }
 357          if (xoopsHiddenTextDomStyle.fontStyle == "italic") {
 358              textDomValue = "[i]" + textDomValue + "[/i]";
 359              xoopsHiddenTextDomStyle.fontStyle = "normal";
 360          }
 361          if (xoopsHiddenTextDomStyle.textDecoration == "underline") {
 362              textDomValue = "[u]" + textDomValue + "[/u]";
 363              xoopsHiddenTextDomStyle.textDecoration = "none";
 364          }
 365          if (xoopsHiddenTextDomStyle.textDecoration == "line-through") {
 366              textDomValue = "[d]" + textDomValue + "[/d]";
 367              xoopsHiddenTextDomStyle.textDecoration = "none";
 368          }
 369          xoopsInsertText(textareaDom, textDomValue);
 370          textDom.value = "";
 371          xoopsHiddenTextDomStyle.color = "#000000";
 372          xoopsHiddenTextDomStyle.fontFamily = "";
 373          xoopsHiddenTextDomStyle.fontSize = "12px";
 374          xoopsHiddenTextDomStyle.visibility = "hidden";
 375          textareaDom.focus();
 376      }
 377  }
 378  
 379  function xoopsValidate(subjectId, textareaId, submitId, plzCompletePhrase, msgTooLongPhrase, allowedCharPhrase, currCharPhrase) {
 380      var maxchars = 65535;
 381      var subjectDom = xoopsGetElementById(subjectId);
 382      var textareaDom = xoopsGetElementById(textareaId);
 383      var submitDom = xoopsGetElementById(submitId);
 384      if (textareaDom.value == "" || subjectDom.value == "") {
 385          if (plzCompletePhrase == null) {
 386              plzCompletePhrase = "Please complete the subject and message fields.";
 387          }
 388          alert(plzCompletePhrase);
 389          return false;
 390      }
 391      if (maxchars != 0) {
 392          if (textareaDom.value.length > maxchars) {
 393              if (msgTooLongPhrase == null) {
 394                  msgTooLongPhrase = "Your message is too long.";
 395              }
 396              if (allowedCharPhrase == null) {
 397                  allowedCharPhrase = "Allowed max chars length: ";
 398              }
 399              if (currCharPhrase == null) {
 400                  currCharPhrase = "Current chars length: ";
 401              }
 402              alert(msgTooLongPhrase + "\n\n" + allowedCharPhrase + maxchars + "\n" + currCharPhrase + textareaDom.value.length + "");
 403              textareaDom.focus();
 404              return false;
 405          } else {
 406              submitDom.disabled = true;
 407              return true;
 408          }
 409      } else {
 410          submitDom.disabled = true;
 411          return true;
 412      }
 413  }
 414  
 415  
 416  
 417  
 418  


Généré le : Sun Nov 25 11:44:32 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics