// Определяем спец. событие `rightclick`
$.event.special.rightclick = {
bindType: "mousedown",
delegateType: "mousedown",
handle: function (evt) {
if (evt.button === 2) {
var handleObj = evt.handleObj;
$(document).one('contextmenu', false);
evt.type = handleObj.origType;
ret = handleObj.handler.apply(this, arguments);
evt.type = handleObj.type;
return ret;
}
}
};
// Пример использования
$('.right').on({
'rightclick': function () {
$(this).addClass('pressed');
},
'mouseup': function () {
$(this).removeClass('pressed');
}
});
function doIt(url) {
return $.post(url).then(function (res) {
var result = '';
var queue = $('table tr', res).map(function () {
var url = $(this).find('a').prop('href');
return $.get(url, function (res) {
result += $('#block', res).text();
});
});
return $.when.apply($, queue).then(function () {
return result;
});
});
}
// Используем
doIt('/x').then(function (result) {
alert(result);
});
{
block: "information",
content: [{
elem: "section",
content: [{
block: "phone",
content: [{
elem: "number",
content: "8 (831) 280-96-51"
}, {
elem: "schedule",
content: "Пн-Пт: 9:00-18:00"
}]
}, {
block: "phone",
content: [{
elem: "number",
content: "8 (800) 555-18-38"
}, {
elem: "details",
content: "Звонок по России бесплатный"
}]
}]
}, {
elem: "section",
content: [{
block: "city",
content: [{
elem: "name",
content: "Нижний Новгород"
}, {
elem: "details",
content: "Доставка по городу и области бесплатная"
}]
}]
}]
}
function showHideBlocks(val) {
var values = {'businesscards': 1, 'fotoprint': 2, 'blank': 3};
for (var id in values) {
var el = document.getElementById(id);
el && (el.style.display = values[id] == val ? 'block' : 'none');
}
}
$('#calculationTypeProduct').change(function () {
var val = this.value;
$.each({'businesscards': 1, 'fotoprint': 2, 'blank': 3}, function (id, n) {
$('#' + id).toggle(val == n);
});
});
var f = function () {
if (true) {
f = function() {
return a;
};
} else {
f = function() {
return b;
};
}
};
FileAPI.newImage("path/to", function (err, img) {
FileAPI.Image(img).preview(100, 100).get(function (err, image) { /* ... */ });
})
var cloneObj = JSON.parse(JSON.stringify(obj));