Skip to content

Instantly share code, notes, and snippets.

var whenReady = function (name, context) {
context = context || window;
var def = Deferred(), _value;
Object.defineProperty(context, name, {
configurable: true,
get: function () {
return _value;
},
set: function (value) {
_value = value;
var frame = document.createElement('iframe');
document.body.appendChild(frame);
for(var item in window) {
if(frame.contentWindow[item] === undefined){
console.log(item, window[item])
}
}
var getTemplate = (function (html) {
var templates = {};
//<([A-Z]\w+)[^>]*>([\s\S]*?)<\/([A-Z]\w+)[^>]*>
html.replace(/<template\s+data-template-name="(.+)"\s*>([\s\S]*?)<\/template>/g, function (str, name, value) {
templates[name] = value.replace(/([>{])\s+|\s+([<}])/g, '$1$2').replace(/\s+/g, ' ');
});
return function (name, data) {
var template = templates[name];
if (data) {
template = template.replace(/{{([^{}]+)}}/gm, function (match, p1) {
(function presetCss(){
var preloadImages = function (context) {
var arrImg = context.match(/service.maxymiser.net\/cm\/images-[^\/]+([^)'"\\]+)/g) || [];
for (var i = 0; i < arrImg.length; i++) {
new Image().src = "//" + arrImg[i];
}
};
var campaignStyles = campaign.getStyles().join(' ');
if(campaignStyles) {
var $ACTION = function (eventName) {
var SESSION_EVENT_NAME = 'MM_' + eventName;
var catchEvent = function (fn) {
var sessionEventValue = window.sessionStorage[SESSION_EVENT_NAME];
if (typeof fn == 'function' && sessionEventValue) {
fn(sessionEventValue)
}
delete window.sessionStorage[SESSION_EVENT_NAME];
};
@ScalableJS
ScalableJS / Deferred.js
Last active December 12, 2015 10:49
The class Deferrer can register multiple callbacks into a callback queues, invoke callback queues, and relay the success or failure state of any synchronous or asynchronous function.
/*
The class Deferrer can register multiple callbacks into a callback queues,
invoke callback queues, and relay the success or failure state of any synchronous or asynchronous function.
*/
function Deferred() {
var
eventManager = EventManager({once: true,memory: true}),
stateValue = 'pending';
//Interface: presupposes that you can implement basic interface, and extended.
function Promise() {
var mm = {
type:(function () {
var class2type = {};
var arr = "Boolean Number String Function Array Date RegExp Object".split(" ");
for (var n = 0; n < arr.length; n++) {
class2type[ "[object " + arr[n] + "]" ] = arr[n].toLowerCase();
}
return function (obj) {
return obj == null ?
String(obj) :
/**
* Possible options:
*
* once: will ensure the callback list can only be fired once in the triggered event.
*
*
* memory: will keep track of previous values and will call any callback functions added
* after the list has been fired right away with the latest 'memorized' values
* @param options {{once:boolean, memory: boolean}|undefined}
* @constructor
/**
* Класс для работы с приватными переменными
* @param data {Object|undefined} необязательный параметр
* @constructor
*/
var PrivateValue = function (data) {
/**
* Установка переменных ключ значение или селектор значение
* @param name {String}
* @param val {*}
@ScalableJS
ScalableJS / gist:2895568
Created June 8, 2012 13:19
structGenInfo
//Создание списка компаний с масивами максибоксов
mmcore.structGenInfo = {};
mmcore._AddRenderer = decorate(mmcore._AddRenderer, function (mb, fn) {
var gi = mmcore.GenInfo, ngi = this.newGenInfo;
for (var com in gi) {
ngi[com] = ngi[com] || [];
if (gi[com][mb.toLowerCase()]) {
ngi[com].push(mb);
}
}