瀏覽代碼

localstorage feature test in notes plugin, fixes speaker view error in safari

Hakim El Hattab 7 年之前
父節點
當前提交
8725593805
共有 1 個文件被更改,包括 15 次插入2 次删除
  1. 15 2
      plugin/notes/notes.html

+ 15 - 2
plugin/notes/notes.html

@@ -675,7 +675,7 @@
 					document.body.setAttribute( 'data-speaker-layout', value );
 
 					// Persist locally
-					if( window.localStorage ) {
+					if( supportsLocalStorage() ) {
 						window.localStorage.setItem( 'reveal-speaker-layout', value );
 					}
 
@@ -687,7 +687,7 @@
 				 */
 				function getLayout() {
 
-					if( window.localStorage ) {
+					if( supportsLocalStorage() ) {
 						var layout = window.localStorage.getItem( 'reveal-speaker-layout' );
 						if( layout ) {
 							return layout;
@@ -701,6 +701,19 @@
 
 				}
 
+				function supportsLocalStorage() {
+
+					try {
+						localStorage.setItem('test', 'test');
+						localStorage.removeItem('test');
+						return true;
+					}
+					catch( e ) {
+						return false;
+					}
+
+				}
+
 				function zeroPadInteger( num ) {
 
 					var str = '00' + parseInt( num );