Guest User

Untitled

a guest
Dec 1st, 2018
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.53 KB | None | 0 0
  1. //Cookie
  2. function getCookie(name) {
  3. var matches = document.cookie.match(new RegExp(
  4. "(?:^|; )" + name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1') + "=([^;]*)"
  5. ))
  6. return matches ? decodeURIComponent(matches[1]) : undefined
  7. }
  8. function setCookie(name, value, props) {
  9. props = props || {}
  10. var exp = props.expires
  11. if (typeof exp == "number" && exp) {
  12. var d = new Date()
  13. d.setTime(d.getTime() + exp*1000)
  14. exp = props.expires = d
  15. }
  16. if(exp && exp.toUTCString) { props.expires = exp.toUTCString() }
  17.  
  18. value = encodeURIComponent(value)
  19. var updatedCookie = name + "=" + value
  20. for(var propName in props){
  21. updatedCookie += "; " + propName
  22. var propValue = props[propName]
  23. if(propValue !== true){ updatedCookie += "=" + propValue }
  24. }
  25. document.cookie = updatedCookie
  26.  
  27. }
  28. function deleteCookie(name) {
  29. setCookie(name, null, { expires: -1 })
  30. }
  31.  
  32.  
  33. //CLASSES
  34. function addClass(obj, name) {
  35. if ((obj = ge(obj)) && !hasClass(obj, name)) {
  36. obj.className = (obj.className ? obj.className + ' ' : '') + name;
  37. }
  38. }
  39. function removeClass(obj, name) {
  40. if (obj = ge(obj)) {
  41. obj.className = trim((obj.className || '').replace((new RegExp('(\\s|^)' + name + '(\\s|$)')), ' '));
  42. }
  43. }
  44. function replaceClass(obj, oldName, newName) {
  45. removeClass(obj, oldName);
  46. addClass(obj, newName);
  47. }
  48.  
  49. //hash
  50. function getHash(){
  51. var hash = location.hash.replace('#', '');
  52. return hash;
  53. }
  54.  
  55. //createElement
  56. function ce(tagName) {
  57. var el = document.createElement(tagName);
  58. return el;
  59. }
  60.  
  61. //remove Element
  62. function re(el) {
  63. el = ge(el);
  64. if (el && el.parentNode) el.parentNode.removeChild(el);
  65. return el;
  66. }
  67.  
  68. //style
  69. function sS(el, attr, value) {
  70. if (el=ge(el)){eval("el.style.attr=+value")}
  71. }
  72.  
  73. //attributes
  74. function sA(el, attr, value) {
  75. if (el=ge(el)) {el.setAttribute(attr, value)}
  76. }
  77. function rA(el, attr, value) {
  78. var el=ge(el)
  79. if (ge(el)) {el.removeAttribute(attr)}
  80. }
  81.  
  82. //request
  83. function ownFrameServerRequest(f,a,m,pl){
  84. //объявление переменных
  85. var requestFrameName = "IRequest";
  86. var form = ge(f);
  87. var pl = ge(pl);
  88. //вывод окна ожидания (окна создаются м выводятся после последнего ребёнка тела)
  89. popup_window('wait','Выполняется запрос!')
  90. //создаём фрейм
  91. pl.innerHTML="<iframe src='about:blank' hidden name='IRequest' height='250px'></iframe>"
  92. //присвоение атрибутов форме
  93. form.setAttribute("target",requestFrameName)
  94. form.setAttribute("action",a)
  95. form.setAttribute("method",m || "POST")
  96. form.setAttribute("accept-charset","utf-8")
  97. form.setAttribute("enctype","multipart/form-data")
  98. //отправка формы
  99. form.submit()
  100. //вывод результата
  101. //в зависимости от результата переход на главную, либо ничего если есть ошибки
  102. }
  103.  
  104. //getElementById
  105. function ge(el) {
  106. return (typeof el == 'string' || typeof el == 'number') ? document.getElementById(el) : el;
  107. }
  108.  
  109. //location
  110. function href(link){
  111. location.href=link
  112. }
  113.  
  114. //popUps
  115. function popup_window(status,text,time,req){
  116. //ввод переменных
  117. var request = req;
  118. var cname = "popUp_contayner";
  119. var info = text.toUpperCase()
  120. //проверка наличия уже открытого окна
  121. if(cid = ge(cname)){rEl(cname);}//закрытие окна если существует
  122. //условия создания нового попАп
  123. if(status=="wait"){position="background-position: 0px 0px;"}
  124. else if(status=="ok"){position="background-position: -35px 0px;"}
  125. else{position="background-position: -70px 0px;"}
  126. //создание див\а
  127. var contayner = ce("div")
  128. contayner.id = cname
  129. document.body.appendChild(contayner)
  130. //параметры див\а
  131. sA(cname, "style", "width:100%;height:100%;")
  132. //наполнение контейнера
  133. 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>"
  134. //проверка автоматического закрытия окна
  135. if(time>0){setTimeout("document.getElementById('popUp_contayner').outerHTML=''",time * 1000)}
  136. if(req){window.location.pathname=request}
  137. }
  138.  
  139. //userAgent
  140. if (!window._ua) {
  141. var _ua = navigator.userAgent.toLowerCase();
  142. }
  143.  
  144. //parentNode
  145. function parent(el){
  146. el=ge(el)
  147. if(!el){return;}
  148. else{return el.parentNode};
  149. }
  150.  
  151. //utilits
  152. function rand(mi, ma) { return Math.random() * (ma - mi + 1) + mi; }
  153. function irand(mi, ma) { return Math.floor(rand(mi, ma)); }
  154. function trim(text) { return (text || '').replace(/^\s+|\s+$/g, ''); }
  155. function stripHTML(text) { return text ? text.replace(/<(?:.|\s)*?>/g, '') : ''; }
  156. function intval(value){
  157. if(value===true) return 1;
  158. return parseInt(value) || 0;
  159. }
  160. function floatval(value) {
  161. if (value === true) return 1;
  162. return parseFloat(value) || 0;
  163. }
  164.  
  165. function positive(value) {
  166. value = intval(value);
  167. return value < 0 ? 0 : value;
  168. }
  169.  
  170. //scrolling get
  171. function scrollGetY() {
  172. return window.pageYOffset || scrollNode.scrollTop || document.documentElement.scrollTop;
  173. }
  174. function scrollGetX() {
  175. return window.pageXOffset || scrollNode.scrollLeft || document.documentElement.scrollLeft;
  176. }
  177.  
  178. //setFavIcon
  179. function setFavIcon(href) {
  180. if (!window.icoNode) return;
  181. if (icoNode.href == href) return;
  182. var ico = ce('link', {rel: 'shortcut icon', type: 'image/gif', href: href});
  183. headNode.replaceChild(ico, icoNode);
  184. icoNode = ico;
  185. }
  186.  
  187. //parse
  188. function parseLatin(text){
  189. var outtext = text;
  190. var lat1 = ['yo','zh','kh','ts','ch','sch','shch','sh','eh','yu','ya','YO','ZH','KH','TS','CH','SCH','SHCH','SH','EH','YU','YA',"'"];
  191. var rus1 = ['ё', 'ж', 'х', 'ц', 'ч', 'щ', 'щ', 'ш', 'э', 'ю', 'я', 'Ё', 'Ж', 'Х', 'Ц', 'Ч', 'Щ', 'Щ', 'Ш', 'Э', 'Ю', 'Я', 'ь'];
  192. for (var i = 0, l = lat1.length; i < l; i++) {
  193. outtext = outtext.split(lat1[i]).join(rus1[i]);
  194. }
  195. var lat2 = 'abvgdezijklmnoprstufhcyABVGDEZIJKLMNOPRSTUFHCYёЁ';
  196. var rus2 = 'абвгдезийклмнопрстуфхцыАБВГДЕЗИЙКЛМНОПРСТУФХЦЫеЕ';
  197. for (var i = 0, l = lat2.length; i < l; i++) {
  198. outtext = outtext.split(lat2.charAt(i)).join(rus2.charAt(i));
  199. }
  200. return (outtext == text) ? null : outtext;
  201. }
  202.  
  203. function parseLatKeys(text) {
  204. var outtext = text, i;
  205. lat = "qwertyuiop[]asdfghjkl;'zxcvbnm,./`",
  206. rus = "йцукенгшщзхъфывапролджэячсмитьбю.ё";
  207. for (i = 0; i < lat.length; i++) {
  208. outtext = outtext.split(lat.charAt(i)).join(rus.charAt(i));
  209. }
  210. return (outtext == text) ? false : outtext;
  211. }
  212.  
  213. function parseCyr(text) {
  214. var outtext = text, i,
  215. lat1 = ['yo','zh','kh','ts','ch','sch','shch','sh','eh','yu','ya','YO','ZH','KH','TS','CH','SCH','SHCH','SH','EH','YU','YA',"'"],
  216. rus1 = ['ё', 'ж', 'х', 'ц', 'ч', 'щ', 'щ', 'ш', 'э', 'ю', 'я', 'Ё', 'Ж', 'Х', 'Ц', 'Ч', 'Щ', 'Щ', 'Ш', 'Э', 'Ю', 'Я', 'ь'],
  217. lat2 = 'abvgdezijklmnoprstufhcyABVGDEZIJKLMNOPRSTUFHCYёЁ',
  218. rus2 = 'абвгдезийклмнопрстуфхцыАБВГДЕЗИЙКЛМНОПРСТУФХЦЫеЕ';
  219. for (i = 0; i < rus1.length; i++) {
  220. outtext = outtext.split(rus1[i]).join(lat1[i]);
  221. }
  222. for (i = 0; i < rus2.length; i++) {
  223. outtext = outtext.split(rus2.charAt(i)).join(lat2.charAt(i));
  224. }
  225. return (outtext == text) ? false : outtext;
  226. }
Add Comment
Please, Sign In to add comment