The forum of the forums
Welcome to the Official Support Forum of Forumotion!

To take full advantage of everything offered by our forum, please log in if you are already a member, or join our community if you've not yet.



Create a free forum like this one.

Optimizing the script

View previous topic View next topic Go down

Solved Optimizing the script

Post by BloodDrunk on May 6th 2017, 10:14 pm

Technical Details


Forum version : #phpBB3
Position : Founder
Concerned browser(s) : Google Chrome
Who the problem concerns : All members
Forum link : http://www.nfssecrets.tk/

Description of problem

Hello,

Is anybody here interested in checking a jQuery code out, and if possible, optimize it?
It was in tutorials here, and it seems to work well, but starts to really lag the browser when writing the message (approaching 60+ messages).

Here's the code:
Code:
window.localStorage&&$(function(){
$(function(){
if($("#text_editor_textarea").length&&typeof $.sceditor!="undefined"){
var a=$(document.post.mode).val(),
d=$("#text_editor_textarea").sceditor("instance"),
e,f,g=function(){
localStorage.setItem(a,d.val());
f=0},
b=JSON.parse(localStorage.getItem("br-data"))||[],c;
switch(a){
case"editpost":return;
case"reply":a+=$(document.post.t).val();
break;
case"newtopic":a+=$(document.post.f).val()
}
a=parseInt((my_getcookie("fa_"+location.hostname.replace(/\./g,"_")+"_data")||"0").replace(/.*s:6:"userid";(i:([0-9]+)|s:[0-9]+:"([0-9]+)");.*/,"$2$3"))+a;
-1!=(c=$.inArray(a,b))&&b.splice(c,1);
if(20<b.length){
for(c=b.length-1;0<=c;c--)/^\s*$/.test(localStorage.getItem(b[c])||"")&&(localStorage.removeItem(b[c]),
b.splice(c,1));
20<b.length&&(localStorage.removeItem(b[0]),
b.splice(0,1))}b.push(a);
localStorage.setItem("br-data",JSON.stringify(b));
$(document.post).submit(function(){
localStorage.setItem("br-target",a)
});
!d.val()&&((e=localStorage.getItem(a))&&d.val(e));
d.keyDown(function(){
f||(f=setTimeout(g,3E3))
})}})});
window.localStorage&&(localStorage.getItem("br-target")&&function(){
$("meta[http-equiv='refresh'][content]:first").length&&function(){
var a=JSON.parse(localStorage.getItem("br-data")),
b=localStorage.getItem("br-target"),c;
if(-1!=(c=$.inArray(b,a)))a.splice(c,1),
localStorage.setItem("br-data",JSON.stringify(a));
localStorage.removeItem(b)}();
localStorage.removeItem("br-target")}());


Last edited by BloodDrunk on May 9th 2017, 5:48 pm; edited 1 time in total
avatar
BloodDrunk
Forumember

Posts : 122
Reputation : 4
Language : English

http://www.nfssecrets.tk/

Back to top Go down

Solved Re: Optimizing the script

Post by zenzo on May 6th 2017, 11:28 pm

can you link where you get this tutorial.
avatar
zenzo
Forumember

Posts : 563
Reputation : 13
Language : english,tagalog
Location : philippines

Back to top Go down

Solved Re: Optimizing the script

Post by BloodDrunk on May 7th 2017, 12:04 am

avatar
BloodDrunk
Forumember

Posts : 122
Reputation : 4
Language : English

http://www.nfssecrets.tk/

Back to top Go down

Solved Re: Optimizing the script

Post by Draxion on May 7th 2017, 1:49 am

Try this.
Code:
window.localStorage && $(function() {
    $(function() {
        if ($("#text_editor_textarea").length && typeof $.sceditor != "undefined") {
            var a = $(document.post.mode).val(),
                d = $("#text_editor_textarea").sceditor("instance"),
                e, f, g = function() {
                    localStorage.setItem(a, d.val());
                    f = 0
                },
                b = JSON.parse(localStorage.getItem("br-data")) || [],
                c;
            switch (a) {
                case "editpost":
                    return;
                case "reply":
                    a += $(document.post.t).val();
                    break;
                case "newtopic":
                    a += $(document.post.f).val()
            }
            a = parseInt((my_getcookie("fa_" + location.hostname.replace(/\./g, "_") + "_data") || "0").replace(/.*s:6:"userid";(i:([0-9]+)|s:[0-9]+:"([0-9]+)");.*/, "$2$3")) + a; -
            1 != (c = $.inArray(a, b)) && b.splice(c, 1);
            if (20 < b.length) {
                for (c = b.length - 1; 0 <= c; c--) /^\s*$/.test(localStorage.getItem(b[c]) || "") && (localStorage.removeItem(b[c]),
                    b.splice(c, 1));
                20 < b.length && (localStorage.removeItem(b[0]),
                    b.splice(0, 1))
            }
            b.push(a);
            localStorage.setItem("br-data", JSON.stringify(b));
            $(document.post).submit(function() {
                localStorage.setItem("br-target", a)
            });
            !d.val() && ((e = localStorage.getItem(a)) && d.val(e));
            d.keyDown(function() {
                f || (f = setTimeout(g, 3E3))
            })
        }
    })
});
window.localStorage && (localStorage.getItem("br-target") && function() {
    $("meta[http-equiv='refresh'][content]:first").length && function() {
        var a = JSON.parse(localStorage.getItem("br-data")),
            b = localStorage.getItem("br-target"),
            c;
        if (-1 != (c = $.inArray(b, a))) a.splice(c, 1),
            localStorage.setItem("br-data", JSON.stringify(a));
        localStorage.removeItem(b)
    }();
    localStorage.removeItem("br-target")
}());


NEVER provide your founder's account or email
Please provide forum's URL when dealing with design and appearance issues
Don't forget to mark the topic as when the issue is resolved. This helps the staff greatly.
PM Support is prohibited!
TOS | General Rules | FAQ | Tricks & Tips | Latest Updates | Introduce Yourself

avatar
Draxion
Support Moderator
Support Moderator

Male Posts : 1708
Reputation : 223
Language : English
Location : USA

http://www.draxionsgameden.com/

Back to top Go down

Solved Re: Optimizing the script

Post by BloodDrunk on May 7th 2017, 11:56 am

Still starts to get laggy after 30 words..
avatar
BloodDrunk
Forumember

Posts : 122
Reputation : 4
Language : English

http://www.nfssecrets.tk/

Back to top Go down

Solved Re: Optimizing the script

Post by SLGray on May 7th 2017, 10:39 pm

Are you sure it is this code, not other things on your forum?


When your topic has been solved, ensure you mark the topic solved.
Never post your email in public.

avatar
SLGray
Administrator
Administrator

Male Posts : 40177
Reputation : 2714
Language : English
Location : United States

https://fmthemes.forumotion.com/

Back to top Go down

Solved Re: Optimizing the script

Post by BloodDrunk on May 7th 2017, 10:45 pm

SLGray wrote:Are you sure it is this code, not other things on your forum?

You know what, now when I tried disabling some other codes, it stopped lagging. Now it lags while having this following code:
Code:
$(function(){$(function(){
 
      var MinNumberOfWords = 1;
      var LetterCountPerWord = 4;
      var ico_compl = "http://i73.servimg.com/u/f73/18/10/89/49/ok-gre10.png";
      var ico_incompl = "http://i73.servimg.com/u/f73/18/10/89/49/exclam10.png"; 
 
    if($("#text_editor_textarea").length != 0){
          $("input[type='submit'][name='post']").attr("disabled", true).css("opacity", "0.5");     
          $(".sceditor-container").after("<br/><div id='div_minchars' align='center'><div id='div_minchars_header'> Minimum words to send a message: " + MinNumberOfWords + " (at least " + LetterCountPerWord + " letters)</div><div id='div_minchars_info'></div></div>");
         
          var sceditor = $("#text_editor_textarea").sceditor("instance");                 
          var str = sceditor.val();
          var regex = new RegExp('\\w{' + LetterCountPerWord + ',}\\b', 'g');
          var str_arr = str.match(regex);
          var str_len = str_arr == null ? 0 : str_arr.length;
         
          if(str_len >= MinNumberOfWords) $("input[type='submit'][name='post']").attr("disabled", false).css("opacity", "1");
         
          sceditor.keyUp(function(e) {
            str = sceditor.val();
            str_arr = str.match(regex);
            str_len = str_arr == null ? 0 : str_arr.length;
            if(str_len >= MinNumberOfWords) {
                $("#div_minchars_info").html("You've written <span style='color:green'>" + str_len + "</span> word(s). You can now send the message <img src='" + ico_compl  + "' />"); 
            $("input[type='submit'][name='post']").attr("disabled", false).css("opacity", "1");
            }else{
                $("#div_minchars_info").html("You've written <span style='color:red'>" + str_len + "</span> word(s). You need " + (MinNumberOfWords - str_len) + " word(s) to send this message <img src='" + ico_incompl  + "' />");
                $("input[type='submit'][name='post']").attr("disabled", true).css("opacity", "0.5");
            }
          });
      }
    })});
avatar
BloodDrunk
Forumember

Posts : 122
Reputation : 4
Language : English

http://www.nfssecrets.tk/

Back to top Go down

Solved Re: Optimizing the script

Post by BloodDrunk on May 9th 2017, 5:48 pm

Nevermind, I removed that word counter.
You can archive this now. Solved!
avatar
BloodDrunk
Forumember

Posts : 122
Reputation : 4
Language : English

http://www.nfssecrets.tk/

Back to top Go down

Solved Re: Optimizing the script

Post by APE on May 9th 2017, 5:54 pm

Problem solved & topic archived.
Please read our forum rules: ESF General Rules



avatar
APE
Manager
Manager

Male Posts : 10652
Reputation : 996
Language : fluent in dork / mumbojumbo & English haha
Location : STUCK IN FORUMOTIONS SERVERS HELP ME !!!!!!

http://chatworld.forumotion.co.uk/

Back to top Go down

View previous topic View next topic Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum