Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature(river): convert river JS to AMD modules
Deprecates elgg.ui.river library in favour of component AMD modules. Autofocusing of the comment input in river is no longer dependant on the the river selector being present on the page (that was the only view loading the JS library).
- Loading branch information
1 parent
c589e8e
commit 790a1a0
Showing
10 changed files
with
84 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,17 @@ | ||
elgg.provide('elgg.ui.river'); | ||
/** | ||
* This file is registered as a elgg/ui.river.js view in engine/views.php | ||
* and loaded as elgg.ui.river js via simplecache URL. | ||
* Since deprecation in 2.2, core does not use this file any more. Plugins may still | ||
* be loading it from core/river/filter view via elgg_load_js("elgg.ui.river") | ||
* @deprecated 2.2 | ||
*/ | ||
require(['elgg'], function (elgg) { | ||
elgg.provide('elgg.ui.river'); | ||
|
||
elgg.ui.river.init = function() { | ||
$(document).on('change', '#elgg-river-selector', function() { | ||
var url = window.location.href; | ||
if (window.location.search.length) { | ||
url = url.substring(0, url.indexOf('?')); | ||
} | ||
url += '?' + $(this).val(); | ||
elgg.forward(url); | ||
}); | ||
elgg.ui.river.init = function () { | ||
elgg.deprecated_notice('ui.river.js library has been deprecated. Update core/river/filter and forms/comment/save views to require component AMD modules instead.', '2.2') | ||
require(['core/river/filter', 'forms/comment/save']); | ||
}; | ||
|
||
$(document).on('elgg_ui_toggle', function (e, data) { | ||
var $toggle = $(e.target); | ||
var $elements = data.$toggled_elements; | ||
|
||
if ($elements.is('.elgg-river-responses > .elgg-form-comment-save')) { | ||
if ($toggle.hasClass('elgg-state-active')) { | ||
$elements.find('.elgg-input-text').focus(); | ||
} else { | ||
$toggle.blur(); | ||
} | ||
} | ||
}); | ||
}; | ||
|
||
elgg.register_hook_handler('init', 'system', elgg.ui.river.init); | ||
elgg.register_hook_handler('init', 'system', elgg.ui.river.init); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/** | ||
* Initiates page reload when river selector value changes | ||
* @module core/river/filter | ||
*/ | ||
define(function (require) { | ||
var $ = require('jquery'); | ||
$(document).on('change', '#elgg-river-selector', function () { | ||
var url = window.location.href; | ||
if (window.location.search.length) { | ||
url = url.substring(0, url.indexOf('?')); | ||
} | ||
url += '?' + $(this).val(); | ||
window.location.href = url; | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?php | ||
|
||
/** | ||
* Extends core/river/filter view to load AMD modules in a BC way | ||
*/ | ||
elgg_require_js('core/river/filter'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** | ||
* Autofocuses first text input in a comment form when toggled | ||
* @module forms/comment/save | ||
*/ | ||
define(function (require) { | ||
var $ = require('jquery'); | ||
$(document).on('elgg_ui_toggle', function (e, data) { | ||
var $toggle = $(e.target); | ||
var $elements = data.$toggled_elements; | ||
|
||
if ($elements.is('.elgg-river-responses > .elgg-form-comment-save')) { | ||
if ($toggle.hasClass('elgg-state-active')) { | ||
$elements.find('.elgg-input-text').focus(); | ||
} else { | ||
$toggle.blur(); | ||
} | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?php | ||
|
||
/** | ||
* Extends forms/comment/save view to load AMD modules in a BC way | ||
*/ | ||
elgg_require_js('forms/comment/save'); |