Вход Регистрация
Файл: static/plugins/base/js/console.js
Строк: 714
<?php
PEEP_DataModel 
= function( data )
{
    
this.data data || {};
    
this.observers = [];
};

PEEP_DataModel.PROTO = function()
{
    var 
isEqual = function( x)
    {
        if ( 
=== ) return true;
        if ( ! ( 
instanceof Object ) || ! ( instanceof Object ) ) return false;
        if ( 
x.constructor !== y.constructor ) return false;

        for ( var 
p in x )
        {
            if ( ! 
x.hasOwnProperty) ) continue;
            if ( ! 
y.hasOwnProperty) ) return false;
            if ( 
x] === y] ) continue;
            if ( 
typeofx] ) !== "object" ) return false;
            if ( !
isEqualx],  y] ) ) return false;
        }

        for ( 
p in y )
        {
            if ( 
y.hasOwnProperty) && ! x.hasOwnProperty) ) return false;
        }

        return 
true;
    };

    
this.get = function( key )
    {
        if ( !
key )
        {
            return 
this.data;
        }

        var 
dataBranch this.datadataPathout null;

        
dataPath key.split('.');

        for ( var 
0dataPath.lengthi++ )
        {
            if ( 
dataPath[iin dataBranch )
            {
                
out dataBranch[dataPath[i]];
                
dataBranch dataBranch[dataPath[i]];
            }
        }

        return 
out;
    };

    
this.set = function( keyvaluenotifyObservers )
    {
        var 
self this;
        var 
notify notifyObservers || true;
        var 
changed false;

        if ( 
value === undefined && key )
        {
            
changed changed || !isEqual(this.datakey);
            
this.data key;
        }
        else
        {
            var 
0dataBranch this.datadataPath;

            
dataPath key key.split('.') : [];

            for ( 
0dataPath.length 1i++ )
            {
                if ( !$.
isPlainObject(dataBranch[dataPath[i]]) )
                {
                    
dataBranch[dataPath[i]] = {};
                }

                
dataBranch dataBranch[dataPath[i]];
            }

            
changed changed || !isEqual(dataBranch[dataPath[i]], value);
            
dataBranch[dataPath[i]] = value;
        }

        if ( 
notify && changed )
        {
            
window.setTimeout(function()
            {
                
self.notifyObservers();
            });
        }
    };

    
this.addObserver = function( observermethod )
    {
        
method method || 'onDataChange';

        var 
_observerself this;

        if ( $.
isFunction(observer) )
        {
            
_observer = function() {
                
observer.call(selfself);
            };
        }
        else
        {
            
_observer = function() {
                
observer[method].call(observerself);
            };
        }

        
this.observers.push(_observer);
    };

    
this.onChange = function(){};

    
this.notifyObservers = function()
    {
        
this.onChange(this);

        $.
each(this.observers, function(iobs)
        {
            
obs.call();
        });
    };
};

PEEP_DataModel.prototype = new PEEP_DataModel.PROTO();


PEEP_Console = function( paramsmodelsData )
{
    
modelsData modelsData || {};
    
params params || {};

    var 
self this;
    var 
_models = {};

    
this.items = {};

    
this.addItem = function( itemkey )
    {
        
key key || item.uniqId;
        
this.items[key] = item;
    };

    
this.getItem = function( key )
    {
        return 
this.items[key];
    };

    
this.getData = function( key )
    {
        
_models[key] = _models[key] || new PEEP_DataModel();

        return 
_models[key];
    };

    
this.hideOtherContents = function( item )
    {
        $.
each(this.items, function(io)
        {
            if ( 
item != )
            {
                
o.hideContent();
            }
        });
    };

    
this.hideAllContents = function()
    {
        $.
each(this.items, function(io)
        {
            
o.hideContent();
        });
    };

    $.
eachmodelsData, function (keydata)
    {
        
self.getData(key).set(data);
    });

    var 
command PEEP.getPing().addCommand('consoleUpdate',
    {
        
before: function()
        {
            var 
this;

            $.
each_models, function (keymodel)
            {
                
c.params[key] = model.get();
            });
        },
        
after: function( dataList )
        {
            $.
eachdataList, function (keydata)
            {
                
self.getData(key).set(data);
            });

        }
    });

    
window.setTimeout(function()
    {
        
command.start(params.pingInterval);
    }, 
params.pingInterval);
};










PEEP_ConsoleItem =
{
    
animatefalse,
    
openedfalse,

    
init: function( uniqIdcontentUniqId )
    {
        var 
self this;

        
this.uniqId uniqId;
        
this.contentUniqId contentUniqId;

        
this.$node = $('#' this.uniqId);
        
this.$contentNode = $('#' this.contentUniqId);
        
this._$tooltip this.$contentNode.find('.console_tooltip');

        
this.observers = [];
        
this.observers.notify = function(method)
        {
            for ( var 
0this.lengthi++ )
            {
                if ( 
this[i][method] )
                {
                    
this[i][method].call(this[i], self);
                }
            }
        };
    },

    
getKey: function()
    {
        return 
this.uniqId;
    },

    
showItem: function()
    {
        
this.$node.show();
    },

    
hideItem: function()
    {
        if ( 
this.opened )
        {
            
this.hideContent();
        }

        
this.$node.hide();
    },

    
showContent: function()
    {
        var 
self this;

        
PEEP.Console.hideOtherContents(this);

        if ( 
this.opened )
        {
            return;
        }

        
this.$contentNode.show();

        
this.animate true;
        
this._$tooltip.css({opacity0topthis.$node.height() - 12}).stop(truetrue).animate({topthis.$node.height(), opacity1}, 'fast', function()
        {
            
self.animate false;
            
PEEP.addScrolls(self.$contentNode);
            
self.observers.notify('afterShow');
        });

        
this.opened true;
        
this.observers.notify('beforeShow');


        
this.onShow();
        
this._onShow();
    },

    
hideContent: function()
    {
        var 
self this;

        if ( !
this.opened )
        {
            return;
        }

        
this.animate true;

        
this.observers.notify('beforeHide');
        
this._$tooltip.stop(truetrue).animate({topthis.$node.height() - 12opacity0}, 'fast', function()
        {
            
self.animate false;
            
self.observers.notify('afterHide');

            
self.onHide();
            
self._onHide();

            
self.$contentNode.hide();
        });

        
this.opened false;
    },

    
//TODO replace this with bind
    
onShow: function() {},
    
_onShow: function() {},
    
onHide: function() {},
    
_onHide: function() {},

    
addObserver: function( observer )
    {
        
this.observers.push(observer);
    }
};




PEEP_ConsoleDropdownHover = function( uniqIdcontentUniqId )
{
    
this.inituniqIdcontentUniqId );

    var 
self this;
    var 
hideTimeout;

    
this.$node.hover(function()
    {
        if (
self.animate)
        {
            return 
false;
        }

        if ( 
hideTimeout )
        {
            
window.clearTimeout(hideTimeout);
        }

        
self.showContent();
    },
    function()
    {
        
hideTimeout window.setTimeout(function()
        {
            
self.hideContent();
        }, 
300);
    });
}
PEEP_ConsoleDropdownHover.prototype PEEP_ConsoleItem;


PEEP_ConsoleDropdownClick = function( uniqIdcontentUniqId )
{
    
this.inituniqIdcontentUniqId );

    
this.initDropdown();
}
$.
extend(PEEP_ConsoleDropdownClick.prototypePEEP_ConsoleItem,
{
    
initDropdown: function()
    {
        var 
self this;

        
this.addObserver({
           
beforeShow: function()
           {
               
self.$node.addClass('peep_console_dropdown_pressed');
           },

           
beforeHide: function()
           {
               
self.$node.removeClass('peep_console_dropdown_pressed');
           }
        });

        $(
document).click(function( )
        {
            if ( !$(
e.target).is(':visible') )
            {
                return;
            }

            var 
isContent self.$contentNode.find(e.target).length;
            var 
isTarget self.$node.is(e.target) || self.$node.find(e.target).length;

            if ( 
isTarget && !isContent )
            {
                if ( 
self.opened )
                {
                    
self.hideContent();

                }
                else
                {
                    
self.showContent();

                }
            }
            else if ( !
isContent )
            {
                
self.hideContent();
            }
        });
    }
});




PEEP_ConsoleDropdownList = function( uniqIdcontentUniqId )
{
    
this.inituniqIdcontentUniqId );
    
this.initDropdown();

    var 
$counter = $('.PEEP_ConsoleItemCounter'this.$node),
        
$number $counter.find('.PEEP_ConsoleItemCounterNumber'),
        
$place $counter.find('.PEEP_ConsoleItemCounterPlace');

    var 
shown false,
        
currentNumber null;

    var 
numberSetActive = function( active )
    {
        
active active === false false true;
        
$placeactive 'addClass' 'removeClass' ]('peep_count_active');
    }

    var 
numberShow = function( numberanimate )
    {
        
animate animate === false false true;

        var 
placeHeight $place.height();

        
$number.text(number);
        
$number.css({visibility"visible"});
        
currentNumber number;

        var 
numberHeight $number.outerHeight();
        
$place.animate({heightnumberHeight}, 'fast');

        if ( 
animate )
        {
            
$number.css({top: -placeHeight}).animate({top0}, 'fast');
        }
    };

    var 
numberHide = function( callBack )
    {
        var 
placeHeight $place.height();

        
$number.animate({topplaceHeight}, 'fast'callBack);
    };

    var 
counterShow = function( callBack )
    {
        var 
placeHeight;

        
$counter.show();
        
placeHeight $place.height();
        
$place.css({height2}).animate({heightplaceHeight}, 'fast'callBack);

        
shown true;
    };
 var 
counterHide = function( callBack )
    {
        
numberHide(function()
        {
            
$place.animate({height0}, 'fast', function()
            {
                
$number.text(0);
                
$place.css({height'auto'});
                
$counter.hide();
                if ( $.
isFunction(callBack) ) callBack.apply($counter.get(0));
            });
        });

        
shown false;
    };

    

    
// Public Methods

    
this.setCounter = function( numberactive )
    {
        var 
intNumber parseInt(number);
        
intNumber isNaN(intNumber) ? intNumber;

        if ( 
intNumber <= )
        {
            
counterHide();

            return;
        }

        if ( !
shown )
        {
            
counterShow(function()
            {
                
numberShow(number);
                
numberSetActive(active);
            });
        }
        else if ( 
number == currentNumber )
        {
            
numberSetActive(active);
        }
        else
        {
            
numberHide(function()
            {
                
numberShow(number);
                
numberSetActive(active);
            });
        }
    };
}
PEEP_ConsoleDropdownList.prototype PEEP_ConsoleDropdownClick.prototype;



PEEP_ConsoleList =
{
    
construct: function( params )
    {
        var 
self this;

        
this.rsp params.rsp;
        
this.key params.key;
        
this.data PEEP.Console.getData(this.key);
        
this.item PEEP.Console.getItem(this.key);

        
this.$container = function() {
            return $(
'.PEEP_ConsoleListContainer'self.$contentNode);
        };

        
this.$list = function() {
            return $(
'.PEEP_ConsoleList'self.$container());
        };

        
this.$preloader = function() {
            return $(
'.PEEP_ConsoleListPreloader'self.$container());
        };

        
this.$noContent = function() {
            return $(
'.PEEP_ConsoleListNoContent'self.$container());
        };

        
this.isListFull false;
        
this.isListLoading false;
        
this.isListLoaded false;

        
this.item.onShow = function()
        {
            
this.loadList();
        };

        
this.item._onShow = function()
        {
            if ( 
this.isListLoaded )
            {
                
this.updateScroll(true);
            }
        };

        
this.item._onHide = function()
        {
            
PEEP.removeScroll(this.$container().get(0));
        };
    },

    
clearList: function()
    {
        
PEEP.removeScroll(this.$container().get(0));

        
this.$list().empty();
        
this.setIsListFull(false);
    },

    
loadList: function()
    {
        
this.clearList();
        
this.showPreloader();

        
this.isListLoaded false;

        
this._loadList();
    },

    
_loadList: function()
    {
        if ( 
this.isListLoading )
        {
            return;
        }

        var 
target this.key;
        var 
request JSON.stringify({
            
consolePEEP.Console.getData('console').get(),
            
datathis.data.get(),
            
targettarget,
            
offsetthis.getItemsCount(),
            
idsthis._getItemIds()
        });

        
this._ajaxStart();

        $.
ajax({
            
type'post',
            
urlthis.rsp,
            
contextthis,
            
dataType'json',
            
data: {
                
requestrequest
            
},
            
successthis._ajaxSuccess,
            
completethis._ajaxComplete
        
});
    },

    
getItemsCount: function()
    {
        return 
this.getItems().length;
    },

    
_getItemIds: function()
    {
        var 
ids = [];

        
this.getItems().each(function()
        {
            var 
id = $(this).data('id');
            if ( 
id )
            {
                
ids.push(id);
            }
        });

        return 
ids;
    },

    
getItems: function()
    {
        return 
this.$list().children();
    },

    
getItem: function( itemId )
    {
        return $(
'#' itemIdthis.$list());
    },

    
removeItem: function( item )
    {
        var 
itemObject = $.type(item) == 'object' item this.getItem(item);
        
itemObject.remove();

        if ( 
this.getItemsCount() == )
        {
            
this.showNoContent();
        }

        
this.updateScroll();
    },

    
addItems: function( itemsupdateScrooll )
    {
        var 
self this;

        $.
each(items, function(iitem)
        {
            var 
$item = $(item.html).data('id'item.id);

            
$item.find('.console_item_with_url').click(function( )
            {
                if ( !$(
e.target).is('a') )
                {
                    
//window.open($(this).data('url'));
                    
window.location.href = $(this).data('url');
                }
            });

            
self.$list().append($item);
            
PEEP.trigger('base.onAddConsoleItem', [], $item);
        });

        if ( 
updateScrooll !== false )
        {
            
this.updateScroll();
        }

    },

    
showPreloader: function()
    {
        
this.$preloader().css({'visibility''visible'});
        
this.$noContent().hide();
    },

    
hidePreloader: function()
    {
        
this.$preloader().css({'visibility''hidden'});
    },

    
showNoContent: function()
    {
        
this.$list().hide();
        
this.$preloader().hide();
        
this.$noContent().show();
    },

    
hideNoContent: function()
    {
        
this.$noContent().hide();
        
this.$list().show();
    },

    
updateScroll: function( toTop )
    {
        var 
self this;

        
toTop toTop || false;

        if ( 
this.opened )
        {
            var 
hasScroll false;
            if ( 
this.$container().data().jsp )
            {
                
hasScroll this.$container().data().jsp.getIsScrollableV();
            }
            else
            {
                
hasScroll this.$container().innerHeight() < this.$container().get(0).scrollHeight
            
}

            
PEEP.removeScroll(this.$container().get(0));

            if ( !
hasScroll )
            {
                
this.setIsListFull(true);

                return;
            }

            var 
jsp PEEP.addScroll(this.$container().get(0));

            if ( 
toTop )
            {
                
jsp.scrollToY(0false);
            }

            
this.$container().on('jsp-arrow-change', function( eventisAtTopisAtBottomisAtLeftisAtRight )
            {
                if ( 
self.isListFull )
                {
                    return;
                }

                if ( 
isAtBottom )
                {
                    
self.showPreloader();
                    
self._loadList();
                }
            });
        }
    },

    
setIsListFull: function( full )
    {
        
this.isListFull full;
        if ( 
full )
        {
            
this.$preloader().hide();
        }
        else
        {
            
this.$preloader().show();
        }
    },

    
_ajaxStart: function()
    {
        
this.isListLoading true;
    },

    
_ajaxComplete: function()
    {
        
this.isListLoading false;
        
this.hidePreloader();
    },

    
_ajaxSuccess: function( resp )
    {
        var 
self this;

        if ( 
resp.data )
        {
            
this.data.set(resp.data);
        }

        if ( 
resp.items.length )
        {
            
this.addItems(resp.itemsfalse);
        }
        else
        {
            
this.setIsListFull(true);
        }

        if( 
this.getItemsCount() == )
        {
            
this.showNoContent();
        }
        else
        {
            
this.hideNoContent();
        }

        if ( 
resp.markup )
        {
            if (
resp.markup.styleSheets)
            {
                $.
each(resp.markup.styleSheets, function(io)
                {
                    
PEEP.addCssFile(o);
                });
            }

            if (
resp.markup.styleDeclarations)
            {
                
PEEP.addCss(resp.markup.styleDeclarations);
            }

            if (
resp.markup.beforeIncludes)
            {
                
PEEP.addScript(resp.markup.beforeIncludes);
            }

            if (
resp.markup.scriptFiles)
            {
                
PEEP.addScriptFiles(resp.markup.scriptFiles, function()
                {
                    if (
resp.markup.onloadScript)
                    {
                        
PEEP.addScript(resp.markup.onloadScript);
                    }
                });
            }
            else
            {
                if (
resp.markup.onloadScript)
                {
                    
PEEP.addScript(markup.onloadScript);
                }
            }
        }

        var 
scrollToTop = !this.isListLoaded;

        
window.setTimeout(function() {
            
self.updateScroll(scrollToTop);
        });


        
this.isListLoaded true;
    }
};



PEEP_Invitation = function( itemKeyparams )
{
    var 
listLoaded false;

    var 
listLoaded false;
    var 
model, list, counter;

    
//public methods

    
this.removeItem = function( invitationKey )
    {
        var 
item = list.getItem(invitationKey);
        var 
= {};

        if ( 
item.hasClass('peep_console_new_message') )
        {
            
c["new"] = counter.get("new") - 1;
        }
        
c["all"] = counter.get("all") - 1;
        
counter.set(c);

        list.
removeItem(item);

        return 
this;
    };

    
this.send = function( commanddata )
    {
        var 
request = $.ajax({
            
urlparams.rsp,
            
type"POST",
            
data: {
                
"command"command,
                
"data"JSON.stringify(data)
            },
            
dataType"json"
        
});

        
request.done(function( res )
        {
            if ( 
res && res.script )
            {
                
PEEP.addScript(res.script);
            }
        });

        return 
this;
    };

    
//code

    
model PEEP.Console.getData(itemKey);
    list = 
PEEP.Console.getItem(itemKey);
    
counter = new PEEP_DataModel();

    
counter.addObserver(function()
    {
        var 
counterNumber 0,
        
newCount counter.get('new');
        
counterNumber newCount newCount counter.get('all');

        list.
setCounter(counterNumbernewCount 0);

        if ( 
counterNumber )
        {
            list.
showItem();
        }
    });

    
model.addObserver(function()
    {
        if ( !list.
opened )
        {
            
counter.set(model.get('counter'));
        }

        if ( 
model.get('listFull') )
        {
            list.
setIsListFull(true);
        }
    });

    list.
onHide = function()
    {
        list.
getItems().removeClass('peep_console_new_message');
        
counter.set('new'0);
        
model.set('counter'counter.get());
    };

    list.
onShow = function()
    {
        if ( 
counter.get('all') <= )
        {
            
this.showNoContent();

            return;
        }

        if ( 
counter.get('new') > || !listLoaded )
        {
            
this.loadList();
            
listLoaded true;
        }
    };
}

PEEP.Invitation null;
?>
Онлайн: 1
Реклама