Tampilkan postingan dengan label Eksperimen. Tampilkan semua postingan
Tampilkan postingan dengan label Eksperimen. Tampilkan semua postingan

Minggu, 26 April 2015

Password Overlay

Di sini, JavaScript btoa digunakan untuk menyembunyikan teks, sedangkan atob digunakan untuk mengembalikan teks yang tersembunyi tersebut:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Password Overlay Test</title>

<style>
.body {
padding:10% 0;
text-align:center;
}
.overlay {
position:fixed;
top:0;
right:0;
bottom:0;
left:0;
z-index:9999;
background-color:black;
color:white;
padding:10% 0;
text-align:center;
}
</style>

</head>
<body>

<div id="protect-body" class="body">Content goes here…</div>
<div id="protect-overlay" class="overlay">
<form action="#">
<input name="answer" type="password" placeholder="Password?"/> <button type="submit">Open</button>
</form>
</div>

<script>
// https://developer.mozilla.org/En/DOM/Window.btoa
// https://developer.mozilla.org/en/DOM/window.atob
// to get the obfuscated text, use `console.log(btoa('your text goes here'))`
// `aSBsb3ZlIHlvdQ==` => `i love you`
(function() {
var o = document.getElementById('protect-overlay');
o.getElementsByTagName('form')[0].onsubmit = function() {
if (this.answer.value === atob('aSBsb3ZlIHlvdQ==')) {
o.style.display = "none"; // passed!
} else {
alert('Wrong password!');
}
return false;
};
})();
</script>

</body>
</html>

Demo

Kata kunci: i love you

Minggu, 06 Juli 2014

Fake Link

HTML

<form class="fake-link" action="http://example.org" method="get" target="_blank">
<input name="aff" type="hidden" value="1234567">
<button type="submit">affiliate link</button>
</form>

CSS

.fake-link,
.fake-link button {
margin:0;
padding:0;
width:auto;
height:auto;
background:none;
border:none;
font:inherit;
text-transform:none;
display:inline;
}
.fake-link button {
color:blue;
cursor:pointer;
}
.fake-link button::-moz-focus-inner {
margin:0;
padding:0;
border:none;
outline:none;
}
.fake-link button:focus,
.fake-link button:hover {text-decoration:underline}
.fake-link button:active {color:red}

Demo

Rabu, 19 Februari 2014

Simple Text Editor Library

Markdown Text Editor
Editor Teks untuk Format Markdown

Pembuatan perpustakaan JavaScript ini dikhususkan untuk menangani aplikasi-aplikasi editor teks berbasis elemen <textarea>. Target awal ingin Saya jadikan sebagai pendukung aplikasi editor teks Markdown, tapi Anda juga bisa menggunakan ini untuk membuat aplikasi editor teks sekelas MarkItUp! jika mau:

Demo

NB: Butuh judul posting berbahasa Indonesia untuk ini.

Kamis, 05 Desember 2013

Mengubah Tipe Kursor pada Scrollbar

Mengubah Tipe Pointer Scrollbar
Kursor pada scrollbar berubah menjadi pointer.

Mungkin ini tidak penting tapi terkadang kita merasa bahwa menggeser-geser scrollbar dengan kursor bertipe pointer akan terasa lebih “enak” dibandingkan dengan menggeser-geser scrollbar dengan kursor bertipe default. Akan tetapi mengubah tipe kursor pada scrollbar tidak mungkin bisa dilakukan karena scrollbar tidak termasuk ke dalam elemen HTML (pengecualian jika kita menggunakan manipulasi seperti JavaScript Custom Scrollbar, karena setiap item penggulung dibuat menggunakan elemen HTML). Bahkan selektor CSS scrollbar milik WebKit pun tidak bisa dimanipulasi:

::-webkit-scrollbar-thumb {
cursor:pointer; /* tidak bekerja! :( */
}

Satu cara sederhana yang bisa kita lakukan untuk mengubah tipe kursor pada scrollbar adalah dengan menerapkan tipe kursor menjadi pointer secara keseluruhan kepada area yang diinginkan, kemudian mengembalikan tipe kursor ke keadaan semula pada bagian dalam. Di sini kita membutuhkan elemen pembungkus ekstra:

HTML

<div class="scrollable-area">
<div class="scrollable-area-content">
<p>Lorem ipsum dolor sit amet...</p>
</div>
</div>

CSS

.scrollable-area {cursor:pointer}
.scrollable-area-content {cursor:auto}

Demo

Contoh lain, mengubah tipe kursor menjadi n-resize pada scrollbar vertikal dengan tampilan kustom (buka halaman demo menggunakan peramban Google Chrome atau Safari):

Sabtu, 23 Maret 2013

CSS3 Facebook Chatbox

HTML

.chat-box {
font:normal normal 11px/1.4 Tahoma,Verdana,Sans-Serif;
color:#333;
width:200px; /* Chatbox width */
border:1px solid #344150;
border-bottom:none;
background-color:white;
position:fixed;
right:10px;
bottom:0;
z-index:9999;
-webkit-box-shadow:1px 1px 5px rgba(0,0,0,.2);
-moz-box-shadow:1px 1px 5px rgba(0,0,0,.2);
box-shadow:1px 1px 5px rgba(0,0,0,.2);
}

.chat-box > input[type="checkbox"] {
display:block;
margin:0 0;
padding:0 0;
position:absolute;
top:0;
right:0;
left:0;
width:100%;
height:26px;
z-index:4;
cursor:pointer;
opacity:0;
filter:alpha(opacity=0);
}

.chat-box > label {
display:block;
height:24px;
line-height:24px;
background-color:#344150;
color:white;
font-weight:bold;
padding:0 1em 1px;
}

.chat-box > label:before {content:attr(data-collapsed)}

.chat-box .chat-box-content {
/* padding:10px; */
display:none;
}

/* hover state */
.chat-box > input[type="checkbox"]:hover + label {background-color:#404D5A}

/* checked state */
.chat-box > input[type="checkbox"]:checked + label {background-color:#212A35}
.chat-box > input[type="checkbox"]:checked + label:before {content:attr(data-expanded)}
.chat-box > input[type="checkbox"]:checked ~ .chat-box-content {display:block}

HTML

<div class="chat-box">
<input type="checkbox">
<label data-expanded="Close Chatbox" data-collapsed="Open Chatbox"></label>
<div class="chat-box-content">

<!-- Kode buku tamu dsb... -->

</div>
</div>

Sabtu, 02 Maret 2013

Eksperimen Infinite Scroll dengan JSON Blogger

Blogger Infinite Scroll Experiment
Blogger Infinite Scroll Experiment

Eksperimen membuat infinite scroll dengan JSON Blogger. Sebuah sistem yang akan memperbaharui jumlah item posting setiap kali pengguna mencapai batas akhir layar ketika pengguna sedang menggulung halaman. Metode ini sebenarnya sudah pernah Saya tuliskan di sini. Saya mengganti kondisional batas akhir yang tadinya berupa perbandingan antara tinggi kontainer dengan batas akhir gulungan area seperti ini:

container.onscroll = function() {
if ((this.scrollTop + this.offsetHeight) == inner.offsetHeight) {
myFunction();
}
};

Menjadi berdasarkan perbandingan antara tinggi layar dengan batas akhir gulungan layar seperti ini:

window.onscroll = function() {
if (navigator.userAgent.toLowerCase().indexOf("chrome") > -1 || navigator.userAgent.toLowerCase().indexOf("safari") > -1) {
if (document.documentElement.scrollHeight == (document.body.scrollTop + document.documentElement.clientHeight)) {
myFunction();
}
} else {
if (document.documentElement.scrollHeight == (document.documentElement.scrollTop + document.documentElement.clientHeight)) {
myFunction();
}
}
};

Selengkapnya mengenai potongan kode untuk mengecek batas akhir gulungan layar bisa Anda baca di sini.

Silakan dipelajari dan dimodifikasi sesuka hati Anda dengan mengikuti persetujuan yang Saya tuliskan di dalam kode sumbernya. Eksperimen ini akan diperbaharui jika memang ada yang perlu diperbaharui. Begitu.

Rabu, 30 Januari 2013

Input Teks dengan Pelengkap Sugesti

Text Input with Suggestion

Elemen UI ini terinspirasi dari Google, lebih tepatnya pada bagian atas dasbor Forum Blogger (2013). Ini hanyalah penerapan konsep drop-down menu sebagai pelengkap elemen input teks dan sama sekali tidak ada hubungannya dengan cara kerja filter penelusuran/sortir topik pembicaraan seperti pada grup Google.

Elemen ini bisa Anda gunakan untuk memberikan sugesti atau pilihan kata kunci secara tidak langsung tanpa harus repot-repot menuliskan perintah-perintah khusus di sekitar formulir untuk pengguna agar mereka menuliskan kata kunci seperti ini dan itu. Cukup letakkan beberapa sugesti kata kunci pada menu drop-down, maka para pengguna akan segera mengerti gambaran formulir tersebut saat mereka menampilkan menu:

HTML

<div class="input-text-wrap">
<form action="http://your_site_name.com/search" method="get">
<input class="text-input" type="text" name="q" autocomplete="off">
<span class="down-arrow"></span>
<input class="submit-button" type="submit" value="Search">
<ul>
<li>Wallpaper 3D</li>
<li>Anime</li>
<li>Manga</li>
<li>Comics List</li>
<li>Characters</li>
<li>Animepedia</li>
</ul>
</form>
</div>

CSS

/*
@credit: http://www.dte.web.id, https://plus.google.com/108949996304093815163/about
font-family: Segoe,"Segoe UI",Arial,Sans-Serif
font-size: 12px
line-height: 30px
border-color: #8E8E74, black
color: #333, #666, black
background-color: white, #FFEAD3, #EDD8BF, #E0CBB2
*/

/* outer */
.input-text-wrap {
text-align:left;
display:inline-block;
background-color:white;
border:1px solid #8E8E74;
height:30px;
position:relative;
font:normal normal 12px/30px Segoe,"Segoe UI",Arial,Sans-Serif;
color:#333;
-webkit-box-shadow:inset 0 1px 2px -1px rgba(0,0,0,.4);
-moz-box-shadow:inset 0 1px 2px -1px rgba(0,0,0,.4);
box-shadow:inset 0 1px 2px -1px rgba(0,0,0,.4);
}

/* focused `.input-text-wrap` */
.input-text-wrap.focused {
-webkit-box-shadow:inset 0 1px 2px -1px rgba(0,0,0,.7);
-moz-box-shadow:inset 0 1px 2px -1px rgba(0,0,0,.7);
box-shadow:inset 0 1px 2px -1px rgba(0,0,0,.7);
border-color:black;
}

/* resets or netralize all element inside */
.input-text-wrap input,
.input-text-wrap form,
.input-text-wrap ul,
.input-text-wrap li {
margin:0 0;
padding:0 0;
list-style:none;
border:none;
background:none;
font:inherit;
color:inherit;
vertical-align:top;
}

.input-text-wrap input {display:inline-block}

.input-text-wrap .text-input,
.input-text-wrap .submit-button {
height:30px;
line-height:30px;
font-weight:bold;
margin:0 20px 0 5px;
outline:none;
}

/* the text input */
.input-text-wrap .text-input {
width:160px; /* set the text input width here */
}

/* the submit button */
.input-text-wrap .submit-button {
width:70px;
padding:0 0 2px;
margin:0 0;
background-color:#FFEAD3;
border-left:1px solid #8E8E74;
color:#666;
cursor:pointer;
-webkit-box-shadow:0 0 2px rgba(0,0,0,.4);
-moz-box-shadow:0 0 2px rgba(0,0,0,.4);
box-shadow:0 0 2px rgba(0,0,0,.4);
position:relative;
}

.input-text-wrap .submit-button:hover {
background-color:#EDD8BF;
color:black;
}

/* the drop-down menu */
.input-text-wrap ul {
position:absolute;
top:100%;
right:-1px;
left:-1px;
z-index:99;
background-color:white;
border:1px solid black;
-webkit-box-shadow:0 1px 2px rgba(0,0,0,.4);
-moz-box-shadow:0 1px 2px rgba(0,0,0,.4);
box-shadow:0 1px 2px rgba(0,0,0,.4);
display:none;
}

/* drop-down menu item */
.input-text-wrap li {
line-height:26px;
padding:0 10px;
cursor:pointer;
}

.input-text-wrap li:hover {
background-color:#E0CBB2;
color:black;
}

/* the down arrow before the submit button */
.input-text-wrap .down-arrow {
display:block;
width:20px;
height:30px;
position:absolute;
top:0;
right:70px;
cursor:pointer;
}

.input-text-wrap .down-arrow:hover,
.input-text-wrap .down-arrow.active {
background-color:white;
-webkit-box-shadow:-1px 1px 2px rgba(0,0,0,.4);
-moz-box-shadow:-1px 1px 2px rgba(0,0,0,.4);
box-shadow:-1px 1px 2px rgba(0,0,0,.4);
z-index:2;
}

.input-text-wrap .down-arrow:active,
.input-text-wrap .down-arrow.active {
-webkit-box-shadow:-1px 1px 1px rgba(0,0,0,.2);
-moz-box-shadow:-1px 1px 1px rgba(0,0,0,.2);
box-shadow:-1px 1px 1px rgba(0,0,0,.2);
}

/* create the down-arrow triangle with pseudo-element and border hack */
.input-text-wrap .down-arrow:before {
content:"";
display:block;
width:0;
height:0;
border:4px solid transparent;
border-top-color:#666;
position:absolute;
top:14px;
left:50%;
margin-left:-4px;
}

JQuery

(function($) {

var $inputWrap = $('.input-text-wrap'),
$arrow = $inputWrap.find('.down-arrow');

// Hide the dropdown menu when user click outside the `.input-text-wrap`, anywhere...
$(document).on("click", function() {
$inputWrap.find('ul').hide();
$arrow.removeClass('active');
});

$arrow.on("click", function(e) {

// Remove all the `focused` class and hide all visible drop-down menu
$inputWrap.removeClass('focused').find('ul:visible').hide();
// Remove al the `active` down arrow
$arrow.removeClass('active');

// Toggle the `.down-arrow` active class
$(this).toggleClass('active')
// Add a `focused` class to the `.input-text-wrap`
.closest('.input-text-wrap').addClass('focused')
// Show or hide the dropdown `ul`
.find('ul').toggle()
// When we click the `li`...
.find('li').on("click", function() {
// Set the input text value to the clicked `li`'s text
$(this).closest('.input-text-wrap').find('.text-input').val($(this).text())
// and trigger the focus event to it
.trigger("focus");
// After that, hide the visible dropdown menu
$(this).parent().hide();
});

// Prevent event bubbling!
e.stopPropagation();

});

// When the text input focused...
$inputWrap.find('.text-input').on("focus", function() {
// Add a `focused` class to the `.input-text-wrap`
$(this).closest('.input-text-wrap').addClass('focused');
// When the text input loses the focus...
}).on("blur", function(e) {
// Remove the `focused` class from `.input-text-wrap`
$(this).closest('.input-text-wrap').removeClass('focused');
});

})(jQuery);

Demo

Senin, 28 Januari 2013

CSS3 Google Chrome Minimalis

Google Chrome
CSS3 Google Chrome

Peramban Google Chrome minimalis yang terbuat dari CSS3:

HTML

<div class="chrome-window">
<h1>Window Title</h1>
<div class="right-buttons">
<a title="Minimize" class="minimize-btn" href="#minimize">Minimize</a>
<a title="Maximize" class="maximize-btn" href="#maximize">Maximize</a>
<a title="Close" class="close-btn" href="#close">Close</a>
</div>
<div class="window-header">
<input type="text" onfocus="this.select();" spellcheck="false" value="chrome://chrome">
</div>
<div class="window-inner">
Contents...
</div>
</div>

CSS

/* Window */
.chrome-window {
background-color:#3B68B5;
background-image:-webkit-linear-gradient(#5F91DC 0%,#3B68B5 25px,#3B68B5 100%);
background-image:-moz-linear-gradient(#5F91DC 0%,#3B68B5 25px,#3B68B5 100%);
background-image:-ms-linear-gradient(#5F91DC 0%,#3B68B5 25px,#3B68B5 100%);
background-image:-o-linear-gradient(#5F91DC 0%,#3B68B5 25px,#3B68B5 100%);
background-image:linear-gradient(#5F91DC 0%,#3B68B5 25px,#3B68B5 100%);
width:600px;
border:1px solid;
border-color:#595959 #444 #444 #494949;
-webkit-border-radius:3px;
-moz-border-radius:3px;
border-radius:3px;
-webkit-box-shadow:inset 0 0 0 1px rgba(255,255,255,.1);
-moz-box-shadow:inset 0 0 0 1px rgba(255,255,255,.1);
box-shadow:inset 0 0 0 1px rgba(255,255,255,.1);
position:absolute;
top:50%;
left:50%;
margin-left:-300px;
margin-top:-150px;
overflow:hidden;
font:normal normal 12px Segoe,"Segoe UI",Arial,Sans-Serif;
color:#222;
z-index:999;
}

/* Window title */
.chrome-window h1 {
font:inherit;
font-weight:bold;
color:white;
margin:0 0;
padding:4px 0 4px 10px;
}

/* Window address bar */
.window-header {
margin:0 2px;
padding:1px 0;
border:1px solid #2E518C;
border-bottom-color:#AAAAAB;
background-color:white;
position:relative;
}

.window-header:before {
content:"";
display:block;
width:10px;
height:13px;
background-color:#eee;
border:1px solid #949495;
border-bottom-color:#838384;
-webkit-box-shadow:inset 0 0 0 1px white,0 1px 2px #ccc;
-moz-box-shadow:inset 0 0 0 1px white,0 1px 2px #ccc;
box-shadow:inset 0 0 0 1px white,0 1px 2px #ccc;
position:absolute;
top:6px;
left:8px;
}

.window-header input {
width:592px;
display:block;
margin:0 auto;
padding:4px 4px 5px 24px;
font:inherit;
color:inherit;
border:1px solid #B4BCC7;
outline:none;
background-color:white;
-webkit-box-sizing:border-box;
-moz-box-sizing:border-box;
box-sizing:border-box;
}

/* Window body */
.window-inner {
height:200px;
border:1px solid #2E518C;
border-top:none;
margin:0 2px 2px;
background-color:white;
-webkit-box-shadow:inset 0 0 0 1px #DFDFDF;
-moz-box-shadow:inset 0 0 0 1px #DFDFDF;
box-shadow:inset 0 0 0 1px #DFDFDF;
padding:4px;
word-wrap:break-word;
overflow:auto;
cursor:text;
}

/* Buttons */
.right-buttons {
position:absolute;
top:-1px;
right:4px;
font:0/0 a;
text-shadow:none;
}

.right-buttons a {
display:block;
float:left;
margin:0 0 0 -1px;
width:26px;
height:16px;
border:1px solid #345181;
-webkit-box-shadow:inset 1px 1px 0 rgba(255,255,255,.2);
-moz-box-shadow:inset 1px 1px 0 rgba(255,255,255,.2);
box-shadow:inset 1px 1px 0 rgba(255,255,255,.2);
text-decoration:none;
position:relative;
cursor:default;
-webkit-transition:all .2s ease-out;
-moz-transition:all .2s ease-out;
-ms-transition:all .2s ease-out;
-o-transition:all .2s ease-out;
transition:all .2s ease-out;
}

.right-buttons a:after {
content:"";
display:block;
position:absolute;
}

.right-buttons .minimize-btn {
-webkit-border-radius:0 0 0 3px;
-moz-border-radius:0 0 0 3px;
border-radius:0 0 0 3px;
}

.right-buttons .minimize-btn:after {
right:7px;
bottom:4px;
left:7px;
height:3px;
background-color:#BCCFEF;
border:1px solid #233656;
-webkit-border-radius:2px;
-moz-border-radius:2px;
border-radius:2px;
}

.right-buttons .maximize-btn:after {
top:4px;
right:8px;
bottom:4px;
left:8px;
border:2px solid #BCCFEF;
-webkit-box-shadow:0 0 0 1px #233656,inset 0 0 0 1px #233656;
-moz-box-shadow:0 0 0 1px #233656,inset 0 0 0 1px #233656;
box-shadow:0 0 0 1px #233656,inset 0 0 0 1px #233656;
-webkit-border-radius:1px;
-moz-border-radius:1px;
border-radius:1px;
}

.right-buttons .close-btn {
-webkit-border-radius:0 0 3px 0;
-moz-border-radius:0 0 3px 0;
border-radius:0 0 3px 0;
}

.right-buttons .close-btn {
width:42px;
}

.right-buttons .close-btn:after {
content:"x";
font:normal normal 14px/13px Verdana,Arial,Sans-Serif;
color:#BCCFEF;
text-shadow:0 1px #233656,1px 0 #233656,-1px 0 #233656,0 -1px #233656;
top:0;
right:0;
bottom:0;
left:0;
text-align:center;
}

.right-buttons a:hover {
background-color:#8BAEE4;
-webkit-box-shadow:inset 1px 1px 0 rgba(255,255,255,.4);
-moz-box-shadow:inset 1px 1px 0 rgba(255,255,255,.4);
box-shadow:inset 1px 1px 0 rgba(255,255,255,.4);

}

.right-buttons a.close-btn:hover {
background-color:#DA4D4B;
}

.right-buttons .minimize-btn:hover:after {background-color:white}
.right-buttons .maximize-btn:hover:after {border-color:white}
.right-buttons .close-btn:hover:after {color:white}