Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
jmd_admin_js: Run page-specific JS in the backend
This is a little plugin that extends stm_javascript (and with a little fix also spf_js). You can use it to run JS on specific events or on all events in the admin interface (excluding “plugin”).
{Edited to add the pointer to spf_js. – Uli}
Last edited by uli (2014-10-13 15:52:01)
Offline
Re: jmd_admin_js: Run page-specific JS in the backend
Excellent! Does this mean we could, for instance, add a date-picker to certain custom fields?
TXP Builders – finely-crafted code, design and txp
Online
Re: jmd_admin_js: Run page-specific JS in the backend
You most certainly can :).
Offline
Re: jmd_admin_js: Run page-specific JS in the backend
Me likey. :)
—
T
Offline
Re: jmd_admin_js: Run page-specific JS in the backend
It’s like a plugin for simpler plugins…
Piwik Dashboard, Google Analytics Dashboard, Minibar, Article Image Colorpicker, Admin Datepicker, Admin Google Map, Admin Colorpicker
Offline
Re: jmd_admin_js: Run page-specific JS in the backend
But how to use it? Where to write js code?
Providing help in hacking ATM! Come to courses and don’t forget to bring us notebook and hammer! What for notebook? What a kind of hacker you are without notebok?
Offline
Re: jmd_admin_js: Run page-specific JS in the backend
Write your JS in Presentation>JS (stm_javascript) and save it as “default” to have it loaded on every admin page or save it as an event name to have it run on certain pages (see help for a list).
Offline
Re: jmd_admin_js: Run page-specific JS in the backend
Jon-Michael, What’s the best way to include javascript libraries such as a jquery add-on (or series thereof)?
For the moment I ‘tricked it’ by closing the open tag, inserting my linked js-file and re-opening the tag:
</script>
<link rel="stylesheet" media="screen" type="text/css" href="/js/theme/ui.all.css" />
<script src='/js/jquery-ui-personalized-1.5.3.js' type='text/javascript'></script>
<script type="text/javascript">
// Adds date-picker to custom-2
$(document).ready(function(){
$("#custom-2").datepicker({ dateFormat: 'yy-mm-dd', showOn: 'button', buttonImage: '/js/theme/calendar.gif', buttonImageOnly: true });
});
Is there a better way?
Last edited by jakob (2009-02-18 22:53:00)
TXP Builders – finely-crafted code, design and txp
Online
Re: jmd_admin_js: Run page-specific JS in the backend
If you didn’t want HTML in there, you could paste the contents of the library into default, or use getScript:
$.getScript('/js/jquery-ui-personalized-1.5.3.js');
For the CSS, try:
$('head').append('<link .../>');
Offline
Re: jmd_admin_js: Run page-specific JS in the backend
Thanks. I didn’t know about those two and that looks altogether neater.
TXP Builders – finely-crafted code, design and txp
Online
Re: jmd_admin_js: Run page-specific JS in the backend
Sorry, still having problems here. This works fine:
</script>
<link rel="stylesheet" media="screen" type="text/css" href="/js/theme/ui.all.css" />
<script src='/js/jquery-ui-personalized-1.5.3.js' type='text/javascript'></script>
<script type="text/javascript">
// Adds date-picker to custom-2
$(document).ready(function(){
$("#custom-2").datepicker({ dateFormat: 'yy-mm-dd', showOn: 'button', buttonImage: '/js/theme/calendar.gif', buttonImageOnly: true });
});
But the following returns no action and an error in firebug: $("#custom-2").datepicker is not a function
.
// Load script source
$.getScript('/js/jquery-ui-personalized-1.5.3.js');
// Add CSS to head
$('head').append('<link rel="stylesheet" media="screen" type="text/css" href="/js/theme/ui.all.css" />');
// Adds date-picker to custom-2
$("#custom-2").datepicker({ dateFormat: 'yy-mm-dd', showOn: 'button', buttonImage: '/js/theme/calendar.gif', buttonImageOnly: true });
Firebug indicates that both the script and the css has been loaded, as does attaching an alert to test loading as in the example on the jquery site. The jquery docs says getScript loads and executes the javascript file.
Wrapping either the whole lot or just the datepicker in $(document).ready(function(){ ... });
makes no difference. I’ve tried paring in down, leaving out the css, using datepicker() without any settings etc.
Any ideas on what I’m missing?
TXP Builders – finely-crafted code, design and txp
Online
Re: jmd_admin_js: Run page-specific JS in the backend
What about placing your $('#custom-2').datepicker(...)
code in the getScript callback?
$.getScript('/js/jquery-ui-personalized-1.5.3.js', function(){
$("#custom-2").datepicker({ dateFormat: 'yy-mm-dd', showOn: 'button', buttonImage: '/js/theme/calendar.gif', buttonImageOnly: true });
});
I haven’t tried this out, but I’ll try to take a look at it this weekend.
Offline