vendor: 8,077 bytes, lines 1-205
1// Unobtrusive Ajax support library for jQuery 2// Copyright (c) .NET Foundation. All rights reserved. 3// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 4// @version v3.2.6 5// 6// Microsoft grants you the right to use these script files for the sole 7// purpose of either: (i) interacting through your browser with the Microsoft 8// website or online service, subject to the applicable licensing or use 9// terms; or (ii) using the files as included with a Microsoft product subject 10// to that product's license terms. Microsoft reserves all other rights to the 11// files not expressly granted by Microsoft, whether by implication, estoppel 12// or otherwise. Insofar as a script file is dual licensed under GPL, 13// Microsoft neither took the code under GPL nor distributes it thereunder but 14// under the terms set out in this paragraph. All notices and licenses 15// below are for informational purposes only. 16 17/*jslint white: true, browser: true, onevar: true, undef: true, nomen: true, eqeqeq: true, plusplus: true, bitwise: true, regexp: true, newcap: true, immed: true, strict: false */ 18/*global window: false, jQuery: false */ 19 20(function ($) { 21 var data_click = "unobtrusiveAjaxClick", 22 data_target = "unobtrusiveAjaxClickTarget", 23 data_validation = "unobtrusiveValidation"; 24 25 function getFunction(code, argNames) { 26 var fn = window, parts = (code || "").split("."); 27 while (fn && parts.length) { 28 fn = fn[parts.shift()]; 29 } 30 if (typeof (fn) === "function") { 31 return fn; 32 } 33 argNames.push(code); 34 return Function.constructor.apply(null, argNames); 35 } 36 37 function isMethodProxySafe(method) { 38 return method === "GET" || method === "POST"; 39 } 40 41 function asyncOnBeforeSend(xhr, method) { 42 if (!isMethodProxySafe(method)) { 43 xhr.setRequestHeader("X-HTTP-Method-Override", method); 44 } 45 } 46 47 function asyncOnSuccess(element, data, contentType) { 48 var mode; 49 50 if (contentType.indexOf("application/x-javascript") !== -1) { // jQuery already executes JavaScript for us 51 return; 52 } 53 54 mode = (element.getAttribute("data-ajax-mode") || "").toUpperCase(); 55 $(element.getAttribute("data-ajax-update")).each(function (i, update) { 56 var top; 57 58 switch (mode) { 59 case "BEFORE": 60 $(update).prepend(data); 61 break; 62 case "AFTER": 63 $(update).append(data); 64 break; 65 case "REPLACE-WITH": 66 $(update).replaceWith(data); 67 break; 68 default: 69 $(update).html(data); 70 break; 71 } 72 }); 73 } 74 75 function asyncRequest(element, options) { 76 var confirm, loading, method, duration; 77 78 confirm = element.getAttribute("data-ajax-confirm"); 79 if (confirm && !window.confirm(confirm)) { 80 return; 81 } 82 83 loading = $(element.getAttribute("data-ajax-loading")); 84 duration = parseInt(element.getAttribute("data-ajax-loading-duration"), 10) || 0; 85 86 $.extend(options, { 87 type: element.getAttribute("data-ajax-method") || undefined, 88 url: element.getAttribute("data-ajax-url") || undefined, 89 cache: (element.getAttribute("data-ajax-cache") || "").toLowerCase() === "true", 90 beforeSend: function (xhr) { 91 var result; 92 asyncOnBeforeSend(xhr, method); 93 result = getFunction(element.getAttribute("data-ajax-begin"), ["xhr"]).apply(element, arguments); 94 if (result !== false) { 95 loading.show(duration); 96 } 97 return result; 98 }, 99 complete: function () { 100 loading.hide(duration); 101 getFunction(element.getAttribute("data-ajax-complete"), ["xhr", "status"]).apply(element, arguments); 102 }, 103 success: function (data, status, xhr) { 104 asyncOnSuccess(element, data, xhr.getResponseHeader("Content-Type") || "text/html"); 105 getFunction(element.getAttribute("data-ajax-success"), ["data", "status", "xhr"]).apply(element, arguments); 106 }, 107 error: function () { 108 getFunction(element.getAttribute("data-ajax-failure"), ["xhr", "status", "error"]).apply(element, arguments); 109 } 110 }); 111 112 options.data.push({ name: "X-Requested-With", value: "XMLHttpRequest" }); 113 114 method = options.type.toUpperCase(); 115 if (!isMethodProxySafe(method)) { 116 options.type = "POST"; 117 options.data.push({ name: "X-HTTP-Method-Override", value: method }); 118 } 119 120 // change here: 121 // Check for a Form POST with enctype=multipart/form-data 122 // add the input file that were not previously included in the serializeArray() 123 // set processData and contentType to false 124 var $element = $(element); 125 if ($element.is("form") && $element.attr("enctype") == "multipart/form-data") { 126 var formdata = new FormData(); 127 $.each(options.data, function (i, v) { 128 formdata.append(v.name, v.value); 129 }); 130 $("input[type=file]", $element).each(function () { 131 var file = this; 132 $.each(file.files, function (n, v) { 133 formdata.append(file.name, v); 134 }); 135 }); 136 $.extend(options, { 137 processData: false, 138 contentType: false, 139 data: formdata 140 }); 141 } 142 // end change 143 144 $.ajax(options); 145 } 146 147 function validate(form) { 148 var validationInfo = $(form).data(data_validation); 149 return !validationInfo || !validationInfo.validate || validationInfo.validate(); 150 } 151 152 $(document).on("click", "a[data-ajax=true]", function (evt) { 153 evt.preventDefault(); 154 asyncRequest(this, { 155 url: this.href, 156 type: "GET", 157 data: [] 158 }); 159 }); 160 161 $(document).on("click", "form[data-ajax=true] input[type=image]", function (evt) { 162 var name = evt.target.name, 163 target = $(evt.target), 164 form = $(target.parents("form")[0]), 165 offset = target.offset(); 166 167 form.data(data_click, [ 168 { name: name + ".x", value: Math.round(evt.pageX - offset.left) }, 169 { name: name + ".y", value: Math.round(evt.pageY - offset.top) } 170 ]); 171 172 setTimeout(function () { 173 form.removeData(data_click); 174 }, 0); 175 }); 176 177 $(document).on("click", "form[data-ajax=true] :submit", function (evt) { 178 var name = evt.currentTarget.name, 179 target = $(evt.target), 180 form = $(target.parents("form")[0]); 181 182 form.data(data_click, name ? [{ name: name, value: evt.currentTarget.value }] : []); 183 form.data(data_target, target); 184 185 setTimeout(function () { 186 form.removeData(data_click); 187 form.removeData(data_target); 188 }, 0); 189 }); 190 191 $(document).on("submit", "form[data-ajax=true]", function (evt) { 192 var clickInfo = $(this).data(data_click) || [], 193 clickTarget = $(this).data(data_target), 194 isCancel = clickTarget && (clickTarget.hasClass("cancel") || clickTarget.attr('formnovalidate') !== undefined); 195 evt.preventDefault(); 196 if (!isCancel && !validate(this)) { 197 return; 198 } 199 asyncRequest(this, { 200 url: this.action, 201 type: this.method || "GET", 202 data: clickInfo.concat($(this).serializeArray()) 203 }); 204 }); 205}(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.