Skip to content

Instantly share code, notes, and snippets.

@roine
roine / jquery.revealit.js
Created July 4, 2012 07:12
auto add checkbox after input type password, checking it allow to see the content
var reveal = function(msgIn, msgOut){
msgIn = msgIn || "Reveal it!";
msgOut = msgOut || "Hide It!";
$("input[type=password]").each(function(){
var self = $(this);
$(this).after("<span id='revealctrl'></span>")
.next()
.append("<input type=checkbox id='revealCheckbox'>")
@roine
roine / index.html
Created July 6, 2012 05:32
shadow and light
<link href="http://fonts.googleapis.com/css?family=Squada+One" rel="stylesheet" type="text/css">
<script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<link href="style.css" rel="stylesheet" type="text/css">
<script src="script.js"></script>
<body>
<span id="pos">
</span>
<span id="text">
if(localStorage in window)
if(typeof localStorage.view == 'undefined') localStorage.view = 0
localStorage.view++;
maxView = 10;
if(maxView > localStorage.view){
// display a message 10 times
}
@roine
roine / gist:4115823
Created November 20, 2012 03:48
css transition callback in js
myElement.addEventListener("transitionend", function() {
alert('transition completed')
}, true);
@roine
roine / main.js
Created November 28, 2012 02:30
track the users history
(function(window){
// add ability to save an object
if(localStorage){
Storage.prototype.setObj = function (key, obj) {
return this.setItem(key, JSON.stringify(obj));
}
Storage.prototype.getObj = function(key) {
return JSON.parse(this.getItem(key));
@roine
roine / inheritance.js
Created November 28, 2012 10:17
inheritance javascript
// create an object a and clone it in b
var a = {
init:function(){return 'hello'}
}, b = Object.create(a);
// check the values
a.init(); // hello
b.init(); // hello
// set a new return value to init
class Author {
private $firstName;
private $lastName;
public function __construct($firstName, $lastName) {
$this->firstName = $firstName;
$this->lastName = $lastName;
}
public function getFirstName() {
return $this->firstName;
}
//compare two distinct array
// check for length and value at each index
function equalArrays(a,b) {
if (a.length != b.length) return false;
for(var i = 0; i < a.length; i++)
if (a[i] !== b[i]) return false;
return true;
}
@roine
roine / oop.js
Created December 10, 2012 08:57
var MyClass = function(options) {
/* create a private variable */
privateOpt = options;
/* create a public variable*/
this.opt = options;
/* to access this variable into the method */
var that = this;
false == false // true
0 == false // true
-0 == false // true
'' == false //true
// converting to a Number will return 0
// exemple: