Запоминание открыто или закрыто меню в куки

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • Запоминание открыто или закрыто меню в куки

      и так решил поделится запоминание меню или вкладки в куки что порой очень удобно

      скрипт библиотека jquery
      создаем файл jquery.ezCookie.js

      Source Code

      1. (function($){
      2. // Default options
      3. dOptions = {
      4. expires : 365,
      5. domain : '',
      6. secure : false,
      7. path : '/'
      8. }
      9. // Returns the cookie or null if it does not exist.
      10. $.cookie = function(cookieName) {
      11. var value = null;
      12. if(document.cookie && document.cookie != ''){
      13. var cookies = document.cookie.split(';');
      14. for (var i = 0; i < cookies.length; i++) {
      15. var cookie = jQuery.trim(cookies[i]);
      16. if (cookie.substring(0, cookieName.length + 1) == (cookieName + '=')) {
      17. value = decodeURIComponent(cookie.substring(cookieName.length + 1));
      18. break;
      19. }
      20. }
      21. }
      22. try {
      23. // Test for a JSON string and return the object
      24. return JSON.parse(value);
      25. } catch(e){
      26. // or return the string
      27. return value;
      28. }
      29. }
      30. $.subCookie = function(cookie,key){
      31. var cookie = $.cookie(cookie);
      32. if(!cookie || typeof cookie != 'object'){return null;}
      33. return cookie[key];
      34. }
      35. // Write the defined value to the given cookie
      36. $.setCookie = function(cookieName,cookieValue,options){
      37. // Combine defaults and passed options, if any
      38. var options = typeof options != 'undefined' ? $.extend(dOptions, options) : dOptions;
      39. // Set cookie attributes based on options
      40. var path = '; path=' + (options.path);
      41. var domain = '; domain=' + (options.domain);
      42. var secure = options.secure ? '; secure' : '';
      43. if (cookieValue && (typeof cookieValue == 'function' || typeof cookieValue == 'object')) {
      44. cookieValue = JSON.stringify(cookieValue);
      45. }
      46. cookieValue = encodeURIComponent(cookieValue);
      47. var date;
      48. // Set expiration
      49. if (typeof options.expires == 'number') {
      50. date = new Date();
      51. date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
      52. } else {
      53. date = options.expires;
      54. }
      55. var expires = '; expires=' + date.toUTCString();
      56. // Write the cookie
      57. document.cookie = [cookieName, '=', cookieValue, expires, path, domain, secure].join('');
      58. }
      59. $.setSubCookie = function(cookie,key,value,options){
      60. var options = typeof options != 'undefined' ? $.extend(dOptions, options) : dOptions;
      61. var existingCookie = $.cookie(cookie);
      62. var cookieObject = existingCookie && typeof existingCookie == 'object' ? existingCookie : {};
      63. cookieObject[key] = value;
      64. $.setCookie(cookie,cookieObject,options);
      65. }
      66. $.removeSubCookie = function(cookie,key){
      67. var cookieObject = $.cookie(cookie);
      68. if(cookieObject && typeof cookieObject == 'object' && typeof cookieObject[key] != 'undefined'){
      69. delete cookieObject[key];
      70. $.setCookie(cookie,cookieObject);
      71. }
      72. }
      73. $.removeCookie = function(cookie){
      74. $.setCookie(cookie,'',{expires:-1});
      75. }
      76. $.clearCookie = function(cookie){
      77. $.setCookie(cookie,'');
      78. }
      79. })(jQuery);
      80. // Begin minified json2.js library from json.org
      81. // http://www.json.org/js.html
      82. if(!this.JSON){this.JSON={};}
      83. (function(){function f(n){return n<10?'0'+n:n;}
      84. if(typeof Date.prototype.toJSON!=='function'){Date.prototype.toJSON=function(key){return isFinite(this.valueOf())?this.getUTCFullYear()+'-'+
      85. f(this.getUTCMonth()+1)+'-'+
      86. f(this.getUTCDate())+'T'+
      87. f(this.getUTCHours())+':'+
      88. f(this.getUTCMinutes())+':'+
      89. f(this.getUTCSeconds())+'Z':null;};String.prototype.toJSON=Number.prototype.toJSON=Boolean.prototype.toJSON=function(key){return this.valueOf();};}
      90. var cx=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,escapable=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,gap,indent,meta={'\b':'\\b','\t':'\\t','\n':'\\n','\f':'\\f','\r':'\\r','"':'\\"','\\':'\\\\'},rep;function quote(string){escapable.lastIndex=0;return escapable.test(string)?'"'+string.replace(escapable,function(a){var c=meta[a];return typeof c==='string'?c:'\\u'+('0000'+a.charCodeAt(0).toString(16)).slice(-4);})+'"':'"'+string+'"';}
      91. function str(key,holder){var i,k,v,length,mind=gap,partial,value=holder[key];if(value&&typeof value==='object'&&typeof value.toJSON==='function'){value=value.toJSON(key);}
      92. if(typeof rep==='function'){value=rep.call(holder,key,value);}
      93. switch(typeof value){case'string':return quote(value);case'number':return isFinite(value)?String(value):'null';case'boolean':case'null':return String(value);case'object':if(!value){return'null';}
      94. gap+=indent;partial=[];if(Object.prototype.toString.apply(value)==='[object Array]'){length=value.length;for(i=0;i<length;i+=1){partial[i]=str(i,value)||'null';}
      95. v=partial.length===0?'[]':gap?'[\n'+gap+
      96. partial.join(',\n'+gap)+'\n'+
      97. mind+']':'['+partial.join(',')+']';gap=mind;return v;}
      98. if(rep&&typeof rep==='object'){length=rep.length;for(i=0;i<length;i+=1){k=rep[i];if(typeof k==='string'){v=str(k,value);if(v){partial.push(quote(k)+(gap?': ':':')+v);}}}}else{for(k in value){if(Object.hasOwnProperty.call(value,k)){v=str(k,value);if(v){partial.push(quote(k)+(gap?': ':':')+v);}}}}
      99. v=partial.length===0?'{}':gap?'{\n'+gap+partial.join(',\n'+gap)+'\n'+
      100. mind+'}':'{'+partial.join(',')+'}';gap=mind;return v;}}
      101. if(typeof JSON.stringify!=='function'){JSON.stringify=function(value,replacer,space){var i;gap='';indent='';if(typeof space==='number'){for(i=0;i<space;i+=1){indent+=' ';}}else if(typeof space==='string'){indent=space;}
      102. rep=replacer;if(replacer&&typeof replacer!=='function'&&(typeof replacer!=='object'||typeof replacer.length!=='number')){throw new Error('JSON.stringify');}
      103. return str('',{'':value});};}
      104. if(typeof JSON.parse!=='function'){JSON.parse=function(text,reviver){var j;function walk(holder,key){var k,v,value=holder[key];if(value&&typeof value==='object'){for(k in value){if(Object.hasOwnProperty.call(value,k)){v=walk(value,k);if(v!==undefined){value[k]=v;}else{delete value[k];}}}}
      105. return reviver.call(holder,key,value);}
      106. text=String(text);cx.lastIndex=0;if(cx.test(text)){text=text.replace(cx,function(a){return'\\u'+
      107. ('0000'+a.charCodeAt(0).toString(16)).slice(-4);});}
      108. if(/^[\],:{}\s]*$/.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,'@').replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,']').replace(/(?:^|:|,)(?:\s*\[)+/g,''))){j=eval('('+text+')');return typeof reviver==='function'?walk({'':j},''):j;}
      109. throw new SyntaxError('JSON.parse');};}}());
      Display All
      css



      Source Code

      1. .one {width:25vw;height: 25vw;}
      2. img.two { width:150px;}
      3. img.three { width:150px;}
      4. img.four{ width:150px;}
      5. img.five{ width:150px;}
      6. .toogle {
      7. float: left;
      8. background: #eeeeee;
      9. background: #191e24c7;
      10. position: fixed;
      11. margin: .5vw;
      12. width: 20.6vw;
      13. color: #666;
      14. font-family: Tahoma;
      15. font-size: 1vw;
      16. text-shadow: #fff 0px 1px 0px;
      17. box-shadow: 0px 2px 7px 1px rgba( 0, 0, 0, 0.7);
      18. }
      19. .close {
      20. text-align:center;
      21. cursor:pointer;
      22. margin-top: 4px;
      23. }
      Display All
      Делаю качественно в сроки! на любой версии moons, встрою, или напишу любой мод , но дорого! afire-space.com
    • сама инициализация библиотеки

      Source Code

      1. <script type="text/javascript">
      2. $(document).ready(function(){
      3. $(".close").toggle(
      4. function(){
      5. $(this).prev().slideUp();
      6. $(this).html("Открыть");
      7. var class_name = $(this).prev().attr("class");
      8. $.setSubCookie("ui_save", class_name, 0);
      9. },
      10. function(){
      11. $(this).prev().slideDown();
      12. $(this).html("Закрыть");
      13. var class_name = $(this).prev().attr("class");
      14. $.setSubCookie("ui_save", class_name, 1);
      15. }
      16. );
      17. //Устанавливаем необходимую позиции интерфейса
      18. var ck = $.cookie("ui_save");
      19. for(key in ck){
      20. if(ck[key] == 0){
      21. $("." + key).next().trigger('click');
      22. }
      23. }
      24. });
      25. </script>
      Display All
      или делаем кнопки тут сами

      и сам код

      <div class="toogle">

      <div class="one"></div>
      <div class="close">Закрыть</div>
      </div>
      Делаю качественно в сроки! на любой версии moons, встрою, или напишу любой мод , но дорого! afire-space.com