Guest User

Untitled

a guest
Jul 22nd, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.14 KB | None | 0 0
  1. /**-----------------------------------------------------------------------------
  2. * ElementPanel class
  3. *
  4. * @updated: 15:22 27/01/2011
  5. *---------------------------------------------------------------------------*/
  6. var ElementPanel = function(options) {
  7.  
  8. options = options || {};
  9.  
  10. this.selector = options.selector || ".managed-system";
  11. this.store_key = options.store_key || "element"
  12. this.cls = options.cls || "element-panel" ;
  13. this.hoverCls = options.hoverCls;
  14.  
  15. this.render();
  16.  
  17. }; // ElementPanel
  18.  
  19. ElementPanel.prototype = {
  20.  
  21. init: function() {
  22.  
  23. var self = this;
  24. $(this.selector).each(function() {
  25. self.initEvents($(this));
  26. });
  27.  
  28. }, // init
  29.  
  30. render: function() {
  31.  
  32. if (!this.rendered) {
  33.  
  34. this.rendered = true;
  35. var self = this;
  36.  
  37. this.el = $("<div/>");
  38. this.el.addClass(this.cls);
  39.  
  40. var position = this.el.css("position");
  41. if (position != "absolute" || position != "fixed") {
  42. this.el.css("position", "absolute");
  43. }
  44.  
  45. this.el
  46. .mouseenter(function() { self.show(); })
  47. .mouseleave(function() { self.hide(); });
  48.  
  49. this.addButton('edit');
  50. this.addButton('delete');
  51.  
  52. this.hide();
  53. this.el.appendTo('body');
  54.  
  55. this.init();
  56.  
  57. };
  58.  
  59. }, // render
  60.  
  61. addButton: function(action) {
  62.  
  63. if (this.el && action) {
  64. var self = this;
  65. $(
  66. '<div class="awesome-button icon icon-' + action + '">' +
  67. '<span>&nbsp;</span></div>'
  68. ).click(function() { self.onClick(action); })
  69. .appendTo(this.el);
  70. }
  71. return this;
  72.  
  73. }, // addButton
  74.  
  75. initEvents: function(el) {
  76.  
  77. var self = this;
  78. el.mouseenter(function() { self.onMouseOver(el); })
  79. .mouseleave(function() { self.onMouseOut(); });
  80.  
  81. }, // initEvents
  82.  
  83. setPosition: function(el) {
  84.  
  85. var o = el.offset();
  86. o.left += (el.width() - this.width());
  87. this.el.css(o);
  88. return this;
  89.  
  90. }, // setPosition
  91.  
  92. getXY: function() {
  93. return this.el.offset();
  94. }, // getXY
  95.  
  96. onMouseOver: function(el) {
  97. this.target = el;
  98. this.show();
  99. }, // onMouseOver
  100.  
  101. onMouseOut: function() {
  102. this.hide();
  103. }, // onMouseOver
  104.  
  105. show: function() {
  106.  
  107. if (this.target) {
  108. if (this.hoverCls) {
  109. this.target.addClass(this.hoverCls);
  110. }
  111. this.setPosition(this.target);
  112. }
  113. this.el.show();
  114. return this;
  115.  
  116. }, // show
  117.  
  118. hide: function() {
  119.  
  120. if (this.target && this.hoverCls) {
  121. this.target.removeClass(this.hoverCls);
  122. }
  123. this.el.hide();
  124. return this;
  125.  
  126. }, // hide
  127.  
  128. height: function() {
  129. return this.el.height();
  130. }, // height
  131.  
  132. width: function() {
  133. return this.el.width();
  134. }, // width
  135.  
  136. getData: function() {
  137.  
  138. if (this.store_key && this.target) {
  139. return this.target.data(this.store_key);
  140. }
  141. return null;
  142.  
  143. }, // getData
  144.  
  145. fireEvent: function(name, data) {
  146. var event = new $.Event(name);
  147. this.el.trigger(event, data);
  148. return event.result !== false;
  149. }, // fireEvent
  150.  
  151. on: function(evt, fn, scope) {
  152.  
  153. if (typeof fn == "function") {
  154. this.el.bind(evt, function(e, data) {
  155. fn.call( scope || window, data );
  156. });
  157. }
  158. return this;
  159.  
  160. }, // on
  161.  
  162. onClick: function(action) {
  163. this.fireEvent(action, this.getData());
  164. } // onClick
  165.  
  166. }; // ElementPanel
  167.  
  168. ElementPanel.prototype.bind = ElementPanel.prototype.on;
  169.  
  170. /**-------------------------------------------------------------------------
  171. * ElementManager class
  172. *
  173. * @updated:
  174. *------------------------------------------------------------------------*/
  175. ElementManager = function(panel, options) {
  176.  
  177. options = options || {};
  178. this.cls = options.cls || "notice-win";
  179. this.expires = options.expires || 5; // min
  180. this.wait = options.wait || 5; // sec
  181. this.deleteMsg = options.deleteMsg || "Удалить выбранный элемент?";
  182. this.init(panel);
  183.  
  184. }; // ElementManager
  185.  
  186. ElementManager.prototype = {
  187.  
  188. init: function(target) {
  189.  
  190. this.render();
  191. target
  192. .on("edit", this.onEdit, this)
  193. .on("delete", this.onDelete, this);
  194.  
  195. }, // init
  196.  
  197. render: function() {
  198.  
  199. if (!this.rendered) {
  200.  
  201. this.rendered = true;
  202.  
  203. this.el = $("<div/>");
  204. this.el.css({
  205. "position": "absolute",
  206. "right": 20,
  207. "top": 20,
  208. "bottom": 0,
  209. "height": "100%",
  210. "overflow": "hidden",
  211. "z-index": "10000"
  212. });
  213. this.el.appendTo("body");
  214.  
  215. var self = this;
  216. $(window).scroll(function() {
  217. self.el.css("top", $(window).scrollTop() + 20);
  218. });
  219.  
  220. }
  221.  
  222. }, // render
  223.  
  224. onEdit: function(data) {
  225. this.onSet('edit', data);
  226. }, // onEdit
  227.  
  228. onDelete: function(data) {
  229.  
  230. if (confirm(this.deleteMsg)) {
  231. this.onSet('delete', data);
  232. }
  233.  
  234. }, // onDelete
  235.  
  236. onNotice: function(mark, msg) {
  237.  
  238. this.register($(
  239. "<div class=\"" + this.cls + " " +
  240. (mark == 0 ? "" : this.cls + "-error") +
  241. "\">" + msg + "</div>"
  242. ));
  243.  
  244. }, // onNotice
  245.  
  246. onSet: function(action, data) {
  247.  
  248. var key = this.createKey(action, data);
  249. if ($.cookie(key) === undefined) {
  250.  
  251. var values = [];
  252. for(var m in $.csrf) {
  253. values.push(m + ":" + $.csrf[m])
  254. }
  255.  
  256. var result = $.cookie(key, values.join(';'), { expires:this.expires*60 });
  257. if (result === undefined) {
  258. this.onNotice(1, "Не могу не добавить задачу в очередь выполнения.");
  259. } else {
  260. this.onNotice(0, "Задача добавлена в очередь выполнения.");
  261. }
  262.  
  263. } else {
  264. this.onNotice(0, "Действие обрабатывается. Подождите.");
  265. }
  266.  
  267. }, // onSet
  268.  
  269. createKey: function(action ,data) {
  270.  
  271. var key = action + "@" + data.type;
  272. if (data.id) {
  273. key += ":" + data.id;
  274. }
  275. return key;
  276.  
  277. }, // createKey
  278.  
  279. register: function(el) {
  280.  
  281. el.appendTo(this.el);
  282.  
  283. el.click(function() {
  284. $(this).slideUp(100, function() {
  285. el.remove();
  286. })
  287. });
  288.  
  289. setTimeout(function() {
  290. el.slideUp(100, function() {
  291. el.remove();
  292. });
  293. }, this.wait*1000);
  294.  
  295. } // register
  296.  
  297. }; // ElementManager
  298.  
  299.  
  300. /**-------------------------------------------------------------------------
  301. * Cookie class
  302. *
  303. * @updated: 10:49 24/06/2010
  304. *------------------------------------------------------------------------*/
  305. (function($) {
  306.  
  307. $.cookie = function() {
  308.  
  309. var Cookie = {
  310.  
  311. set : function(name, value, options) {
  312.  
  313. options = options || {}
  314. options.path = (options.path && options.path.length > 0 ? ';path=' + (options.path) : ';path=/');
  315. options.domain = (options.domain && options.domain.length > 0 ? ';domain=' + (options.domain) : '');
  316. options.secure = (options.secure && options.secure.length > 0 ? ';secure' : '');
  317.  
  318. if (value === null) {
  319. value = '';
  320. options.expires = -1;
  321. } else {
  322. value = (typeof value == "string" ? $.trim(value) : value);
  323. }
  324.  
  325. var date;
  326. if (typeof options.expires == 'number') {
  327. date = new Date();
  328. date.setTime(date.getTime() + (options.expires * 1000));
  329. } else if (options.expires instanceof Date) {
  330. date = options.expires;
  331. } else {
  332. date = new Date();
  333. date.setTime(date.getTime() + (7 * 24 * 60 * 60 * 1000));
  334. }
  335. options.expires = ';expires=' + date.toUTCString();
  336.  
  337. document.cookie = [name, '=', encodeURIComponent(value),
  338. options.expires, options.path, options.domain, options.secure].join('');;
  339.  
  340. return Cookie.get(name);
  341.  
  342. }, // set
  343.  
  344. get : function(name) {
  345.  
  346. var b = document.cookie.indexOf(name + "=");
  347. if (b == -1) { return; }
  348.  
  349. b = b + name.length + 1;
  350. var e = document.cookie.indexOf(";", b);
  351. if (e == -1) {
  352. e = document.cookie.length;
  353. }
  354. return decodeURIComponent(document.cookie.substring(b, e));
  355.  
  356. }, // get
  357.  
  358. getBy : function(str, func) {
  359.  
  360. if (document.cookie.length == 0) { return; }
  361. if (!(str instanceof RegExp)) {
  362. return Cookie.get(str);
  363. }
  364.  
  365. var arr = document.cookie.match(str);
  366. if (!arr || arr.length == 0) { return; }
  367. if (!func) { return arr; }
  368.  
  369. for(var i=0,size = arr.length, tmp; i < size; i++) {
  370. tmp = arr[i].split("=");
  371. func.apply(this, [tmp[0], decodeURIComponent(tmp[1])]);
  372. }
  373.  
  374. } // getBy
  375.  
  376. }; // Cookie
  377.  
  378. switch (arguments.length) {
  379.  
  380. case 0 :
  381. return;
  382. break;
  383.  
  384. case 1 :
  385.  
  386. return Cookie.getBy.apply(this, arguments);
  387. break;
  388.  
  389. case 2:
  390.  
  391. if (typeof arguments[1] == "function") {
  392. return Cookie.getBy.apply(this, arguments);
  393. } else {
  394. return Cookie.set.apply(this, arguments);
  395. }
  396. break;
  397.  
  398. default:
  399. return Cookie.set.apply(this, arguments);
  400. }
  401.  
  402. }; // $.cookie
  403.  
  404. $.csrf = (function() {
  405.  
  406. var o = {};
  407.  
  408. $(document).ready(function() {
  409.  
  410. var csrf_token = $('meta[name=csrf-token]').attr('content'),
  411. csrf_param = $('meta[name=csrf-param]').attr('content');
  412.  
  413. if (csrf_param !== undefined && csrf_token !== undefined) {
  414. o[csrf_param] = csrf_token;
  415. }
  416.  
  417. });
  418.  
  419. return o;
  420.  
  421. })(); // $.csrf
  422.  
  423. })(jQuery);
  424.  
  425. $(document).ready(function() {
  426.  
  427. $('a.forgot').click(function(event) {
  428.  
  429. if ('undefined' != typeof event.preventDefault) { event.preventDefault(); }
  430. if ('undefined' != typeof event.stopPropagation) { event.stopPropagation(); }
  431. alert("Не стоит забывать пароли от админок!");
  432. return false;
  433.  
  434. });
  435.  
  436. var panel = new ElementPanel({
  437. cls: "admin-element-panel",
  438. hoverCls: "admin-element-hover"
  439. });
  440.  
  441. new ElementManager(panel, {
  442. expires: 5
  443. });
  444.  
  445. });
Add Comment
Please, Sign In to add comment