borkolivic

jq za tabove

Apr 4th, 2016
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 1.29 KB | None | 0 0
  1. (function ($) {
  2.  
  3.     $.mx_custom_tab_mod = $.mx_custom_tab_mod || {};
  4.  
  5.     $.mx_custom_tab_mod.init = function () {
  6.  
  7.         var template = $('#tmpl-add-custom-tab').html();
  8.  
  9.         $('.custom-box-holder').sortable({
  10.             placeholder: 'mad-custom-tab-highlight',
  11.             handle: ".handle-area"
  12.         });
  13.  
  14.         ({
  15.             init: function () {
  16.                 this.listeners();
  17.             },
  18.             listeners: function () {
  19.                 var base = this;
  20.  
  21.                 $('#meta_custom_tabs').on('click', '.add-custom-tab', function (e) {
  22.                     e.preventDefault();
  23.  
  24.                     var rString = base.randomString(5, 'abcdefghijklmnopqrstuvwxyz'),
  25.                         html = template.replace(/__REPLACE_SSS__/gi, rString);
  26.  
  27.                     newTemplate = $(html).appendTo('.custom-box-holder').css({ display: "none" });
  28.  
  29.                     quicktags(rString);
  30.                     QTags._buttonsInit();
  31.  
  32.                     newTemplate.slideDown(200);
  33.  
  34.                 }).on('click', '.remove-custom-tab', function (e) {
  35.                     e.preventDefault();
  36.                     var $this = $(this),
  37.                         $item = $this.parents('li');
  38.                     $item.slideUp(200, function () { $item.remove(); });
  39.                 });
  40.             },
  41.             randomString: function (length, chars) {
  42.                 var result = '';
  43.                 for (var i = length; i > 0; --i) result += chars[Math.round(Math.random() * (chars.length - 1))];
  44.                 return result;
  45.             }
  46.         }).init();
  47.     }
  48.  
  49.     $(function() {
  50.         $.mx_custom_tab_mod.init();
  51.     });
  52.  
  53. })(jQuery);
Add Comment
Please, Sign In to add comment