Просмотр исходного кода

move if block into growi-renderer plugin.

Yuto Iwata 7 лет назад
Родитель
Сommit
0bc261be90
1 измененных файлов с 45 добавлено и 1 удалено
  1. 45 1
      src/client/js/util/reveal/plugins/growi-renderer.js

+ 45 - 1
src/client/js/util/reveal/plugins/growi-renderer.js

@@ -41,8 +41,52 @@ import GrowiRenderer from '../../GrowiRenderer';
       section = sections[i];
       // add data separator '\n\n\n' to markdown.
       markdown = divideSlides(marked.getMarkdownFromSlide(section));
+      if ( section.getAttribute( 'data-markdown' ).length ) {
+        let xhr = new XMLHttpRequest(),
+          url = section.getAttribute( 'data-markdown' );
 
-      if (section.getAttribute('data-separator')
+        let datacharset = section.getAttribute( 'data-charset' );
+
+        // see https://developer.mozilla.org/en-US/docs/Web/API/element.getAttribute#Notes
+        if ( datacharset != null && datacharset !== '' ) {
+          xhr.overrideMimeType( 'text/html; charset=' + datacharset );
+        }
+
+        xhr.onreadystatechange = function() {
+          if ( xhr.readyState === 4 ) {
+            // file protocol yields status code 0 (useful for local debug, mobile applications etc.)
+            if ( ( xhr.status >= 200 && xhr.status < 300 ) || xhr.status === 0 ) {
+
+              section.outerHTML = marked.slidify( xhr.responseText, {
+                separator: section.getAttribute( 'data-separator' ),
+                verticalSeparator: section.getAttribute( 'data-separator-vertical' ),
+                notesSeparator: section.getAttribute( 'data-separator-notes' ),
+                attributes: marked.getForwardedAttributes( section )
+              });
+
+            }
+            else {
+
+              section.outerHTML = '<section data-state="alert">' +
+                'ERROR: The attempt to fetch ' + url + ' failed with HTTP status ' + xhr.status + '.' +
+                'Check your browser\'s JavaScript console for more details.' +
+                '<p>Remember that you need to serve the presentation HTML from a HTTP server.</p>' +
+                '</section>';
+
+            }
+          }
+        };
+
+        xhr.open( 'GET', url, false );
+
+        try {
+          xhr.send();
+        }
+        catch ( e ) {
+          alert( 'Failed to get the Markdown file ' + url + '. Make sure that the presentation and the file are served by a HTTP server and the file can be found there. ' + e );
+        }
+      }
+      else if (section.getAttribute('data-separator')
         || section.getAttribute('data-separator-vertical')
         || section.getAttribute('data-separator-notes')) {
         section.outerHTML = marked.slidify(markdown, {