Esempio n. 1
0
function onReady() {
    handleAppCache();
    doc = dom.bindIDs();
    client = new clientLib.Client(exports);
    client.saveInterval = 0;

    
//    client.addAppBar();

    $(doc.save).click(function saveEdit(evt) {
    	$.ajax({
    		  type: 'POST',
    		  url: '/save',
    		  data: {text: doc.editor.value},
    		  dataType: "text",
    		  success: function(){},
//    		  error: function(){},
    		});
    });

    
    $(doc.edit).click(toggleEditor);
    $(doc.insert).click(insertStockCode);
    $(doc.editor).keydown(tabToSpace);
    $(doc.editor).bind('keydown click', setSlidePosFromCursor);
    $(window).bind('resize', onResize);
    $(doc.fullscreen).bind('click', viewSlideshowFullscreen);
    $(doc.next).click(nextSlide);
    $(doc.prev).click(prevSlide);

    $(doc.output).html("<section class='slides'><article></article></section>");
    handleDomLoaded();
    // check the url if there exists a doc to be loaded
    var urlData = handleLocationHash();
    // if there isn't, load default doc
    if (!urlData.doc) {
        $.ajax({
            url: 'slides.html',
            error: function(result, status) {
                console.log('ajax load error');
            },
            success: function(slides) {
                var json = {title: 'Editable HTML5 Slides', blob: {version: 1.1, slides: slides}};
                setDoc(json);
            }
        });
    }
    // get stock code samples from script tags in editor(.html)
    var scripts = $('script[type=slide-template]');
    var s;
    for (var i = 0; i < scripts.length; i++) {
        s = scripts[i];
        stockCode[s.title] = $(s).text();
    }
    onReadyFlag = true;
}
function onReady() {
    handleAppCache();
    doc = dom.bindIDs();
    client = new clientLib.Client(exports);
    client.saveInterval = 0;

    client.addAppBar();

    $(doc.edit).click(toggleEditor);
    $(doc.insert).click(insertStockCode);
    $(doc.editor).keydown(tabToSpace);
    $(doc.editor).bind('keydown click', setSlidePosFromCursor);
    $(window).bind('resize', onResize);
    $(doc.fullscreen).bind('click', viewSlideshowFullscreen);
    $(doc.next).click(nextSlide);
    $(doc.prev).click(prevSlide);

    $(doc.output).html("<section class='slides'><article></article></section>");
    handleDomLoaded();
    // check the url if there exists a doc to be loaded
    var urlData = handleLocationHash();
    // if there isn't, load default doc
    if (!urlData.doc) {
        $.ajax({
            url: 'slides.html',
            error: function(result, status) {
                console.log('ajax load error');
            },
            success: function(slides) {
                var json = {title: 'Editable HTML5 Slides', blob: {version: 1.1, slides: slides}};
                setDoc(json);
            }
        });
    }
    
    
    
    
  editor = setupAceEditor('editor','editor_text');
  var h = window.location.search;
  function setSrc(msg) {
    if (msg) {
      alert('unable to read URL ' + h + '\n\nusing default R Markdown example');
    }
    $('#editor_text').val(editor.getValue());
    $('#proxy button').trigger('click');
  }
  var w = Math.max($(window).width()/2, 300);
  $('#notebook').width(w - 10);
  $('#outputBlock').css('left', w + 10 + 'px');
    
  if (h) {
    // pass a url as a query string after ? in the url
    h = h.replace('?', '');
    $.get(h, {}, function(res) {
      var data = res.data, str = data.content;
      if (typeof(str) != 'string') return(setSrc(true));
      if (data.encoding == 'base64') {
        str = str.replace(/\n/g, '');
        str = decodeURIComponent(escape(window.atob( str )));
      }
      if (str) {
        editor.setValue(str);
        editor.gotoLine(1);
        setSrc(false);
      } else setSrc(true);
    }, 'jsonp')
    .error(function() {
      setSrc(true);
    });
  } else setSrc(false);

    
    
    
    
    
    
    
    
    // get stock code samples from script tags in editor(.html)
    var scripts = $('script[type=slide-template]');
    var s;
    for (var i = 0; i < scripts.length; i++) {
        s = scripts[i];
        stockCode[s.title] = $(s).text();
    }
    onReadyFlag = true;
}