Optimizing the script
5 posters
Page 1 of 1
Optimizing the script
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
Re: Optimizing the script
can you link where you get this tutorial.
zenzo- Forumember
- Posts : 564
Reputation : 13
Language : english,tagalog
Location : philippines
Re: Optimizing the script
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")
}());
Re: Optimizing the script
Are you sure it is this code, not other things on your forum?


Lost Founder's Password |Forum's Utilities |Report a Forum |General Rules |FAQ |Tricks & Tips
You need one post to send a PM.
You need one post to send a PM.
When your topic has been solved, ensure you mark the topic solved.
Never post your email in public.
Re: Optimizing the script
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");
}
});
}
})});
Re: Optimizing the script
Problem solved & topic archived.
|

» Suggested Script (Need Someone that can read script)
» register Script (I Need The Script)
» Optimizing my forum to the next level :)
» embed Script code in forum? (<script </script>)
» [JAVA script]How to set a countdown script to forum/portal?
» register Script (I Need The Script)
» Optimizing my forum to the next level :)
» embed Script code in forum? (<script </script>)
» [JAVA script]How to set a countdown script to forum/portal?
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum