Strana 1 z 1

digital clock

Napísané: Ne Aug 03, 2008 8:09 pm
od používateľa gabo
tento snippet je z eto.org ide myslim o digitalne hodinočky, mne po graf uprave bežia na http://www.kchajd.sk

Kód: Vybrať všetko

//Snippet Digital Clock
//Etomized by Cris D.
//Use: displays a java clock with the browser's time using pre-loaded images

// Instructions:
//1) FTP up the images to your chosen folder and set the folder address in the snippet.
//2) Copy and paste this code into your snippet library, cal it "clock"
//3) Place on the page where you want the clock to show up [!clock!]

//Configuration:
//set to the path where the images are uploaded
$imagePath="assets/clock";

############ Snippet starts here  #############

$output.=
<<<END
<script type="text/javascript">

/***********************************************

* JavaScript Image Clock- by JavaScript Kit (www.javascriptkit.com)
* This notice must stay intact for usage
* Visit JavaScript Kit at http://www.javascriptkit.com/ for this script and 100s more

***********************************************/

var imageclock=new Object()
	//Enter path to clock digit images here, in order of 0-9, then "am/pm", then colon image:
	imageclock.digits=["$imagePath/c0.jpg", "$imagePath/c1.jpg", "$imagePath/c2.jpg", "$imagePath/c3.jpg", "$imagePath/c4.jpg", "$imagePath/c5.jpg", "$imagePath/c6.jpg", "$imagePath/c7.jpg", "$imagePath/c8.jpg", "$imagePath/c9.jpg", "$imagePath/cam.jpg", "$imagePath/cpm.jpg", "$imagePath/colon.jpg"]
	imageclock.instances=0
	var preloadimages=[]
	for (var i=0; i<imageclock.digits.length; i++){ //preload images
		preloadimages[i]=new Image()
		preloadimages[i].src=imageclock.digits[i]
	}

	imageclock.imageHTML=function(timestring){ //return timestring (ie: 1:56:38) into string of images instead
		var sections=timestring.split(":")
		if (sections[0]=="0") //If hour field is 0 (aka 12 AM)
			sections[0]="12"
		else if (sections[0]>=13)
			sections[0]=sections[0]-12+""
		for (var i=0; i<sections.length; i++){
			if (sections[i].length==1)
				sections[i]='<img src="'+imageclock.digits[0]+'" />'+'<img src="'+imageclock.digits[parseInt(sections[i])]+'" />'
			else
				sections[i]='<img src="'+imageclock.digits[parseInt(sections[i].charAt(0))]+'" />'+'<img src="'+imageclock.digits[parseInt(sections[i].charAt(1))]+'" />'
		}
		return sections[0]+'<img src="'+imageclock.digits[12]+'" />'+sections[1]+'<img src="'+imageclock.digits[12]+'" />'+sections[2]
	}

	imageclock.display=function(){
		var clockinstance=this
		this.spanid="clockspan"+(imageclock.instances++)
		document.write('<span id="'+this.spanid+'"></span>')
		this.update()
		setInterval(function(){clockinstance.update()}, 1000)
	}

	imageclock.display.prototype.update=function(){
		var dateobj=new Date()
		var currenttime=dateobj.getHours()+":"+dateobj.getMinutes()+":"+dateobj.getSeconds() //create time string
		var currenttimeHTML=imageclock.imageHTML(currenttime)+'<img src="'+((dateobj.getHours()>=12)? imageclock.digits[11] : imageclock.digits[10])+'" />'
		document.getElementById(this.spanid).innerHTML=currenttimeHTML

	}
</script>
END;

$output.=
<<<END
<script type="text/javascript">

new imageclock.display()

</script>
END;

return $output;
ja som akurat pozmenil .gifka za .jpg nakolko sa mi lepsie urpravovali pre moju potrebu

obrazky v subore clock.rar nakopčit do .....assets/clock

Re: digital clock

Napísané: Ne Aug 03, 2008 8:11 pm
od používateľa gabo
este by som niekoho poprosil ak vie mi ten snippetik tak upravit aby som tam vedel pouzivat format 24h a nie len 12h, mozno to tam niekde je len ja lama som nenasiel, dakujem

Re: digital clock

Napísané: St Aug 06, 2008 10:58 pm
od používateľa _rasel^
Keď prerobíš tento script podľa http://www.javascriptmall.com/jsc/jsC4Uclocks.htm (sú tam hodinky s 24 hodinovým formátom) tak ti to pobeží. :)