Integrate bootstrap, wait for js components to load

This commit is contained in:
Victor Dubiniuk 2013-10-22 16:18:03 +03:00
parent 8eea7805e7
commit efcc0ed3f9
2 changed files with 48 additions and 38 deletions

View File

@ -1,20 +0,0 @@
/*globals navigator,dojoConfig */
var usedLocale = "C";
if (navigator && navigator.language.match(/^(de)/)) {
usedLocale = navigator.language.substr(0,2);
}
dojoConfig = {
locale: usedLocale,
paths: {
"webodf/editor": OC.appswebroots.documents + "/js/3rdparty/webodf/editor",
"dijit": OC.appswebroots.documents + "/js/3rdparty/resources/dijit",
"dojox": OC.appswebroots.documents + "/js/3rdparty/resources/dojox",
"dojo": OC.appswebroots.documents + "/js/3rdparty/resources/dojo",
"resources": OC.appswebroots.documents + "/js/3rdparty/resources"
}
};
//alert("bootstrap hello");

View File

@ -6,6 +6,7 @@ var documentsMain = {
isEditormode : false, isEditormode : false,
useUnstable : false, useUnstable : false,
isGuest : false, isGuest : false,
ready :false,
UI : { UI : {
/* Overlay HTML */ /* Overlay HTML */
@ -49,7 +50,7 @@ var documentsMain = {
$(documentsMain.UI.overlay).hide().appendTo(document.body); $(documentsMain.UI.overlay).hide().appendTo(document.body);
documentsMain.UI.mainTitle = $('title').text(); documentsMain.UI.mainTitle = $('title').text();
}, },
showOverlay : function(){ showOverlay : function(){
$('#documents-overlay,#documents-overlay-below').fadeIn('slow'); $('#documents-overlay,#documents-overlay-below').fadeIn('slow');
}, },
@ -87,16 +88,17 @@ var documentsMain = {
}, },
onStartup: function() { onStartup: function() {
var fileId;
"use strict"; "use strict";
documentsMain.useUnstable = $('#webodf-unstable').val()==='true'; documentsMain.useUnstable = $('#webodf-unstable').val()==='true';
documentsMain.UI.init(); documentsMain.UI.init();
if (!OC.currentUser){ if (!OC.currentUser){
documentsMain.isGuest = true; documentsMain.isGuest = true;
var fileId;
} else { } else {
// Does anything indicate that we need to autostart a session? // Does anything indicate that we need to autostart a session?
var fileId = parent.location.hash.replace(/\W*/g, ''); fileId = parent.location.hash.replace(/\W*/g, '');
} }
if (!fileId){ if (!fileId){
@ -106,18 +108,16 @@ var documentsMain = {
} }
OC.addScript('documents', '3rdparty/webodf/dojo-amalgamation', function() { OC.addScript('documents', '3rdparty/webodf/webodf-debug').done(function() {
OC.addScript('documents', '3rdparty/webodf/webodf-debug').done(function() { // preload stuff in the background
// preload stuff in the background require({}, ["dojo/ready"], function(ready) {
require({}, ["dojo/ready"], function(ready) { ready(function() {
ready(function() { require({}, ["webodf/editor/Editor"], function(Editor) {
require({}, ["webodf/editor/Editor"], function(Editor) { documentsMain.ready = true;
if (fileId){
if (fileId){ documentsMain.prepareSession();
documentsMain.prepareSession(); documentsMain.joinSession(fileId);
documentsMain.joinSession(fileId); }
}
});
}); });
}); });
}); });
@ -137,7 +137,7 @@ var documentsMain = {
initSession: function(response) { initSession: function(response) {
"use strict"; "use strict";
if (!response || !response.es_id || !response.status || response.status==='error'){ if (!response || !response.es_id || !response.status || response.status==='error'){
OC.Notification.show(t('documents', 'Failed to load this document. Please check if it can be opened with an external odt editor. This might also mean it has been unshared or deleted recently.')); OC.Notification.show(t('documents', 'Failed to load this document. Please check if it can be opened with an external odt editor. This might also mean it has been unshared or deleted recently.'));
documentsMain.prepareGrid(); documentsMain.prepareGrid();
@ -145,6 +145,13 @@ var documentsMain = {
setTimeout(OC.Notification.hide, 7000); setTimeout(OC.Notification.hide, 7000);
return; return;
} }
//Wait for 3 sec if editor is still loading
if (!documentsMain.ready){
setTimeout(function(){ documentsMain.initSession(response) }, 3000);
console.log('Waiting for the editor to start...');
return;
}
require({ }, ["webodf/editor/server/owncloud/ServerFactory", "webodf/editor/Editor"], function (ServerFactory, Editor) { require({ }, ["webodf/editor/server/owncloud/ServerFactory", "webodf/editor/Editor"], function (ServerFactory, Editor) {
// fade out file list and show WebODF canvas // fade out file list and show WebODF canvas
@ -335,14 +342,36 @@ var documentsMain = {
}; };
//web odf bootstrap code. Added here to reduce number of requests
/*globals navigator,dojoConfig */
var usedLocale = "C";
if (navigator && navigator.language.match(/^(de)/)) {
usedLocale = navigator.language.substr(0,2);
}
dojoConfig = {
locale: usedLocale,
paths: {
"webodf/editor": OC.appswebroots.documents + "/js/3rdparty/webodf/editor",
"dijit": OC.appswebroots.documents + "/js/3rdparty/resources/dijit",
"dojox": OC.appswebroots.documents + "/js/3rdparty/resources/dojox",
"dojo": OC.appswebroots.documents + "/js/3rdparty/resources/dojo",
"resources": OC.appswebroots.documents + "/js/3rdparty/resources"
}
};
//init
$(document).ready(function() { $(document).ready(function() {
"use strict"; "use strict";
$('.documentslist').on('click', 'li:not(.add-document)', function(event) { $('.documentslist').on('click', 'li:not(.add-document)', function(event) {
event.preventDefault(); event.preventDefault();
if (documentsMain.isEditorMode){ if (documentsMain.isEditorMode){
return; return;
} }
documentsMain.prepareSession(); documentsMain.prepareSession();
if ($(this).attr('data-id')){ if ($(this).attr('data-id')){
documentsMain.joinSession($(this).attr('data-id')); documentsMain.joinSession($(this).attr('data-id'));
@ -353,6 +382,7 @@ $(document).ready(function() {
$(document.body).on('click', '#odf-invite', documentsMain.onInvite); $(document.body).on('click', '#odf-invite', documentsMain.onInvite);
$(document.body).on('click', '#odf-join', function(event){ $(document.body).on('click', '#odf-join', function(event){
event.preventDefault(); event.preventDefault();
// !Login page mess wih WebODF toolbars // !Login page mess wih WebODF toolbars
$(document.body).attr('id', 'body-user'); $(document.body).attr('id', 'body-user');
$('header,footer').hide(); $('header,footer').hide();
@ -366,6 +396,6 @@ $(document).ready(function() {
var file_upload_start = $('#file_upload_start'); var file_upload_start = $('#file_upload_start');
file_upload_start.on('fileuploaddone', documentsMain.show); file_upload_start.on('fileuploaddone', documentsMain.show);
//TODO when ending a session as the last user close session? //TODO when ending a session as the last user close session?
OC.addScript('documents', '3rdparty/webodf/webodf_bootstrap', documentsMain.onStartup); OC.addScript('documents', '3rdparty/webodf/dojo-amalgamation', documentsMain.onStartup);
}); });