Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**-----------------------------------------------------------------------------
- * ElementPanel class
- *
- * @updated: 15:22 27/01/2011
- *---------------------------------------------------------------------------*/
- var ElementPanel = function(options) {
- options = options || {};
- this.selector = options.selector || ".managed-system";
- this.store_key = options.store_key || "element"
- this.cls = options.cls || "element-panel" ;
- this.hoverCls = options.hoverCls;
- this.render();
- }; // ElementPanel
- ElementPanel.prototype = {
- init: function() {
- var self = this;
- $(this.selector).each(function() {
- self.initEvents($(this));
- });
- }, // init
- render: function() {
- if (!this.rendered) {
- this.rendered = true;
- var self = this;
- this.el = $("<div/>");
- this.el.addClass(this.cls);
- var position = this.el.css("position");
- if (position != "absolute" || position != "fixed") {
- this.el.css("position", "absolute");
- }
- this.el
- .mouseenter(function() { self.show(); })
- .mouseleave(function() { self.hide(); });
- this.addButton('edit');
- this.addButton('delete');
- this.hide();
- this.el.appendTo('body');
- this.init();
- };
- }, // render
- addButton: function(action) {
- if (this.el && action) {
- var self = this;
- $(
- '<div class="awesome-button icon icon-' + action + '">' +
- '<span> </span></div>'
- ).click(function() { self.onClick(action); })
- .appendTo(this.el);
- }
- return this;
- }, // addButton
- initEvents: function(el) {
- var self = this;
- el.mouseenter(function() { self.onMouseOver(el); })
- .mouseleave(function() { self.onMouseOut(); });
- }, // initEvents
- setPosition: function(el) {
- var o = el.offset();
- o.left += (el.width() - this.width());
- this.el.css(o);
- return this;
- }, // setPosition
- getXY: function() {
- return this.el.offset();
- }, // getXY
- onMouseOver: function(el) {
- this.target = el;
- this.show();
- }, // onMouseOver
- onMouseOut: function() {
- this.hide();
- }, // onMouseOver
- show: function() {
- if (this.target) {
- if (this.hoverCls) {
- this.target.addClass(this.hoverCls);
- }
- this.setPosition(this.target);
- }
- this.el.show();
- return this;
- }, // show
- hide: function() {
- if (this.target && this.hoverCls) {
- this.target.removeClass(this.hoverCls);
- }
- this.el.hide();
- return this;
- }, // hide
- height: function() {
- return this.el.height();
- }, // height
- width: function() {
- return this.el.width();
- }, // width
- getData: function() {
- if (this.store_key && this.target) {
- return this.target.data(this.store_key);
- }
- return null;
- }, // getData
- fireEvent: function(name, data) {
- var event = new $.Event(name);
- this.el.trigger(event, data);
- return event.result !== false;
- }, // fireEvent
- on: function(evt, fn, scope) {
- if (typeof fn == "function") {
- this.el.bind(evt, function(e, data) {
- fn.call( scope || window, data );
- });
- }
- return this;
- }, // on
- onClick: function(action) {
- this.fireEvent(action, this.getData());
- } // onClick
- }; // ElementPanel
- ElementPanel.prototype.bind = ElementPanel.prototype.on;
- /**-------------------------------------------------------------------------
- * ElementManager class
- *
- * @updated:
- *------------------------------------------------------------------------*/
- ElementManager = function(panel, options) {
- options = options || {};
- this.cls = options.cls || "notice-win";
- this.expires = options.expires || 5; // min
- this.wait = options.wait || 5; // sec
- this.deleteMsg = options.deleteMsg || "Удалить выбранный элемент?";
- this.init(panel);
- }; // ElementManager
- ElementManager.prototype = {
- init: function(target) {
- this.render();
- target
- .on("edit", this.onEdit, this)
- .on("delete", this.onDelete, this);
- }, // init
- render: function() {
- if (!this.rendered) {
- this.rendered = true;
- this.el = $("<div/>");
- this.el.css({
- "position": "absolute",
- "right": 20,
- "top": 20,
- "bottom": 0,
- "height": "100%",
- "overflow": "hidden",
- "z-index": "10000"
- });
- this.el.appendTo("body");
- var self = this;
- $(window).scroll(function() {
- self.el.css("top", $(window).scrollTop() + 20);
- });
- }
- }, // render
- onEdit: function(data) {
- this.onSet('edit', data);
- }, // onEdit
- onDelete: function(data) {
- if (confirm(this.deleteMsg)) {
- this.onSet('delete', data);
- }
- }, // onDelete
- onNotice: function(mark, msg) {
- this.register($(
- "<div class=\"" + this.cls + " " +
- (mark == 0 ? "" : this.cls + "-error") +
- "\">" + msg + "</div>"
- ));
- }, // onNotice
- onSet: function(action, data) {
- var key = this.createKey(action, data);
- if ($.cookie(key) === undefined) {
- var values = [];
- for(var m in $.csrf) {
- values.push(m + ":" + $.csrf[m])
- }
- var result = $.cookie(key, values.join(';'), { expires:this.expires*60 });
- if (result === undefined) {
- this.onNotice(1, "Не могу не добавить задачу в очередь выполнения.");
- } else {
- this.onNotice(0, "Задача добавлена в очередь выполнения.");
- }
- } else {
- this.onNotice(0, "Действие обрабатывается. Подождите.");
- }
- }, // onSet
- createKey: function(action ,data) {
- var key = action + "@" + data.type;
- if (data.id) {
- key += ":" + data.id;
- }
- return key;
- }, // createKey
- register: function(el) {
- el.appendTo(this.el);
- el.click(function() {
- $(this).slideUp(100, function() {
- el.remove();
- })
- });
- setTimeout(function() {
- el.slideUp(100, function() {
- el.remove();
- });
- }, this.wait*1000);
- } // register
- }; // ElementManager
- /**-------------------------------------------------------------------------
- * Cookie class
- *
- * @updated: 10:49 24/06/2010
- *------------------------------------------------------------------------*/
- (function($) {
- $.cookie = function() {
- var Cookie = {
- set : function(name, value, options) {
- options = options || {}
- options.path = (options.path && options.path.length > 0 ? ';path=' + (options.path) : ';path=/');
- options.domain = (options.domain && options.domain.length > 0 ? ';domain=' + (options.domain) : '');
- options.secure = (options.secure && options.secure.length > 0 ? ';secure' : '');
- if (value === null) {
- value = '';
- options.expires = -1;
- } else {
- value = (typeof value == "string" ? $.trim(value) : value);
- }
- var date;
- if (typeof options.expires == 'number') {
- date = new Date();
- date.setTime(date.getTime() + (options.expires * 1000));
- } else if (options.expires instanceof Date) {
- date = options.expires;
- } else {
- date = new Date();
- date.setTime(date.getTime() + (7 * 24 * 60 * 60 * 1000));
- }
- options.expires = ';expires=' + date.toUTCString();
- document.cookie = [name, '=', encodeURIComponent(value),
- options.expires, options.path, options.domain, options.secure].join('');;
- return Cookie.get(name);
- }, // set
- get : function(name) {
- var b = document.cookie.indexOf(name + "=");
- if (b == -1) { return; }
- b = b + name.length + 1;
- var e = document.cookie.indexOf(";", b);
- if (e == -1) {
- e = document.cookie.length;
- }
- return decodeURIComponent(document.cookie.substring(b, e));
- }, // get
- getBy : function(str, func) {
- if (document.cookie.length == 0) { return; }
- if (!(str instanceof RegExp)) {
- return Cookie.get(str);
- }
- var arr = document.cookie.match(str);
- if (!arr || arr.length == 0) { return; }
- if (!func) { return arr; }
- for(var i=0,size = arr.length, tmp; i < size; i++) {
- tmp = arr[i].split("=");
- func.apply(this, [tmp[0], decodeURIComponent(tmp[1])]);
- }
- } // getBy
- }; // Cookie
- switch (arguments.length) {
- case 0 :
- return;
- break;
- case 1 :
- return Cookie.getBy.apply(this, arguments);
- break;
- case 2:
- if (typeof arguments[1] == "function") {
- return Cookie.getBy.apply(this, arguments);
- } else {
- return Cookie.set.apply(this, arguments);
- }
- break;
- default:
- return Cookie.set.apply(this, arguments);
- }
- }; // $.cookie
- $.csrf = (function() {
- var o = {};
- $(document).ready(function() {
- var csrf_token = $('meta[name=csrf-token]').attr('content'),
- csrf_param = $('meta[name=csrf-param]').attr('content');
- if (csrf_param !== undefined && csrf_token !== undefined) {
- o[csrf_param] = csrf_token;
- }
- });
- return o;
- })(); // $.csrf
- })(jQuery);
- $(document).ready(function() {
- $('a.forgot').click(function(event) {
- if ('undefined' != typeof event.preventDefault) { event.preventDefault(); }
- if ('undefined' != typeof event.stopPropagation) { event.stopPropagation(); }
- alert("Не стоит забывать пароли от админок!");
- return false;
- });
- var panel = new ElementPanel({
- cls: "admin-element-panel",
- hoverCls: "admin-element-hover"
- });
- new ElementManager(panel, {
- expires: 5
- });
- });
Add Comment
Please, Sign In to add comment