Archive for Birželis, 2007
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]
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]
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]
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]
