1(function ($) { 2 3 // наÑÑÑойки Ñо знаÑением по ÑмолÑÐ°Ð½Ð¸Ñ 4 var defaults = { 5 modalId: '#api_typo_modal', 6 message: {} 7 }; 8 9 // пÑблиÑнÑе меÑÐ¾Ð´Ñ 10 var methods = { 11 12 // иниÑиализаÑÐ¸Ñ Ð¿Ð»Ð°Ð³Ð¸Ð½Ð° 13 init: function (params) { 14 15 // акÑÑалÑнÑе наÑÑÑойки, бÑдÑÑ Ð¸Ð½Ð´Ð¸Ð²Ð¸Ð´ÑалÑнÑми пÑи каждом запÑÑке 16 var options = $.extend({}, defaults, params); 17 18 // иниÑиализиÑÑем лиÑÑ ÐµÐ´Ð¸Ð½Ð¾Ð¶Ð´Ñ 19 if (!this.data('apiTypo')) { 20 21 // закинем наÑÑÑойки в ÑееÑÑÑ data 22 this.data('apiTypo', options); 23 24 var modalId = options.modalId; 25 26 //options.modalId = modalId; 27 $(document).on('keydown', function (e) { 28 if (e.keyCode == 13 && e.ctrlKey) 29 { 30 31 var selectedText = ""; 32 if (window.getSelection) { 33 selectedText = window.getSelection().toString(); 34 } else if (document.getSelection) { 35 selectedText = document.getSelection().toString(); 36 } else if (document.selection && document.selection.type != "Control") { 37 selectedText = document.selection.createRange().text; 38 } 39 40 if(selectedText.length > options.MAX_LENGTH) 41 $.fn.apiTypo('showMessage', options, {'status':'error', 'message':options.MESS_ALERT_TEXT_MAX}); 42 else if(selectedText.length == 0) 43 $.fn.apiTypo('showMessage', options, {'status':'error', 'message':options.MESS_ALERT_TEXT_EMPTY}); 44 else 45 $.fn.apiTypo('showModal', options, selectedText); 46 } 47 }); 48 49 50 $(document).on('click', '.api-typo-modal, .api-typo-modal-close', function (e) { 51 e.preventDefault(); 52 53 $(modalId + ' .api-typo-modal-dialog').css({ 54 'transform': 'translateY(-200px)', 55 '-webkit-transform': 'translateY(-200px)' 56 }); 57 $(modalId).animate({opacity: 0}, 300, function () { 58 $(this).hide(); 59 $.fn.apiTypo('hideModal', options); 60 }); 61 62 }); 63 64 $(document).on('click', '.api-typo-modal-dialog', function (e) { 65 e.preventDefault(); 66 e.stopPropagation(); 67 }); 68 69 $(document).on('click', modalId + ' .api-button-send', function () { 70 71 var submitButton = this; 72 73 $(modalId + ' input:text').attr('readonly', true); 74 $(submitButton).prop('disabled', true); 75 76 $.ajax({ 77 url: options.AJAX_URL, 78 type: 'POST', 79 dataType: 'json', 80 data: { 81 sessid: BX.bitrix_sessid(), 82 SITE_ID: options.SITE_ID, 83 URL: window.location.href, 84 OPTIONS: options, 85 FORM: $(modalId + ' form').serialize() 86 }, 87 error: function(jqXHR, textStatus, errorThrown){ 88 console.log('textStatus: ' + textStatus); 89 console.log('errorThrown: ' + errorThrown); 90 /*$.each( jqXHR, function(k, v){ 91 console.log('key: ' + k + ', value: ' + v ); 92 });*/ 93 }, 94 success: function (data) { 95 $.fn.apiTypo('showMessage', options, data); 96 } 97 }); 98 99 }); 100 } 101 102 return this; 103 }, 104 showModal: function (options, selectedText) { 105 $('html').addClass('api-typo-modal-active'); 106 107 var modalId = options.modalId.replace('#',''); 108 109 if (!$(options.modalId).length) 110 $('body').append('<div id="'+modalId+'" class="api-typo-modal fade"></div>'); 111 112 var modalWindow = '' + 113 '<div class="api-typo-modal-dialog">' + 114 '<div class="api-typo-modal-close api-typo-close"></div>' + 115 '<div class="api-header">' + 116 '<div class="api-title">'+options.MESS_MODAL_TITLE+'</div>' + 117 '</div>' + 118 '<div class="api-content">' + 119 '<form class="api-form">' + 120 '<div class="api-fields">' + 121 '<input type="hidden" name="TYPO[ERROR]" value="' + selectedText + '">' + 122 '<input type="text" name="TYPO[COMMENT]" tabindex="1" placeholder="'+options.MESS_MODAL_COMMENT+'">' + 123 '</div>' + 124 '<div class="api-buttons">' + 125 '<button type="button" class="api-button-send" tabindex="2">'+options.MESS_MODAL_SUBMIT+'</button> ' + 126 '<button type="button" class="api-typo-modal-close" tabindex="3">'+options.MESS_MODAL_CLOSE+'</button>' + 127 '</div>' + 128 '</form>' + 129 '</div>' + 130 '</div>'; 131 132 $(options.modalId).html(modalWindow).show().animate({opacity: 1}, 0, function () { 133 $(options.modalId).addClass('api-typo-open'); 134 $.fn.apiTypo('resize', options); 135 }); 136 }, 137 hideModal: function (options) { 138 $(options.modalId).remove().removeClass('api-typo-open'); 139 $('html').removeClass('api-typo-modal-active'); 140 }, 141 showMessage: function (options, data) { 142 $('html').addClass('api-typo-modal-active'); 143 144 var modalId = options.modalId.replace('#',''); 145 var dialogStyle = $(options.modalId + ' .api-typo-modal-dialog').attr('style'); 146 147 if (!$(options.modalId).length) 148 $('body').append('<div id="'+modalId+'" class="api-typo-modal fade"></div>'); 149 150 var modalMessage = '' + 151 '<div class="api-typo-modal-dialog" style="'+dialogStyle+'">' + 152 '<div class="api-typo-modal-close api-typo-close"></div>' + 153 '<div class="api-alert api-alert-success">' + 154 '<span></span>' + 155 '<div class="api-alert-title">'+data.message+'</div>' + 156 '</div>' + 157 '</div>'; 158 159 $(options.modalId).html(modalMessage).show().animate({opacity: 1}, 0, function () { 160 $(options.modalId).addClass('api-typo-open'); 161 $.fn.apiTypo('resize', options); 162 163 window.setTimeout(function(){ 164 $.fn.apiTypo('hideModal', options); 165 },2000); 166 }); 167 168 /*var alert = options.modalId + ' .api-alert'; 169 $(alert).animate({marginTop: -1*(parseInt($(alert).outerHeight())/2)}, 100, function () { 170 window.setTimeout(function(){ 171 $.fn.apiTypo('hideModal', options); 172 },2000); 173 });*/ 174 }, 175 resize: function (options) { 176 177 var modalId = options.modalId; 178 var dialog = $(modalId + ' .api-typo-modal-dialog'); 179 180 $('.api-typo-modal.api-typo-open').each(function () { 181 var dh = dialog.outerHeight(), 182 pad = parseInt(dialog.css('margin-top'), 10) + parseInt(dialog.css('margin-bottom'), 10); 183 184 if ((dh + pad) < window.innerHeight) { 185 dialog.animate({top: (window.innerHeight - (dh + pad)) / 2}, 100); 186 } else { 187 dialog.animate({top: ''}, 100); 188 } 189 }); 190 } 191 }; 192 193 $.fn.apiTypo = function (method) { 194 if (methods[method]) { 195 return methods[method].apply(this, Array.prototype.slice.call(arguments, 1)); 196 } else if (typeof method === 'object' || !method) { 197 return methods.init.apply(this, arguments); 198 } else { 199 $.error('Error! Method "' + method + '" not found in plugin $.fn.apiTypo'); 200 } 201 }; 202 203})(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.