Home
Download
Add-ons
Help
Forum
Organisation
Project
Welcome,
Guest
. Please
login
or
register
.
Did you miss your
activation email?
May 26, 2012, 06:48:45 PM
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
Search:
Advanced search
Wollen Sie dem WebsiteBaker Team beitreten?
Nähere Informationen finden Sie unter
hier
und auf unserer
neuen Webseite
.
155549
Posts in
21714
Topics by
7760
Members
Latest Member:
gx-world
WebsiteBaker Community Forum
English
Help & Support
(Moderators:
Argos
,
badknight
)
moveCssToHead($content)
Pages: [
1
]
Go Down
Author
Topic: moveCssToHead($content) (Read 641 times)
crnogorac081
AddOn Development
Offline
Posts: 1706
moveCssToHead($content)
«
on:
June 30, 2011, 03:21:36 PM »
Could someone please direct me how this moveCssToHead($content) works ?
I tried but no luck.. How $content must be styled? and is there a way to include JS on simular way ?
Edit: could someone please post example code ?
«
Last Edit: June 30, 2011, 03:28:38 PM by crnogorac081
»
Logged
Wow, I coded something myself: PM Messanger Modul ,Searchbox with suggestions
Stefek
WebsiteBaker Org e.V.
Offline
Posts: 4884
Re: moveCssToHead($content)
«
Reply #1 on:
June 30, 2011, 03:53:40 PM »
Hello Ivan,
this new function looks in the content if some css is in there.
If yes, it will be put in the <head> section of the html page.
See:
[WB_ROOT]\framework\frontend.functions.php
Code:
<?php
//
$pattern1
=
'/(?:.*?<body.*?)(<link[^>]*?\"text\/css\".*?\/>)(?:.*)/si'
;
$pattern2
=
'/(?:.*?<body.*?)(<style[^>]*?\"text\/css\"[^>]*?>
.*?<\/style>)(?:.*)/si';
The only advantage of this function is, that it ensures that there is no css in body anymore.
Unfortunatley the css will be put right before the closing </head> tag.
This is inconvenient while using with most of jquery scripts, where in most cases you need to have css loaded before the jquery stuff.
Kind regards,
Stefek
Logged
"In a time of universal deceit, telling the truth becomes a revolutionary act."
- George Orwell, Nineteen eighty-four (1984)
crnogorac081
AddOn Development
Offline
Posts: 1706
Re: moveCssToHead($content)
«
Reply #2 on:
June 30, 2011, 04:52:04 PM »
Hi,
here is a quick solution for this, you can load css right after <head> tag:
Code:
function moveCssToHead($content) {
// move css definitions into head section
$pattern1 = '/(?:.*?<body.*?)(<link[^>]*?\"text\/css\".*?\/>)(?:.*)/si';
$pattern2 = '/(?:.*?<body.*?)(<style[^>]*?\"text\/css\"[^>]*?>.*?<\/style>)(?:.*)/si';
$insert1 = array();
$insert2 = array();
if(preg_match_all($pattern1, $content, $matches)) {
$insert1 = $matches[1];
$content = str_replace($insert1, '', $content);
}
if(preg_match_all($pattern2, $content, $matches)) {
$insert2 = $matches[1];
$content = str_replace($insert2, '', $content);
}
$insert = array_merge($insert1, $insert2);
$insert = "\n<head>\n".implode("\n", $insert)."\n<";
$content = preg_replace('/<head>.*?</si', $insert, $content);
return $content;
}
previous code was inserting script before </head></body> and this one after <head>
so now you can load JS above and I think it should work without problems
Logged
Wow, I coded something myself: PM Messanger Modul ,Searchbox with suggestions
Stefek
WebsiteBaker Org e.V.
Offline
Posts: 4884
Re: moveCssToHead($content)
«
Reply #3 on:
June 30, 2011, 05:20:14 PM »
Hello Ivan,
thank you.
What I think, it would be much better (core wise) to combine this function
with the
register_frontend_m
odfiles()
Function.
So CSS from Body would be moved directly to the the place where the function call
register_frontend_m
odfiles("css");
is put in the index.php of the template.
Kind regards,
Stefek
Logged
"In a time of universal deceit, telling the truth becomes a revolutionary act."
- George Orwell, Nineteen eighty-four (1984)
crnogorac081
AddOn Development
Offline
Posts: 1706
Re: moveCssToHead($content)
«
Reply #4 on:
June 30, 2011, 06:10:21 PM »
Another modification,
Code:
function moveCssToHead($content) {
// move css definitions into head section
$pattern1 = '/(?:.*?<body.*?)(<link[^>]*?\"text\/css\".*?\/>)(?:.*)/si';
$pattern2 = '/(?:.*?<body.*?)(<style[^>]*?\"text\/css\"[^>]*?>.*?<\/style>)(?:.*)/si';
$insert1 = array();
$insert2 = array();
if(preg_match_all($pattern1, $content, $matches)) {
$insert1 = $matches[1];
$content = str_replace($insert1, '', $content);
}
if(preg_match_all($pattern2, $content, $matches)) {
$insert2 = $matches[1];
$content = str_replace($insert2, '', $content);
}
$insert = array_merge($insert1, $insert2);
//
$insert = "\n<head>\n".implode("\n", $insert)."\n<";
//
$content = preg_replace('/<head>.*?</si', $insert, $content);
$insert = "<link $1 />\n".implode("\n", $insert)."\n";
$content = preg_replace('/<link (.+?) \/>(.*?)/si', $insert, $content,1);
return $content;
}
Now, it the css is not loaded after <head> tag, but after first <link .... /> tag. It is ussually the css of the template
Logged
Wow, I coded something myself: PM Messanger Modul ,Searchbox with suggestions
Luisehahne
Board Member
Development Team
Offline
Posts: 3147
Re: moveCssToHead($content)
«
Reply #5 on:
June 30, 2011, 08:43:06 PM »
In many modules you have following code:
Code:
// check if backend.css file needs to be included into the <body></body> of modify.php
if(!method_exists($admin, 'register_backend_modfiles') && file_exists(WB_PATH ."/modules/droplets/backend.css")) {
echo '<style type="text/css">';
include(WB_PATH .'/modules/droplets/backend.css');
echo "n</style>n";
}
and the style block will be set within the body tag. In my point of view not all styleblock combination are proofed.
Please create a Ticket on project side.
Dietmar
Logged
We are human beings - and nobody is perfect at all.
Stefek
WebsiteBaker Org e.V.
Offline
Posts: 4884
Re: moveCssToHead($content)
«
Reply #6 on:
June 30, 2011, 08:50:25 PM »
Quote from: crnogorac081 on June 30, 2011, 06:10:21 PM
Now, it the css is not loaded after <head> tag, but after first <link .... /> tag. It is ussually the css of the template
I like this one more.
Nice, Ivan.
Some day we should have a more sophisticated css/js inclusion as we do today.
In best case the
moveCssToHead()
function repair some inconsistencies with the W3C Validator.
BTW.
I am using OpF Dashboard to gain full control of js/css files.
Works like a charm.
Regards,
Stefek
Logged
"In a time of universal deceit, telling the truth becomes a revolutionary act."
- George Orwell, Nineteen eighty-four (1984)
DarkViper
Development Team
Offline
Posts: 1253
Re: moveCssToHead($content)
«
Reply #7 on:
June 30, 2011, 09:22:26 PM »
Quote from: Stefek on June 30, 2011, 08:50:25 PM
Some day we should have a more sophisticated css/js inclusion as we do today.
is planned for 2.9.1 or 2.9.2 (needs little mods in modules)
Quote from: Stefek on June 30, 2011, 08:50:25 PM
In best case the
moveCssToHead()
function repair some inconsistencies with the W3C Validator.
for this reason only the function is made.
Logged
Anleitungen lesen und selber nachdenken ist anstrengend... Da lass ich doch lieber andere für mich denken...
In
1984
: Nineteen Eighty-Four is a unrealistic utopia!!
In
2012
: Nineteen Eighty-Four is a little piece only of our reality!!
crnogorac081
AddOn Development
Offline
Posts: 1706
Re: moveCssToHead($content)
«
Reply #8 on:
June 30, 2011, 11:17:28 PM »
Quote from: Luisehahne on June 30, 2011, 08:43:06 PM
In many modules you have following code:
Code:
// check if backend.css file needs to be included into the <body></body> of modify.php
if(!method_exists($admin, 'register_backend_modfiles') && file_exists(WB_PATH ."/modules/droplets/backend.css")) {
echo '<style type="text/css">';
include(WB_PATH .'/modules/droplets/backend.css');
echo "n</style>n";
}
but does this work for frontend ?
and the style block will be set within the body tag. In my point of view not all styleblock combination are proofed.
Please create a Ticket on project side.
Dietmar
Logged
Wow, I coded something myself: PM Messanger Modul ,Searchbox with suggestions
Pages: [
1
]
Go Up
Jump to:
Please select a destination:
-----------------------------
General
-----------------------------
=> General Announcements
=> Security Announcements
=> Documentation
=> WebsiteBaker Website Showcase
=> Guest Area & Off-Topic
-----------------------------
English
-----------------------------
=> WebsiteBaker 2.9
===> Announcements
===> Help/Support
=====> Modules / Extensions
===> Suggestions
===> Software bugs
=> Help & Support
=> Modules
=> Droplets (PHP code for use with Droplet module) & Snippets (raw PHP code)
=> jQuery
=> Templates, Menus & Design
=> WebsiteBaker Language Files
=> WebsiteBaker 2.x discussion
=> WebsiteBaker 3
=> Archive (posts up to 2007)
-----------------------------
Deutsch (German)
-----------------------------
=> Ankündigungen
=> WebsiteBaker 2.9
===> Ankündigungen
===> Hilfe/Support
=====> Module / Extensions
===> Vorschläge
===> Softwarefehler
===> Erfahrungs und Testberichte
=> Hilfe/Support
=> Module & Snippets
=> Templates & Design
=> Tutorials
=> jQuery
=> Diskussion über WB
=> Off-Topic
=> Archiv für Themen bis 2007
-----------------------------
Nederlands (Dutch)
-----------------------------
=> Aankondigingen
=> Hulp & Ondersteuning
=> Niet-Terzake (Off Topic)
-----------------------------
Francais (French)
-----------------------------
=> Help/Support
-----------------------------
Italiano (Italian)
-----------------------------
=> Help/Support
-----------------------------
Bakery (WB shop module)
-----------------------------
=> Bakery English
=> Bakery Deutsch
-----------------------------
KeepInTouch (Multi Contact Module)
-----------------------------
=> KeepInTouch English
=> KeepInTouch Deutsch
Loading...