Including javascript with plugin

I’m a little confused about how to include javascript alongside plugin functions. If I do this:

myplugin/myplugin.php

function myPluginFunction() {
 ...
}

js('/assets/plugins/myplugin/js/scripts.js')

myplugin/assets/js/scripts.js

console.log('success!');

it doesn’t work. This error comes up in the console:

scripts.js:1 Uncaught SyntaxError: Unexpected token <

and when I look at the resource in Dev Tools, it looks like this:

<script src="http://project.dev/assets/plugins/myplugin/js/reset.js"></script>console.log('success!')

I could always just load these scripts in my templates, but in this case I need to add a small bit of JS functionality to the panel.

What’s up?

Looks like your script is parsed outside the scoop.

I use it like this;

<?php

class MyField extends TextField {

  static public $assets = array(
    'js' => array(
      'my_script.js'
    )
  );

  public function content() {
...
  }

  public function input() {
...
  }
}

?>

- edit - Nevermind, this is the code for a field, not a plug-in. (still your code is rendered outside the scoop, 'though).

You can’t currently load JS into the Panel from a plugin, only from a field.