JAVASCRIPT   18
slider
Guest on 18th September 2023 07:55:45 AM


  1. (function(c, a) {
  2.     a.SliderFormController = a.FormController.extend({}, {
  3.         optionControllers: {},
  4.         dependency: {},
  5.         disabled_dependency: {},
  6.         preview_wrapper: null,
  7.         init: function(d, e) {
  8.             var b = this;
  9.             this._super(d, e);
  10.             this.changeShortcode();
  11.             this.optionControllers.alias.on("change", function() {
  12.                 b.changeShortcode()
  13.             });
  14.             c("#mpsl-slider-settings-tabs").tabs({
  15.                 activate: function(b, f) {
  16.                     a.CodeMirrorControl.refreshEditors(f.newPanel)
  17.                 }
  18.             });
  19.             var f = c(".mpsl-slider-posts-preview");
  20.             f.length && new a.PostControls(f);
  21.             this.preview_wrapper = c(".mpsl-slider-preview");
  22.             this.previewIframe = this.preview_wrapper.find("iframe");
  23.             this.preloader = this.preview_wrapper.find(".mpsl-preloader");
  24.             this.previewUrl = a.Vars.menu_url;
  25.             this.previewSliderId = null;
  26.             this.resolutionWrapper = this.preview_wrapper.find(".mpsl-resolution-buttons-wrapper");
  27.             this.desktopIcon = this.preview_wrapper.find(".desktop");
  28.             this.footerMessageWrapper = this.preview_wrapper.find(".mpsl-slider-preview-footer-message");
  29.             this.previewUrl = a.Functions.addParamToUrl(this.previewUrl, "view", "preview");
  30.             this.previewUrl = a.Functions.addParamToUrl(this.previewUrl,
  31.                 "type", "slider");
  32.             this.preview_wrapper.dialog({
  33.                 resizable: !1,
  34.                 draggable: !1,
  35.                 autoOpen: !1,
  36.                 modal: !0,
  37.                 width: c(window).width() - 100,
  38.                 height: c(window).height() - 100,
  39.                 title: a.Vars.lang.preview_dialog_title,
  40.                 closeText: "",
  41.                 dialogClass: "mpsl-preview-dialog",
  42.                 close: function() {
  43.                     (b.previewIframe[0].contentDocument || b.previewIframe[0].contentWindow.document).documentElement.innerHTML = ""
  44.                 },
  45.                 beforeClose: function() {
  46.                     c("body").css("overflow", "inherit");
  47.                     b.footerMessageWrapper.addClass("hidden")
  48.                 },
  49.                 open: function() {
  50.                     b.footerMessageWrapper.removeClass("hidden");
  51.                     c("body").css("overflow", "hidden");
  52.                     b.preloader.show();
  53.                     b.previewUrl = a.Functions.removeParamFromUrl(b.previewUrl, "slider_id");
  54.                     b.previewUrl = a.Functions.addParamToUrl(b.previewUrl, "slider_id", b.previewSliderId);
  55.                     b.previewIframe.attr("src", b.previewUrl);
  56.                     b.previewIframe.width("100%");
  57.                     b.desktopIcon.siblings().removeClass("active");
  58.                     b.desktopIcon.addClass("active")
  59.                 },
  60.                 create: function() {
  61.                     b.resolutionWrapper.removeClass("hidden")
  62.                 }
  63.             });
  64.             this.resBtns = [{
  65.                 type: "desktop",
  66.                 resolution: "100%"
  67.             }, {
  68.                 type: "tablet",
  69.                 resolution: "768px"
  70.             }, {
  71.                 type: "mobile",
  72.                 resolution: "480px"
  73.             }];
  74.             this.resBtns.forEach(function(a) {
  75.                 b.preview_wrapper.on("click", "." + a.type, function() {
  76.                     b.previewIframe.width(a.resolution);
  77.                     c(this).siblings().removeClass("active");
  78.                     c(this).addClass("active");
  79.                     (b.previewIframe[0].contentWindow || b.previewIframe[0].contentDocument)._mpslResizePreview()
  80.                 })
  81.             });
  82.             this.previewIframe.on("load", function() {
  83.                 b.preloader.hide()
  84.             })
  85.         },
  86.         changeShortcode: function(c) {
  87.             this.optionControllers.shortcode.setValue("[" + a.Vars.settings.shortcode_name + " " + this.optionControllers.alias.getValue() +
  88.                 "]")
  89.         },
  90.         disableBtns: function() {
  91.             this.element.find("#update_slider, #delete_slider, #create_slider, #edit_slides").attr("disabled", "disabled")
  92.         },
  93.         enableBtns: function() {
  94.             this.element.find("#update_slider, #delete_slider, #create_slider, #edit_slides").removeAttr("disabled", "disabled")
  95.         },
  96.         "#update_slider, #slider_preview click": function(d, e) {
  97.             e.preventDefault();
  98.             var b = this,
  99.                 f = "slider_preview" === d.attr("id");
  100.             f || this.disableBtns();
  101.             if (b.verifyOptions()) {
  102.                 var g = this.getFormData(),
  103.                     g = {
  104.                         action: "mpsl_update_slider",
  105.                         nonce: a.Vars.nonces.update_slider,
  106.                         options: JSON.stringify(g),
  107.                         preview: f
  108.                     },
  109.                     h = a.Vars.page.id;
  110.                 h && (g.id = h);
  111.                 c.ajax({
  112.                     type: "POST",
  113.                     url: a.Vars.ajax_url,
  114.                     data: g,
  115.                     success: function(c) {
  116.                         f ? (b.previewSliderId = h, b.preview_wrapper.dialog("open")) : (b.enableBtns(), c.hasOwnProperty("result") && (!0 === c.result ? a.Functions.showMessage(a.Vars.lang.slider_updated, a.Functions.MSG_SUCCESS_TYPE) : a.Functions.showMessage(a.Vars.lang.slider_update_error + c.error, a.Functions.MSG_ERROR_TYPE)))
  117.                     },
  118.                     error: function(f) {
  119.                         f = c.parseJSON(f.responseText);
  120.                         f.debug ? console.log(f.message) :
  121.                             a.Functions.showMessage(f.message, a.Functions.MSG_ERROR_TYPE);
  122.                         b.enableBtns()
  123.                     },
  124.                     dataType: "JSON"
  125.                 })
  126.             } else b.enableBtns()
  127.         },
  128.         "#create_slider click": function(d) {
  129.             var e = this;
  130.             e.disableBtns();
  131.             if (e.verifyOptions()) {
  132.                 d = e.getFormData();
  133.                 var b = e.optionControllers.slider_type.getValue();
  134.                 d = {
  135.                     action: "mpsl_create_slider",
  136.                     nonce: a.Vars.nonces.create_slider,
  137.                     options: JSON.stringify(d),
  138.                     slider_type: b
  139.                 };
  140.                 c.ajax({
  141.                     type: "POST",
  142.                     url: a.Vars.ajax_url,
  143.                     data: d,
  144.                     success: function(f) {
  145.                         if (f.hasOwnProperty("result"))
  146.                             if (!0 === f.result) {
  147.                                 a.Functions.showMessage(a.Vars.lang.slider_created,
  148.                                     a.Functions.MSG_SUCCESS_TYPE);
  149.                                 var c = a.Functions.removeParamFromUrl(window.location.href, "view"),
  150.                                     c = a.Functions.removeParamFromUrl(c, "slider_type"),
  151.                                     c = "custom" === b ? a.Functions.addParamsToUrl(c, {
  152.                                         view: "slides",
  153.                                         id: f.id
  154.                                     }) : a.Functions.addParamsToUrl(c, {
  155.                                         view: "slide",
  156.                                         id: f.template_id
  157.                                     });
  158.                                 window.location.href = c
  159.                             } else a.Functions.showMessage(f.error, a.Functions.MSG_ERROR_TYPE);
  160.                         else a.Functions.showMessage(a.Vars.lang.ajax_result_not_found, a.Functions.MSG_ERROR_TYPE);
  161.                         e.enableBtns()
  162.                     },
  163.                     error: function(b) {
  164.                         var d = c.parseJSON(b.responseText);
  165.                         d.debug ? console.log(d.message) : a.Functions.showMessage(d.message, a.Functions.MSG_ERROR_TYPE);
  166.                         e.enableBtns();
  167.                         console.error(b)
  168.                     },
  169.                     dataType: "JSON"
  170.                 })
  171.             } else e.enableBtns()
  172.         },
  173.         "#delete_slider click": function(d) {
  174.             var e = this;
  175.             this.disableBtns();
  176.             d = a.Vars.page.id;
  177.             if (0 == confirm(a.Vars.lang.slider_want_delete_single.replace("%d", d))) return !0;
  178.             var b = {
  179.                 action: "mpsl_delete_slider",
  180.                 nonce: a.Vars.nonces.delete_slider
  181.             };
  182.             d && (b.id = d);
  183.             c.ajax({
  184.                 type: "POST",
  185.                 url: a.Vars.ajax_url,
  186.                 data: b,
  187.                 success: function(b) {
  188.                     e.enableBtns();
  189.                     b.hasOwnProperty("result") ?
  190.                         1 == b.result ? (a.Functions.showMessage(a.Vars.lang.slider_deleted, a.Functions.MSG_SUCCESS_TYPE), b = a.Functions.removeParamsFromUrl(window.location.href, ["view", "id"]), window.location.href = b) : a.Functions.showMessage(b.error, a.Functions.MSG_ERROR_TYPE) : a.Functions.showMessage(a.Vars.lang.ajax_result_not_found, a.Functions.MSG_ERROR_TYPE);
  191.                     e.enableBtns()
  192.                 },
  193.                 error: function(b) {
  194.                     b = c.parseJSON(b.responseText);
  195.                     b.debug ? console.log(b.message) : a.Functions.showMessage(b.message, a.Functions.MSG_ERROR_TYPE);
  196.                     e.enableBtns()
  197.                 },
  198.                 dataType: "JSON"
  199.             })
  200.         }
  201.     });
  202.     a.PostControls = can.Control.extend({}, {
  203.         formController: null,
  204.         tableBody: null,
  205.         init: function(a, e) {
  206.             this.formController = c(".mpsl-slider-settings-wrapper").control();
  207.             this.postsTable = c(".mpsl-posts-table");
  208.             this.tableBody = this.postsTable.find("tbody");
  209.             this.postsTableCount = c("#mpsl-preview-posts-count");
  210.             this.getPosts()
  211.         },
  212.         getPosts: function() {
  213.             var d = this,
  214.                 e = d.formController.getFormData(),
  215.                 e = {
  216.                     action: "mpsl_posts_preview",
  217.                     nonce: a.Vars.nonces.posts_preview,
  218.                     options: JSON.stringify(e.post_settings),
  219.                     type: this.formController.optionControllers.slider_type.getValue()
  220.                 };
  221.             c.ajax({
  222.                 type: "POST",
  223.                 url: a.Vars.ajax_url,
  224.                 data: e,
  225.                 success: function(b) {
  226.                     d.tableBody.empty();
  227.                     b && b.result && (d.postsTableCount.text(" (" + b.posts.length + ")"), c.each(b.posts, function(b, a) {
  228.                         var e = a.image ? c("<img />", {
  229.                             src: a.image,
  230.                             width: 150
  231.                         }).prop("outerHTML") : "";
  232.                         d.tableBody.append("<tr><td >" + a.ID + '</td><td ><a  class="row-title" href="' + a.url + '" target="_blank" >' + e + '</a></td><td><a  class="row-title" href="' + a.url + '" target="_blank">' + a.title + "</a> (" + a.date + ")</td><td>" + a.excerpt + "</td></tr>")
  233.                     }))
  234.                 },
  235.                 error: function(b) {
  236.                     console.log(b.responseText);
  237.                     b = c.parseJSON(b.responseText);
  238.                     b.debug ? console.log(b.message) : a.Functions.showMessage(b.message, a.Functions.MSG_ERROR_TYPE)
  239.                 }
  240.             })
  241.         },
  242.         "#get_posts click": function() {
  243.             this.formController.verifyOptions() && this.getPosts()
  244.         }
  245.     })
  246. })(jQuery, MPSL);
  247. jQuery(function(c) {
  248.     new MPSL.SliderFormController(c(".mpsl-slider-settings-wrapper"))
  249. });

Raw Paste

Login or Register to edit or fork this paste. It's free.