@ -8,7 +8,7 @@ define([
'/customize/pad.js'
'/customize/pad.js'
var $ = window . jQuery ;
var $ = window . jQuery ;
var ifrw = $ ( '#pad-iframe' ) [ 0 ] . contentWindow ;
var ifrw = $ ( '#pad-iframe' ) [ 0 ] . contentWindow ;
var CMeditor = ifrw . CodeMirror ;
var CMeditor ;
$ ( function ( ) {
$ ( function ( ) {
$ ( window ) . on ( 'hashchange' , function ( ) {
$ ( window ) . on ( 'hashchange' , function ( ) {
@ -18,6 +18,8 @@ define([
window . location . href = window . location . href + '#' + Crypto . genKey ( ) ;
window . location . href = window . location . href + '#' + Crypto . genKey ( ) ;
return ;
return ;
}
}
var andThen = function ( ) {
var key = Crypto . parseKey ( window . location . hash . substring ( 1 ) ) ;
var key = Crypto . parseKey ( window . location . hash . substring ( 1 ) ) ;
var editor = CMeditor . fromTextArea ( $ ( '#pad-iframe' ) . contents ( ) . find ( '#editor1' ) [ 0 ] , {
var editor = CMeditor . fromTextArea ( $ ( '#pad-iframe' ) . contents ( ) . find ( '#editor1' ) [ 0 ] , {
lineNumbers : true ,
lineNumbers : true ,
@ -45,5 +47,21 @@ define([
editor . save ( ) ;
editor . save ( ) ;
rtw . onEvent ( ) ;
rtw . onEvent ( ) ;
} ) ;
} ) ;
} ;
var interval = 100 ;
var first = function ( ) {
if ( CMeditor = ifrw . CodeMirror ) {
// it exists, call your continuation
andThen ( ) ;
} else {
console . log ( "CMeditor was not defined. Trying again in %sms" , interval ) ;
// try again in 'interval' ms
setTimeout ( first , interval ) ;
}
} ;
first ( ) ;
} ) ;
} ) ;
} ) ;
} ) ;