* Parses any current data-markdown slides, splits * multi-slide markdown into separate sections and * handles loading of external markdown.
()
| 206 | * handles loading of external markdown. |
| 207 | */ |
| 208 | function processSlides() { |
| 209 | |
| 210 | var sections = document.querySelectorAll( '[data-markdown]'), |
| 211 | section; |
| 212 | |
| 213 | for( var i = 0, len = sections.length; i < len; i++ ) { |
| 214 | |
| 215 | section = sections[i]; |
| 216 | |
| 217 | if( section.getAttribute( 'data-markdown' ).length ) { |
| 218 | |
| 219 | var xhr = new XMLHttpRequest(), |
| 220 | url = section.getAttribute( 'data-markdown' ); |
| 221 | |
| 222 | datacharset = section.getAttribute( 'data-charset' ); |
| 223 | |
| 224 | // see https://developer.mozilla.org/en-US/docs/Web/API/element.getAttribute#Notes |
| 225 | if( datacharset != null && datacharset != '' ) { |
| 226 | xhr.overrideMimeType( 'text/html; charset=' + datacharset ); |
| 227 | } |
| 228 | |
| 229 | xhr.onreadystatechange = function() { |
| 230 | if( xhr.readyState === 4 ) { |
| 231 | // file protocol yields status code 0 (useful for local debug, mobile applications etc.) |
| 232 | if ( ( xhr.status >= 200 && xhr.status < 300 ) || xhr.status === 0 ) { |
| 233 | |
| 234 | section.outerHTML = slidify( xhr.responseText, { |
| 235 | separator: section.getAttribute( 'data-separator' ), |
| 236 | verticalSeparator: section.getAttribute( 'data-separator-vertical' ), |
| 237 | notesSeparator: section.getAttribute( 'data-separator-notes' ), |
| 238 | attributes: getForwardedAttributes( section ) |
| 239 | }); |
| 240 | |
| 241 | } |
| 242 | else { |
| 243 | |
| 244 | section.outerHTML = '<section data-state="alert">' + |
| 245 | 'ERROR: The attempt to fetch ' + url + ' failed with HTTP status ' + xhr.status + '.' + |
| 246 | 'Check your browser\'s JavaScript console for more details.' + |
| 247 | '<p>Remember that you need to serve the presentation HTML from a HTTP server.</p>' + |
| 248 | '</section>'; |
| 249 | |
| 250 | } |
| 251 | } |
| 252 | }; |
| 253 | |
| 254 | xhr.open( 'GET', url, false ); |
| 255 | |
| 256 | try { |
| 257 | xhr.send(); |
| 258 | } |
| 259 | catch ( e ) { |
| 260 | 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 ); |
| 261 | } |
| 262 | |
| 263 | } |
| 264 | else if( section.getAttribute( 'data-separator' ) || section.getAttribute( 'data-separator-vertical' ) || section.getAttribute( 'data-separator-notes' ) ) { |
| 265 |
no test coverage detected