javascript - Rails: Namespace CoffeeScript so a script is only called on given page(s) -
i'm calling java/coffescript function, typehandler
(not shown), repeatedly different parameters. happening on every page load application. needs happen on 3 or 4 pages script applicable. and, within pages should called twice given appropriate parameters:
#app/assets/javascripts/disk_items.js.coffee jquery(document).ready -> typehandler = (selector, url, hidden_id, entry_id) -> ... ## if page diskitem#edit typehandler '.projects_tt', '/projects.json', '#disk_file_project_code', '#project_code' typehandler '.products_tt', '/products.json', '#disk_file_product_id', '#product_title' ## if page inventoryitem#edit_multiple typehandler '.projects_tt', '/projects.json', '#inventory_item_project_code', '#project_code' typehandler '.products_tt', '/products.json', '#inventory_item_product_id', '#product_title' ...
how to:
- only run script on pages
- set 3rd parameter,
#disk_file_project_code
, given page? maybe html5data
element or perhaps pickid
within form?
thanks in advance insight…
is embedding function calls within actual html page in script tag undesirable? because that's simplest way forward.
if seen bad form, and/or function call has within js.coffee file reason, check location
if window.location.href.indexof("diskitem/edit") > -1
and pull 3rd parameter html via data attribute or form value had suggested.
Comments
Post a Comment