Skip to content

Instantly share code, notes, and snippets.

@kalinchernev
kalinchernev / passwordValidator.js
Last active August 29, 2015 13:58
JavaScript password validator
/**
* Validates if the input for password field matches requirements for password strength
* @returns {void}
*/
function validatePassword() {
var inputValue;
var requirement = new RegExp("(^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[@#$%*]).{8,}$)");
// clear previous
jQuery(".reg-validate-message").remove();
@kalinchernev
kalinchernev / emailValidator.js
Created April 10, 2014 14:31
Email validators for javascript
/**
* Validates if the input for email field matches requirements and if it's a valid email
* @returns {void}
*/
function validateEmail() {
var inputValue;
// clear previous
jQuery(".reg-validate-email").remove();
@kalinchernev
kalinchernev / breadcrumb.php
Created April 15, 2014 13:35
Drupal helper to display the breadcrumbs - decoupled from the theme
<?php
/**
* Helper to display the breadcrumbs
* @return string Breadcrumbs markup
*/
function _display_breadcrubs() {
$breadcrumbs = drupal_get_breadcrumb();
return theme('breadcrumb', array('breadcrumb' => $breadcrumbs));
}
@kalinchernev
kalinchernev / index.html
Created June 5, 2014 14:01
Example user information bar, which re-sizes in width depending on the length of the user's name.
<!DOCTYPE html>
<!--[if lt IE 7 ]> <html dir="ltr" lang="en-US" class="no-js ie6"> <![endif]-->
<!--[if IE 7 ]> <html dir="ltr" lang="en-US" class="no-js ie7"> <![endif]-->
<!--[if IE 8 ]> <html dir="ltr" lang="en-US" class="no-js ie8"> <![endif]-->
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=9; IE=8; IE=7" />
<title>Resizable user info bar</title>
<style type="text/css">
@kalinchernev
kalinchernev / children.css
Created June 11, 2014 11:32
Selecting children elements in IE
/* equivalent to li:nth-child(1) */
#mainNav ul li:first-child a {
background: #1b77af;
width: 236px;
text-align: center;
margin-right: 10px;
}
/* equivalent to li:nth-child(2) */
#mainNav ul li:first-child + li a {
background: #33a0ff;
@kalinchernev
kalinchernev / search.html
Created July 21, 2014 13:23
Search form
<?php
/*
* Available variables
* $query array current query from the URL
*/
?>
<?php // dpm($query); ?>
<div id="search-products">
<h2><?php echo t("Rechercher un produit");?></h2>
<form method="GET" id="search-form" action="catalog-search">
@kalinchernev
kalinchernev / image_error.js
Created October 21, 2014 11:54
replacing broken images with existing image
$(document).ready(function(){
$('img').error(function(){
$(this).attr('src', 'http://mysite/myimage.jpg');
});
});
@kalinchernev
kalinchernev / font-resizor.js
Created October 23, 2014 12:13
Resizor of font-size in a given div container
var zoomText = function (change) {
var fontSize, fonts, container;
container = $("#block-system-main");
fontSize = Math.floor(parseFloat(container.css('font-size')) / 16);
fonts = ["1em", "1.2em", "1.4em"];
if (change === -1 & fontSize > 0) {
fontSize--;
}
@kalinchernev
kalinchernev / angular-time.html
Created November 13, 2014 11:10
Angular clock
<!doctype html>
<html ng-app="Time">
<head>
<title>Time</title>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.2/angular.min.js"></script>
</head>
<body>
<div ng-controller="MyController">
<h1>{{ clock | date : 'medium' }}</h1>
</div>
@kalinchernev
kalinchernev / domain-replace.js
Created November 19, 2014 10:10
Function to replace development and production urls
// development is a string containing the domain base of the dev site
// production is a string containing the domain base of the production site
function replaceDomains(development,production){
var links = jQuery("a");
for (var i = 0; i < links.length; i++) {
var href = jQuery(links[i]).attr("href");
if ((href !== undefined) && (href.indexOf(production) > -1)) {
href = href.replace(production, development);
jQuery(links[i]).attr("href", href);
}