tabs-memory.js 941 B

1234567891011121314151617181920212223242526272829
  1. import $ from 'jquery';
  2. import Cookies from 'cookies-js';
  3. import { Instance as Editors } from '../forms/fields/editor';
  4. let Data = JSON.parse(Cookies.get('grav-tabs-state') || '{}');
  5. $('body').on('touchstart click', '[data-tabid]', (event) => {
  6. event && event.stopPropagation();
  7. let target = $(event.currentTarget);
  8. Data[target.data('tabkey')] = target.data('scope');
  9. Cookies.set('grav-tabs-state', JSON.stringify(Data), { expires: Infinity });
  10. const panel = $(`[id="${target.data('tabid')}"]`);
  11. target.siblings('[data-tabid]').removeClass('active');
  12. target.addClass('active');
  13. panel.siblings('[id]').removeClass('active');
  14. panel.addClass('active');
  15. Editors.editors.each((index, editor) => {
  16. let codemirror = $(editor).data('codemirror');
  17. if (!codemirror) { return; }
  18. if (codemirror.display.lastWrapWidth === 0) {
  19. codemirror.refresh();
  20. }
  21. });
  22. });