Vahid_Nasiri
پنج شنبه 06 شهریور 1382, 02:15 صبح
با سلام
قسمت های عمده ای از سورس تمام صفحات این فوروم تکراری است که می شود آنها را به سادگی در دو فایل css و js قرار داد. یک قسمت مربوط به استایل شیت صفحات است و یک قسمت مربوط به اسکریپت صفحات.
برای مثال :
این اسکریپت در سورس تمام صفحات هست (فقط کافی است روی هر صفحه کلیک راست نموده و از منو سورس را مشاهده کرد ) :
<script language="javascript" type="text/javascript">
var lang = 0; // 1: Farsi, 0: English
// Farsi keyboard map based on ISIRI-2901
var farsikey = [
0x0020, 0x0021, 0x061B, 0x066B, 0x00A4, 0x066A, 0x060C, 0x06AF,
0x0029, 0x0028, 0x002A, 0x002B, 0x0648, 0x002D, 0x002E, 0x002F,
0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037,
0x0038, 0x0039, 0x003A, 0x0643, 0x003E, 0x003D, 0x003C, 0x061F,
0x066C, 0x0624, 0x200C, 0x0698, 0x0649, 0x064D, 0x0625, 0x0623,
0x0622, 0x0651, 0x0629, 0x00BB, 0x00AB, 0x0621, 0x004E, 0x005D,
0x005B, 0x0652, 0x064B, 0x0626, 0x064F, 0x064E, 0x0056, 0x064C,
0x0058, 0x0650, 0x0643, 0x062C, 0x005C, 0x0686, 0x00D7, 0x0640,
0x200D, 0x0634, 0x0630, 0x0632, 0x064A, 0x062B, 0x0628, 0x0644,
0x0627, 0x0647, 0x062A, 0x0646, 0x0645, 0x067E, 0x062F, 0x062E,
0x062D, 0x0636, 0x0642, 0x0633, 0x0641, 0x0639, 0x0631, 0x0635,
0x0637, 0x063A, 0x0638, 0x007D, 0x007C, 0x007B, 0x007E ];
function changeLang() {
if (lang == 0) {
lang = 1;
return true;
}
else {
lang = 0;
return true;
}
}
function FKeyDown (txtFrm){
var key = window.event.keyCode;
if (key == 145){
if (lang == 0) {
lang = 1;
return true;
}
else {
lang = 0;
return true;
}
}
}
function FKeyPress(txtFrm) {
var key = window.event.keyCode;
if (key == 13) { window.event.keyCode = 13; return true; }
if (key == 0x06cc) {
window.event.keyCode = 0x064a;
}
if (lang == 1) { // If Farsi
if (key == 0x0020 && window.event.shiftKey) // Shift-space -> ZWNJ
window.event.keyCode = 0x200C;
else
window.event.keyCode = farsikey[key - 0x0020];
if (farsikey[key - 0x0020] == 92) {
window.event.keyCode = 0x0698;
}
if (farsikey[key - 0x0020] == 8205) {
window.event.keyCode = 0x067E;
}
}
return true;
}
</script>
خیلی هم عالی! ولی می شود آنرا درون یک فایل js قرار داد تا یکبار برای همیشه لود شود و نه هر بار با باز کردن هر صفحه.
مثال دیگر:
این مورد هم در سورس جاری تمام صفحات این فوروم تکراری است که نباید به این صورت باشد:
<!-- link rel="stylesheet" href="templates/subSilver/subSilver.css" type="text/css" -->
<style type="text/css">
<!--
/*
The original subSilver Theme for phpBB version 2+
Created by subBlue design
http://www.subBlue.com
NOTE: These CSS definitions are stored within the main page body so that you can use the phpBB2
theme administration centre. When you have finalised your style you could cut the final CSS code
and place it in an external file, deleting this section to save bandwidth.
*/
/* General page style. The scroll bar colours only visible in IE5.5+ */
img.banner1{
border-width: 2px;
border-style: solid;
border-color: #32CD32;
}
body {
background-color: #E5E5E5;
scrollbar-face-color: #DEE3E7;
scrollbar-highlight-color: #FFFFFF;
scrollbar-shadow-color: #DEE3E7;
scrollbar-3dlight-color: #D1D7DC;
scrollbar-arrow-color: #006699;
scrollbar-track-color: #EFEFEF;
scrollbar-darkshadow-color: #98AAB1;
}
/* General font families for common tags */
font,th,td,p { font-family: Tahoma, Tahoma, Tahoma, Tahoma }
a:link,a:active,a:visited { color : #006699; }
a:hover { text-decoration: underline; color : #DD6900; }
hr { height: 0px; border: solid #D1D7DC 0px; border-top-width: 1px;}
/* This is the border line & background colour round the entire page */
.bodyline { background-color: #FFFFFF; border: 1px #98AAB1 solid; }
/* This is the outline round the main forum tables */
.forumline { background-color: #FFFFFF; border: 2px #006699 solid; }
/* Main table cell colours and backgrounds */
td.row1 { background-color: #EFEFEF; }
td.row2 { background-color: #DEE3E7; }
td.row3 { background-color: #D1D7DC; }
/*
This is for the table cell above the Topics, Post & Last posts on the index.php page
By default this is the fading out gradiated silver background.
However, you could replace this with a bitmap specific for each forum
*/
td.rowpic {
background-color: #FFFFFF;
background-image: url(templates/subSilver/images/cellpic2.jpg);
background-repeat: repeat-y;
}
/* Header cells - the blue and silver gradient backgrounds */
th {
color: #FFA34F; font-size: 11px; font-weight : bold;
background-color: #006699; height: 25px;
background-image: url(templates/subSilver/images/cellpic3.gif);
}
td.cat,td.catHead,td.catSides,td.catLeft,td.catRig ht,td.catBottom {
background-image: url(templates/subSilver/images/cellpic1.gif);
background-color:#D1D7DC; border: #FFFFFF; border-style: solid; height: 28px;
}
/*
Setting additional nice inner borders for the main table cells.
The names indicate which sides the border will be on.
Don't worry if you don't understand this, just ignore it :-)
*/
td.cat,td.catHead,td.catBottom {
height: 29px;
border-width: 0px 0px 0px 0px;
}
th.thHead,th.thSides,th.thTop,th.thLeft,th.thRight ,th.thBottom,th.thCornerL,th.thCornerR {
font-weight: bold; border: #FFFFFF; border-style: solid; height: 28px;
}
td.row3Right,td.spaceRow {
background-color: #D1D7DC; border: #FFFFFF; border-style: solid;
}
th.thHead,td.catHead { font-size: 12px; border-width: 1px 1px 0px 1px; }
th.thSides,td.catSides,td.spaceRow { border-width: 0px 1px 0px 1px; }
th.thRight,td.catRight,td.row3Right { border-width: 0px 1px 0px 0px; }
th.thLeft,td.catLeft { border-width: 0px 0px 0px 1px; }
th.thBottom,td.catBottom { border-width: 0px 1px 1px 1px; }
th.thTop { border-width: 1px 0px 0px 0px; }
th.thCornerL { border-width: 1px 0px 0px 1px; }
th.thCornerR { border-width: 1px 1px 0px 0px; }
/* The largest text used in the index page title and toptic title etc. */
.maintitle {
font-weight: bold; font-size: 22px; font-family: "Tahoma",Tahoma, Tahoma, Tahoma, Tahoma;
text-decoration: none; line-height : 120%; color : #000000;
}
/* General text */
.gen { font-size : 12px; }
.genmed { font-size : 11px; }
.gensmall { font-size : 10px; }
.gen,.genmed,.gensmall { color : #000000; }
a.gen,a.genmed,a.gensmall { color: #006699; text-decoration: none; }
a.gen:hover,a.genmed:hover,a.gensmall:hover { color: #DD6900; text-decoration: underline; }
/* The register, login, search etc links at the top of the page */
.mainmenu { font-size : 11px; color : #000000 }
a.mainmenu { text-decoration: none; color : #006699; }
a.mainmenu:hover{ text-decoration: underline; color : #DD6900; }
/* Forum category titles */
.cattitle { font-weight: bold; font-size: 12px ; letter-spacing: 1px; color : #006699}
a.cattitle { text-decoration: none; color : #006699; }
a.cattitle:hover{ text-decoration: underline; }
/* Forum title: Text and link to the forums used in: index.php */
.forumlink { font-weight: bold; font-size: 12px; color : #006699; }
a.forumlink { text-decoration: none; color : #006699; }
a.forumlink:hover{ text-decoration: underline; color : #DD6900; }
/* Used for the navigation text, (Page 1,2,3 etc) and the navigation bar when in a forum */
.nav { font-weight: bold; font-size: 11px; color : #000000;}
a.nav { text-decoration: none; color : #006699; }
a.nav:hover { text-decoration: underline; }
/* titles for the topics: could specify viewed link colour too */
.topictitle,h1,h2 { font-weight: bold; font-size: 11px; color : #000000; }
a.topictitle:link { text-decoration: none; color : #006699; }
a.topictitle:visited { text-decoration: none; color : #5493B4; }
a.topictitle:hover { text-decoration: underline; color : #DD6900; }
/* Name of poster in viewmsg.php and viewtopic.php and other places */
.name { font-size : 11px; color : #000000;}
/* Location, number of posts, post date etc */
.postdetails { font-size : 10px; color : #000000; }
/* The content of the posts (body of text) */
.postbody { font-size : 12px; line-height: 18px}
a.postlink:link { text-decoration: none; color : #006699 }
a.postlink:visited { text-decoration: none; color : #5493B4; }
a.postlink:hover { text-decoration: underline; color : #DD6900}
/* Quote & Code blocks */
/* font-family: Tahoma, Tahoma, Tahoma; font-size: 11px; color: #006600;*/
.code { direction:ltr;
font-family: "Helvetica"; font-size: 11px; color: "#000000";
background-color: #FAFAFA; border: #D1D7DC; border-style: solid;
border-left-width: 1px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px
}
.quote {
font-family: Tahoma, Tahoma, Tahoma, Tahoma; font-size: 11px; color: #444444; line-height: 125%;
background-color: #FAFAFA; border: #D1D7DC; border-style: solid;
border-left-width: 1px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px
}
/* Copyright and bottom info */
.copyright { font-size: 10px; font-family: Tahoma, Tahoma, Tahoma, Tahoma; color: #444444;
letter-spacing: -1px;}
a.copyright { color: #444444; text-decoration: none;}
a.copyright:hover { color: #000000; text-decoration: underline;}
/* Form elements */
input,textarea, select {
color : #000000;
font: normal 11px Tahoma, Tahoma, Tahoma, Tahoma;
border-color : #000000;
}
/* The text input fields background colour */
input.post, textarea.post, select {
background-color : #FFFFFF;
}
input { text-indent : 2px; }
/* The buttons used for bbCode styling in message post */
input.button {
background-color : #EFEFEF;
color : #000000;
font-size: 11px; font-family: Tahoma, Tahoma, Tahoma, Tahoma;
}
/* The main submit button option */
input.mainoption {
background-color : #FAFAFA;
font-weight : bold;
}
/* None-bold submit button */
input.liteoption {
background-color : #FAFAFA;
font-weight : normal;
}
/* This is the line in the posting page which shows the rollover
help line. This is actually a text box, but if set to be the same
colour as the background no one will know ;)
*/
.helpline { background-color: #DEE3E7; border-style: none; }
/* Import the fancy styles for IE only (NS4.x doesn't use the @import function) */
@import url("templates/subSilver/formIE.css");
-->
</style>
<script language="Javascript" type="text/javascript">
<!--
if ( 0 )
{
window.open('privmsg.php?mode=newpm', '_phpbbprivmsg',
'HEIGHT=225,resizable=yes,WIDTH=400');;
}
//-->
خیلی راحت اینرا هم می توان در یک فایل css ذخیره کرد تا یکبار برای همیشه لود شود.
مزایا:
1- هر چند وقت به چند وقت سایت نمی خوابد! زیرا حجم هر صفحه به شدت کاهش پیدا می کند :wink:
2- صفحات بسیار سریعتر لود می شوند چون فایلهای js و css در دایرکتوری تمپ اینترنت اکسپلورر ذخیره می شوند و نیازی به بارگذاری مجدد ندارند و برای تمام صفحات هم یکسان است
موفق باشید.
قسمت های عمده ای از سورس تمام صفحات این فوروم تکراری است که می شود آنها را به سادگی در دو فایل css و js قرار داد. یک قسمت مربوط به استایل شیت صفحات است و یک قسمت مربوط به اسکریپت صفحات.
برای مثال :
این اسکریپت در سورس تمام صفحات هست (فقط کافی است روی هر صفحه کلیک راست نموده و از منو سورس را مشاهده کرد ) :
<script language="javascript" type="text/javascript">
var lang = 0; // 1: Farsi, 0: English
// Farsi keyboard map based on ISIRI-2901
var farsikey = [
0x0020, 0x0021, 0x061B, 0x066B, 0x00A4, 0x066A, 0x060C, 0x06AF,
0x0029, 0x0028, 0x002A, 0x002B, 0x0648, 0x002D, 0x002E, 0x002F,
0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037,
0x0038, 0x0039, 0x003A, 0x0643, 0x003E, 0x003D, 0x003C, 0x061F,
0x066C, 0x0624, 0x200C, 0x0698, 0x0649, 0x064D, 0x0625, 0x0623,
0x0622, 0x0651, 0x0629, 0x00BB, 0x00AB, 0x0621, 0x004E, 0x005D,
0x005B, 0x0652, 0x064B, 0x0626, 0x064F, 0x064E, 0x0056, 0x064C,
0x0058, 0x0650, 0x0643, 0x062C, 0x005C, 0x0686, 0x00D7, 0x0640,
0x200D, 0x0634, 0x0630, 0x0632, 0x064A, 0x062B, 0x0628, 0x0644,
0x0627, 0x0647, 0x062A, 0x0646, 0x0645, 0x067E, 0x062F, 0x062E,
0x062D, 0x0636, 0x0642, 0x0633, 0x0641, 0x0639, 0x0631, 0x0635,
0x0637, 0x063A, 0x0638, 0x007D, 0x007C, 0x007B, 0x007E ];
function changeLang() {
if (lang == 0) {
lang = 1;
return true;
}
else {
lang = 0;
return true;
}
}
function FKeyDown (txtFrm){
var key = window.event.keyCode;
if (key == 145){
if (lang == 0) {
lang = 1;
return true;
}
else {
lang = 0;
return true;
}
}
}
function FKeyPress(txtFrm) {
var key = window.event.keyCode;
if (key == 13) { window.event.keyCode = 13; return true; }
if (key == 0x06cc) {
window.event.keyCode = 0x064a;
}
if (lang == 1) { // If Farsi
if (key == 0x0020 && window.event.shiftKey) // Shift-space -> ZWNJ
window.event.keyCode = 0x200C;
else
window.event.keyCode = farsikey[key - 0x0020];
if (farsikey[key - 0x0020] == 92) {
window.event.keyCode = 0x0698;
}
if (farsikey[key - 0x0020] == 8205) {
window.event.keyCode = 0x067E;
}
}
return true;
}
</script>
خیلی هم عالی! ولی می شود آنرا درون یک فایل js قرار داد تا یکبار برای همیشه لود شود و نه هر بار با باز کردن هر صفحه.
مثال دیگر:
این مورد هم در سورس جاری تمام صفحات این فوروم تکراری است که نباید به این صورت باشد:
<!-- link rel="stylesheet" href="templates/subSilver/subSilver.css" type="text/css" -->
<style type="text/css">
<!--
/*
The original subSilver Theme for phpBB version 2+
Created by subBlue design
http://www.subBlue.com
NOTE: These CSS definitions are stored within the main page body so that you can use the phpBB2
theme administration centre. When you have finalised your style you could cut the final CSS code
and place it in an external file, deleting this section to save bandwidth.
*/
/* General page style. The scroll bar colours only visible in IE5.5+ */
img.banner1{
border-width: 2px;
border-style: solid;
border-color: #32CD32;
}
body {
background-color: #E5E5E5;
scrollbar-face-color: #DEE3E7;
scrollbar-highlight-color: #FFFFFF;
scrollbar-shadow-color: #DEE3E7;
scrollbar-3dlight-color: #D1D7DC;
scrollbar-arrow-color: #006699;
scrollbar-track-color: #EFEFEF;
scrollbar-darkshadow-color: #98AAB1;
}
/* General font families for common tags */
font,th,td,p { font-family: Tahoma, Tahoma, Tahoma, Tahoma }
a:link,a:active,a:visited { color : #006699; }
a:hover { text-decoration: underline; color : #DD6900; }
hr { height: 0px; border: solid #D1D7DC 0px; border-top-width: 1px;}
/* This is the border line & background colour round the entire page */
.bodyline { background-color: #FFFFFF; border: 1px #98AAB1 solid; }
/* This is the outline round the main forum tables */
.forumline { background-color: #FFFFFF; border: 2px #006699 solid; }
/* Main table cell colours and backgrounds */
td.row1 { background-color: #EFEFEF; }
td.row2 { background-color: #DEE3E7; }
td.row3 { background-color: #D1D7DC; }
/*
This is for the table cell above the Topics, Post & Last posts on the index.php page
By default this is the fading out gradiated silver background.
However, you could replace this with a bitmap specific for each forum
*/
td.rowpic {
background-color: #FFFFFF;
background-image: url(templates/subSilver/images/cellpic2.jpg);
background-repeat: repeat-y;
}
/* Header cells - the blue and silver gradient backgrounds */
th {
color: #FFA34F; font-size: 11px; font-weight : bold;
background-color: #006699; height: 25px;
background-image: url(templates/subSilver/images/cellpic3.gif);
}
td.cat,td.catHead,td.catSides,td.catLeft,td.catRig ht,td.catBottom {
background-image: url(templates/subSilver/images/cellpic1.gif);
background-color:#D1D7DC; border: #FFFFFF; border-style: solid; height: 28px;
}
/*
Setting additional nice inner borders for the main table cells.
The names indicate which sides the border will be on.
Don't worry if you don't understand this, just ignore it :-)
*/
td.cat,td.catHead,td.catBottom {
height: 29px;
border-width: 0px 0px 0px 0px;
}
th.thHead,th.thSides,th.thTop,th.thLeft,th.thRight ,th.thBottom,th.thCornerL,th.thCornerR {
font-weight: bold; border: #FFFFFF; border-style: solid; height: 28px;
}
td.row3Right,td.spaceRow {
background-color: #D1D7DC; border: #FFFFFF; border-style: solid;
}
th.thHead,td.catHead { font-size: 12px; border-width: 1px 1px 0px 1px; }
th.thSides,td.catSides,td.spaceRow { border-width: 0px 1px 0px 1px; }
th.thRight,td.catRight,td.row3Right { border-width: 0px 1px 0px 0px; }
th.thLeft,td.catLeft { border-width: 0px 0px 0px 1px; }
th.thBottom,td.catBottom { border-width: 0px 1px 1px 1px; }
th.thTop { border-width: 1px 0px 0px 0px; }
th.thCornerL { border-width: 1px 0px 0px 1px; }
th.thCornerR { border-width: 1px 1px 0px 0px; }
/* The largest text used in the index page title and toptic title etc. */
.maintitle {
font-weight: bold; font-size: 22px; font-family: "Tahoma",Tahoma, Tahoma, Tahoma, Tahoma;
text-decoration: none; line-height : 120%; color : #000000;
}
/* General text */
.gen { font-size : 12px; }
.genmed { font-size : 11px; }
.gensmall { font-size : 10px; }
.gen,.genmed,.gensmall { color : #000000; }
a.gen,a.genmed,a.gensmall { color: #006699; text-decoration: none; }
a.gen:hover,a.genmed:hover,a.gensmall:hover { color: #DD6900; text-decoration: underline; }
/* The register, login, search etc links at the top of the page */
.mainmenu { font-size : 11px; color : #000000 }
a.mainmenu { text-decoration: none; color : #006699; }
a.mainmenu:hover{ text-decoration: underline; color : #DD6900; }
/* Forum category titles */
.cattitle { font-weight: bold; font-size: 12px ; letter-spacing: 1px; color : #006699}
a.cattitle { text-decoration: none; color : #006699; }
a.cattitle:hover{ text-decoration: underline; }
/* Forum title: Text and link to the forums used in: index.php */
.forumlink { font-weight: bold; font-size: 12px; color : #006699; }
a.forumlink { text-decoration: none; color : #006699; }
a.forumlink:hover{ text-decoration: underline; color : #DD6900; }
/* Used for the navigation text, (Page 1,2,3 etc) and the navigation bar when in a forum */
.nav { font-weight: bold; font-size: 11px; color : #000000;}
a.nav { text-decoration: none; color : #006699; }
a.nav:hover { text-decoration: underline; }
/* titles for the topics: could specify viewed link colour too */
.topictitle,h1,h2 { font-weight: bold; font-size: 11px; color : #000000; }
a.topictitle:link { text-decoration: none; color : #006699; }
a.topictitle:visited { text-decoration: none; color : #5493B4; }
a.topictitle:hover { text-decoration: underline; color : #DD6900; }
/* Name of poster in viewmsg.php and viewtopic.php and other places */
.name { font-size : 11px; color : #000000;}
/* Location, number of posts, post date etc */
.postdetails { font-size : 10px; color : #000000; }
/* The content of the posts (body of text) */
.postbody { font-size : 12px; line-height: 18px}
a.postlink:link { text-decoration: none; color : #006699 }
a.postlink:visited { text-decoration: none; color : #5493B4; }
a.postlink:hover { text-decoration: underline; color : #DD6900}
/* Quote & Code blocks */
/* font-family: Tahoma, Tahoma, Tahoma; font-size: 11px; color: #006600;*/
.code { direction:ltr;
font-family: "Helvetica"; font-size: 11px; color: "#000000";
background-color: #FAFAFA; border: #D1D7DC; border-style: solid;
border-left-width: 1px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px
}
.quote {
font-family: Tahoma, Tahoma, Tahoma, Tahoma; font-size: 11px; color: #444444; line-height: 125%;
background-color: #FAFAFA; border: #D1D7DC; border-style: solid;
border-left-width: 1px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px
}
/* Copyright and bottom info */
.copyright { font-size: 10px; font-family: Tahoma, Tahoma, Tahoma, Tahoma; color: #444444;
letter-spacing: -1px;}
a.copyright { color: #444444; text-decoration: none;}
a.copyright:hover { color: #000000; text-decoration: underline;}
/* Form elements */
input,textarea, select {
color : #000000;
font: normal 11px Tahoma, Tahoma, Tahoma, Tahoma;
border-color : #000000;
}
/* The text input fields background colour */
input.post, textarea.post, select {
background-color : #FFFFFF;
}
input { text-indent : 2px; }
/* The buttons used for bbCode styling in message post */
input.button {
background-color : #EFEFEF;
color : #000000;
font-size: 11px; font-family: Tahoma, Tahoma, Tahoma, Tahoma;
}
/* The main submit button option */
input.mainoption {
background-color : #FAFAFA;
font-weight : bold;
}
/* None-bold submit button */
input.liteoption {
background-color : #FAFAFA;
font-weight : normal;
}
/* This is the line in the posting page which shows the rollover
help line. This is actually a text box, but if set to be the same
colour as the background no one will know ;)
*/
.helpline { background-color: #DEE3E7; border-style: none; }
/* Import the fancy styles for IE only (NS4.x doesn't use the @import function) */
@import url("templates/subSilver/formIE.css");
-->
</style>
<script language="Javascript" type="text/javascript">
<!--
if ( 0 )
{
window.open('privmsg.php?mode=newpm', '_phpbbprivmsg',
'HEIGHT=225,resizable=yes,WIDTH=400');;
}
//-->
خیلی راحت اینرا هم می توان در یک فایل css ذخیره کرد تا یکبار برای همیشه لود شود.
مزایا:
1- هر چند وقت به چند وقت سایت نمی خوابد! زیرا حجم هر صفحه به شدت کاهش پیدا می کند :wink:
2- صفحات بسیار سریعتر لود می شوند چون فایلهای js و css در دایرکتوری تمپ اینترنت اکسپلورر ذخیره می شوند و نیازی به بارگذاری مجدد ندارند و برای تمام صفحات هم یکسان است
موفق باشید.