Skip to content

Instantly share code, notes, and snippets.

View SergeyNarozhny's full-sized avatar

SergeyNarozhny

  • Saint-Petersburg, Russia
View GitHub Profile
function NewProto() {};
NewProto.prototype = {
pull: function(data) {
return $.ajax("ajax.php", {
data: data,
type: "POST",
context: this.el,
});
},
fill: function(params) {
// var items = <?=CUtil::PhpToJSObject($arResult["ITEMS"])?>;
function Parser(formname) {
this.formname = formname;
this.init = function() {
var instarr = $("#"+this.formname).serializeArray();
var base = {};
for (var i in instarr) {
base[instarr[i].name] = instarr[i].value;
}
this.base = base;
$.fn.decide = function(options){
this.each(function(){
var settings = $.extend({str: "default"}, options);
var decision = $(this);
var getdata = $.ajax(decision.attr('href'), {
type: 'POST', dataType: 'json', data: decision.data('params')
});
decision.on('click', function(e){
e.preventDefault();
getdata.done(function(result){
<?
if (CModule::IncludeModule("iblock") && CModule::IncludeModule("catalog")){
$arParams["IBLOCK_ID"] = IntVal(2);
$arResult = Array();
$prices = CIBlockPriceTools::GetCatalogPrices($arParams["IBLOCK_ID"], Array(0=>"BASE"));
$arrk = array_keys($prices);
$res = CIBlockElement::GetList(Array("SORT"=>"ASC"), Array("IBLOCK_TYPE"=>"catalog", "IBLOCK_ID"=>$arParams["IBLOCK_ID"], "ACTIVE"=>"Y", "GLOBAL_ACTIVE" => "Y"), false, false, Array("ID", "NAME", "IBLOCK_ID", "IBLOCK_SECTION_ID", "XML_ID", "CATALOG_GROUP_".$prices[$arrk[0]]["ID"]));
while ($ob = $res->GetNextElement()) {
$arFields = $ob->GetFields();
$arResult["ITEMS"][] = Array($arFields["XML_ID"], $arFields["CATALOG_PRICE_".$prices[$arrk[0]]["ID"]]);
@SergeyNarozhny
SergeyNarozhny / ajax_scroll.js
Last active August 29, 2015 14:08
Bitrix ajax on scroll ymaps loader (template.php)
var stp = "<?=SITE_TEMPLATE_PATH?>",
ids = [],
globalStop = false;
function collectId(){
while(ids.length) { ids.pop(); }
$("ul.contacts-list").children("li").each(function(){
ids.push($(this).attr("data-id"));
});
return true;
@SergeyNarozhny
SergeyNarozhny / ymaps.js
Last active August 29, 2015 14:08
Yandex map popup with required load (by modules)
var map = $("#map_wrapper"), editorParams = {
wayPointFinishDraggable: false,
addWayPoints: false,
editorDrawOver: false,
wayPointFinishIconLayout: "default#image",
wayPointFinishIconImageHref: '/new/include/img/footer-map-point.png',
wayPointFinishIconImageSize: [171, 48],
wayPointFinishIconImageOffset: [-55, -48],
};
@SergeyNarozhny
SergeyNarozhny / throttle.js
Created July 21, 2015 13:09
Throttle native js realization
function throttle(method, context)
{
clearTimeout(method.tId);
method.tId = setTimeout(function(){
method.call(context);
}, 100);
}
//usage example
window.onresize = function()
@SergeyNarozhny
SergeyNarozhny / eh.js
Created July 21, 2015 13:28
AngularJS $exceptionHandler decorator
app.config(function($provide){
$provide.decorator("$exceptionHandler", ["$delegate", function($delegate){
return function(exception, cause)
{
exception.message = "Some exception message";
$delegate(exception, cause); //call out basic implementation
alert(exception.message); //our custom alert
}
}]);
});
@SergeyNarozhny
SergeyNarozhny / app_logger.js
Last active August 29, 2015 14:25
NodeJS simple middleware logger
#logger.js
module.exports = function(request, response, next)
{
var start = +new Date(),
stream = process.stdout,
url = request.url,
method = request.method;
response.on("finish", function(){
var duration = +new Date() - start,
@SergeyNarozhny
SergeyNarozhny / events_subscription.js
Created July 21, 2015 14:16
Simple event subscription pattern in NodeJS
var events = require('events'),
net = require('net'),
channel = new events.EventEmitter();
channel.clients = {};
channel.subscriptions = {};
// Add listener on join event
// we save client user object and send
channel.on('join', function(id, client) {