Post by boraz » Wed Aug 20, 2008 11:10 pm

I've noticed that when i include stylesheet in a template file (e.g. account_login.tpl) the tag is automatically moved into section of the page. Can anyone tell me where's the code responsible for that? I'd also like to 'move' the tags containing javascript files to same way.
Thanks for help.

Newbie

Posts

Joined
Tue Jul 29, 2008 5:37 am

Post by Qphoria » Wed Aug 20, 2008 11:16 pm

Hmm.. I don't see that happening at all at my site. Note the source shows the default.css at the top, but the product.css in the middle. I wish it would do what you say it does actually, but I think the css should be setup differently anyway to be automatic, so that proper overrides can take place, without hardcoding the css file in the tpl file, and it would keep it all in the head tag

Also, the css needs to move to the head tag so that it can properly validate, as it is highly illegal the way it is now :P

So I guess what I'm saying is that css and js should be handled a lot differently. We will see what changes are in store for 0.8 and what may need to be done to improve on the system.

I already have a plan on paper for the css stuff in my override system discussion topic:
http://forum.opencart.com/index.php/top ... ml#msg7771

js would actually follow the same path.
Last edited by Qphoria on Wed Aug 20, 2008 11:25 pm, edited 1 time in total.

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by boraz » Wed Aug 20, 2008 11:47 pm

Hm, I'm sure it's working the way i wrote, but only for the CSS links. I think I'm using v 0.7.7. In the store demo it doesn't work actually - the links are in the middle, as You said (older version?). In my store css link is behaving as i'd expect (moving to ) but Javascript not. I wish someone could tell me why it's happening and show some code, so i can fix the javascript tags too. I haven't modified code to do that, it's default behavior.

Newbie

Posts

Joined
Tue Jul 29, 2008 5:37 am

Post by Qphoria » Thu Aug 21, 2008 12:04 am

hmm.. I have 0.7.8.. maybe they changed that. I am not familiar with previous versions

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by boraz » Thu Aug 21, 2008 3:02 am

There must be a built-in function (at least in v 0.7.7) which grabs all the elements from the template file and puts them into . Can anyone help me?
Last edited by boraz on Thu Aug 21, 2008 3:05 am, edited 1 time in total.

Newbie

Posts

Joined
Tue Jul 29, 2008 5:37 am

Post by bruce » Thu Aug 21, 2008 9:56 am

if you are using the xhtml contribution (possibly built into 0.7.8), this is what it does

Active Member

Posts

Joined
Wed Dec 12, 2007 2:26 pm

Post by boraz » Thu Aug 21, 2008 6:18 pm

bruce wrote: if you are using the xhtml contribution (possibly built into 0.7.8), this is what it does
Yeah, that's it. Thanks Bruce  :)

Code: Select all

static function linkReordered( $str ) {
		//return $str;
		$headEnd = stripos( $str, "</head>", 0 );
		if ($headEnd === FALSE) {
			return $str;
		}
		$result = substr( $str, 0, $headEnd+strlen("</head>") );
		$previousPos = $headEnd + strlen("</head>");
		while (TRUE) {
			$linkStart = stripos( $str, "<link", $previousPos );
			if ($linkStart === FALSE) {
				$result = $result . substr( $str, $previousPos );
				break;
			}
			$linkEnd = stripos( $str, ">", $linkStart );
			if ($linkEnd == FALSE) {
				$result = $result . substr( $str, $previousPos );
				break;
			}
			// insert everything from $previousPos to $linkStart at the end of $result
			$result = $result . substr( $str, $previousPos, $linkStart-$previousPos );
			// insert everything from $linkStart to $linkEnd+1 inclusive to $result at postion $headEnd
			$result = substr( $result, 0, $headEnd ) . PHP_EOL . substr( $str, $linkStart, $linkEnd-$linkStart+1 ) . PHP_EOL . substr( $result, $headEnd );
			$previousPos = $linkEnd+1;
		}
		return $result;
	}
Btw if anyone could add support for tags to this function, I'd be glad. My php knowledge is pretty limited. It'd be very nice to include javascript files in specific templates, not in main template file (template.tpl) by checking controller variables. I'm sure it's not only me who thinks so:)
Last edited by boraz on Thu Aug 21, 2008 6:50 pm, edited 1 time in total.

Newbie

Posts

Joined
Tue Jul 29, 2008 5:37 am

Post by JNeuhoff » Thu Aug 21, 2008 8:07 pm

boraz wrote: I've noticed that when i include stylesheet in a template file (e.g. account_login.tpl) the tag is automatically moved into section of the page. Can anyone tell me where's the code responsible for that? I'd also like to 'move' the tags containing javascript files to same way.
Thanks for help.
Moving the tags into the section is done by the OpenCart XHTML plugin module which I wrote a while ago for OpenCart version 0.7.7. Please be aware that I have never tested it for OpenCart 0.7.8 so no guarantee it will even work with that version. The code which relocates the tags can be found in the file

  /library/environment/response.php

which has been modified by the XHTML plugin. The function where it happens is called  linkReordered

Export/Import Tool * SpamBot Buster * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Tag Manager * Survey Plus * OpenTwig


User avatar
Guru Member
Online

Posts

Joined
Wed Dec 05, 2007 3:38 am


Post by boraz » Thu Aug 21, 2008 8:45 pm

JNeuhoff could you also add tag support to this function? I've tried to modify it and ended up with this (just added some variables):

Code: Select all

static function linkReordered( $str ) {
		//return $str;
		$headEnd = stripos( $str, "</head>", 0 );
		if ($headEnd === FALSE) {
			return $str;
		}
		$result = substr( $str, 0, $headEnd+strlen("</head>") );
		$previousPos = $headEnd + strlen("</head>");
		while (TRUE) {
			$linkStart = stripos( $str, "<link", $previousPos );
			$scriptStart = stripos( $str, "<script", $previousPos );
			if ($linkStart === FALSE || $scriptStart === FALSE) {
				$result = $result . substr( $str, $previousPos );
				break;
			}
			$linkEnd = stripos( $str, ">", $linkStart );
			$scriptEnd = stripos( $str, "</script>", $scriptStart );
			if ($linkEnd == FALSE || $scriptEnd === FALSE) {
				$result = $result . substr( $str, $previousPos );
				break;
			}
			// insert everything from $previousPos to $linkStart at the end of $result
			$result = $result . substr( $str, $previousPos, $linkStart-$previousPos );
			// insert everything from $linkStart to $linkEnd+1 inclusive to $result at postion $headEnd
			$result = substr( $result, 0, $headEnd ) . PHP_EOL . substr( $str, $linkStart, $linkEnd-$linkStart+1 ) . PHP_EOL . substr( $result, $headEnd );
			$previousPos = $linkEnd+1;
		}
		return $result;
	}

Newbie

Posts

Joined
Tue Jul 29, 2008 5:37 am

Post by Qphoria » Thu Aug 21, 2008 9:20 pm

Haven't tried it, but maybe you could just clone the function and make a new one for script:

Code: Select all

    static function scriptReordered( $str ) {
		//return $str;
		$headEnd = stripos( $str, "</head>", 0 );
		if ($headEnd === FALSE) {
			return $str;
		}
		$result = substr( $str, 0, $headEnd+strlen("</head>") );
		$previousPos = $headEnd + strlen("</head>");
		while (TRUE) {
			$scriptStart = stripos( $str, "<script", $previousPos );
			if ($scriptStart === FALSE) {
				$result = $result . substr( $str, $previousPos );
				break;
			}
			$scriptEnd = stripos( $str, ">", $scriptStart );
			if ($scriptEnd == FALSE) {
				$result = $result . substr( $str, $previousPos );
				break;
			}
			// insert everything from $previousPos to $scriptStart at the end of $result
			$result = $result . substr( $str, $previousPos, $scriptStart-$previousPos );
			// insert everything from $scriptStart to $scriptEnd+1 inclusive to $result at postion $headEnd
			$result = substr( $result, 0, $headEnd ) . PHP_EOL . substr( $str, $scriptStart, $scriptEnd-$scriptStart+1 ) . PHP_EOL . substr( $result, $headEnd );
			$previousPos = $scriptEnd+1;
		}
		return $result;
	}
Then just add the call for it underneath the call for the link one

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by fido-x » Thu Aug 21, 2008 9:32 pm

While it is necessary to place links to external stylesheets in the head for standards compliance, the same is not true for javascript, because a script can be placed anywhere in the HTML code. Inline scripting is, after all, part of the HTML specification.

Image
Modules for OpenCart 2.3.0.2
Homepage Module [Free - since OpenCart 0.7.7]
Multistore Extensions
Store Manager Multi-Vendor/Multi-Store management tool

If you're not living on the edge ... you're taking up too much space!


User avatar
Expert Member

Posts

Joined
Sat Jun 28, 2008 1:09 am
Location - Tasmania, Australia

Post by Qphoria » Thu Aug 21, 2008 9:49 pm

Good point.

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by JNeuhoff » Sat Aug 23, 2008 12:25 am

fido-x wrote: While it is necessary to place links to external stylesheets in the head for standards compliance, the same is not true for javascript, because a script can be placed anywhere in the HTML code. Inline scripting is, after all, part of the HTML specification.
Precisely. That's why I didn't include tags in the relocation. I am not even changing the ampersands within tags.

Export/Import Tool * SpamBot Buster * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Tag Manager * Survey Plus * OpenTwig


User avatar
Guru Member
Online

Posts

Joined
Wed Dec 05, 2007 3:38 am

Who is online

Users browsing this forum: No registered users and 3 guests