Commit fd84ce97 authored by Richard Mansfield's avatar Richard Mansfield Committed by Gerrit Code Review
Browse files

Merge changes I40a04f66,I819f911a

* changes:
  Fixes for javascript when first adding a plans block to a page
  Allow get_get_javascript_javascript to take a success callback
parents 06486d22 8d3d737e
......@@ -2,6 +2,7 @@ function rewriteTaskTitles(blockid) {
forEach(
getElementsByTagAndClassName('a', 'task-title', 'tasktable_' + blockid),
function(element) {
disconnectAll(element);
connect(element, 'onclick', function(e) {
e.stop();
var description = getFirstElementByTagAndClassName('div', 'task-desc', element.parentNode);
......
......@@ -55,11 +55,13 @@ class PluginBlocktypePlans extends PluginBlocktype {
}
public static function get_instance_javascript(BlockInstance $bi) {
return array('js/plansblock.js');
}
public static function get_instance_inline_javascript(BlockInstance $bi) {
return 'rewriteTaskTitles(' . $bi->get('id') . ');';
$blockid = $bi->get('id');
return array(
array(
'file' => 'js/plansblock.js',
'initjs' => "rewriteTaskTitles($blockid);",
)
);
}
public static function render_instance(BlockInstance $instance, $editing=false) {
......@@ -110,6 +112,7 @@ class PluginBlocktypePlans extends PluginBlocktype {
}
public static function instance_config_form($instance) {
$instance->set('artefactplugin', 'plans');
$configdata = $instance->get('configdata');
$form = array();
......
......@@ -14,14 +14,14 @@
</tbody>
</table>
{if $tasks.pagination}
<div id="plans_page_container">{$tasks.pagination|safe}</div>
<div id="plans_page_container_{$blockid}" class="hidden">{$tasks.pagination|safe}</div>
{/if}
{if $tasks.pagination_js}
<script>
{literal}
addLoadEvent(function() {{/literal}
{$tasks.pagination_js|safe}
removeElementClass('plans_page_container', 'hidden');
removeElementClass('plans_page_container_{$blockid}', 'hidden');
{literal}}{/literal});
var taskPager_{$blockid} = new TaskPager({$blockid});
......
......@@ -1266,23 +1266,38 @@ class BlockInstance {
/**
* Returns javascript to grab & eval javascript from files on the web
*
* @param array $jsfiles Each element of $jsfiles is either a url, a local filename,
* or an array of the form
* array(
* 'file' => string // url or local js filename
* 'initjs' => string // js to be executed once the file's
* // contents have been loaded
* )
*
* @return string
*/
public function get_get_javascript_javascript($jsfiles) {
foreach ($jsfiles as &$jsfile) {
if (stripos($jsfile, 'http://') === false && stripos($jsfile, 'https://') === false) {
$js = '';
foreach ($jsfiles as $jsfile) {
$file = (is_array($jsfile) && isset($jsfile['file'])) ? $jsfile['file'] : $jsfile;
if (stripos($file, 'http://') === false && stripos($file, 'https://') === false) {
$file = 'blocktype/' . $this->blocktype . '/' . $file;
if ($this->artefactplugin) {
$jsfile = 'artefact/' . $this->artefactplugin . '/blocktype/' .
$this->blocktype . '/' . $jsfile;
$file = 'artefact/' . $this->artefactplugin . '/' . $file;
}
else {
$jsfile = 'blocktype/' . $this->blocktype . '/' . $jsfile;
}
$jsfile = '$j.getScript("' . get_config('wwwroot') . $jsfile . '");';
$file = get_config('wwwroot') . $file;
}
else {
$jsfile = '$j.getScript("' . $jsfile . '");';
$js .= '$j.getScript("' . $file . '"';
if (is_array($jsfile) && !empty($jsfile['initjs'])) {
// Pass success callback to getScript
$js .= ', function(data) {' . $jsfile['initjs'] . '}';
}
$js .= ");\n";
}
return implode('', $jsfiles);
return $js;
}
}
......@@ -1704,6 +1704,7 @@ class View {
$blockinstance
);
foreach($instancejs as &$jsfile) {
$jsfile = (is_array($jsfile) && isset($jsfile['file'])) ? $jsfile['file'] : $jsfile;
if(strpos($jsfile, 'http://') === false) {
if($artefactplugin = get_field('blocktype_installed', 'artefactplugin', 'name', $pluginname)) {
$jsfile = 'artefact/' . $artefactplugin . '/blocktype/' .
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment