0

I am using django version 1.82 with django-pipeline. I call a particular javascript function from html by name.

 <form class="navbar-form navbar-right vcenter" 
 action="javascript:search();" role="search" id='searchform'>

Unfortunately in the compressed js file, the name of the function is changed and hence the frontend functionality is not workig. How do I maintain the same name for that function or how do I change the reference to the js function in html?

I have installed yuglify and the settings I use is

PIPELINE_CSS = {
'allstyles': {
    'source_filenames': (
      'css/application.css',
      'feedback/css/feedback-form.css',
    ),
    'output_filename': 'css/nifty.css',
    'extra_context': {
        'media': 'screen,projection',
    },
},
}

PIPELINE_JS = {
'actions': {
    'source_filenames': (
      'js/nifty.js',
      'feedback/js/feedback-form.js',
    ),
    'output_filename': 'js/nifty.js',
}
}
STATICFILES_STORAGE = 'pipeline.storage.PipelineStorage'
PIPELINE_JS_COMPRESSOR = 'pipeline.compressors.yuglify.YuglifyCompressor'
PIPELINE_DISABLE_WRAPPER = True
PIPELINE_ENABLED=True 
Sharmila
  • 1,637
  • 2
  • 23
  • 30

2 Answers2

1

Are you sure that search() is a global function? To make sure you can assign it to the window variable:

window.search = function() {
    ...
}
Lukasz Wiktor
  • 19,644
  • 5
  • 69
  • 82
1

I'd do it the other way around.

<form ... action="/nojs.html" ... id='searchform'>

and then intercept the submit event on the form.

(function(){
    var sf = document.getElementById('searchform');
    sf.addEventListener('submit', function(ev){
        ev.preventDefault();
        // do here whatever "search()" needs to do
    });
})();

That way you don't need to add anything into the window namespace, are independent of minified function names, and a browser with disabled JS gets a readable error page.

C14L
  • 12,153
  • 4
  • 39
  • 52