Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions core/js/core.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"jquery.ocdialog.js",
"oc-dialogs.js",
"js.js",
"l10n.js",
"share.js",
"sharetemplates.js",
"sharesocialmanager.js",
Expand All @@ -21,8 +20,6 @@
"sharedialogshareelistview.js",
"octemplate.js",
"contactsmenu_templates.js",
"eventsource.js",
"config.js",
"public/appconfig.js",
"public/comments.js",
"public/publicpage.js",
Expand Down
39 changes: 30 additions & 9 deletions core/js/dist/main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion core/js/dist/main.js.map

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions core/js/merged-template-prepend.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
9 changes: 7 additions & 2 deletions core/js/config.js → core/src/OC/appconfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -63,4 +65,7 @@ OC.AppConfig={
deleteKey:function(app,key){
OCP.AppConfig.deleteKey(app, key);
}

};

export default AppConfig;
106 changes: 55 additions & 51 deletions core/js/eventsource.js → core/src/OC/eventsource.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,70 +30,72 @@

/* 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){
var dataStr='';
const OCEventSource = function (src, data) {
var dataStr = '';
var name;
var joinChar;
this.typelessListeners=[];
this.typelessListeners = [];
this.closed = false;
this.listeners={};
if(data){
for(name in data){
dataStr+=name+'='+encodeURIComponent(data[name])+'&';
this.listeners = {};
if (data) {
for (name in data) {
dataStr += name + '=' + encodeURIComponent(data[name]) + '&';
}
}
dataStr+='requesttoken='+encodeURIComponent(oc_requesttoken);
if(!this.useFallBack && typeof EventSource !== 'undefined'){
dataStr += 'requesttoken=' + encodeURIComponent(oc_requesttoken);
if (!this.useFallBack && typeof EventSource !== 'undefined') {
joinChar = '&';
if(src.indexOf('?') === -1) {
if (src.indexOf('?') === -1) {
joinChar = '?';
}
this.source= new EventSource(src+joinChar+dataStr);
this.source.onmessage=function(e){
for(var i=0;i<this.typelessListeners.length;i++){
this.source = new EventSource(src + joinChar + dataStr);
this.source.onmessage = function (e) {
for (var i = 0; i < this.typelessListeners.length; i++) {
this.typelessListeners[i](JSON.parse(e.data));
}
}.bind(this);
}else{
var iframeId='oc_eventsource_iframe_'+OC.EventSource.iframeCount;
OC.EventSource.fallBackSources[OC.EventSource.iframeCount]=this;
this.iframe=$('<iframe/>');
this.iframe.attr('id',iframeId);
} else {
var iframeId = 'oc_eventsource_iframe_' + OCEventSource.iframeCount;
OCEventSource.fallBackSources[OCEventSource.iframeCount] = this;
this.iframe = $('<iframe/>');
this.iframe.attr('id', iframeId);
this.iframe.hide();

joinChar = '&';
if(src.indexOf('?') === -1) {
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++;
this.useFallBack = true;
OCEventSource.iframeCount++;
}
//add close listener
this.listen('__internal__',function(data){
if(data === 'close'){
this.listen('__internal__', function (data) {
if (data === 'close') {
this.close();
}
}.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={
typelessListeners:[],
iframe:null,
listeners:{},//only for fallback
useFallBack:false,
OCEventSource.prototype = {
typelessListeners: [],
iframe: null,
listeners: {},//only for fallback
useFallBack: false,
/**
* Fallback callback for browsers that don't have the
* native EventSource object.
Expand All @@ -104,61 +106,63 @@ OC.EventSource.prototype={
* @param {String} type event type
* @param {Object} data received data
*/
fallBackCallBack:function(type,data){
fallBackCallBack: function (type, data) {
var i;
// ignore messages that might appear after closing
if (this.closed) {
return;
}
if(type){
if (type) {
if (typeof this.listeners.done !== 'undefined') {
for(i=0;i<this.listeners[type].length;i++){
for (i = 0; i < this.listeners[type].length; i++) {
this.listeners[type][i](data);
}
}
}else{
for(i=0;i<this.typelessListeners.length;i++){
} else {
for (i = 0; i < this.typelessListeners.length; i++) {
this.typelessListeners[i](data);
}
}
},
lastLength:0,//for fallback
lastLength: 0,//for fallback
/**
* Listen to a given type of events.
*
* @param {String} type event type
* @param {Function} callback event callback
*/
listen:function(type,callback){
if(callback && callback.call){
listen: function (type, callback) {
if (callback && callback.call) {

if(type){
if(this.useFallBack){
if(!this.listeners[type]){
this.listeners[type]=[];
if (type) {
if (this.useFallBack) {
if (!this.listeners[type]) {
this.listeners[type] = [];
}
this.listeners[type].push(callback);
}else{
this.source.addEventListener(type,function(e){
} else {
this.source.addEventListener(type, function (e) {
if (typeof e.data !== 'undefined') {
callback(JSON.parse(e.data));
} else {
callback('');
}
},false);
}, false);
}
}else{
} else {
this.typelessListeners.push(callback);
}
}
},
/**
* Closes this event source.
*/
close:function(){
close: function () {
this.closed = true;
if (typeof this.source !== 'undefined') {
this.source.close();
}
}
};

export default OCEventSource;
6 changes: 6 additions & 0 deletions core/src/OC/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -34,6 +37,9 @@ Object.assign(Backbone, {
/** @namespace OC */
export default {
Apps,
AppConfig,
Backbone,
ContactsMenu,
EventSource,
L10N,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

god I'm loving this <3
It's so beautiful I could cry 👀

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️ 💃 😹

};
33 changes: 10 additions & 23 deletions core/js/l10n.js → core/src/OC/l10n.js
Original file line number Diff line number Diff line change
Expand Up @@ -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>}
Expand Down Expand Up @@ -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);
});

21 changes: 21 additions & 0 deletions core/src/globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);