1'use strict'; 2 3var social = new function () { 4 this.titleId = '#additemform-url'; 5 this.formId = '#add-item-form'; 6 this.containerId = '#modal-popup'; 7 this.$container = $('#modal-popup'); 8 this.context = ''; 9 10 this.init = function () { 11 var self = this; 12 13 /*$('#addItem').click(function () { 14 self.open(); 15 }); 16 17 $('.add-item').click(function () { 18 if ($(this).closest('#edit-content').length == 0) { 19 self.open($(this).data()); 20 } 21 });*/ 22 23 $('#modal-popup').on('click', 'form .message button.close', function (e) { 24 $(this).parent().hide(); 25 }); 26 27 $('#modal-popup').on('click', '.context-buttons button', function (e) { 28 $('#additemform-type').val($(this).data('type')); 29 30 var title = $('#title_' + $(this).data('type')).html(); 31 var placeholder = $('#placeholder_' + $(this).data('type')).html(); 32 33 $('#page2 p:first').html(title); 34 $('#page2 #additemform-url').prop('placeholder', placeholder); 35 36 $('#page1').fadeOut(function() { 37 $('#page2').fadeIn(); 38 }); 39 //self.save(); 40 }); 41 42 $('#modal-popup').on('click', '#page2 button', function () { 43 self.save(); 44 }); 45 46 this.$container.on('paste', this.titleId, function () { 47 setTimeout(function () { 48 if ($(self.titleId).val().indexOf('http') === 0) { 49 self.save(); 50 } 51 }, 100); 52 }); 53 54 this.$container.on('beforeSubmit', this.formId, function (e) { 55 self.save(); 56 return false; 57 }).on('submit', this.formId, function (e) { 58 e.preventDefault(); 59 return false; 60 }); 61 }; 62 63 this.loader = function ($isShow) { 64 if ($isShow) { 65 this.$container.find('.loader').fadeIn(); 66 } else { 67 this.$container.find('.loader').hide(); 68 } 69 }; 70 71 this.open = function (params) { 72 params = params || []; 73 popup.open('/popup/add-item?' + $.param(params)); 74 }; 75 76 this.reset = function () { 77 $(this.titleId).val(''); 78 this.loader(false); 79 80 $("#modal-popup form .kv-alert").remove(); 81 $("#modal-popup form .message").hide(); 82 }; 83 84 this.message = function (type, text, title) { 85 type = type || 'danger'; 86 title = title || false; 87 if (this.messageType) { 88 $(this.containerId).find(".message").removeClass('alert-' + type); 89 } 90 91 this.messageType = type; 92 93 var message = ''; 94 if (title) { 95 message += '<h3>' + title + '</h3>'; 96 } 97 98 message += '<div>
98' + text + '</div>'; 99 100 $('#modal-popup form .message .msg').html(message); 101 $("#modal-popup form .message").addClass('alert-' + type).fadeIn(); 102 }; 103 104 this.messageHtml = function (html) { 105 var self = this; 106 $(html).each(function (index, value) { 107 $(self.containerId + ' form').append(value); 108 }); 109 }; 110 111 this.save = function ($context) { 112 var self = this; 113 this.loader(true); 114 115 $("#modal-popup form .kv-alert").hide(); 116 117 $.ajax({ 118 url: '/popup/add-item', 119 method: 'POST', 120 dataType: 'json', 121 data: $(self.containerId + ' form').serialize(), 122 success: function (data) { 123 self.loader(false); 124 if (data.success) { 125 $("#modal-popup #page2").hide(); 126 } 127 if (data.msg) { 128 self.message(data.success ? 'success' : 'danger', data.msg + '<div class="loader"></div>'); 129 } 130 131 if (data.msgHtml) { 132 self.messageHtml(data.msgHtml); 133 } 134 135 if (data.success && data.redirect) { 136 setTimeout(function () { 137 document.location.href = data.redirect; 138 }, 3000); 139 } 140 }, 141 error: function (e) { 142 var type = 'danger'; 143 var title = null; 144 var text = null; 145 146 self.loader(false); 147 148 if (e.status == 200) { 149 type = 'success'; 150 } 151 152 if (e.responseText) { 153 text = e.responseText; 154 } else { 155 title = e.statusText; 156 text = e.status; 157 } 158 159 self.message(type, text, title); 160 } 161 }); 162 }; 163 164 165}; 166 167(function () { 168 social.init(); 169})(); 170
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.