init.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. var _shorten_expanded_threshold = 1.5; //window heights
  2. function expandSizeWrapper(id) {
  3. try {
  4. var row = $(id);
  5. console.log(row);
  6. if (row) {
  7. var content = row.select(".contentSizeWrapper")[0];
  8. var link = row.select(".expandPrompt")[0];
  9. if (content) content.removeClassName("contentSizeWrapper");
  10. if (link) Element.hide(link);
  11. }
  12. } catch (e) {
  13. exception_error("expandSizeWrapper", e);
  14. }
  15. return false;
  16. }
  17. require(['dojo/_base/kernel', 'dojo/ready'], function (dojo, ready) {
  18. ready(function() {
  19. PluginHost.register(PluginHost.HOOK_ARTICLE_RENDERED_CDM, function(row) {
  20. if (getInitParam('cdm_expanded')) {
  21. window.setTimeout(function() {
  22. if (row) {
  23. if (row.offsetHeight >= _shorten_expanded_threshold * window.innerHeight) {
  24. var content = row.select(".cdmContentInner")[0];
  25. if (content) {
  26. content.innerHTML = "<div class='contentSizeWrapper'>" +
  27. content.innerHTML + "</div><button class='expandPrompt' onclick='return expandSizeWrapper(\""+row.id+"\")' "+
  28. "href='#'>" + __("Click to expand article") + "</button>";
  29. }
  30. }
  31. }
  32. }, 150);
  33. }
  34. return true;
  35. });
  36. });
  37. });