Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2009-05-15 15:37:33

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,793
Website

soo_required_files: per-article loading of JavaScript and CSS files

This plugin, in combination with a custom field, allows you to load JavaScript and CSS files in the document <head>, on a per-article basis. Useful if you use a JavaScript/CSS package such as Slimbox and only want to load the relevant files on pages where you actually need them.

Version history

0.2.8 (2020/3/15)

  • Fixed error notice when running plugin under Txp 4.8+ on a page with no required files

0.2.7 (2017/3/14)

  • Removes the preference added in 0.2.6 in favor of the global doctype preference. (NB: see Upgrade notes.)

0.2.6 (2017-02-23)

  • Tidier link and script tag output for HTML5

0.2.5 (2017-02-13)

  • Txp 4.6 compatibility update

0.2.3 (2010/12/20), 0.2.4 (2010/12/27)

  • Code cleaning only; no functional changes

0.2.2, released 2010/07/10

  • Tag contents can now include other Txp tags, allowing e.g. Txp conditional tags for further automation options.

0.2.1, released 2009/10/04

  • Fixed per-page/section loading in sub-directory installations

0.2, released 2009/09/26

  • per-page and/or per-section file loading
  • soo_required_files tag now works either as single or container tag
    • container tag: specify additional files/forms as tag contents
  • use any combination of per-article, per-page, per-section, or tag contents

0.1.1, released 2009/09/18

  • per-article loading of files and forms from a custom field
  • compatible with soo_plugin_pref

Documentation, download, and examples

Last edited by jsoo (2020-03-15 18:32:55)


Code is topiary

Offline

#2 2009-05-15 16:01:39

net-carver
Archived Plugin Author
Registered: 2006-03-08
Posts: 1,648

Re: soo_required_files: per-article loading of JavaScript and CSS files

Jeff

thanks for your plugins!


Steve

Offline

#3 2009-05-15 16:49:13

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,793
Website

Re: soo_required_files: per-article loading of JavaScript and CSS files

Thanks Steve — great to see you’re still around the forum. I won’t read too much into this, though ;)


Code is topiary

Offline

#4 2009-05-15 17:57:34

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,090
Website GitHub Mastodon Twitter

Re: soo_required_files: per-article loading of JavaScript and CSS files

jsoo wrote:

This plugin, in combination with a custom field, allows you to load JavaScript and CSS files in the document <head>, on a per-article basis. Useful if you use a JavaScript/CSS package such as Slimbox and only want to load the relevant files on pages where you actually need them.

Hi J Soo… apologies for not getting this. I’m not sure why this cannot be achieved with <txp:if_article_id ="1,2,5" >... or with <txp:if_custom_field name="javascript" val="js">


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#5 2009-05-15 18:06:33

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,793
Website

Re: soo_required_files: per-article loading of JavaScript and CSS files

colak wrote:

I’m not sure why this cannot be achieved with <txp:if_article_id ="1,2,5" >...

It can. It just becomes terribly awkward if you’re talking about more than one or two files.

or with <txp:if_custom_field name="javascript" val="js">

Only allows one value in the field.

Last edited by jsoo (2009-05-15 18:07:26)


Code is topiary

Offline

#6 2009-05-15 21:00:11

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: soo_required_files: per-article loading of JavaScript and CSS files

It’s nice to have this functionality as a plugin.
Thanks, jsoo.

I also think it could be done (not so) easily using custom fields + built-in tags (as colak posted) mixed with smd_each (yes, it requires a plugin too…, althought smd_each can also be used for other tasks in a site…).


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#7 2009-05-15 21:14:51

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,793
Website

Re: soo_required_files: per-article loading of JavaScript and CSS files

Good pointer. It’s hard to keep up with all of Bloke’s plugins! It could definitely be done as you say, although I suspect would involve some <txp:php> to get the preg_match() stuff I do to differentiate between files and form names. (I could easily be overlooking something, though.)


Code is topiary

Offline

#8 2009-09-18 14:25:33

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,793
Website

Re: soo_required_files: per-article loading of JavaScript and CSS files

Version 0.1.1 just released. The only change is compatibility with the soo_plugin_pref plugin preference management system.


Code is topiary

Offline

#9 2009-09-18 18:15:23

candyman
Member
From: Italy
Registered: 2006-08-08
Posts: 684

Re: soo_required_files: per-article loading of JavaScript and CSS files

The plugin is very interesting but, at least, one article must be published to load JavaScript or CSS for a custom page. Is there a way to choose the relevant files without any article?

Offline

#10 2009-09-18 18:55:20

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,793
Website

Re: soo_required_files: per-article loading of JavaScript and CSS files

candyman wrote:

The plugin is very interesting but, at least, one article must be published to load JavaScript or CSS for a custom page. Is there a way to choose the relevant files without any article?

No, the plugin is intentionally article-based. Can you give me an example of the situation you have in mind?


Code is topiary

Offline

#11 2009-09-25 15:21:26

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,793
Website

Re: soo_required_files: per-article loading of JavaScript and CSS files

candyman, I’ve had a few ideas about this. I’m considering adding two or three new attributes to expand the plugin’s scope:

  • page_files (boolean) — if true, look for css/js files with the same name as the current page (template)
  • section_files (boolean) — if true, look for css/js files with the same name as the current section

and maybe even:

  • category_files (boolean) — if true, look for css/js files with the same name as the current article categories

The plugin would do a file_exists() check in the default css and js directories (defaults as set in the plugin prefs), then output <link /> elements for existing files.

Is that the kind of thing you were thinking of?


Code is topiary

Offline

#12 2009-09-25 18:23:45

candyman
Member
From: Italy
Registered: 2006-08-08
Posts: 684

Re: soo_required_files: per-article loading of JavaScript and CSS files

I’ve a page that implement geoblogging: only the map, no articles in that page. It would be useful to load the GoogleMap script for this page only: from this my previous request.

In the meantime I’ve found the stm_javascript and jmd_admin_js plugins also.

Anyway if you can add these features it would be useful, I think.

Last edited by candyman (2009-09-25 18:25:47)

Offline

Board footer

Powered by FluxBB