Using jQuery with Batman.js

I am experimenting with Batman.js and I would like to use jQuery with it for some standard Ajax and animation functionality.

I am following the installation instructions located at http://batmanjs.org/download.html and at the bottom of the page there is a short description of how to use jQuery, which I don't really understand how to set up.

I see some of the files listed at https://github.com/Shopify/batman/tree/master/lib , but I'm not sure where they go or how to install this. Any advice on using jQuery with Batman.js is the right way to go.

Thank.

+3


source to share


3 answers


Here's the order of my scripts (standalone app, not rails). est.js contains my app (conveniently called EST):

      <script src="/app/vendor/coffee-script.js" type="text/javascript"></script>
      <script src="/app/vendor/es5-shim.js" type="text/javascript"></script>
      <script src="/app/vendor/batman.js" type="text/javascript"></script>
      <script src="/app/vendor/batman.jquery.js" type="text/javascript"></script>
      <script src="/app/vendor/jquery-1.7.2.min.js" type="text/javascript"></script>
      <script src="est.js" type="text/javascript"></script>

      

Everything pulled from batman lib and jquery from jquery site .

Make sure your application launch method is executed after loading:



  <script src="/app/vendor/coffee-script.js" type="text/javascript"></script>
  <script src="/app/vendor/es5-shim.js" type="text/javascript"></script>
  <script src="/app/vendor/batman.js" type="text/javascript"></script>
  <script src="/app/vendor/batman.jquery.js" type="text/javascript"></script>
  <script src="/app/vendor/jquery-1.7.2.min.js" type="text/javascript"></script>
  <script src="est.js" type="text/javascript"></script>

</head>
  <body>
     <div id="container" data-yield="main">

     </div>
  </body>
</html>

<script type="text/javascript">
  EST.run();
</script>

      

Also make sure your application is included in the window class, otherwise the launch method will explode:

est.js:

window.EST = class EST extends Batman.App

  Batman.ViewStore.prefix = 'app/views'

  # loads up controllers
  @controller 'app', 'sections', 'sectionrows', 'rows'
  @model 'section', 'sectionrow', 'row'

  @root 'app#index'
  @resources 'sections', 'sectionrows', 'rows'

  @on 'run', ->
    console?.log "Running ...."

  @on 'ready', ->
    console?.log "EST ready for use."

      

+1


source


Batman depends on adapters to implement Batman.Request

and help query the DOM. To use Batman with jQuery, include both libraries and the Batman.jQuery adapter:



<script src='batman.js'></script>
<script src='jquery.js'></script>
<script src='batman.jquery.js'></script>
<script src='your_app.js'></script>
<script>
  YourApp.run()
</script>

      

+1


source


It says that it comes with 2 (or more) files, of which are named:

batman.js

      

and

batman.jquery.js

      

If you want to use jQuery on your website along with batman, you need to add an adapter that is included in batman.jquery.js, so your <head> will look like this:

//disclude the following line, and instead, use batman.jquery.js
//<script type="text/javascript" src="/path/to/batman.js"></script>
<script type="text/javascript" src="/path/to/batman.jquery.js"></script>
<script type="text/javascript" src="/path/to/jquery.js"></script>

      

Good material?

0


source







All Articles