LocalStorage Coding help Hitskin_logo Hitskin.com

This is a Hitskin.com skin preview
Install the skinReturn to the skin page

The forum of the forums
Would you like to react to this message? Create an account in a few clicks or log in to continue.
3 posters

    LocalStorage Coding help

    Astariel
    Astariel
    New Member


    Female Posts : 16
    Reputation : 3
    Language : English
    Location : USA

    Solved LocalStorage Coding help

    Post by Astariel Mon Mar 04, 2019 3:02 am

    So, I was having trouble with a status update widget the other day. I did manage to get it fixed thanks to Twisted. However, I am having a small problem editing the LocalStorage script to work with the widget. The widget isn't showing the current status, which leads me to believe that it's due to not setting up the LocalStorage script correctly due to my lack of knowledge in Java. Below are the current codes I have for the widget and widget's Java page.

    Any assistance in setting up the LocalStorage script would be amazing. I'm so lost with Java x.x

    Widget Code
    Code:
     <div align="center">
                 <span id="tm_currstat">Current Status:</span><br /><br />         
       <div class="form-group row p-2">
                            <label for="input-text-help" id="tmst_stnotice" class="control-label"></label>                 
          <div class="input-group">
                                                  
             <div class="input-group-prepend">
                                        <span class="input-group-text"><em class="fa fa-paypal"></em></span>                             
             </div>
                                   <input maxlength="150" type="text" class="form-control" id="tstatus" value="" />                           
          </div>
                                                               
       </div>
                        
       <div class="form-group row p-2">
                                           
          <button class="btn btn-light px-5" type="button" onclick="updstatus()">
                                   <em class="fa fa-floppy-o mr-1" id="tmst_stnotice"> </em> Save Status                       
          </button>
                                                         
       </div>
    </div>


    Widget Java Code
    Code:
     jQuery(function()
    {
    var id = 'field_id1';
     
      dataStore.set('Stat', '', 60*1000);
      if(dataStore.get('Stat').value =="")
      {
          jQuery.get('/u'+_userdata.user_id, function (data)
          {
            var cstat= jQuery('#'+id+' .field_uneditable', data).eq(0).text();
            jQuery('#tm_currstat').text('Current Status: '+cstat);
            jQuery('#tstatus').val(cstat);
            dataStore.set('Stat', cstat, 60*1000);
          })
      }else{
          jQuery('#tstatus').val(cstat);
          jQuery('#tm_currstat').text('Current Status: '+dataStore.get('Stat').value);
      }
    });
     
    function updstatus()
    {
      var id = 'field_id1';
      var name = 'profile_field_13_8';
     
      jQuery.getScript('https://illiweb.com/rs3/86/frm/jquery/json/jquery.json-1.3.min.js', function()
      {
          jQuery('#tmst_stnotice').text('Updating.');
          var content = new Array();
          var newstat = jQuery('#tstatus').val();
          content.push(new Array(name, newstat));
          jQuery.post('/ajax_profile.forum?jsoncallback=?', {
                id: id.substring(8, id.length),
                user: _userdata.user_id,
                active: '1',
                content: jQuery.toJSON(content),
                tid: document.getElementById('logout').href.replace(/.*tid=(.*?)&.*/,'$1')
            },function(data)
            {
               
                jQuery.get('/u'+_userdata.user_id, function (data)
                {
                  var cstat= jQuery('dl:contains(Status) .field_uneditable', data).eq(0).text();
                  if (jQuery('#tstatus').val()==cstat)
                  {
                      jQuery('#tm_currstat').text('Current Status: '+cstat); 
                      dataStore.set('Stat', cstat, 60*1000);
                      jQuery('#tmst_stnotice').text('Done...');
                  }else{
                      jQuery('#tmst_stnotice').text('Error Try Again.');
                  }
                })
            }, 'json');
      });
    };


    Last edited by Astariel on Tue Mar 05, 2019 11:01 pm; edited 2 times in total
    _Twisted_Mods_
    _Twisted_Mods_
    Helper
    Helper


    Male Posts : 2083
    Reputation : 336
    Language : English
    Location : Ms

    Solved Re: LocalStorage Coding help

    Post by _Twisted_Mods_ Mon Mar 04, 2019 11:10 am

    the local storage code from that page you just copy the first code box and create a new javascript and run it on the pages you need it on no changes are needed
    Astariel
    Astariel
    New Member


    Female Posts : 16
    Reputation : 3
    Language : English
    Location : USA

    Solved Re: LocalStorage Coding help

    Post by Astariel Mon Mar 04, 2019 11:37 pm

    @_Twisted_Mods_

    I don't need to set up any of the set or get functions? If not, does the status widget just not keep track of the current status like the widget shows?
    _Twisted_Mods_
    _Twisted_Mods_
    Helper
    Helper


    Male Posts : 2083
    Reputation : 336
    Language : English
    Location : Ms

    Solved Re: LocalStorage Coding help

    Post by _Twisted_Mods_ Tue Mar 05, 2019 12:36 am

    the get and set functions are already setup in the code for the status widget .. all it does is prevent the widget from making the request to get the status every time the page loads. it saves it for a hour then it will make the request again when the page is loaded. this will prevent a large load on your website if you had a lot of users opening pages with the widget on it
    Astariel
    Astariel
    New Member


    Female Posts : 16
    Reputation : 3
    Language : English
    Location : USA

    Solved Re: LocalStorage Coding help

    Post by Astariel Tue Mar 05, 2019 1:57 am

    @_Twisted_Mods_

    So, the widget itself should only show the status when they update it? And it'll only stay on the until they reload the page?
    _Twisted_Mods_
    _Twisted_Mods_
    Helper
    Helper


    Male Posts : 2083
    Reputation : 336
    Language : English
    Location : Ms

    Solved Re: LocalStorage Coding help

    Post by _Twisted_Mods_ Tue Mar 05, 2019 10:21 pm

    the status will load each time the page is loaded but it does not grab the status each time it only grabs it once every hour no matter how many times its loaded unless the user changes the status then it will grab the new status
    Astariel
    Astariel
    New Member


    Female Posts : 16
    Reputation : 3
    Language : English
    Location : USA

    Solved Re: LocalStorage Coding help

    Post by Astariel Tue Mar 05, 2019 10:25 pm

    @_Twisted_Mods_

    Oh, well that's my problem with it then. It's not grabbing the status. Like, once you add your status, it shows until you leave the page. Then it just says 'Current Status: '. It never grabs the current status. That's why I thought I set the LocalStorage up wrong x.x
    _Twisted_Mods_
    _Twisted_Mods_
    Helper
    Helper


    Male Posts : 2083
    Reputation : 336
    Language : English
    Location : Ms

    Solved Re: LocalStorage Coding help

    Post by _Twisted_Mods_ Tue Mar 05, 2019 10:28 pm

    you might have because that's where it saves the status and keeps it from updating every time the page loads. pm me a test account and ill check it out
    Astariel
    Astariel
    New Member


    Female Posts : 16
    Reputation : 3
    Language : English
    Location : USA

    Solved Re: LocalStorage Coding help

    Post by Astariel Tue Mar 05, 2019 10:44 pm

    @_Twisted_Mods_

    Admin test account? C:
    _Twisted_Mods_
    _Twisted_Mods_
    Helper
    Helper


    Male Posts : 2083
    Reputation : 336
    Language : English
    Location : Ms

    Solved Re: LocalStorage Coding help

    Post by _Twisted_Mods_ Tue Mar 05, 2019 10:49 pm

    it would make it easier
    Astariel
    Astariel
    New Member


    Female Posts : 16
    Reputation : 3
    Language : English
    Location : USA

    Solved Re: LocalStorage Coding help

    Post by Astariel Tue Mar 05, 2019 10:52 pm

    @_Twisted_Mods_

    Okay. Just wanted to make sure C: Pm'd you the account info.
    _Twisted_Mods_
    _Twisted_Mods_
    Helper
    Helper


    Male Posts : 2083
    Reputation : 336
    Language : English
    Location : Ms

    Solved Re: LocalStorage Coding help

    Post by _Twisted_Mods_ Tue Mar 05, 2019 10:58 pm

    i missed a part of the code when i was changing stuff

    in the first script
    Code:

    var cstat= jQuery('#'+id+' .field_uneditable', data).eq(0).text();

    had to be changed to

    Code:

     var cstat= jQuery('dl:contains(Status) .field_uneditable', data).eq(0).text();


    can you confirm its working now?
    Astariel
    Astariel
    New Member


    Female Posts : 16
    Reputation : 3
    Language : English
    Location : USA

    Solved Re: LocalStorage Coding help

    Post by Astariel Tue Mar 05, 2019 11:01 pm

    @_Twisted_Mods_

    You are literally a coding genius, Twisted. It's grabbing the current status perfectly now! Thank you so much! <3
    _Twisted_Mods_
    _Twisted_Mods_
    Helper
    Helper


    Male Posts : 2083
    Reputation : 336
    Language : English
    Location : Ms

    Solved Re: LocalStorage Coding help

    Post by _Twisted_Mods_ Tue Mar 05, 2019 11:02 pm

    Awesome glad i could help
    Astariel
    Astariel
    New Member


    Female Posts : 16
    Reputation : 3
    Language : English
    Location : USA

    Solved Re: LocalStorage Coding help

    Post by Astariel Tue Mar 05, 2019 11:05 pm

    @_Twisted_Mods_

    You have many times in the past and especially now!


    Marked as solved.
    Ape
    Ape
    Administrator
    Administrator


    Male Posts : 19325
    Reputation : 2005
    Language : fluent in dork / mumbojumbo & English haha

    Solved Re: LocalStorage Coding help

    Post by Ape Tue Mar 05, 2019 11:10 pm

    Thank you so much for your help @_Twisted_Mods_
    Problem solved & topic archived.
    Please read our forum rules: ESF General Rules



    LocalStorage Coding help Left1212LocalStorage Coding help Center11LocalStorage Coding help Right112
    LocalStorage Coding help Ape_b110
    LocalStorage Coding help Ape1010