J!2.5 JCaption code

General questions relating to Joomla! 2.5. Note: All 1.6 and 1.7 releases have reached end of life and should be updated to 2.5. There are other boards for more specific help on Joomla! features and extensions.

Moderator: General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting.
Forum Post Assistant - If you are serious about wanting help, you should use this tool to help you post.
Locked
RedEye
Joomla! Ace
Joomla! Ace
Posts: 1460
Joined: Sat Jan 21, 2006 8:42 pm

J!2.5 JCaption code

Post by RedEye » Wed Jan 25, 2012 7:57 pm

Does someone know where the JCaption is added? I guess it`s a JHtml::_() call how adds this code but where it is, I not want this by default >:(

Code: Select all

  <script>
window.addEvent('load', function() {
				new JCaption('img.caption');
			});
  </script>
Last edited by RedEye on Wed Jan 25, 2012 8:51 pm, edited 1 time in total.

RedEye
Joomla! Ace
Joomla! Ace
Posts: 1460
Joined: Sat Jan 21, 2006 8:42 pm

Re: J!2.5 JCaption code

Post by RedEye » Wed Jan 25, 2012 8:51 pm

Finally found it... but pls tell me what the hell does this make in the main controller for the content component?
This should go into the views so that we easily can override it from templates if we not want it.
It is also there in 1.7 but in 1.7 was no script declaration added only the caption.js script itself what was not a problem at all but know I need to comment this out in the core file :(

Alex1974
Joomla! Apprentice
Joomla! Apprentice
Posts: 5
Joined: Fri Jan 27, 2012 7:51 pm

Re: J!2.5 JCaption code

Post by Alex1974 » Fri Jan 27, 2012 8:03 pm

Good Day
Me too, I want to delete J!2.5 JCaption code.

Code: Select all

<script>
     window.addEvent('load', function() {
            new JCaption('img.caption');
         });
</script>

vyatka
Joomla! Fledgling
Joomla! Fledgling
Posts: 4
Joined: Sun Nov 27, 2011 1:54 pm
Location: Kazan, Russia
Contact:

Re: J!2.5 JCaption code

Post by vyatka » Thu Feb 02, 2012 3:14 pm

Yeah, me too. WTF, I don't need this code on my site.

lyndonr
Joomla! Apprentice
Joomla! Apprentice
Posts: 44
Joined: Tue Oct 16, 2007 2:33 am

Re: J!2.5 JCaption code

Post by lyndonr » Fri Feb 03, 2012 8:17 pm

same here...

this worked nicely in 1.7.x the head of my template:

Code: Select all

unset($this->_scripts['/media/system/js/caption.js']);
up until my automatic update to 2.5.1 this morning! now unset seems to have no effect on caption.js. thankfully I can still remove mootools-core.js with unset.

what happened?

GameX32
Joomla! Fledgling
Joomla! Fledgling
Posts: 1
Joined: Mon Feb 06, 2012 11:23 am

Re: J!2.5 JCaption code

Post by GameX32 » Mon Feb 06, 2012 11:25 am

I also think this is very bad behavior. Possible this will be fixed soon?

kfmstudio
Joomla! Fledgling
Joomla! Fledgling
Posts: 1
Joined: Fri Feb 10, 2012 1:45 am

Re: J!2.5 JCaption code

Post by kfmstudio » Fri Feb 10, 2012 1:52 am

There is a dirty way of fixing it!
Refer to this link http://garrettbluma.com/2010/12/18/disa ... oomla-1-6/
It disables the Mootools Core but I did some additions in order to disable JCaptions based on his principle.

Below is the code :

Code: Select all

//$this->_scripts = (isset($data['scripts']) && !empty($data['scripts'])) ? $data['scripts'] : $this->_scripts;   // old code
$this->_scripts = (isset($data['scripts']) && is_array($data['scripts'])) ? $data['scripts'] : $this->_scripts;   // fix code
//$this->_script = (isset($data['script']) && !empty($data['script'])) ? $data['script'] : $this->_script;				// old code
$this->_script = (isset($data['script']) && is_array($data['script'])) ? $data['script'] : $this->_script;				// fix code
But wait, there is more! See code below you need to add in your template file:

Code: Select all

// at the top of your template
$headers=$this->getHeadData();
//var_dump($headers);
$headers['scripts'] = array();
$headers['script'] = array();
$this->setHeadData($headers);
Cheers! Hurray Joomla 2.5!

vyatka
Joomla! Fledgling
Joomla! Fledgling
Posts: 4
Joined: Sun Nov 27, 2011 1:54 pm
Location: Kazan, Russia
Contact:

Re: J!2.5 JCaption code

Post by vyatka » Fri Feb 10, 2012 12:33 pm

I think it's bug, and it's must be fixed in Joomla 2.5.2

Chris Burgess
Joomla! Intern
Joomla! Intern
Posts: 78
Joined: Sat Sep 17, 2011 11:53 pm
Location: Wollongong, Australia
Contact:

Re: J!2.5 JCaption code

Post by Chris Burgess » Thu Feb 23, 2012 6:18 am

For those wanting to find the source, it's in components/com_content/controller.php, line 51 (in 2.5.1). The line:

JHtml::_('behavior.caption');

Just remove that line to remove the JCaption code.

Alternatively, you could use a plugin that I've developed for managing MooTools and jQuery, and includes an option to remove the JCaption code. It's called InterExt. Look for it on the JED if you're interested. It's free.

lyndonr
Joomla! Apprentice
Joomla! Apprentice
Posts: 44
Joined: Tue Oct 16, 2007 2:33 am

Re: J!2.5 JCaption code

Post by lyndonr » Thu Feb 23, 2012 3:24 pm

chris - I used to be able to get rid of this with one line of code in the header of my template:

Code: Select all

unset($this->_scripts['/media/system/js/caption.js']);
is there some way to remove the new code in the same way?

hacking the core or installing a plugin just seems overkill to me. it's annoying that I have to do more to make newer versions of Joomla function as I wish. shouldn't it be the other way around?

any help is greatly appreciated.

Chris Burgess
Joomla! Intern
Joomla! Intern
Posts: 78
Joined: Sat Sep 17, 2011 11:53 pm
Location: Wollongong, Australia
Contact:

Re: J!2.5 JCaption code

Post by Chris Burgess » Fri Feb 24, 2012 12:20 am

Well, now that you've asked, I think I have worked out a way. The difficulty is that all calls to addScriptDeclaration simply concatenate on to a single variable _script. So it's not as simple as using unset on a single variable to remove it. But here is where the magic of regular expressions come in handy. Try putting this in your template header:

Code: Select all

unset($this->_scripts[JURI::root(true).'/media/system/js/caption.js']);
$this->_script = preg_replace('%window\.addEvent\(\'load\',\s*function\(\)\s*{\s*new\s*JCaption\(\'img.caption\'\);\s*}\);\s*%', '', $this->_script);
The preg_replace scans the whole content of the script block, replacing the JCaption block of code with an empty string. I just got it to work on a local test setup, and the regular expression is the same one I used in the plugin that I mentioned.

Chris Burgess
Joomla! Intern
Joomla! Intern
Posts: 78
Joined: Sat Sep 17, 2011 11:53 pm
Location: Wollongong, Australia
Contact:

Re: J!2.5 JCaption code

Post by Chris Burgess » Tue Feb 28, 2012 5:01 am

If anyone is interested I've written up a blog on this.

http://www.acuit.com.au/Blogs/removing- ... la2.5.html

lyndonr
Joomla! Apprentice
Joomla! Apprentice
Posts: 44
Joined: Tue Oct 16, 2007 2:33 am

Re: J!2.5 JCaption code

Post by lyndonr » Tue Feb 28, 2012 4:21 pm

great blog write-up. thanks very much.

-- any chance you could modify your regex to get rid of the script tags as well?

the script gets removed correctly, but I'm left with empty tags...

Code: Select all

  <script type="text/javascript">

  </script>
Last edited by lyndonr on Tue Feb 28, 2012 4:58 pm, edited 1 time in total.

Chris Burgess
Joomla! Intern
Joomla! Intern
Posts: 78
Joined: Sat Sep 17, 2011 11:53 pm
Location: Wollongong, Australia
Contact:

Re: J!2.5 JCaption code

Post by Chris Burgess » Wed Feb 29, 2012 2:50 am

@lyndor: Yes. Good point. Though it's not actually the regex that'll do it. The script tags themselves aren't part of the string, they get added later when rendering the page. The trick is to check if the _script variable is empty and then unset it so that you don't end up with an empty script tag.

Code: Select all

if (isset($this->_script['text/javascript']))
{
	$this->_script['text/javascript'] = preg_replace('%window\.addEvent\(\'load\',\s*function\(\)\s*{\s*new\s*JCaption\(\'img.caption\'\);\s*}\);\s*%', '', $this->_script['text/javascript']);
	if (empty($this->_script['text/javascript']))
		unset($this->_script['text/javascript']);
}

lyndonr
Joomla! Apprentice
Joomla! Apprentice
Posts: 44
Joined: Tue Oct 16, 2007 2:33 am

Re: J!2.5 JCaption code

Post by lyndonr » Wed Feb 29, 2012 4:11 pm

yup,. that did it. thanks so much for the help. incidentally, this is the full battery of clean up I currently use to get rid of joomla's annoying default scripts.. small and concise as I can get it. if anyone sees any room for improvement or compression by all means..

Code: Select all

unset($this->_scripts['/media/system/js/core.js']);
unset($this->_scripts['/media/system/js/mootools-core.js']);
// remove script and tags, needed since 2.5 update
unset($this->_scripts['/media/system/js/caption.js']);
$this->_script = preg_replace('%window\.addEvent\(\'load\',\s*function\(\)\s*{\s*new\s*JCaption\(\'img.caption\'\);\s*}\);\s*%', '', $this->_script);
if (empty($this->_script['text/javascript'])) unset($this->_script['text/javascript']);

hartsmar
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Sun Mar 04, 2012 2:37 pm

Re: J!2.5 JCaption code

Post by hartsmar » Sun Mar 04, 2012 3:08 pm

Hey... The above solution works like a charm. However, there is one thing I just noticed.
On all pages that are Category Blog type menu items, Joomla add the "tooltip" code (atleast on my site).
Which means it loads mootools-more.js and adds these lines of code to the head-section:

Code: Select all

<script type="text/javascript">
window.addEvent('domready', function() {
			$$('.hasTip').each(function(el) {
				var title = el.get('title');
				if (title) {
					var parts = title.split('::', 2);
					el.store('tip:title', parts[0]);
					el.store('tip:text', parts[1]);
				}
			});
			var JTooltips = new Tips($$('.hasTip'), { maxTitleChars: 50, fixed: false});
		});
</script>
Since mootools-core.js isn't loaded anymore, the page throws a javascript error and I'm therefor forced to load mootools-core.js all the time.
I really don't want the tooltip part in there because I don't use it and the mootools-more.js file is a whopping 233KB + the 93KB mootools-core.js!

Anyone have any idea how to disable the tooltip-inclusion on these pages?

lyndonr
Joomla! Apprentice
Joomla! Apprentice
Posts: 44
Joined: Tue Oct 16, 2007 2:33 am

Re: J!2.5 JCaption code

Post by lyndonr » Sun Mar 04, 2012 5:02 pm

@hartsmar this is not the case on my category blog pages. I think there's some script tags put in by default at the beginning of some of the included template files... might want to have a look at your category blog override and see if anything needs commenting out there. good luck.

hartsmar
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Sun Mar 04, 2012 2:37 pm

Re: J!2.5 JCaption code

Post by hartsmar » Sun Mar 04, 2012 5:10 pm

Well... Until I find a better solution (or the actual reason for why on earth the Tooltip code is included on those pages, I simply added a regexp replace for that code as well and removed loading of mootools-more.js just as with mootools-core.js...

Chris Burgess
Joomla! Intern
Joomla! Intern
Posts: 78
Joined: Sat Sep 17, 2011 11:53 pm
Location: Wollongong, Australia
Contact:

Re: J!2.5 JCaption code

Post by Chris Burgess » Mon Mar 05, 2012 5:32 am

I think the tooltip comes from components/com_content/views/category/tmpl/blog_item.php, the line:

Code: Select all

JHtml::_('behavior.tooltip');
The blog item template is also loaded conditionally from blog.php. From a quick scan, it looks like it depends on leading/intro article settings, which might explain why the tooltip is added in some category blog pages and not others.

But yes, if removing it from the core doesn't change anything, checking your template overrides is always a good idea.

User avatar
jessihance
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 113
Joined: Fri Apr 23, 2010 5:55 pm
Location: Santa Cruz, California, USA

How about modal.js?

Post by jessihance » Wed Mar 07, 2012 10:44 pm

Hi all,

Thanks for this help. It's way over my head and all I can do is copy and paste, but it works. :)

Anyone know how to stop loading modal.js? I tried adding another similar line:

Code: Select all

unset($this->_scripts['/media/system/js/modal.js']);
but it didn't seem to do anything.
Jessi Hance
Cruzio Internet

TownWebsites
Joomla! Apprentice
Joomla! Apprentice
Posts: 20
Joined: Tue Jan 11, 2011 4:00 am
Contact:

Re: J!2.5 JCaption code

Post by TownWebsites » Thu Mar 22, 2012 8:23 pm

Just stumbled on this one after version upgrades on a couple sites several weeks ago.

A vote for Joomla core developers to remember many people cannot use Joomla if it (front-end) requires jcaption , mootools, jquery, or any other large JS libraries! I serve dialup clients, and want to be able to continue to use Joomla!

Thanks.

Chris Burgess
Joomla! Intern
Joomla! Intern
Posts: 78
Joined: Sat Sep 17, 2011 11:53 pm
Location: Wollongong, Australia
Contact:

Re: J!2.5 JCaption code

Post by Chris Burgess » Sat Mar 24, 2012 1:58 am

@TownWebsites: Agreed. There really should be a simple admin option to be able to run the front-end in "MooTools free" mode, for those who either don't want the overhead of the library and are happy to go without the front-end MooTools features, or those who would prefer to use jQuery (or another library) instead and don't want both.
It is possible to remove all references to mootools in your template as (at least partially) outlined in this thread. If php editing is not something your comfortable with, there are plugins available in the JED under Core Enhancements -> Scripts. One of them I can vouch for given that I developed it, called InterExt. I haven't used any of the others.

lip420
Joomla! Explorer
Joomla! Explorer
Posts: 468
Joined: Thu Feb 17, 2011 6:13 am

Re: J!2.5 JCaption code

Post by lip420 » Wed Oct 24, 2012 6:46 pm

Chris Burgess wrote:Well, now that you've asked, I think I have worked out a way. The difficulty is that all calls to addScriptDeclaration simply concatenate on to a single variable _script. So it's not as simple as using unset on a single variable to remove it. But here is where the magic of regular expressions come in handy. Try putting this in your template header:

Code: Select all

unset($this->_scripts[JURI::root(true).'/media/system/js/caption.js']);
$this->_script = preg_replace('%window\.addEvent\(\'load\',\s*function\(\)\s*{\s*new\s*JCaption\(\'img.caption\'\);\s*}\);\s*%', '', $this->_script);
The preg_replace scans the whole content of the script block, replacing the JCaption block of code with an empty string. I just got it to work on a local test setup, and the regular expression is the same one I used in the plugin that I mentioned.
This gives me a warning error:

Warning: preg_replace() [function.preg-replace]: Compilation failed: unmatched parentheses at offset 17 in /home/eslins5/public_html/testsite/templates/mytemplate/index.php on line 29

lip420
Joomla! Explorer
Joomla! Explorer
Posts: 468
Joined: Thu Feb 17, 2011 6:13 am

Re: J!2.5 JCaption code

Post by lip420 » Wed Oct 24, 2012 7:19 pm

This is what is on that line: $document->_script = preg_replace('window\.addEvent\(\'domready\',\s*function\(\)\s*{\s*\$\$\(\'.hasTip\'\).each\(function\(el\)\s*{\s*var\s*title\s*=\s*el.get\(\'title\'\);\s*if\s*\(title\)\s*{\s*var\s*parts\s*=\s*title.split\(\'::\',\s*2\);\s*el.store\(\'tip:title\',\s*parts\[0\]\);\s*el.store\(\'tip:text\',\s*parts\[1\]\);\s*}\s*}\);\s*var\s*JTooltips\s*=\s*new\s*Tips\(\$\$\(\'.hasTip\'\),\s*{\s*maxTitleChars:\s*50,\s*fixed:\s*false}\);\s*}\);', '', $document->_script);


It seems to work on my root domain-I don't get errors there, but not in the test site folder.

lip420
Joomla! Explorer
Joomla! Explorer
Posts: 468
Joined: Thu Feb 17, 2011 6:13 am

Re: J!2.5 JCaption code

Post by lip420 » Sat Oct 27, 2012 3:51 pm



Locked

Return to “General Questions/New to Joomla! 2.5”