Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Cookie
- function getCookie(name) {
- var matches = document.cookie.match(new RegExp(
- "(?:^|; )" + name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1') + "=([^;]*)"
- ))
- return matches ? decodeURIComponent(matches[1]) : undefined
- }
- function setCookie(name, value, props) {
- props = props || {}
- var exp = props.expires
- if (typeof exp == "number" && exp) {
- var d = new Date()
- d.setTime(d.getTime() + exp*1000)
- exp = props.expires = d
- }
- if(exp && exp.toUTCString) { props.expires = exp.toUTCString() }
- value = encodeURIComponent(value)
- var updatedCookie = name + "=" + value
- for(var propName in props){
- updatedCookie += "; " + propName
- var propValue = props[propName]
- if(propValue !== true){ updatedCookie += "=" + propValue }
- }
- document.cookie = updatedCookie
- }
- function deleteCookie(name) {
- setCookie(name, null, { expires: -1 })
- }
- //CLASSES
- function addClass(obj, name) {
- if ((obj = ge(obj)) && !hasClass(obj, name)) {
- obj.className = (obj.className ? obj.className + ' ' : '') + name;
- }
- }
- function removeClass(obj, name) {
- if (obj = ge(obj)) {
- obj.className = trim((obj.className || '').replace((new RegExp('(\\s|^)' + name + '(\\s|$)')), ' '));
- }
- }
- function replaceClass(obj, oldName, newName) {
- removeClass(obj, oldName);
- addClass(obj, newName);
- }
- //hash
- function getHash(){
- var hash = location.hash.replace('#', '');
- return hash;
- }
- //createElement
- function ce(tagName) {
- var el = document.createElement(tagName);
- return el;
- }
- //remove Element
- function re(el) {
- el = ge(el);
- if (el && el.parentNode) el.parentNode.removeChild(el);
- return el;
- }
- //style
- function sS(el, attr, value) {
- if (el=ge(el)){eval("el.style.attr=+value")}
- }
- //attributes
- function sA(el, attr, value) {
- if (el=ge(el)) {el.setAttribute(attr, value)}
- }
- function rA(el, attr, value) {
- var el=ge(el)
- if (ge(el)) {el.removeAttribute(attr)}
- }
- //request
- function ownFrameServerRequest(f,a,m,pl){
- //объявление переменных
- var requestFrameName = "IRequest";
- var form = ge(f);
- var pl = ge(pl);
- //вывод окна ожидания (окна создаются м выводятся после последнего ребёнка тела)
- popup_window('wait','Выполняется запрос!')
- //создаём фрейм
- pl.innerHTML="<iframe src='about:blank' hidden name='IRequest' height='250px'></iframe>"
- //присвоение атрибутов форме
- form.setAttribute("target",requestFrameName)
- form.setAttribute("action",a)
- form.setAttribute("method",m || "POST")
- form.setAttribute("accept-charset","utf-8")
- form.setAttribute("enctype","multipart/form-data")
- //отправка формы
- form.submit()
- //вывод результата
- //в зависимости от результата переход на главную, либо ничего если есть ошибки
- }
- //getElementById
- function ge(el) {
- return (typeof el == 'string' || typeof el == 'number') ? document.getElementById(el) : el;
- }
- //location
- function href(link){
- location.href=link
- }
- //popUps
- function popup_window(status,text,time,req){
- //ввод переменных
- var request = req;
- var cname = "popUp_contayner";
- var info = text.toUpperCase()
- //проверка наличия уже открытого окна
- if(cid = ge(cname)){rEl(cname);}//закрытие окна если существует
- //условия создания нового попАп
- if(status=="wait"){position="background-position: 0px 0px;"}
- else if(status=="ok"){position="background-position: -35px 0px;"}
- else{position="background-position: -70px 0px;"}
- //создание див\а
- var contayner = ce("div")
- contayner.id = cname
- document.body.appendChild(contayner)
- //параметры див\а
- sA(cname, "style", "width:100%;height:100%;")
- //наполнение контейнера
- contayner.innerHTML="<div style='z-index:99998;left:0;top:0;width:100%;height:100%;background:rgba(0,0,0,0.4);position:fixed;'></div><div style='z-index:99999;width:100%;height:100px;top:40%;position:fixed;'><div style='width:345px;height:55px;margin:0 auto;background:rgba(0,0,0,0.4);border-radius:10px;border: 4px solid rgba(0, 0, 0, 0.1);box-shadow: 0 0 30px rgba(0,0,0,0.6);'><div style='height:32px;width:35px;background:url(status.png);"+position+"margin:10px;float:left;'></div><div style='font-size:10pt;font-family:arial;color:white;margin:18px 0 0 30px;float:left;'><strong>"+info+"</strong></div></div></div>"
- //проверка автоматического закрытия окна
- if(time>0){setTimeout("document.getElementById('popUp_contayner').outerHTML=''",time * 1000)}
- if(req){window.location.pathname=request}
- }
- //userAgent
- if (!window._ua) {
- var _ua = navigator.userAgent.toLowerCase();
- }
- //parentNode
- function parent(el){
- el=ge(el)
- if(!el){return;}
- else{return el.parentNode};
- }
- //utilits
- function rand(mi, ma) { return Math.random() * (ma - mi + 1) + mi; }
- function irand(mi, ma) { return Math.floor(rand(mi, ma)); }
- function trim(text) { return (text || '').replace(/^\s+|\s+$/g, ''); }
- function stripHTML(text) { return text ? text.replace(/<(?:.|\s)*?>/g, '') : ''; }
- function intval(value){
- if(value===true) return 1;
- return parseInt(value) || 0;
- }
- function floatval(value) {
- if (value === true) return 1;
- return parseFloat(value) || 0;
- }
- function positive(value) {
- value = intval(value);
- return value < 0 ? 0 : value;
- }
- //scrolling get
- function scrollGetY() {
- return window.pageYOffset || scrollNode.scrollTop || document.documentElement.scrollTop;
- }
- function scrollGetX() {
- return window.pageXOffset || scrollNode.scrollLeft || document.documentElement.scrollLeft;
- }
- //setFavIcon
- function setFavIcon(href) {
- if (!window.icoNode) return;
- if (icoNode.href == href) return;
- var ico = ce('link', {rel: 'shortcut icon', type: 'image/gif', href: href});
- headNode.replaceChild(ico, icoNode);
- icoNode = ico;
- }
- //parse
- function parseLatin(text){
- var outtext = text;
- var lat1 = ['yo','zh','kh','ts','ch','sch','shch','sh','eh','yu','ya','YO','ZH','KH','TS','CH','SCH','SHCH','SH','EH','YU','YA',"'"];
- var rus1 = ['ё', 'ж', 'х', 'ц', 'ч', 'щ', 'щ', 'ш', 'э', 'ю', 'я', 'Ё', 'Ж', 'Х', 'Ц', 'Ч', 'Щ', 'Щ', 'Ш', 'Э', 'Ю', 'Я', 'ь'];
- for (var i = 0, l = lat1.length; i < l; i++) {
- outtext = outtext.split(lat1[i]).join(rus1[i]);
- }
- var lat2 = 'abvgdezijklmnoprstufhcyABVGDEZIJKLMNOPRSTUFHCYёЁ';
- var rus2 = 'абвгдезийклмнопрстуфхцыАБВГДЕЗИЙКЛМНОПРСТУФХЦЫеЕ';
- for (var i = 0, l = lat2.length; i < l; i++) {
- outtext = outtext.split(lat2.charAt(i)).join(rus2.charAt(i));
- }
- return (outtext == text) ? null : outtext;
- }
- function parseLatKeys(text) {
- var outtext = text, i;
- lat = "qwertyuiop[]asdfghjkl;'zxcvbnm,./`",
- rus = "йцукенгшщзхъфывапролджэячсмитьбю.ё";
- for (i = 0; i < lat.length; i++) {
- outtext = outtext.split(lat.charAt(i)).join(rus.charAt(i));
- }
- return (outtext == text) ? false : outtext;
- }
- function parseCyr(text) {
- var outtext = text, i,
- lat1 = ['yo','zh','kh','ts','ch','sch','shch','sh','eh','yu','ya','YO','ZH','KH','TS','CH','SCH','SHCH','SH','EH','YU','YA',"'"],
- rus1 = ['ё', 'ж', 'х', 'ц', 'ч', 'щ', 'щ', 'ш', 'э', 'ю', 'я', 'Ё', 'Ж', 'Х', 'Ц', 'Ч', 'Щ', 'Щ', 'Ш', 'Э', 'Ю', 'Я', 'ь'],
- lat2 = 'abvgdezijklmnoprstufhcyABVGDEZIJKLMNOPRSTUFHCYёЁ',
- rus2 = 'абвгдезийклмнопрстуфхцыАБВГДЕЗИЙКЛМНОПРСТУФХЦЫеЕ';
- for (i = 0; i < rus1.length; i++) {
- outtext = outtext.split(rus1[i]).join(lat1[i]);
- }
- for (i = 0; i < rus2.length; i++) {
- outtext = outtext.split(rus2.charAt(i)).join(lat2.charAt(i));
- }
- return (outtext == text) ? false : outtext;
- }
Add Comment
Please, Sign In to add comment