1(function ($) { 2 $.fn.adsModalSubscription = function (option) { 3 4 var adsModalSubscription = function (element, options) { 5 this.settings = $.extend({}, adsModalSubscription.defaultOptions, options); 6 7 this.$element = $(element); 8 this.$modal = $("#" + this.settings.modalId); 9 this.$objectIdInput = $(this.settings.objectIdInputSelector, this.$element); 10 this.$loaderSpinner = $("<span>", {"style": "background: none;"}).append($("<img>", { 11 "class": "ads-subscription-loader", 12 "src": "/design/images/loader.gif", 13 "style": "height: inherit;" 14 })); 15 16 this._initEventHandlers(); 17 this._updateShowDialogButtons(); 18 }; 19 20 adsModalSubscription.namespace = "adsModalSubscription"; 21 22 adsModalSubscription.defaultOptions = { 23 modalId: '', 24 buttonsShowSelector: "a.show-dialog", 25 objectIdInputSelector: "input.object-id", 26 hookPageDataLoaded: true, 27 pageDataLoadedEvent: "newPageDataLoaded", 28 infiniteServicesAttribute: "infiniteServices", 29 removeButtonIfEmpty: true, 30 getExcludedServicesUrl: '/get-excluded-services', 31 isAdaptive: true 32 }; 33 34 adsModalSubscription.prototype._updateShowDialogButtons = function () { 35 var self = this, 36 settings = this.settings; 37 $(settings.buttonsShowSelector).each(function (index, element) { 38 var $this = $(this), 39 excludedServices = $this.data(settings.infiniteServicesAttribute); 40 if (self.$element.adsSubscription("hasAvailableServices", excludedServices)) { 41 $this.show(); 42 } 43 }); 44 }; 45 46 adsModalSubscription.prototype._showLoadSpinner = function ($button) { 47 if (0 === this.$loaderSpinner.length) { 48 return; 49 } 50 this._hideLoadSpinner(); 51 if ($button.length) { 52 this.$loaderSpinner 53 .insertBefore($button) 54 .prop("class", $button.prop("class")) 55 .height($button.height()); 56 $button.hide(); 57 } 58 }; 59 60 adsModalSubscription.prototype._hideLoadSpinner = function () { 61 if (0 === this.$loaderSpinner.length) { 62 return; 63 } 64 this.$loaderSpinner.next(this.settings.buttonsShowSelector).show(); 65 this.$loaderSpinner.detach(); 66 }; 67 68 adsModalSubscription.prototype._showModalDialog = function (objectId, $button, excludedServices) { 69 if (0 === this.$objectIdInput.length) { 70 return; 71 } 72 excludedServices = excludedServices || []; 73 this.$objectIdInput.val(objectId); 74 var isAdaptive = this.settings.isAdaptive; 75 if (!isAdaptive) { 76 $(".pop-reg").fadeOut(); 77 $(".pop-bg").fadeIn(); 78 } 79 this.$element.adsSubscription("resetForm"); 80 if (this.$element.adsSubscription("hideServices", excludedServices) && this.settings.removeButtonIfEmpty) { 81 $button.remove(); 82 } 83 if (isAdaptive) { 84 this.$modal.modal("show"); 85 } else { 86 this.$modal.fadeIn(); 87 } 88 }; 89 90 adsModalSubscription.prototype._initEventHandlers = function () { 91 var self = this, 92 settings = this.settings; 93 if (settings.hookPageDataLoaded) { 94 $(document).on(settings.pageDataLoadedEvent + '.' + adsModalSubscription.namespace, function (event) { 95 self._updateShowDialogButtons(); 96 }); 97 } 98 $(document).on("click." + adsModalSubscription.namespace, settings.buttonsShowSelector, function (event) { 99 var $selfButton = $(this), 100 adsId = $selfButton.data("adsId"); 101 if (self.xhr) { 102 self.xhr.abort(); 103 } 104 self._showLoadSpinner($selfButton); 105 106 var csrf = yii.getCsrfToken(), 107 ajaxSettings = { 108 url: settings.getExcludedServicesUrl, 109 data: JSON.stringify({adsId: adsId}), 110 type: "POST", 111 dataType: "JSON", 112 contentType: "application/json", 113 }; 114 if (undefined !== csrf) { 115 ajaxSettings.headers = {"X-CSRF-Token": csrf}; 116 } 117 self.xhr = $.ajax(ajaxSettings) 118 .done(function (data) { 119 self._showModalDialog(adsId, $selfButton, data.result); 120 }) 121 .fail(function (jqXHR, textStatus, errorThrown) { 122 console.log(textStatus + ": " + errorThrown); 123 }) 124 .always(function () { 125 self._hideLoadSpinner($selfButton); 126 }); 127 return false;
128 }); 129 }; 130 131 adsModalSubscription.methods = { 132 }; 133 134 var scopeArguments = arguments; 135 if ('string' === typeof option && 'function' === typeof adsModalSubscription.methods[option]) { 136 var data = this.data('cis.' + adsModalSubscription.namespace); 137 if (data) { 138 return adsModalSubscription.methods[option].apply(data, Array.prototype.slice.call(scopeArguments, 1)); 139 } 140 } 141 return this.each(function (index, element) { 142 var $this = $(this); 143 var data = $this.data('cis.' + adsModalSubscription.namespace); 144 var options = 'object' === typeof option && option; 145 146 if (!data) { 147 $this.data('cis.' + adsModalSubscription.namespace, (data = new adsModalSubscription(this, options))); 148 } 149 if ('string' === typeof option && 'function' === typeof adsModalSubscription.methods[option]) { 150 adsModalSubscription.methods[option].apply(data, Array.prototype.slice.call(scopeArguments, 1)); 151 } 152 }); 153 }; 154})(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.