Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds options param to javascript queue functions. #363

Merged
merged 1 commit into from
Nov 5, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 8 additions & 5 deletions application/libraries/globals.php
Original file line number Diff line number Diff line change
Expand Up @@ -938,16 +938,18 @@ function format_date($date, $format = Zend_Date::DATE_MEDIUM)
* member will be treated like a file.
* @param string $dir Directory to search for the file. Keeping the default is
* recommended.
* @param array $options An array of options.
*/
function queue_js_file($file, $dir = 'javascripts')
function queue_js_file($file, $dir = 'javascripts', $options = array())
{
if (is_array($file)) {
foreach ($file as $singleFile) {
queue_js_file($singleFile, $dir);
queue_js_file($singleFile, $dir, $options);
}
return;
}
get_view()->headScript()->appendFile(src($file, $dir, 'js'));

get_view()->headScript()->appendFile(src($file, $dir, 'js'), null, $options);
}

/**
Expand All @@ -959,10 +961,11 @@ function queue_js_file($file, $dir = 'javascripts')
* @package Omeka\Function\View\Head
* @see head_js()
* @param string $string JavaScript string to include.
* @param array $options An array of options.
*/
function queue_js_string($string)
function queue_js_string($string, $options = array())
{
get_view()->headScript()->appendScript($string);
get_view()->headScript()->appendScript($string, null, $options);
}

/**
Expand Down
22 changes: 22 additions & 0 deletions application/tests/suite/Helpers/AssetFunctions/DisplayJsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,26 @@ public function testQueueJsString()
"Script tag for inline script not found.");
$this->assertContains($script, $output);
}

public function testQueueJsConditional()
{
queue_js_file('search', 'javascripts', array('conditional' => 'lt IE 9'));

$output = $this->_getJsOutput(false);

$this->assertContains('<!--[if lt IE 9]>', $output);

}

public function testQueueJsStringConditional()
{
$script = 'Inline JS script.';
queue_js_string($script, array('conditional' => 'lt IE 9'));

$output = $this->_getJsOutput(false);

$this->assertContains('<!--[if lt IE 9]>', $output);
$this->assertContains($script, $output);
}

}