Skip to content

Instantly share code, notes, and snippets.

@epoberezkin
epoberezkin / Placeholders for IE
Created March 16, 2013 11:21
Placeholders for IE without touching the field content
All placeholders plugins I could find were inserting placeholder in the field itself.
This approach has many disadvantages.
1. If your JavaScript code throws an exception you are stuck with the wrong field content that can be submitted.
2. Few of these plugins work for password fields, and those that do are quite complex.
3. You can't style placeholder created this way differently from the field content.
So I created placeholders that are additional elements that places themselves on top of the fields and show/hide depending on whether the filed is empty.
Placeholder element created with this function is span.placeholder, it should be added to the list of CSS rules used to style placeholders.
@epoberezkin
epoberezkin / Resizing elements backgrounds with jQuery
Last active December 14, 2015 10:18
Resizing elements backgrounds with jQuery is simple!
Why use plugin in a separate file for something that takes less than 20 lines of code?
@epoberezkin
epoberezkin / Shared javascript module template
Last active February 11, 2024 22:55
Javascript module template to share code between Node (CommonJS) and browser with requirejs (AMD).
All modules templates I've seen were not suited for code sharing
between client/server in case the module has dependencies.
This template will only work on server-side if module's dependencies
are in node_modules (installed with npm) on server side and are
available without any path in require.
In case the dependencies are part of the application, their paths
will be different in nodejs and in browser,
so some adaptation will be required to use correct dependencies paths.
@epoberezkin
epoberezkin / Popups without Javascript
Last active October 25, 2022 09:27
Popup windows without Twitter bootstrap or Javascript
It's easy to make popup windows without Twitter bootstrap or Javascript.
Example below uses :target pseudoclass to do it.
It adds one extra <a> tag to HTML, used as anchor (see comments in HTML file).
And it adds just 2 lines of CSS to show popup and its background.
You can have as many popups as you need - they will all work.
@jlong
jlong / uri.js
Created April 20, 2012 13:29
URI Parsing with Javascript
var parser = document.createElement('a');
parser.href = "http://example.com:3000/pathname/?search=test#hash";
parser.protocol; // => "http:"
parser.hostname; // => "example.com"
parser.port; // => "3000"
parser.pathname; // => "/pathname/"
parser.search; // => "?search=test"
parser.hash; // => "#hash"
parser.host; // => "example.com:3000"
//
// Regular Expression for URL validation
//
// Author: Diego Perini
// Created: 2010/12/05
// Updated: 2018/09/12
// License: MIT
//
// Copyright (c) 2010-2018 Diego Perini (http://www.iport.it)
//