-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.imageengine.js
102 lines (87 loc) · 3.31 KB
/
jquery.imageengine.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/// <reference path="~/Content/Scripts/jquery-1.10.2.min.js" />
if (!jQuery)
throw new Error("The ImageEngine plugin requires jQuery");
// =========================================================
// Implementation
(function ($) {
$.fn.imageEngine = function (options) {
var settings = $.extend({
accountType: "normal",
addBootstrapResponsive: true,
debug: false,
account: "",
width: "",
height: "",
percentage: "",
compression: "",
mode: "",
transparencyColor: "",
format:""
}, options);
this.filter("img").each(function () {
var computedUrl = "//try.imgeng.in/";
var img = $(this);
// =========================================================
// Turn the IMG source into an absolute URL
var absoluteUrl = img.attr("src");
var r = new RegExp('^(?:[a-z]+:)?//', 'i');
if (!r.test(absoluteUrl)) {
absoluteUrl = window.location.origin + absoluteUrl;
}
// =========================================================
// Manage WIT settings
// Fix account reference
if (settings.account) {
//Lite account is not recommended for new installations!
if (accountType === "lite") {
computedUrl = "//" + settings.account + ".lite.imgeng.in/";
}else{
computedUrl = "//" + settings.account + ".imgeng.in/";
}
}
// width-height || percentage
if (settings.width || settings.height) {
if (settings.width) {
computedUrl += "w_" + settings.width + "/";
}
if (settings.height) {
computedUrl += "h_" + settings.height + "/";
}
} else {
if (settings.percentage) {
computedUrl += "pc_" + settings.percentage + "/";
}
}
// fit mode
if (settings.mode) {
computedUrl += "m_" + settings.mode;
if (settings.mode === "letterbox" && settings.transparencyColor) {
computedUrl += "_" + settings.transparencyColor;
}
computedUrl += "/";
}
// image format
if (settings.format) {
computedUrl += "f_" + settings.format + "/";
}
// compression rate
if (settings.compression) {
computedUrl += "cmpr_" + settings.compression + "/";
}
// =========================================================
// Core work
computedUrl += absoluteUrl;
img.attr("src", computedUrl);
// =========================================================
// Further configuration
if (settings.addBootstrapResponsive) {
img.addClass("img-responsive");
}
if (settings.debug) {
img.attr("alt", computedUrl);
img.attr("title", computedUrl);
}
});
return this;
};
}(jQuery));