Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MMM-page-indicator.js 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. Module.register('MMM-page-indicator', {
  2. /**
  3. * By default, we should try to make the configuration match the demo
  4. * implementation. This means 3 pages, and some default enabled styles.
  5. */
  6. defaults: {
  7. pages: 3,
  8. activeBright: false,
  9. inactiveDimmed: true,
  10. inactiveHollow: true,
  11. },
  12. /**
  13. * Apply any styles, if we have any.
  14. */
  15. getStyles() {
  16. return ['font-awesome.css', 'page-indicators.css'];
  17. },
  18. /**
  19. * Pseudo-constructor for our module. Sets the default current page to 0.
  20. */
  21. start() {
  22. this.curPage = 0;
  23. },
  24. /**
  25. * Render the cicles for each page, and highlighting the page we're on.
  26. */
  27. getDom() {
  28. const wrapper = document.createElement('div');
  29. for (let i = 0; i < this.config.pages; i += 1) {
  30. const circle = document.createElement('i');
  31. if (this.curPage === i) {
  32. circle.className = 'fa fa-circle indicator';
  33. if (this.config.activeBright) {
  34. circle.className += ' bright';
  35. }
  36. } else {
  37. circle.className = 'fa indicator';
  38. if (this.config.inactiveDimmed) {
  39. circle.className += ' dimmed';
  40. }
  41. if (this.config.inactiveHollow) {
  42. circle.className += ' fa-circle-thin';
  43. } else {
  44. circle.className += ' fa-circle';
  45. }
  46. }
  47. wrapper.appendChild(circle);
  48. const self = this;
  49. // Lets people change the page by clicking on the respective circle.
  50. // So apparently this doesn't work if we don't call the last two methods,
  51. // despite those methods being called in when calling sendNotification.
  52. // This is likely a bug (because spamming a single button) causes rapid-
  53. // fire page changing, but for most cases that shouldn't be a problem.
  54. circle.onclick = () => {
  55. self.sendNotification('PAGE_CHANGED', i);
  56. self.curPage = i;
  57. self.updateDom();
  58. };
  59. }
  60. return wrapper;
  61. },
  62. /**
  63. * If we recieve a notification that we can respond to, update which page
  64. * we're suppose to show as active.
  65. * @param {string} notification The notification ID
  66. * @param {number} payload the payload type.
  67. */
  68. notificationReceived(notification, payload) {
  69. /**
  70. * Modulo that also works with negative numbers.
  71. * @param {number} x The dividend
  72. * @param {number} n The divisor
  73. */
  74. const mod = (x, n) => ((x % n) + n) % n;
  75. if (notification === 'PAGE_CHANGED') {
  76. Log.log(`[${this.name}]: changing pages to ${payload}`);
  77. this.curPage = mod(payload, this.config.pages);
  78. this.updateDom();
  79. } else if (notification === 'MAX_PAGES_CHANGED') {
  80. Log.log(`[${this.name}]: Changing maximum pages to ${payload}`);
  81. this.config.pages = payload;
  82. if (payload - 1 < this.curPage) {
  83. this.curPage = payload - 1;
  84. }
  85. this.updateDom();
  86. } else if (notification === 'PAGE_INCREMENT') {
  87. this.curPage = mod(this.curPage + 1, this.config.pages);
  88. Log.log(`[${this.name}]: Incrementing page; new page is ${this.curPage}`);
  89. this.updateDom();
  90. } else if (notification === 'PAGE_DECREMENT') {
  91. this.curPage = mod(this.curPage - 1, this.config.pages);
  92. Log.log(`[${this.name}]: Decrementing page; new page is ${this.curPage}`);
  93. this.updateDom();
  94. } else if (notification === 'NEW_PAGE') {
  95. Log.log(`[${this.name}]: Setting page to ${payload}`);
  96. this.curPage = payload;
  97. this.updateDom();
  98. }
  99. },
  100. });