Forums / Setup & design / use of a CSS according to the navigator

use of a CSS according to the navigator

Author Message

tic 9

Wednesday 07 May 2008 4:21:27 am

hi!
I would like well that for each navigator that I can use a different CSS but my code does not function under eZ.
But the same code functions well apart from eZ.
Here my code javasript:

<script language="JavaScript" type="text/javascript">
var nn = (document.layers) ? true : false;
var ie = (document.all) ? true : false;
var dom = (document.getElementById && !document.all) ? true : false;
var oper= (document.all && (navigator.userAgent.toLowerCase().indexOf("opera") != -1)) ? true : false;
if (oper){
document.write( '@import url({"stylesheets/opera.css"|ezdesign(no)});');
}
else if (ie) {
document.writeln(''@import url({"stylesheets/ie.css"|ezdesign(no)});');
}
else if (dom || nn) {
document.write( '@import url({"stylesheets/nce.css"|ezdesign(no)});');
}
</script>

André R.

Wednesday 07 May 2008 6:34:31 am

You need to escape the bractes ( { & } ) used in you javascript code.
Take a look in the doc, search/look for the 'ldelim', 'rdelim' and 'literal' template functions.

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

tic 9

Wednesday 07 May 2008 7:00:52 am

thank you for your answer but the problem always continues! I still do not manage to apply the CSS for each navigator here my modified code:
{literal}
<script language="JavaScript" type="text/javascript">
var nn = (document.layers) ? true : false;
var ie = (document.all) ? true : false;
var dom = (document.getElementById && !document.all) ? true : false;
var oper= (document.all && (navigator.userAgent.toLowerCase().indexOf("opera") != -1)) ? true : false;
if (oper){
document.write( '@import url({ldelim}"stylesheets/opera.css"|ezdesign{rdelim});');
}
else if (ie) {
document.writeln('@import url({ldelim}"stylesheets/ie.css"|ezdesign{rdelim});');
}
else if (dom || nn) {
document.write( '@import url({ldelim}"stylesheets/nce.css"|ezdesign{rdelim});');
}
</script>
{/literal}

Łukasz Serwatka

Wednesday 07 May 2008 7:12:46 am

Do not use {ldelim} together with {literal}. If you are using {literal} then replace {ldelim} with { and same for {rdelim}, repalce with }.

BTW, Opera, Gecko and Webkit based web browsers support web standards better then IE. In most cases the IE conditional comments are sufficient to fix issues. Do you really need this check?

Personal website -> http://serwatka.net
Blog (about eZ Publish) -> http://serwatka.net/blog

tic 9

Thursday 08 May 2008 2:36:06 am

hi!

I need really this control for the need for my site! For what of IE, I think find a means of resoudre the problem. But the difficulty remains on other navigators. Isn't it possible to make this control with eZ?

André R.

Thursday 08 May 2008 4:28:45 am

Here is how you could do it:

<script language="JavaScript" type="text/javascript">
<!--
if ( window.opera )
    document.write( '<link rel="stylesheet" type="text/css" href={"stylesheets/opera.css"|ezdesign} \/>');
else if ( document.all )
    document.writeln('<link rel="stylesheet" type="text/css" href={"stylesheets/ie.css"|ezdesign} \/>');
else if ( document.getElementById || document.layers )
    document.write( '<link rel="stylesheet" type="text/css" href={"stylesheets/nce.css"|ezdesign} \/>');
//-->
</script>

And here is how you use javascript brackets inside templates:

<script language="JavaScript" type="text/javascript">
<!--
if ( window.opera )
{ldelim}
    document.write( '<link rel="stylesheet" type="text/css" href={"stylesheets/opera.css"|ezdesign} \/>');
{rdelim}
else if ( document.all )
{ldelim}
    document.writeln('<link rel="stylesheet" type="text/css" href={"stylesheets/ie.css"|ezdesign} \/>');
{rdelim}
else if ( document.getElementById || document.layers )
{ldelim}
    document.write( '<link rel="stylesheet" type="text/css" href={"stylesheets/nce.css"|ezdesign} \/>');
{rdelim}
//-->
</script>

But this way of browser sniffing is not very modern, this is how web developer did things 5-10 years ago.
Today most web developers tend to code for new browsers, and have extra css that is added for older browsers, witch is mostly internet explorer..

<!-- first include you standard css, then for ie 6 and lower, then ie 7 -->
<!--[if lt IE 7]>
<link rel="stylesheet" type="text/css" href={"stylesheets/ie6.css"|ezdesign} />
<![endif]-->
<!--[if IE 7]>
<link rel="stylesheet" type="text/css" href={"stylesheets/ie7.css"|ezdesign} />
<![endif]-->

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

eZ debug

Timing: Jan 18 2025 22:31:48
Script start
Timing: Jan 18 2025 22:31:48
Module start 'content'
Timing: Jan 18 2025 22:31:49
Module end 'content'
Timing: Jan 18 2025 22:31:49
Script end

Main resources:

Total runtime0.9131 sec
Peak memory usage4,096.0000 KB
Database Queries205

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0077 588.9453180.8281
Module start 'content' 0.00770.7376 769.7734636.3359
Module end 'content' 0.74530.1676 1,406.1094341.0703
Script end 0.9129  1,747.1797 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00520.5668210.0002
Check MTime0.00170.1820210.0001
Mysql Total
Database connection0.00110.117210.0011
Mysqli_queries0.821990.01952050.0040
Looping result0.00260.28162030.0000
Template Total0.877196.120.4385
Template load0.00300.326920.0015
Template processing0.874195.731520.4370
Template load and register function0.00020.018010.0002
states
state_id_array0.00180.201410.0018
state_identifier_array0.00130.137620.0006
Override
Cache load0.00280.3016610.0000
Sytem overhead
Fetch class attribute can translate value0.00190.208740.0005
Fetch class attribute name0.00140.150280.0002
XML
Image XML parsing0.00140.148240.0003
class_abstraction
Instantiating content class attribute0.00000.002090.0000
General
dbfile0.00230.2499360.0001
String conversion0.00000.000630.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
6content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
5content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
9content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
3content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
3content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 28
 Number of unique templates used: 7

Time used to render debug report: 0.0002 secs