Convert base scripts and styles to embedded resources and move to VAR.WebForms.Common.
This commit is contained in:
94
VAR.WebForms.Common/Scripts/01. Base.js
Normal file
94
VAR.WebForms.Common/Scripts/01. Base.js
Normal file
@@ -0,0 +1,94 @@
|
||||
////////////////////////
|
||||
// GetElement
|
||||
//
|
||||
function GetElement(element) {
|
||||
if (typeof element === "string") {
|
||||
element = document.getElementById(element);
|
||||
}
|
||||
return element;
|
||||
}
|
||||
|
||||
////////////////////////
|
||||
// ElementAddClass
|
||||
//
|
||||
function ElementAddClass(element, classname) {
|
||||
element = GetElement(element);
|
||||
if (!element) { return; }
|
||||
var cn = element.className;
|
||||
if (cn.indexOf(classname) !== -1) {
|
||||
return;
|
||||
}
|
||||
if (cn !== '') {
|
||||
classname = ' ' + classname;
|
||||
}
|
||||
element.className = cn + classname;
|
||||
}
|
||||
|
||||
////////////////////////
|
||||
// ElementRemoveClass
|
||||
//
|
||||
function ElementRemoveClass(element, className) {
|
||||
element = GetElement(element);
|
||||
if (!element) { return; }
|
||||
var regex = new RegExp('(?:^|\\s)' + className + '(?!\\S)');
|
||||
if (regex.test(element.className)) {
|
||||
element.className = element.className.replace(regex, '');
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////
|
||||
// ElementToggleClass
|
||||
//
|
||||
function ElementToggleClass(element, className) {
|
||||
element = GetElement(element);
|
||||
if (!element) { return; }
|
||||
var regex = new RegExp('(?:^|\\s)' + className + '(?!\\S)');
|
||||
if (regex.test(element.className)) {
|
||||
element.className = element.className.replace(regex, '');
|
||||
return true;
|
||||
} else {
|
||||
element.className = element.className + ' ' + className;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function escapeHTML(s) {
|
||||
return s.replace(/&/g, '&')
|
||||
.replace(/"/g, '"')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>');
|
||||
}
|
||||
|
||||
function fixedEncodeURIComponent(str) {
|
||||
return encodeURIComponent(str).replace(/[!'()*]/g, function (c) {
|
||||
return '%' + c.charCodeAt(0).toString(16);
|
||||
});
|
||||
}
|
||||
|
||||
////////////////////////
|
||||
// localStorage polyfill
|
||||
//
|
||||
if (!window.localStorage) {
|
||||
window.localStorage = {
|
||||
getItem: function (sKey) {
|
||||
if (!sKey || !this.hasOwnProperty(sKey)) { return null; }
|
||||
return unescape(document.cookie.replace(new RegExp("(?:^|.*;\\s*)" + escape(sKey).replace(/[\-\.\+\*]/g, "\\$&") + "\\s*\\=\\s*((?:[^;](?!;))*[^;]?).*"), "$1"));
|
||||
},
|
||||
key: function (nKeyId) { return unescape(document.cookie.replace(/\s*\=(?:.(?!;))*$/, "").split(/\s*\=(?:[^;](?!;))*[^;]?;\s*/)[nKeyId]); },
|
||||
setItem: function (sKey, sValue) {
|
||||
if (!sKey) { return; }
|
||||
document.cookie = escape(sKey) + "=" + escape(sValue) + "; path=/";
|
||||
this.length = document.cookie.match(/\=/g).length;
|
||||
},
|
||||
length: 0,
|
||||
removeItem: function (sKey) {
|
||||
if (!sKey || !this.hasOwnProperty(sKey)) { return; }
|
||||
var sExpDate = new Date();
|
||||
sExpDate.setDate(sExpDate.getDate() - 1);
|
||||
document.cookie = escape(sKey) + "=; expires=" + sExpDate.toGMTString() + "; path=/";
|
||||
this.length--;
|
||||
},
|
||||
hasOwnProperty: function (sKey) { return (new RegExp("(?:^|;\\s*)" + escape(sKey).replace(/[\-\.\+\*]/g, "\\$&") + "\\s*\\=")).test(document.cookie); }
|
||||
};
|
||||
window.localStorage.length = (document.cookie.match(/\=/g) || window.localStorage).length;
|
||||
}
|
||||
124
VAR.WebForms.Common/Scripts/02. Ajax.js
Normal file
124
VAR.WebForms.Common/Scripts/02. Ajax.js
Normal file
@@ -0,0 +1,124 @@
|
||||
function SendRequest(url, data, onData, onError) {
|
||||
var xhr = new XMLHttpRequest();
|
||||
if (data) {
|
||||
url += "?" + GetDataQueryString(data);
|
||||
}
|
||||
xhr.open("GET", url, true);
|
||||
xhr.onreadystatechange = function () {
|
||||
if (xhr.readyState === 4) {
|
||||
if (xhr.status === 200) {
|
||||
if (onData) {
|
||||
onData(xhr.responseText);
|
||||
}
|
||||
} else {
|
||||
if (onError) {
|
||||
onError();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
xhr.send(null);
|
||||
}
|
||||
|
||||
function GetDataQueryString(data) {
|
||||
var queryString = "";
|
||||
for (var property in data) {
|
||||
if (data.hasOwnProperty(property)) {
|
||||
var value = data[property];
|
||||
queryString += (queryString.length > 0 ? "&" : "")
|
||||
+ fixedEncodeURIComponent(property) + "="
|
||||
+ fixedEncodeURIComponent(String(value));
|
||||
}
|
||||
}
|
||||
return queryString;
|
||||
}
|
||||
|
||||
function SendData(url, data, onData, onError) {
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open("POST", url, true);
|
||||
xhr.onreadystatechange = function () {
|
||||
if (xhr.readyState === 4) {
|
||||
if (xhr.status === 200) {
|
||||
if (onData) {
|
||||
onData(xhr.responseText);
|
||||
}
|
||||
} else {
|
||||
if (onError) {
|
||||
onError();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
xhr.setRequestHeader('Content-Type',
|
||||
'application/x-www-form-urlencoded');
|
||||
xhr.send(GetDataQueryString(data));
|
||||
}
|
||||
|
||||
function GetFormQueryString(idForm) {
|
||||
var form = document.getElementById(idForm);
|
||||
var queryString = "";
|
||||
if (!form)
|
||||
return null;
|
||||
|
||||
function appendVal(name, value) {
|
||||
queryString += (queryString.length > 0 ? "&" : "")
|
||||
+ fixedEncodeURIComponent(name) + "="
|
||||
+ fixedEncodeURIComponent(value ? value : "");
|
||||
}
|
||||
|
||||
var elements = form.elements;
|
||||
for (var i = 0; i < elements.length; i++) {
|
||||
var element = elements[i];
|
||||
var elemType = element.type.toUpperCase();
|
||||
var elemName = element.name;
|
||||
|
||||
if (elemName) {
|
||||
if (
|
||||
elemType.indexOf("TEXT") !== -1 ||
|
||||
elemType.indexOf("TEXTAREA") !== -1 ||
|
||||
elemType.indexOf("PASSWORD") !== -1 ||
|
||||
elemType.indexOf("BUTTON") !== -1 ||
|
||||
elemType.indexOf("HIDDEN") !== -1 ||
|
||||
elemType.indexOf("SUBMIT") !== -1 ||
|
||||
elemType.indexOf("IMAGE") !== -1
|
||||
) {
|
||||
appendVal(elemName, element.value);
|
||||
} else if (elemType.indexOf("CHECKBOX") !== -1 && element.checked) {
|
||||
appendVal(elemName, element.value ? element.value : "On");
|
||||
} else if (elemType.indexOf("RADIO") !== -1 && element.checked) {
|
||||
appendVal(elemName, element.value);
|
||||
} else if (elemType.indexOf("SELECT") !== -1) {
|
||||
for (var j = 0; j < element.options.length; j++) {
|
||||
var option = element.options[j];
|
||||
if (option.selected) {
|
||||
appendVal(elemName,
|
||||
option.value ? option.value : option.text);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return queryString;
|
||||
}
|
||||
|
||||
function SendForm(url, idForm, onData, onError) {
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open("POST", url, true);
|
||||
xhr.onreadystatechange = function () {
|
||||
if (xhr.readyState === 4) {
|
||||
if (xhr.status === 200) {
|
||||
if (onData) {
|
||||
onData(xhr.responseText);
|
||||
}
|
||||
} else {
|
||||
if (onError) {
|
||||
onError();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
xhr.setRequestHeader('Content-Type',
|
||||
'application/x-www-form-urlencoded');
|
||||
xhr.send(GetFormQueryString(idForm));
|
||||
}
|
||||
85
VAR.WebForms.Common/Scripts/03. Controls.js
Normal file
85
VAR.WebForms.Common/Scripts/03. Controls.js
Normal file
@@ -0,0 +1,85 @@
|
||||
|
||||
////////////////////////
|
||||
// CTextBox_Multilin_SetText
|
||||
//
|
||||
var CTextBox_SetText = function (id, text) {
|
||||
var element = document.getElementById(id);
|
||||
element.value = text;
|
||||
};
|
||||
|
||||
////////////////////////
|
||||
// CTextBox_Multiline_KeyDown
|
||||
//
|
||||
var CTextBox_Multiline_KeyDown = function (e) {
|
||||
if (e.keyCode === 9 || e.which === 9) {
|
||||
e.preventDefault();
|
||||
var s = this.selectionStart;
|
||||
this.value = this.value.substring(0, this.selectionStart) + "\t" + this.value.substring(this.selectionEnd);
|
||||
this.selectionEnd = s + 1;
|
||||
}
|
||||
};
|
||||
|
||||
////////////////////////
|
||||
// CTextBox_Multiline_SaveSizeData
|
||||
//
|
||||
var CTextBox_Multiline_SaveSizeData = function (textArea) {
|
||||
var hidSizeData = document.getElementById(textArea.cfg.hidSize);
|
||||
hidSizeData.value = JSON.stringify(textArea.cfg.size);
|
||||
};
|
||||
|
||||
////////////////////////
|
||||
// CTextBox_Multiline_RestoreSizeData
|
||||
//
|
||||
var CTextBox_Multiline_RestoreSizeData = function (textArea) {
|
||||
var hidSizeData = document.getElementById(textArea.cfg.hidSize);
|
||||
|
||||
if (hidSizeData.value !== "") {
|
||||
textArea.cfg.size = JSON.parse(hidSizeData.value);
|
||||
if (textArea.cfg.size.width !== null) {
|
||||
textArea.style.width = textArea.cfg.size.width + "px";
|
||||
}
|
||||
if (textArea.cfg.size.height !== null) {
|
||||
textArea.style.height = textArea.cfg.size.height + "px";
|
||||
}
|
||||
if (textArea.cfg.size.scrollTop !== null) {
|
||||
textArea.scrollTop = textArea.cfg.size.scrollTop;
|
||||
}
|
||||
}
|
||||
textArea.cfg.size = { height: textArea.offsetHeight, width: textArea.offsetWidth, scrollTop: textArea.scrollTop };
|
||||
};
|
||||
|
||||
////////////////////////
|
||||
// CTextBox_Multiline_MouseUp
|
||||
//
|
||||
var CTextBox_Multiline_MouseUp = function (e) {
|
||||
var textArea = e.target;
|
||||
var newSize = { height: textArea.offsetHeight, width: textArea.offsetWidth, scrollTop: textArea.scrollTop };
|
||||
if (textArea.cfg.size.height !== newSize.height) {
|
||||
textArea.cfg.size = newSize;
|
||||
CTextBox_Multiline_SaveSizeData(textArea);
|
||||
}
|
||||
};
|
||||
|
||||
////////////////////////
|
||||
// CTextBox_Multiline_Scrolled
|
||||
//
|
||||
var CTextBox_Multiline_Scrolled = function (e) {
|
||||
var textArea = e.target;
|
||||
textArea.cfg.size = { height: textArea.offsetHeight, width: textArea.offsetWidth, scrollTop: textArea.scrollTop };
|
||||
CTextBox_Multiline_SaveSizeData(textArea);
|
||||
};
|
||||
|
||||
////////////////////////
|
||||
// CTextBox_Multiline_Init
|
||||
//
|
||||
var CTextBox_Multiline_Init = function (cfg) {
|
||||
var textArea = document.getElementById(cfg.txtContent);
|
||||
textArea.cfg = cfg;
|
||||
|
||||
textArea.onkeydown = CTextBox_Multiline_KeyDown;
|
||||
if (cfg.keepSize) {
|
||||
CTextBox_Multiline_RestoreSizeData(textArea);
|
||||
textArea.onmouseup = CTextBox_Multiline_MouseUp;
|
||||
textArea.onscroll = CTextBox_Multiline_Scrolled;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user