Skip to content

Commit c48f44f

Browse files
committed
Updated gulp file to add version to license header
Related to aspnet/jquery-validation-unobtrusive#51
1 parent 0c45b5c commit c48f44f

File tree

8 files changed

+285
-43
lines changed

8 files changed

+285
-43
lines changed

.gitattributes

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
*.doc diff=astextplain
2+
*.DOC diff=astextplain
3+
*.docx diff=astextplain
4+
*.DOCX diff=astextplain
5+
*.dot diff=astextplain
6+
*.DOT diff=astextplain
7+
*.pdf diff=astextplain
8+
*.PDF diff=astextplain
9+
*.rtf diff=astextplain
10+
*.RTF diff=astextplain
11+
12+
*.jpg binary
13+
*.png binary
14+
*.gif binary
15+
16+
*.cs text=auto diff=csharp
17+
*.vb text=auto
18+
*.resx text=auto
19+
*.c text=auto
20+
*.cpp text=auto
21+
*.cxx text=auto
22+
*.h text=auto
23+
*.hxx text=auto
24+
*.py text=auto
25+
*.rb text=auto
26+
*.java text=auto
27+
*.html text=auto
28+
*.htm text=auto
29+
*.css text=auto
30+
*.scss text=auto
31+
*.sass text=auto
32+
*.less text=auto
33+
*.js text=auto
34+
*.lisp text=auto
35+
*.clj text=auto
36+
*.sql text=auto
37+
*.php text=auto
38+
*.lua text=auto
39+
*.m text=auto
40+
*.asm text=auto
41+
*.erl text=auto
42+
*.fs text=auto
43+
*.fsx text=auto
44+
*.hs text=auto
45+
46+
*.csproj text=auto
47+
*.vbproj text=auto
48+
*.fsproj text=auto
49+
*.dbproj text=auto
50+
*.sln text=auto eol=crlf
51+
52+
*.sh eol=lf

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"homepage": "https://github.com/aspnet/jquery-ajax-unobtrusive",
55
"description": "Add-on to jQuery Ajax to enable unobtrusive options in data-* attributes",
66
"main": [
7-
"jquery.unobtrusive-ajax.js"
7+
"dist/jquery.unobtrusive-ajax.js"
88
],
99
"ignore": [
1010
"**/.*",
Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1-
/*
2-
* Microsoft grants you the right to use these script files for the sole
3-
* purpose of either: (i) interacting through your browser with the Microsoft
4-
* website or online service, subject to the applicable licensing or use
5-
* terms; or (ii) using the files as included with a Microsoft product subject
6-
* to that product's license terms. Microsoft reserves all other rights to the
7-
* files not expressly granted by Microsoft, whether by implication, estoppel
8-
* or otherwise. Insofar as a script file is dual licensed under GPL,
9-
* Microsoft neither took the code under GPL nor distributes it thereunder but
10-
* under the terms set out in this paragraph. All notices and licenses
11-
* below are for informational purposes only.
12-
/*!
13-
** Unobtrusive Ajax support library for jQuery
14-
** Copyright (C) Microsoft Corporation. All rights reserved.
15-
*/
1+
// Unobtrusive Ajax support library for jQuery
2+
// Copyright (C) Microsoft Corporation. All rights reserved.
3+
// @version v3.2.4
4+
//
5+
// Microsoft grants you the right to use these script files for the sole
6+
// purpose of either: (i) interacting through your browser with the Microsoft
7+
// website or online service, subject to the applicable licensing or use
8+
// terms; or (ii) using the files as included with a Microsoft product subject
9+
// to that product's license terms. Microsoft reserves all other rights to the
10+
// files not expressly granted by Microsoft, whether by implication, estoppel
11+
// or otherwise. Insofar as a script file is dual licensed under GPL,
12+
// Microsoft neither took the code under GPL nor distributes it thereunder but
13+
// under the terms set out in this paragraph. All notices and licenses
14+
// below are for informational purposes only.
1615

1716
/*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 */
1817
/*global window: false, jQuery: false */

dist/jquery.unobtrusive-ajax.min.js

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gulpfile.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
var gulp = require("gulp"),
22
uglify = require("gulp-uglify"),
3-
rename = require('gulp-rename');
3+
rename = require('gulp-rename'),
4+
replace = require('gulp-replace'),
5+
lec = require('gulp-line-ending-corrector'),
6+
pkg = require('./package.json');
47

5-
gulp.task("minifyJS", function () {
6-
gulp.src(["jquery-ajax-unobtrusive.js"], { base: "." })
7-
.pipe(uglify())
8+
gulp.task("minifyJS", function(){
9+
gulp.src(["src/jquery.unobtrusive-ajax.js"])
10+
.pipe(replace(/@version.*/, '@version v' + pkg.version))
11+
.pipe(gulp.dest("dist"))
12+
.pipe(uglify({
13+
preserveComments: 'license'
14+
}))
15+
.pipe(lec({eolc: 'CRLF'}))
816
.pipe(rename({suffix: '.min'}))
9-
.pipe(gulp.dest("."));
17+
.pipe(gulp.dest("dist"));
1018
});
1119

1220
gulp.task("default", ["minifyJS"]);

jquery.unobtrusive-ajax.min.js

Lines changed: 0 additions & 19 deletions
This file was deleted.

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "jquery-ajax-unobtrusive",
33
"version": "3.2.4",
44
"description": "Add-on to jQuery Ajax to enable unobtrusive options in data-* attributes",
5-
"main": "jquery.unobtrusive-ajax.js",
5+
"main": "dist/jquery.unobtrusive-ajax.js",
66
"repository": {
77
"type": "git",
88
"url": "https://github.com/aspnet/jquery-ajax-unobtrusive"
@@ -24,8 +24,10 @@
2424
"jquery": ">=1.8"
2525
},
2626
"devDependencies": {
27-
"gulp": "3.8.11",
27+
"gulp": "3.9.1",
2828
"gulp-rename": "1.2.2",
29-
"gulp-uglify": "1.2.0"
29+
"gulp-uglify": "2.0.0",
30+
"gulp-replace": "0.5.4",
31+
"gulp-line-ending-corrector": "1.0.1"
3032
}
3133
}

src/jquery.unobtrusive-ajax.js

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

0 commit comments

Comments
 (0)