home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / CMS / xoops-2.0.18.1.exe / xoops-2.0.18.1 / htdocs / include / xoops.js < prev    next >
Encoding:
Text File  |  2008-01-29  |  12.5 KB  |  409 lines

  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.     return (returnwindow != null ? new_window : void(0));
  52. }
  53.  
  54. function setElementColor(id, color){
  55.     xoopsGetElementById(id).style.color = "#" + color;
  56. }
  57.  
  58. function setElementFont(id, font){
  59.     xoopsGetElementById(id).style.fontFamily = font;
  60. }
  61.  
  62. function setElementSize(id, size){
  63.     xoopsGetElementById(id).style.fontSize = size;
  64. }
  65.  
  66. function changeDisplay(id){
  67.     var elestyle = xoopsGetElementById(id).style;
  68.     if (elestyle.display == "") {
  69.         elestyle.display = "none";
  70.     } else {
  71.         elestyle.display = "block";
  72.     }
  73. }
  74.  
  75. function setVisible(id){
  76.     xoopsGetElementById(id).style.visibility = "visible";
  77. }
  78.  
  79. function setHidden(id){
  80.     xoopsGetElementById(id).style.visibility = "hidden";
  81. }
  82.  
  83. function makeBold(id){
  84.     var eleStyle = xoopsGetElementById(id).style;
  85.     if (eleStyle.fontWeight != "bold" && eleStyle.fontWeight != "700") {
  86.         eleStyle.fontWeight = "bold";
  87.     } else {
  88.         eleStyle.fontWeight = "normal";
  89.     }
  90. }
  91.  
  92. function makeItalic(id){
  93.     var eleStyle = xoopsGetElementById(id).style;
  94.     if (eleStyle.fontStyle != "italic") {
  95.         eleStyle.fontStyle = "italic";
  96.     } else {
  97.         eleStyle.fontStyle = "normal";
  98.     }
  99. }
  100.  
  101. function makeUnderline(id){
  102.     var eleStyle = xoopsGetElementById(id).style;
  103.     if (eleStyle.textDecoration != "underline") {
  104.         eleStyle.textDecoration = "underline";
  105.     } else {
  106.         eleStyle.textDecoration = "none";
  107.     }
  108. }
  109.  
  110. function makeLineThrough(id){
  111.     var eleStyle = xoopsGetElementById(id).style;
  112.     if (eleStyle.textDecoration != "line-through") {
  113.         eleStyle.textDecoration = "line-through";
  114.     } else {
  115.         eleStyle.textDecoration = "none";
  116.     }
  117. }
  118.  
  119. function appendSelectOption(selectMenuId, optionName, optionValue){
  120.     var selectMenu = xoopsGetElementById(selectMenuId);
  121.     var newoption = new Option(optionName, optionValue);
  122.     selectMenu.options[selectMenu.length] = newoption;
  123.     selectMenu.options[selectMenu.length].selected = true;
  124. }
  125.  
  126. function disableElement(target){
  127.     var targetDom = xoopsGetElementById(target);
  128.     if (targetDom.disabled != true) {
  129.         targetDom.disabled = true;
  130.     } else {
  131.         targetDom.disabled = false;
  132.     }
  133. }
  134.  
  135. function xoopsCheckAll( form, switchId ) {
  136.     var eltForm = $(form);
  137.     var eltSwitch = $(switchId);
  138.     // You MUST NOT specify names, it's just kept for BC with the old lame crappy code
  139.     if ( !eltForm && document.forms[form] )        eltForm = document.forms[form];
  140.     if ( !eltSwitch && eltForm.elements[switchId] )    eltSwitch=eltForm.elements[switchId];
  141.     
  142.     var i;
  143.     for (i=0;i!=eltForm.elements.length;i++) {
  144.         if ( eltForm.elements[i] != eltSwitch && eltForm.elements[i].type == 'checkbox' ) {
  145.             eltForm.elements[i].checked = eltSwitch.checked;
  146.         }
  147.     }
  148. }
  149.     
  150.  
  151. function xoopsCheckGroup( form, switchId, groupName ) {
  152.     var eltForm = $(form);
  153.     var eltSwitch = $(switchId);
  154.     // You MUST NOT specify names, it's just kept for BC with the old lame crappy code
  155.     if ( !eltForm && document.forms[form] )        eltForm = document.forms[form];
  156.     if ( !eltSwitch && eltForm.elements[switchId] )    eltSwitch=eltForm.elements[switchId];
  157.  
  158.     var i;
  159.     for (i=0;i!=eltForm.elements.length;i++) {
  160.         var e=eltForm.elements[i];
  161.         if ( (e.type == 'checkbox') && ( e.name == groupName ) ) {
  162.             e.checked = eltSwitch.checked;
  163.             e.click(); e.click();  // Click to activate subgroups twice so we don't reverse effect
  164.         }
  165.     }
  166. }
  167.  
  168. function xoopsCheckAllElements(elementIds, switchId) {
  169.     var switch_cbox = xoopsGetElementById(switchId);
  170.     for (var i = 0; i < elementIds.length; i++) {
  171.         var e = xoopsGetElementById(elementIds[i]);
  172.         if ((e.name != switch_cbox.name) && (e.type == 'checkbox')) {
  173.             e.checked = switch_cbox.checked;
  174.         }
  175.     }
  176. }
  177.  
  178. function xoopsSavePosition(id)
  179. {
  180.     var textareaDom = xoopsGetElementById(id);
  181.     if (textareaDom.createTextRange) {
  182.         textareaDom.caretPos = document.selection.createRange().duplicate();
  183.     }
  184. }
  185.  
  186. function xoopsInsertText(domobj, text)
  187. {
  188.     if (domobj.createTextRange && domobj.caretPos){
  189.           var caretPos = domobj.caretPos;
  190.         caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;  
  191.     } else if (domobj.getSelection && domobj.caretPos){
  192.         var caretPos = domobj.caretPos;
  193.         caretPos.text = caretPos.text.charat(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
  194.     } else {
  195.         domobj.value = domobj.value + text;
  196.       }
  197. }
  198.  
  199. function xoopsCodeSmilie(id, smilieCode) {
  200.     var revisedMessage;
  201.     var textareaDom = xoopsGetElementById(id);
  202.     xoopsInsertText(textareaDom, smilieCode);
  203.     textareaDom.focus();
  204.     return;
  205. }
  206.  
  207. function showImgSelected(imgId, selectId, imgDir, extra, xoopsUrl) {
  208.     if (xoopsUrl == null) {
  209.         xoopsUrl = "./";
  210.     }
  211.     imgDom = xoopsGetElementById(imgId);
  212.     selectDom = xoopsGetElementById(selectId);
  213.     imgDom.src = xoopsUrl + "/"+ imgDir + "/" + selectDom.options[selectDom.selectedIndex].value + extra;
  214. }
  215.  
  216. function xoopsCodeUrl(id, enterUrlPhrase, enterWebsitePhrase){
  217.     if (enterUrlPhrase == null) {
  218.         enterUrlPhrase = "Enter the URL of the link you want to add:";
  219.     }
  220.     var text = prompt(enterUrlPhrase, "");
  221.     var domobj = xoopsGetElementById(id);
  222.     if ( text != null && text != "" ) {
  223.         if (enterWebsitePhrase == null) {
  224.             enterWebsitePhrase = "Enter the web site title:";
  225.         }
  226.         var text2 = prompt(enterWebsitePhrase, "");
  227.         if ( text2 != null ) {
  228.             if ( text2 == "" ) {
  229.                 var result = "[url=" + text + "]" + text + "[/url]";
  230.             } else {
  231.                 var pos = text2.indexOf(unescape('%00'));
  232.                 if(0 < pos){
  233.                     text2 = text2.substr(0,pos);
  234.                 }
  235.                 var result = "[url=" + text + "]" + text2 + "[/url]";
  236.             }
  237.             xoopsInsertText(domobj, result);
  238.         }
  239.     }
  240.     domobj.focus();
  241. }
  242.  
  243. function xoopsCodeImg(id, enterImgUrlPhrase, enterImgPosPhrase, imgPosRorLPhrase, errorImgPosPhrase){
  244.     if (enterImgUrlPhrase == null) {
  245.         enterImgUrlPhrase = "Enter the URL of the image you want to add:";
  246.     }
  247.     var text = prompt(enterImgUrlPhrase, "");
  248.     var domobj = xoopsGetElementById(id);
  249.     if ( text != null && text != "" ) {
  250.         if (enterImgPosPhrase == null) {
  251.             enterImgPosPhrase = "Now, enter the position of the image.";
  252.         }
  253.         if (imgPosRorLPhrase == null) {
  254.             imgPosRorLPhrase = "'R' or 'r' for right, 'L' or 'l' for left, or leave it blank.";
  255.         }
  256.         if (errorImgPosPhrase == null) {
  257.             errorImgPosPhrase = "ERROR! Enter the position of the image:";
  258.         }
  259.         var text2 = prompt(enterImgPosPhrase + "\n" + imgPosRorLPhrase, "");
  260.         while ( ( text2 != "" ) && ( text2 != "r" ) && ( text2 != "R" ) && ( text2 != "l" ) && ( text2 != "L" ) && ( text2 != null ) ) {
  261.             text2 = prompt(errorImgPosPhrase + "\n" + imgPosRorLPhrase,"");
  262.         }
  263.         if ( text2 == "l" || text2 == "L" ) {
  264.             text2 = " align=left";
  265.         } else if ( text2 == "r" || text2 == "R" ) {
  266.             text2 = " align=right";
  267.         } else {
  268.             text2 = "";
  269.         }
  270.         var result = "[img" + text2 + "]" + text + "[/img]";
  271.         xoopsInsertText(domobj, result);
  272.     }
  273.     domobj.focus();
  274. }
  275.  
  276. function xoopsCodeEmail(id, enterEmailPhrase){
  277.     if (enterEmailPhrase == null) {
  278.         enterEmailPhrase = "Enter the email address you want to add:";
  279.     }
  280.     var text = prompt(enterEmailPhrase, "");
  281.     var domobj = xoopsGetElementById(id);
  282.     if ( text != null && text != "" ) {
  283.         var result = "[email]" + text + "[/email]";
  284.         xoopsInsertText(domobj, result);
  285.     }
  286.     domobj.focus();
  287. }
  288.  
  289. function xoopsCodeQuote(id, enterQuotePhrase){
  290.     if (enterQuotePhrase == null) {
  291.         enterQuotePhrase = "Enter the text that you want to be quoted:";
  292.     }
  293.     var text = prompt(enterQuotePhrase, "");
  294.     var domobj = xoopsGetElementById(id);
  295.     if ( text != null && text != "" ) {
  296.         var pos = text.indexOf(unescape('%00'));
  297.         if(0 < pos){
  298.             text = text.substr(0,pos);
  299.         }
  300.         var result = "[quote]" + text + "[/quote]";
  301.         xoopsInsertText(domobj, result);
  302.     }
  303.     domobj.focus();
  304. }
  305.  
  306. function xoopsCodeCode(id, enterCodePhrase){
  307.     if (enterCodePhrase == null) {
  308.         enterCodePhrase = "Enter the codes that you want to add.";
  309.     }
  310.     var text = prompt(enterCodePhrase, "");
  311.     var domobj = xoopsGetElementById(id);
  312.     if ( text != null && text != "" ) {
  313.         var result = "[code]" + text + "[/code]";
  314.         xoopsInsertText(domobj, result);
  315.     }
  316.     domobj.focus();
  317. }
  318.  
  319. function xoopsCodeText(id, hiddentext, enterTextboxPhrase){
  320.     var textareaDom = xoopsGetElementById(id);
  321.     var textDom = xoopsGetElementById(id + "Addtext");
  322.     var fontDom = xoopsGetElementById(id + "Font");
  323.     var colorDom = xoopsGetElementById(id + "Color");
  324.     var sizeDom = xoopsGetElementById(id + "Size");
  325.     var xoopsHiddenTextDomStyle = xoopsGetElementById(hiddentext).style;
  326.     var textDomValue = textDom.value;
  327.     var fontDomValue = fontDom.options[fontDom.options.selectedIndex].value;
  328.     var colorDomValue = colorDom.options[colorDom.options.selectedIndex].value;
  329.     var sizeDomValue = sizeDom.options[sizeDom.options.selectedIndex].value;
  330.     if ( textDomValue == "" ) {
  331.         if (enterTextboxPhrase == null) {
  332.             enterTextboxPhrase = "Please input text into the textbox.";
  333.         }
  334.         alert(enterTextboxPhrase);
  335.         textDom.focus();
  336.     } else {
  337.         if ( fontDomValue != "FONT") {
  338.             textDomValue = "[font=" + fontDomValue + "]" + textDomValue + "[/font]";
  339.             fontDom.options[0].selected = true;
  340.         }
  341.         if ( colorDomValue != "COLOR") {
  342.             textDomValue = "[color=" + colorDomValue + "]" + textDomValue + "[/color]";
  343.             colorDom.options[0].selected = true;
  344.         }
  345.         if ( sizeDomValue != "SIZE") {
  346.             textDomValue = "[size=" + sizeDomValue + "]" + textDomValue + "[/size]";
  347.             sizeDom.options[0].selected = true;
  348.         }
  349.         if (xoopsHiddenTextDomStyle.fontWeight == "bold" || xoopsHiddenTextDomStyle.fontWeight == "700") {
  350.             textDomValue = "[b]" + textDomValue + "[/b]";
  351.             xoopsHiddenTextDomStyle.fontWeight = "normal";
  352.         }
  353.         if (xoopsHiddenTextDomStyle.fontStyle == "italic") {
  354.             textDomValue = "[i]" + textDomValue + "[/i]";
  355.             xoopsHiddenTextDomStyle.fontStyle = "normal";
  356.         }
  357.         if (xoopsHiddenTextDomStyle.textDecoration == "underline") {
  358.             textDomValue = "[u]" + textDomValue + "[/u]";
  359.             xoopsHiddenTextDomStyle.textDecoration = "none";
  360.         }
  361.         if (xoopsHiddenTextDomStyle.textDecoration == "line-through") {
  362.             textDomValue = "[d]" + textDomValue + "[/d]";
  363.             xoopsHiddenTextDomStyle.textDecoration = "none";
  364.         }
  365.         xoopsInsertText(textareaDom, textDomValue);
  366.         textDom.value = "";
  367.         xoopsHiddenTextDomStyle.color = "#000000";
  368.         xoopsHiddenTextDomStyle.fontFamily = "";
  369.         xoopsHiddenTextDomStyle.fontSize = "12px";
  370.         xoopsHiddenTextDomStyle.visibility = "hidden";
  371.         textareaDom.focus();
  372.     }
  373. }
  374.  
  375. function xoopsValidate(subjectId, textareaId, submitId, plzCompletePhrase, msgTooLongPhrase, allowedCharPhrase, currCharPhrase) {
  376.     var maxchars = 65535;
  377.     var subjectDom = xoopsGetElementById(subjectId);
  378.     var textareaDom = xoopsGetElementById(textareaId);
  379.     var submitDom = xoopsGetElementById(submitId);
  380.     if (textareaDom.value == "" || subjectDom.value == "") {
  381.         if (plzCompletePhrase == null) {
  382.             plzCompletePhrase = "Please complete the subject and message fields.";
  383.         }
  384.         alert(plzCompletePhrase);
  385.         return false;
  386.     }
  387.     if (maxchars != 0) {
  388.         if (textareaDom.value.length > maxchars) {
  389.             if (msgTooLongPhrase == null) {
  390.                 msgTooLongPhrase = "Your message is too long.";
  391.             }
  392.             if (allowedCharPhrase == null) {
  393.                 allowedCharPhrase = "Allowed max chars length: ";
  394.             }
  395.             if (currCharPhrase == null) {
  396.                 currCharPhrase = "Current chars length: ";
  397.             }
  398.             alert(msgTooLongPhrase + "\n\n" + allowedCharPhrase + maxchars + "\n" + currCharPhrase + textareaDom.value.length + "");
  399.             textareaDom.focus();
  400.             return false;
  401.         } else {
  402.             submitDom.disabled = true;
  403.             return true;
  404.         }
  405.     } else {
  406.         submitDom.disabled = true;
  407.         return true;
  408.     }
  409. }