NeWorld

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]

Leave a Comment 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]

Leave a Comment 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]

Leave a Comment more...

 

You need to log in to vote

The blog owner requires users to be logged in to be able to vote for this post.

Alternatively, if you do not have an account yet you can create one here.

Powered by Vote It Up

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!

Visit our friends!

A few highly recommended friends...