Pages

Ads 468x60px

Senin, 19 Oktober 2009

Pasang calculator di blog; Siapa tahu jadi bos ?!

Lho ? Masa buat calculator dalam blog?! Emang mo buat apa?! Aha.. ini khan sekedar buat pelengkap saja. E..., siapa tahu ada yang butuh! Mungkin saja ada di antara kalian yang saat ini sedang nyambi jual bakso atau jual tahu, atau mungkin setiap kali othak-athik template harus nyari cipoa gara-gara calculatornya dipakai istri atau buat belajar anak. Nggak susah buatnya dan ditanggung pasti ada manfaatnya. E... kali-kali juga penggemar setia blog kalian lagi pusing nyari calkulator yang ketinggalan di toko, jadinya tinggal klik di blog ! Iya, khan ?!


Langkah pasang calculator :

KLIK gambar

1. Copy paste KODE berikut dan tempatkan pada ruang Javascript/HTML di bagian Elemen Laman.
2. SIMPAN dan lihat hasilnya di blog.



<table cellspacing="0" border="2" bordercolor="#99996" onclick="previouskey=event.srcElement.innerText" cellpadding="0" height="270"
style="bgcolor=#222222" width="220">
<tr>
<td id="result" width="100%" style=" border:2px solid #FFFFCC; font:bold 24px Arial; color:#f4fd00;text-align='right'" height="70" bgcolor="#0f1023"></td>
</tr>
<tr><td valign="middle" width="100%"
align="center"><table border="2" bordercolor="#FFFFCC" cellspacing="0" cellpadding="0" style="font:bold 20px Verdana;color:white" width="100%" bgcolor="282825">
<tr><td width="80%" align="center"><table onmouseout="event.srcElement.style.color='#40f6fd'" cellspacing="0" border="1" onselectstart="return false" onclick="calculate()" cellpadding="0" onmouseover="if (event.srcElement.tagName=='TD')event.srcElement.style.color='yellow'" height="168" style="cursor:hand;font:bold 18px Arial; color:#959532" width="100%">
<tr><td width="25%" height="40" align="center">7</td>
<td width="25%" height="40" align="center">8</td>
<td width="25%" height="40" align="center">9</td>
<td width="25%" height="40" align="center">/</td>
</tr>
<tr>
<td width="25%" height="40" align="center">4</td>
<td width="25%" height="40" align="center">5</td>
<td width="25%" height="40" align="center">6</td>
<td width="25%" height="40" align="center">*</td></tr>
<tr><td width="25%" height="40" align="center">1</td>
<td width="25%" height="40" align="center">2</td>
<td width="25%" height="40" align="center">3</td>
<td width="25%" height="40" align="center">-</td></tr>
<tr><td width="25%" height="40" align="center">0</td>
<td width="25%" height="40" onclick="pn();previouskey=1;event.cancelBubble=true" align="center">+/-</td>
<td width="25%" height="40" align="center">.</td>
<td width="25%" height="40" align="center">+</td>
</tr></table></td><td width="20%"><div align="left"><table border="1" width="100%" cellspacing="0" cellpadding="0">
<tr><td width="100%" style="cursor:hand; text-align:center; font:bolder 24px Verdana; color:red; text-align:center" height="50" onclick="result.innerText=0;results=''">C</td></tr></table></div>
<div align="left"><table border="1" width="100%" cellspacing="0" cellpadding="0" height="73">
<tr><td width="100%" style="cursor:hand; text-align:center; font:bold 32px Verdana;color:blue;" onmouseover="event.srcElement.style.color='yellow'"
height="71" onmouseout="event.srcElement.style.color='blue'" onclick="calculateresult()">=</td>
</tr></table></div>
<div align="left"><table border="1" width="100%" cellspacing="0" cellpadding="1" height="40" align="center">
<tr><td width="100%" style=""><img src="http://i35.tinypic.com/2lksolh.gif"/></td></tr></table></div></td>
</tr></table></td></tr></table>
<script language="JavaScript1.2">
/* *bloggerstar1* */
var results=''
var previouskey=''
var re=/(\/|\*|\+|-)/
var re2=/(\/|\*|\+|-){2}$/
var re3=/.+(\/|\*|\+|-).+/
var re4=/\d|\./
var re5=/^[^\/\*\+].+\d$/
var re6=/\./
function calculate(){
if (event.srcElement.tagName=="TD"){
if (event.srcElement.innerText.match(re4)&&previouskey=="=")
results=''
if (result.innerText.match(re3)&&event.srcElement.innerText.match(re)){
if (!results.match(re5)){
result.innerText="Error!"
return
}
results=eval(results)
if (results.toString().length>=12&&results.toString().match(re6))
results=results.toString().substring(0,12)
result.innerText=results
}
results+=event.srcElement.innerText
if (results.match(re2))
results=results.substring(0,results.length-2)+results.charAt(results.length-1)
result.innerText=results
}
}
function calculateresult(){
if (!results.match(re5)){
result.innerText="Error!"
return
}
results=eval(results)
if (results.toString().length>=12&&results.toString().match(re6))
results=results.toString().substring(0,12)
result.innerText=results
}
function pn(){
if (result.innerText.charAt(0)!='-')
result.innerText=results='-'+result.innerText
else if (result.innerText.charAt(0)=='-')
result.innerText=results=result.innerText*(-1)
}
</script>




3. Calculator ini tidak compatible untuk firefox.
4. Beberapa modifikasi bisa dilakukan pada kode selain javascript :
- ukuran : huruf/teks, box/kotak,
- warna : teks, box
- jenis font/huruf/teks

Selamat mecoba!! Mudah-mudahan lebih lancar saat menghitung hasil jualan sate dan sotonya. Saya doakan semoga untungnya tambah gedhe !!!

0 komentar:

Posting Komentar