/* includować tak: robi to np. layout.php w LLayoutMetatags */ function GetXmlHttpObject() { var xmlHttp=null; try{ // Firefox, Opera 8.0+, Safari xmlHttp=new XMLHttpRequest(); } catch (e){ // Internet Explorer try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e){ xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } } return xmlHttp; } /* ogólna funkcja robiąca różne rzeczy zaimplementowane w account_operation_ajax.php synchronicznie. wystarczy wywołać, nie trzeba implementować reakcji (typu on radystatechange) */ function AjaxGeneralOperation(oper, param1, param2, param3){ var ajax=GetXmlHttpObject(); if(ajax==null) { alert("ajax unavailable"); return; } /* ajax.onreadystatechange=function (){ AjaxDoSomething_StateChanged(oper); };*/ var oper_link="account_operation_ajax.php?do="+oper+"¶m1="+param1+"¶m2="+param2+"¶m3="+param3; ajax.open("GET",oper_link,false); ajax.send(null); //alert(ajax.responseText); } /* ustawienie zmiennej w ini aktualnego usera */ function AjaxSetCurUserIniOption(varname, varval){ AjaxGeneralOperation("SetCurUserOption", varname, varval, ""); } /* zwraca (synchronicznie!) to co zwróci strona w podanym url'u przykład: var url="account_todos.php?do=getFolderContents&folderId="+attrFolderId; $("#todos").html(jqueryAjaxGetPageSync(url)); */ function jqueryAjaxGetPageSync(link) { return $.ajax({ url: link, async: false, cache: false }).responseText; } /* jqueryAjaxPostData wywoła asynchronicznie dany plik, z podanymi danymi jsonData wysłanymi jako POST jeśli zapodamy elemIdToFill to zwróconymi danymi wypełni element dom o tym id/klasie (czyli w elemIdToFill zapodać wpierw # lub .) jeśli chcemy by coś było wykonane gdy dane będą pobrane, podać toEval można w owym toEval użyć zmiennej data która ma to co zwrócił wywołany plik przykłady z podanym elem. do wypełnienia: jqueryAjaxPostData("ajax_tasks.php",{"task":"test","someval":"bleeee"},""); jqueryAjaxPostData("ajax_tasks.php",{"task":"test","someval":"bleeee"},"#tests_id"); jqueryAjaxPostData("ajax_tasks.php",{"task":"test","someval":"bleeee"},".someclass"); przykład z toEval: jqueryAjaxPostData("ajax_tasks.php",{"task":"test"},"",'alert("executed by eval:"+data);'); jqueryAjaxPostData("ajax_tasks.php",{"task":"test"},"",'$("#tests2").html(data);'); przykład z toEval gdzie użyjemy param z jsonData : jqueryAjaxPostData("ajax_tasks.php",{"task":"test"},"",'alert(jsonData.task);'); */ function jqueryAjaxPostData(link, jsonData, elemIdToFill, toEval) { $.post( link, jsonData, function(data){ //alert(data); if(elemIdToFill!="") $(elemIdToFill).html(data); if(toEval!="") eval(toEval); } ); } /* otwiera podany link w nowym oknie, np: echo "Open in a new window"; */ function OpenInNewWin(link){ w=window.open(link,'','scrollbars=yes,resizable=yes,width=640,height=550');w.focus(); } /* otwiera podany link w nowym oknie o poldanych rozmiarach, np: echo "Open in a new window"; */ function OpenInNewWin2(link,width,height){ w=window.open(link,'','scrollbars=yes,resizable=yes,width='+width+',height='+height);w.focus(); } function ToggleVisibility(id) { var e = document.getElementById(id); if(e.style.display == 'block') e.style.display = 'none'; else e.style.display = 'block'; } function ToggleVisibilityAnim(id) { var e = document.getElementById(id); var strId="#"+id; //$(strId).toggle("normal"); if ($(strId).is (':visible')) $(strId).fadeOut("slow", function() { $(strId).hide() }); else $(strId).fadeIn("slow", function() { $(strId).show() }); } function ShowElement(id,show){ var e = document.getElementById(id); if(show == false) e.style.display = 'none'; else e.style.display = 'block'; } function GetURLVar(urlVarName) { //divide the URL in half at the '?' var urlHalves = String(document.location).split('?'); var urlVarValue = ''; if(urlHalves[1]){ //load all the name/value pairs into an array var urlVars = urlHalves[1].split('&'); //loop over the list, and find the specified url variable for(i=0; i<=(urlVars.length); i++){ if(urlVars[i]){ //load the name/value pair into an array var urlVarPair = urlVars[i].split('='); if (urlVarPair[0] && urlVarPair[0] == urlVarName) { //I found a variable that matches, load it's value into the return variable urlVarValue = urlVarPair[1]; } } } } return urlVarValue; } //używ. min. przez send.php by zamienić jakiś TEXT na np. [b]TEXT[/b] (bbcodes) function ReplaceSelText(id,withLeft,withRight){ // code for ie var textarea = document.getElementById(id); if (document.selection) { textarea.focus(); var sel = document.selection.createRange(); //alert(sel.text); // Finally replace the value of the selected text with this new replacement one sel.text = withLeft + sel.text + withRight; }else{ textarea.focus(); // code for Mozilla //var textarea = document.getElementById(id); var len = textarea.value.length; var start = textarea.selectionStart; var end = textarea.selectionEnd; var sel = textarea.value.substring(start, end); //alert(sel); var replace = withLeft + sel + withRight; // Here we are replacing the selected text with this one textarea.value = textarea.value.substring(0,start) + replace + textarea.value.substring(end,len); } }