Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2009-02-03 03:44:27

jm
Plugin Author
From: Missoula, MT
Registered: 2005-11-27
Posts: 1,746
Website

jmd_admin_js: Run page-specific JS in the backend

Download 0.1

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

#2 2009-02-03 08:25:59

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,352
Website

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

Offline

#3 2009-02-03 08:33:09

jm
Plugin Author
From: Missoula, MT
Registered: 2005-11-27
Posts: 1,746
Website

Re: jmd_admin_js: Run page-specific JS in the backend

You most certainly can :).

Offline

#4 2009-02-03 14:35:34

renobird
Member
From: Gainesville, Florida
Registered: 2005-03-02
Posts: 786
Website

Re: jmd_admin_js: Run page-specific JS in the backend

Me likey. :)


T

Offline

#5 2009-02-03 16:53:05

MattD
Plugin Author
From: Monterey, California
Registered: 2008-03-21
Posts: 1,254
Website

Re: jmd_admin_js: Run page-specific JS in the backend

It’s like a plugin for simpler plugins…


My Plugins

Piwik Dashboard, Google Analytics Dashboard, Minibar, Article Image Colorpicker, Admin Datepicker, Admin Google Map, Admin Colorpicker

Offline

#6 2009-02-11 22:06:21

the_ghost
Plugin Author
From: Minsk, The Republic of Belarus
Registered: 2007-07-26
Posts: 907
Website

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

#7 2009-02-11 22:08:33

jm
Plugin Author
From: Missoula, MT
Registered: 2005-11-27
Posts: 1,746
Website

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

#8 2009-02-18 22:29:59

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,352
Website

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

Offline

#9 2009-02-19 02:37:10

jm
Plugin Author
From: Missoula, MT
Registered: 2005-11-27
Posts: 1,746
Website

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

#10 2009-02-19 07:16:47

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,352
Website

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

Offline

#11 2009-02-19 09:23:59

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,352
Website

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

Offline

#12 2009-02-19 17:37:59

jm
Plugin Author
From: Missoula, MT
Registered: 2005-11-27
Posts: 1,746
Website

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

Board footer

Powered by FluxBB