Hi everyone,
I have a little problem trying to link to custom javascript from the front-end of my module. I am familiar with this, but it only seems to include the js in the control panel end of tje module. $this->EE->cp->load_package_js(‘jquery.easing-1.3.pack’);
My module contains a number of custom js functions that I would like the front-end to have access to.
Unfortunately, I cannot link to the third party folder using PATH_THIRD as this reveals the server file structure and is a security issue.
Is this even possible?
Nazreen,
I’ve seen two ways that folks handle this:
For an example of the second option, take a look at SafeCracker, specifically safecracker/libraries/safecracker_lib.php around line 932:
//add datepicker class
if ($this->datepicker)
{
$this->head .= '<style type="text/css">.hasDatepicker{background:#fff url('.$this->EE->config->item('theme_folder_url').'cp_themes/default/images/calendar_bg.gif) no-repeat 98% 2px;background-repeat:no-repeat;background-position:99%;}</style>';
$this->head .= '[removed]$.createDatepickerTime=function(){a=new Date();b=a.getHours();c=a.getMinutes();if(c<10){c="0"+c;}if(b>12){b-=12;d=" PM";}else if(b==12){d=" PM";}else{d=" AM";}EE.date_obj_time=" \\'"+b+":"+c+d+"\'";};$.createDatepickerTime();[removed]';
}
//make head appear by default
if (preg_match('/'.LD.'safecracker_head'.RD.'/', $return))
{
$return = $this->EE->TMPL->swap_var_single('safecracker_head', $this->head, $return);
}
else if ($this->bool_string($this->EE->TMPL->fetch_param('safecracker_head'), TRUE))
{
$return .= $this->head;
}What’s happening here is they’re creating a variable and stashing all of the scripts and styles they need in it and then adding it to the end of the return variable.
Wes
Thanks for the speedy response Wes! Using file_get_contents does the trick.
For anyone else looking for this as well, here is what I have:
$output = '[removed]'.file_get_contents(PATH_THIRD.'module_folder_name/javascript/smartform.js').'[removed]';(the forum replaces the opening & closing script tags with [removed])
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.