Merge pull request #13878 from nextcloud/refactor/oc-appconfig-eventsource-l10n

Move OC.AppConfig, OC.EventSource and OC.L10N to the server bundle
This commit is contained in:
Morris Jobke 2019-01-29 10:55:30 +01:00 committed by GitHub
commit 2682d672d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 130 additions and 92 deletions

View File

@ -9,7 +9,6 @@
"jquery.ocdialog.js",
"oc-dialogs.js",
"js.js",
"l10n.js",
"share.js",
"sharetemplates.js",
"sharesocialmanager.js",
@ -21,8 +20,6 @@
"sharedialogshareelistview.js",
"octemplate.js",
"contactsmenu_templates.js",
"eventsource.js",
"config.js",
"public/appconfig.js",
"public/comments.js",
"public/publicpage.js",

39
core/js/dist/main.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -2,13 +2,10 @@
"jquery.ocdialog.js",
"oc-dialogs.js",
"js.js",
"l10n.js",
"octemplate.js",
"eventsource.js",
"public/appconfig.js",
"public/comments.js",
"public/whatsnew.js",
"config.js",
"oc-requesttoken.js",
"mimetype.js",
"mimetypelist.js",

View File

@ -18,11 +18,13 @@
*
*/
import OCP from '../OCP/index';
/**
* @namespace
* @deprecated Use OCP.AppConfig instead
* @deprecated 16.0.0 Use OCP.AppConfig instead
*/
OC.AppConfig={
const AppConfig = {
/**
* @deprecated Use OCP.AppConfig.getValue() instead
*/
@ -63,4 +65,7 @@ OC.AppConfig={
deleteKey:function(app,key){
OCP.AppConfig.deleteKey(app, key);
}
};
export default AppConfig;

View File

@ -30,14 +30,16 @@
/* global EventSource */
import $ from 'jquery'
/**
* Create a new event source
* @param {string} src
* @param {object} [data] to be send as GET
*
* @constructs OC.EventSource
* @constructs OCEventSource
*/
OC.EventSource=function(src,data){
const OCEventSource = function (src, data) {
var dataStr = '';
var name;
var joinChar;
@ -62,8 +64,8 @@ OC.EventSource=function(src,data){
}
}.bind(this);
} else {
var iframeId='oc_eventsource_iframe_'+OC.EventSource.iframeCount;
OC.EventSource.fallBackSources[OC.EventSource.iframeCount]=this;
var iframeId = 'oc_eventsource_iframe_' + OCEventSource.iframeCount;
OCEventSource.fallBackSources[OCEventSource.iframeCount] = this;
this.iframe = $('<iframe/>');
this.iframe.attr('id', iframeId);
this.iframe.hide();
@ -72,10 +74,10 @@ OC.EventSource=function(src,data){
if (src.indexOf('?') === -1) {
joinChar = '?';
}
this.iframe.attr('src',src+joinChar+'fallback=true&fallback_id='+OC.EventSource.iframeCount+'&'+dataStr);
this.iframe.attr('src', src + joinChar + 'fallback=true&fallback_id=' + OCEventSource.iframeCount + '&' + dataStr);
$('body').append(this.iframe);
this.useFallBack = true;
OC.EventSource.iframeCount++;
OCEventSource.iframeCount++;
}
//add close listener
this.listen('__internal__', function (data) {
@ -84,12 +86,12 @@ OC.EventSource=function(src,data){
}
}.bind(this));
};
OC.EventSource.fallBackSources=[];
OC.EventSource.iframeCount=0;//number of fallback iframes
OC.EventSource.fallBackCallBack=function(id,type,data){
OC.EventSource.fallBackSources[id].fallBackCallBack(type,data);
OCEventSource.fallBackSources = [];
OCEventSource.iframeCount = 0;//number of fallback iframes
OCEventSource.fallBackCallBack = function (id, type, data) {
OCEventSource.fallBackSources[id].fallBackCallBack(type, data);
};
OC.EventSource.prototype={
OCEventSource.prototype = {
typelessListeners: [],
iframe: null,
listeners: {},//only for fallback
@ -162,3 +164,5 @@ OC.EventSource.prototype={
}
}
};
export default OCEventSource;

View File

@ -22,7 +22,10 @@
import Backbone from 'backbone';
import Apps from './apps'
import AppConfig from './appconfig'
import ContactsMenu from './contactsmenu';
import EventSource from './eventsource'
import L10N from './l10n'
import {davCall, davSync} from './backbone-webdav';
// Patch Backbone for DAV
@ -34,6 +37,9 @@ Object.assign(Backbone, {
/** @namespace OC */
export default {
Apps,
AppConfig,
Backbone,
ContactsMenu,
EventSource,
L10N,
};

View File

@ -8,12 +8,18 @@
*
*/
import _ from 'underscore'
import $ from 'jquery'
import Handlebars from 'handlebars'
import OC from './index'
/**
* L10N namespace with localization functions.
*
* @namespace
* @namespace OC.L10n
*/
OC.L10N = {
const L10n = {
/**
* String bundles with app name as key.
* @type {Object.<String,String>}
@ -321,28 +327,9 @@ OC.L10N = {
}
};
/**
* translate a string
* @param {string} app the id of the app for which to translate the string
* @param {string} text the string to translate
* @param [vars] map of placeholder key to value
* @param {number} [count] number to replace %n with
* @return {string}
*/
window.t = _.bind(OC.L10N.translate, OC.L10N);
/**
* translate a string
* @param {string} app the id of the app for which to translate the string
* @param {string} text_singular the string to translate for exactly one object
* @param {string} text_plural the string to translate for n objects
* @param {number} count number to determine whether to use singular or plural
* @param [vars] map of placeholder key to value
* @return {string} Translated string
*/
window.n = _.bind(OC.L10N.translatePlural, OC.L10N);
export default L10n;
Handlebars.registerHelper('t', function(app, text) {
return OC.L10N.translate(app, text);
return L10n.translate(app, text);
});

View File

@ -72,3 +72,24 @@ window['moment'] = moment
window['OC'] = OC
window['OCP'] = OCP
window['OCA'] = OCA
/**
* translate a string
* @param {string} app the id of the app for which to translate the string
* @param {string} text the string to translate
* @param [vars] map of placeholder key to value
* @param {number} [count] number to replace %n with
* @return {string}
*/
window.t = _.bind(OC.L10N.translate, OC.L10N);
/**
* translate a string
* @param {string} app the id of the app for which to translate the string
* @param {string} text_singular the string to translate for exactly one object
* @param {string} text_plural the string to translate for n objects
* @param {number} count number to determine whether to use singular or plural
* @param [vars] map of placeholder key to value
* @return {string} Translated string
*/
window.n = _.bind(OC.L10N.translatePlural, OC.L10N);