NeWorld

Aktivuojam nuorodas tekste

by neworld on Bir.07, 2007, under php

Kartais mums reikia aktyvuoti nuorodas tekste. Tačiau, nemokant regular expresion, arba silpnai, gali būti sunku tai padaryti. Tenka naudotis svetimais scriptais. Tai pateiksiu savajį variantą:

[code lang="php"]function searchURL($text) {
$textt=preg_replace("/(http:\/\/)?(([\w]+\.)+)(([\w]{2})|com|net|info|biz|org)((\/)?([\w]+\/)*([\w]+(\.[\w]{2,4})?)?(\?[\w=&%\+]*)?(#[\w]*)?)?(\.|[\W]|\Z)/i
","$2$4$6$13",$text);
return $textt;
}[/code]

Comments Off more...

Dirbam su radiobutton’ais

by neworld on Bir.02, 2007, under Javascript, Programavimas, WEB programavimas

Kartais tenka javascriptu pagalbą pasiimti radiobutton reikšmę. Bet standartiniu būdų jos pasiimti neina

[code lang="javascript"]var value=document.getElementById(element).value);[/code]

Todėl tenka rašyti šiek tiek sudėtingesnę funkciją:

[code lang="javascript"]function getCheckedValue(radioObj) {
if(!radioObj)
return "";
var radioLength = radioObj.length;
if(radioLength == undefined)
if(radioObj.checked)
return radioObj.value;
else
return "";
for(var i = 0; i < radioLength; i++) {
if(radioObj[i].checked) {
return radioObj[i].value;
}
}
return "";
}
function setCheckedValue(radioObj, newValue) {
if(!radioObj)
return;
var radioLength = radioObj.length;
if(radioLength == undefined) {
radioObj.checked = (radioObj.value == newValue.toString());
return;
}
for(var i = 0; i < radioLength; i++) {
radioObj[i].checked = false;
if(radioObj[i].value == newValue.toString()) {
radioObj[i].checked = true;
}
}
}[/code]

naudojimo pavizdys:

[code lang="javascript"]var a=getCheckedValue(document.forms['form1'].elements['myradio']);[/code]

Comments Off more...

Gaunam darbinio lango dydį ir plotį

by neworld on Bir.02, 2007, under Javascript, Programavimas, WEB programavimas

Kartais mum reikia sužinoti darbinio lango dydį bei plotį. Galima pačiam pasirašyti funkciją, tačiau ji gali veikti ne visose naršyklėse. Šios dvi funkcijos veikė ant mano išbandytų naršyklių (IE6,IE7,opera,firefox,maxthon):

[code lang="javascript"]function getWindowHeight() {
var iwindowHeight = 0;
if (typeof(window.innerHeight) == 'number') {
iwindowHeight = window.innerHeight;
}
else {
if (document.documentElement && document.documentElement.clientHeight) {
iwindowHeight = document.documentElement.clientHeight;
}
else {
if (document.body && document.body.clientHeight) {
iwindowHeight = document.body.clientHeight;
}
}
}
return iwindowHeight;
}
function getWindowWidth() {
var iWindowWidth = 0;
if (typeof(window.innerWidth) == 'number') {
iwindowWidth = window.innerWidth;
}
else {
if (document.documentElement && document.documentElement.clientWidth) {
iwindowWidth = document.documentElement.clientWidth;
}
else {
if (document.body && document.body.clientWidth) {
iwindowWidth = document.body.clientWidth;
}
}
}
return iwindowWidth;
}[/code]

1 Comment more...

Kelios naudingos funkcijos dirbant su div (1 part)

by neworld on Bir.02, 2007, under Javascript, Programavimas, WEB programavimas

Dauguma šių funkcijų tinka ne tik div’am.
Norėdami dirbti su divu, turite jam priskirti id
[code lang="javascript"]
gražina į kintamajį elementą. Ją naudosiu tolesnėse funkcijose
function getelement(element) {
return document.getElementById(element);
}
//parodomo diva (veiks jeigu paslepimui naudojote stiliu: "display:none";
function showdiv(name) {
div=getelement(name);
div.style.display='block';
return true;
}
//paslepia diva
function hidediv(name) {
div=getelement(name);
div.style.display='none';
return true;
}
//keičia div rodymo/paslėpimo buseną. Tarkim paslėptą divą parodys, o matomą, paslėps.
function swap_content(name){
displayType=(document.getElementById(name).style.display=='none') ? 'block':'none';
document.getElementById(name).style.display=displayType;
return true;
}
//pakeičiam div'o turinį
function writetodiv(div,text) {
document.getElementById(div).innerHTML=text;
return true;
};
//Diva nusiunčiam į centrą. Būtinai reikės funkcijų gauti lango dydžiui: jas rasite čia
function setContent(content) {
if (document.getElementById) {
var windowHeight = getWindowHeight();
var windowWidth = getWindowWidth();
if (windowHeight > 0) {
var contentElement = document.getElementById(content);
var contentHeight = contentElement.offsetHeight;
var contentWidth = contentElement.offsetWidth;
if (windowHeight - contentHeight > 0) {
contentElement.style.top = ((windowHeight / 2) - (contentHeight / 2)) + 'px';
contentElement.style.left = ((windowWidth / 2) - (contentWidth / 2)) + 'px';
}
}
}
return false;
}
[/code]

Comments Off more...

Ajax klaida

by neworld on Geg.12, 2007, under ajax

Jeigu dirbate su ajax, tikriausiai pastebėjote, jog tuo pačiu komponentu siunčiant antrą užklausą, kai pirmoji nepabaigta įvyksta klaida. Naršyklės išmeta klaidą, sustoja šios ajax užklausos. Tačiau kad taip neatsitiktu galime idėti filtra.

Component returned failure code: 0xc1f30001 (NS_ERROR_NOT_INITIALIZED)
[nsIXMLHttpRequest.send]” nsresult: “0xc1f30001
(NS_ERROR_NOT_INITIALIZED)”

Filtras:

[code lang="javascript"] function query(adr,handle) {
var browser = navigator.appName;
 if (http.readyState==1) {
  if (browser != "Microsoft Internet Explorer") {
   http.onreadystatechange = function() {};
  }
  http.abort();
 }
[/code]

Tiesiog ši koda įterpkite į savo ajax vykdymo pradžią. Nepamirškit http pakeisti į jūsų naudojamą ajax objektą.

O dabar kaip viskas veikia.

var browser = navigator.appName; //bus mum reikalingas nustatatnt naršyklę if (http.readyState==1) { //patikrinam ar mūsų ajax komponento (http) vykdymas lygus 1 (loading)

if (browser != “Microsoft Internet Explorer”) { //patikrinam ar naršyklė IE. Galbūt sugalvosite geresnį buda patikrinti

http.onreadystatechange = function() {}; // išvalome onreadystatechange, tam kad su FF viskas būtų tvarkoje

http.abort(); //sustabdom ajax buvusį querį, kad galėtu kuo puikiausiai dirbti naujas

Be to, jeigu kas nors paklausite, kodėl negaliu tiesiog patikrinti http.onreadystance, ir esant 4 vykdyti, tai viskas veiks, tačiau nulužus serveriui gali kilti bėdų, tarkim operoje bus bandomas įkrauti duomenis iš nulužusio serverio, tol kol duomenys bus gauti, tokiu atveju, teoriškai kol negaus duomenu operą, sustos bet koks ajax vykdymas.

5 Comments more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!