123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- function SaveLocal(){
- if( !ifvisible.now() ) return false;
- var date = new Date();
- var options = {
- year: 'numeric',
- month: 'numeric',
- day: 'numeric',
- hour: 'numeric',
- minute: 'numeric',
- };
- var obj = {
- date: new Date(),
- header: $('#news-title').val()+' ('+date.toLocaleString("ru", options)+')',
- };
- var arr = [ "News[title]", "News[lid]", "News[meta_title]", "News[photo_title]", "News[text]", "News[dt_pub]" ];
- console.log( "save" );
- // console.log( $('#news-form') );
- $.each( $( "form" ).serializeArray() , function( i, field ) {
- if( $.inArray( field.name, arr ) >-1 ){
- value = field.value;
- if( field.name == 'News[text]'){
- // value = LZW.compress( CKEDITOR.instances.editor1.getData() );
- //console.log(CKEDITOR.instances);
- //x = 'js-news-content';
- value = CKEDITOR.instances.js_news_content.getData();
- }
- // console.log( value );
- key = field.name;
- obj[key]=value;
- }
- });
- if( localStorage.getItem('articles') ){
- a = JSON.parse( localStorage.articles );
- a.push( obj );
- }else{
- a = [ obj ];
- }
- // óäàëßåì ñòàðûå çàïèñè
- if( a.length > 15 ){
- a.shift();
- }
- console.log(a);
- localStorage.setItem("articles", JSON.stringify( a ) );
- return false;
- }
- function LoadLocal(){
- if( isset( localStorage.articles ) ){
- obj = JSON.parse( localStorage.articles );
- var sel=0;
- var opt='';
- $.each( obj , function( i, field ) {
- opt += '<option value="'+i+'">'+field.header+'</option>';
- });
- $( '<div id="dialog" title="save copy"><select id="his" name="his" class="input-xxlarge">'+opt+'</select></div>' ).dialog({
- modal: true,
- resizable: true,
- height: "auto",
- width: "60%",
- buttons: {
- Ok: function() {
- //sel = $('#his option:selected').attr('value');
- sel = $('#his option:selected').val();
- $( this ).dialog( "close" ).detach();
- // console.log(sel);
- tmp = obj[sel];
- var arr = [ "News[title]", "News[lid]", "News[meta_title]", "News[photo_title]", "News[text]", "News[dt_pub]" ];
- $.each( tmp , function( i, field ) {
- if( $.inArray( i, arr ) >-1 ){
- value = field;
- if( i == 'News[text]'){
- // value = LZW.decompress( value );
- key = "[name='"+i+"']";
- $(key).val(value);
- console.log(value);
- CKEDITOR.instances['js_news_content'].setData(value);
- }else{
- key = "[name='"+i+"']";
- // console.log(key);
- // console.log(value);
- $(key).val(value);
- }
- }
- });
- }
- }
- });
- }
- /// localStorage.clear();
- return false;
- }
- window.isset = function(v_var) {
- if(typeof(v_var) == 'number'){ if(isNaN(v_var)){return false;}}
- if(typeof(v_var) == 'undefined' || v_var === null){return false;}
- return true;
- };
- $(function() {
- setInterval(SaveLocal, 1000*30);
- ifvisible.setIdleDuration(30);
- ifvisible.on("blur", function() { SaveLocal(); });
- })
|