var NS = 'http://www.w3.org/2000/svg',
NSL = 'http://www.w3.org/1999/xlink',
elements = [
{
name: 'svg',
attr: {
'class': 'main'
},
children: [
{
name: 'symbol',
attr: {
id: 'square',
viewBox: '0 0 100 100'
},
children: [
{
name: 'rect',
attr: {
x: 0,
y: 0,
width: 100,
height: 100,
fill: 'rgba(51,102,204,1)'
}
}
]
},
{
name: 'symbol',
attr: {
id: 'circle',
viewBox: '0 0 100 100'
},
children: [
{
name: 'circle',
attr: {
cx: 50,
cy: 50,
r: 50,
fill: 'rgba(51,204,102,1)'
}
}
]
}
]
},
{
name: 'svg',
attr: {
'class': 'icon'
},
children: [
{
name: 'use',
attr: {
'xlink:href': '#square'
}
}
]
}
],
newElement = {
name: 'svg',
attr: {
'class': 'icon'
},
children: [
{
name: 'use',
attr: {
'xlink:href': '#circle'
}
}
]
};
function createSVG (elem) {
var svgElement = document.createElementNS(NS, elem.name);
if (elem.attr) {
Object.keys(elem.attr).forEach(function (value) {
if (value.indexOf('xlink') < 0) {
svgElement.setAttribute(value, elem.attr[value]);
} else {
svgElement.setAttributeNS(NSL, value, elem.attr[value]);
}
});
}
if (elem.children) {
elem.children.forEach(function (value) {
svgElement.appendChild(createSVG(value));
});
}
return svgElement;
}
elements.forEach(function (element) {
document.body.appendChild(createSVG(element));
});
document.body.appendChild(createSVG(newElement));
.main {
display: none;
}
.icon {
width: 100px;
height: 100px;
}
getUsers({
param1: $('#value1').val(),
param2: $('#value2').val(),
param3: $('#value3').val()
});
function getUsers (params) {
$.ajax({
url: 'obrabotka.php',
data: params,
dataType: 'json'
}).done(function (data) {
console.log('success', data);
}).fail(function (data) {
console.log('error', data);
});
}
user.friends[1].thelocation
var users = [{ "thelocation" : "москва", "":""},{ "thelocation" : "london", "":""}];
console.log(users[1].thelocation);
var object_1 = {
a: {
x: {
value: 3
}
}
},
object_2 = {
a: {
y: {
value: 7
}
}
};
console.log($.extend(true, object_1, object_2));
{
a: {
x: {
value: 3
},
y: {
value: 7
}
}
}
removeOne(17, [3, 5, 17, 8, 17, 34, 5]);
function removeOne (value, array) {
array.some(function (_value, index, _array) {
if (_value == 17) {
_array.splice(index, 1);
return true;
}
}, array);
console.log(array);
}
removeAll(17, [3, 5, 17, 8, 17, 34, 5]);
function removeAll (value, array) {
array.forEach(function (_value, index, _array) {
if (_value == 17) {
_array.splice(index, 1);
}
}, array);
console.log(array);
}
makeUnique([3, 5, 17, 8, 17, 34, 5]);
function makeUnique (array) {
var newArray = [];
array.forEach(function (_value, index) {
if (newArray.indexOf(_value) < 0) {
newArray.push(_value);
}
});
array = newArray; // По необходимости
console.log(newArray);
}
<img id="myImage" src="/i/pic.png">
<canvas id="myCanvas"></canvas>
var myImage = document.getElementById('myImage'),
myCanvas = document.getElementById('myCanvas'),
context = myCanvas.getContext('2d');
if (!myImage.complete) {
myImage.addEventListener('load', function (e) {
done();
});
} else {
done();
}
function done () {
myCanvas.width = myImage.width;
myCanvas.height = myImage.height;
context.drawImage(myImage, 0, 0);
console.log(myCanvas.toDataURL());
}
$(function () {
var start = 0,
delta = 60,
duration = 600;
$('.rotateimg').rotate({
bind: {
click: function () {
$(this).rotate({
angle: start,
animateTo: start + delta,
duration: duration,
callback: function () {
start += delta;
}
});
}
}
});
});
$.ajax({
url: '//api.vk.com/method/database.getCountries',
data: {
need_all: 1,
count: 300
},
dataType: 'jsonp'
})
.done(function(data) {
console.log(data);
});
$.ajax({
url: 'http://api.flickr.com/services/feeds/photos_public.gne',
dataType: 'jsonp',
jsonp: 'jsoncallback',
data: {
tags: 'mount rainier',
tagmode: 'any',
format: 'json'
}
}).done(function (data) {
console.log(data);
});
$(function () {
$('img[data-src]').each(function () {
var image = $(this);
image.attr({
src: image.data('src')
}).removeAttr('data-src');
if (!image.get(0).complete) {
image.parent().addClass('loading');
image.bind('load', function () {
$(this).unbind('load').parent().removeClass('loading');
});
}
});
});
$(function () {
$('img[data-src]').each(function (index) {
var image = $(this),
src = image.data('src'),
_img = $('<img>', {
src: src
});
if (!_img.get(0).complete) {
image.parent().addClass('loading');
_img.bind('load', function () {
image
.attr({
src: src
})
.removeAttr('data-src')
.parent().removeClass('loading');
_img = null;
});
}
});
});
$(document).on('click', '.ui-datepicker .ui-state-default', function () {...});
document.addEventListener('click', function (e) {
var target = $(e.target).closest('.ui-state-default');
if (target.length) {
...
}
}, true);
$('#datepicker').datepicker({
onSelect: function () {
...
}
});