Skip to content

Instantly share code, notes, and snippets.

@handleman
handleman / jquery.inlineStyle.js
Last active August 29, 2015 14:04
very simple (probably in much need of improvement) Jquery plugin I've thrown together that will get you the value of an inline style property
(function ($) {
$.fn.inlineStyle = function (prop) {
var styles = this.attr("style"),
value;
styles && styles.split(";").forEach(function (e) {
var style = e.split(":");
if ($.trim(style[0]) === prop) {
value = style[1];
}
});
@handleman
handleman / module.js
Last active August 29, 2015 14:05
Typical module definition
var MYAPP = MYAPP || {}; //isolated namespace
//общий для всех страниц модуль Функционал общий для всех страниц
MYAPP.mainPage = (function() {
// variables
var that = {};
that.settings = {}; //свойства по умолчанию
//dependences
var common = MYAPP.common;
//private
HLP.whatBrowser({'browser name [browser version]':'string to return by function', ...});
HLP.whatDevice.iOS(); // returns true on iOS Devices
HLP.whatDevice.Android(); // returns true on Android Devices
HLP.whatDevice.BlackBerry(); // returns true on BlackBerry Devices
HLP.whatDevice.Opera(); // returns true on any Devices with Opera Mini or Opera Mobile browser
HLP.whatDevice.Windows(); // returns true on Devices with IE Mobile browser
HLP.whatDevice.any(); // returns true on any mobile device
var inlineStyleElement = document.querySelector("#inlineStyleExample"),
inlineOutputElement = document.querySelector("#resultInline");
inlineOutputElement.innerHTML = HLP.inlineStyle(inlineStyleElement, 'color');
@handleman
handleman / reloadiframe.js
Created September 3, 2014 13:38
How to reload iFrame using jQuery
//reload 1 iframe
$('#iframe')[0].contentWindow.location.reload(true);
//reload all iFrames
$('iframe').each(function() {
this.contentWindow.location.reload(true);
});
//Another way to reload all iFrames
$('iframe').attr('src', $('iframe').attr('src'));
@handleman
handleman / box-shadow.css
Created September 24, 2014 11:31
1) Пример красивой тени под блоком. Тень в меру размашистая, идеально полупрозрачная 2) Пример тени для текста.
-webkit-box-shadow: 0 1px 3px rgba(0, 0, 0, .4);
-moz-box-shadow: 0 1px 3px rgba(0, 0, 0, .4);
-ms-box-shadow: 0 1px 3px rgba(0, 0, 0, .4);
-o-box-shadow: 0 1px 3px rgba(0, 0, 0, .4);
box-shadow: 0 1px 3px rgba(0, 0, 0, .4);
@handleman
handleman / sprite.less
Created September 27, 2014 19:34
LESS mixin for genering sprites
.sprite(@x:0, @y:0){
background: url(../images/sprites.png) @x @y no-repeat;
}
@handleman
handleman / images.less
Created September 27, 2014 19:36
LESS mixin to easily generate background-image CSS property
.png(@name, @x:0, @y:0, @repeat:no-repeat){
background: url('../images/@{name}.png') @x @y @repeat;
}
.jpg(@name, @x:0, @y:0, @repeat:no-repeat){
background: url('../images/@{name}.jpg') @x @y @repeat;
}
@handleman
handleman / removeProperty.js
Created September 29, 2014 15:22
Rename property of an objec You could wrap the work in a function and assign it to the Object prototype. Maybe use the fluent interface style to make multiple renames flow.
Object.prototype.renameProperty = function (oldName, newName) {
// Check for the old property name to avoid a ReferenceError in strict mode.
if (this.hasOwnProperty(oldName)) {
this[newName] = this[oldName];
delete this[oldName];
}
return this;
};