2020-03-25 12:38:16 +03:00
/* eslint-disable @nextcloud/no-deprecations */
2019-03-15 00:34:35 +03:00
/ * *
* @ copyright 2019 Christoph Wurst < christoph @ winzerhof - wurst . at >
2018-12-11 22:56:46 +03:00
*
2019-03-15 00:34:35 +03:00
* @ author 2019 Christoph Wurst < christoph @ winzerhof - wurst . at >
2018-12-11 22:56:46 +03:00
*
* @ license GNU AGPL version 3 or any later version
*
* This program is free software : you can redistribute it and / or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation , either version 3 of the
* License , or ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU Affero General Public License for more details .
*
* You should have received a copy of the GNU Affero General Public License
* along with this program . If not , see < http : //www.gnu.org/licenses/>.
* /
2019-09-25 19:19:42 +03:00
import { initCore } from './init'
import _ from 'underscore'
import $ from 'jquery'
import 'jquery-migrate/dist/jquery-migrate.min'
// TODO: switch to `jquery-ui` package and import widgets and effects individually
// `jquery-ui-dist` is used as a workaround for the issue of missing effects
import 'jquery-ui-dist/jquery-ui'
import 'jquery-ui-dist/jquery-ui.css'
import 'jquery-ui-dist/jquery-ui.theme.css'
// END TODO
import autosize from 'autosize'
import Backbone from 'backbone'
import 'bootstrap/js/dist/tooltip'
import './Polyfill/tooltip'
import ClipboardJS from 'clipboard'
2020-06-24 12:20:15 +03:00
import { dav } from 'davclient.js'
2019-09-25 19:19:42 +03:00
import Handlebars from 'handlebars'
import 'jcrop/js/jquery.Jcrop'
import 'jcrop/css/jquery.Jcrop.css'
import md5 from 'blueimp-md5'
import moment from 'moment'
import 'select2'
import 'select2/select2.css'
import 'snap.js/dist/snap'
import 'strengthify'
import 'strengthify/strengthify.css'
import OC from './OC/index'
import OCP from './OCP/index'
import OCA from './OCA/index'
import { getToken as getRequestToken } from './OC/requesttoken'
2019-05-07 10:03:14 +03:00
2019-05-09 19:09:06 +03:00
const warnIfNotTesting = function ( ) {
2020-05-12 12:54:34 +03:00
if ( window . TESTING === undefined ) {
2019-05-09 19:09:06 +03:00
console . warn . apply ( console , arguments )
}
}
2019-03-15 00:34:35 +03:00
/ * *
2019-09-25 19:19:42 +03:00
* Mark a function as deprecated and automatically
* warn if used !
2019-04-29 19:16:15 +03:00
*
2019-03-15 00:34:35 +03:00
* @ param { Function } func the library to deprecate
* @ param { String } funcName the name of the library
2019-10-04 12:40:35 +03:00
* @ param { Int } version the version this gets removed
2019-09-25 19:19:42 +03:00
* @ returns { function }
2019-03-15 00:34:35 +03:00
* /
2019-10-04 12:40:35 +03:00
const deprecate = ( func , funcName , version ) => {
2019-03-15 00:34:35 +03:00
const oldFunc = func
const newFunc = function ( ) {
2019-10-04 12:40:35 +03:00
warnIfNotTesting ( ` The ${ funcName } library is deprecated! It will be removed in nextcloud ${ version } . ` )
2019-03-15 00:34:35 +03:00
return oldFunc . apply ( this , arguments )
}
Object . assign ( newFunc , oldFunc )
return newFunc
}
2019-05-10 15:18:08 +03:00
const setDeprecatedProp = ( global , cb , msg ) => {
2020-02-10 11:12:58 +03:00
( Array . isArray ( global ) ? global : [ global ] ) . map ( global => {
if ( window [ global ] !== undefined ) {
delete window [ global ]
}
Object . defineProperty ( window , global , {
get : ( ) => {
if ( msg ) {
warnIfNotTesting ( ` ${ global } is deprecated: ${ msg } ` )
} else {
warnIfNotTesting ( ` ${ global } is deprecated ` )
}
2019-05-10 15:18:08 +03:00
2020-02-10 11:12:58 +03:00
return cb ( )
} ,
} )
2019-04-29 19:16:15 +03:00
} )
2019-04-29 19:04:45 +03:00
}
2019-04-29 19:16:15 +03:00
2020-07-31 10:40:53 +03:00
window . _ = _
2020-05-13 11:48:36 +03:00
setDeprecatedProp ( [ '$' , 'jQuery' ] , ( ) => $ , 'The global jQuery is deprecated. It will be updated to v3.x in Nextcloud 21. In later versions of Nextcloud it might be removed completely. Please ship your own.' )
2019-10-04 12:40:35 +03:00
setDeprecatedProp ( 'autosize' , ( ) => autosize , 'please ship your own, this will be removed in Nextcloud 20' )
setDeprecatedProp ( 'Backbone' , ( ) => Backbone , 'please ship your own, this will be removed in Nextcloud 20' )
2020-02-10 11:12:58 +03:00
setDeprecatedProp ( [ 'Clipboard' , 'ClipboardJS' ] , ( ) => ClipboardJS , 'please ship your own, this will be removed in Nextcloud 20' )
2020-07-31 10:40:53 +03:00
window . dav = dav
2019-10-04 12:40:35 +03:00
setDeprecatedProp ( 'Handlebars' , ( ) => Handlebars , 'please ship your own, this will be removed in Nextcloud 20' )
setDeprecatedProp ( 'md5' , ( ) => md5 , 'please ship your own, this will be removed in Nextcloud 20' )
setDeprecatedProp ( 'moment' , ( ) => moment , 'please ship your own, this will be removed in Nextcloud 20' )
2019-01-28 13:24:08 +03:00
2020-07-31 10:40:53 +03:00
window . OC = OC
2019-05-10 15:18:08 +03:00
setDeprecatedProp ( 'initCore' , ( ) => initCore , 'this is an internal function' )
2020-02-14 19:39:49 +03:00
setDeprecatedProp ( 'oc_appswebroots' , ( ) => OC . appswebroots , 'use OC.appswebroots instead, this will be removed in Nextcloud 20' )
setDeprecatedProp ( 'oc_config' , ( ) => OC . config , 'use OC.config instead, this will be removed in Nextcloud 20' )
setDeprecatedProp ( 'oc_current_user' , ( ) => OC . getCurrentUser ( ) . uid , 'use OC.getCurrentUser().uid instead, this will be removed in Nextcloud 20' )
setDeprecatedProp ( 'oc_debug' , ( ) => OC . debug , 'use OC.debug instead, this will be removed in Nextcloud 20' )
setDeprecatedProp ( 'oc_defaults' , ( ) => OC . theme , 'use OC.theme instead, this will be removed in Nextcloud 20' )
setDeprecatedProp ( 'oc_isadmin' , OC . isUserAdmin , 'use OC.isUserAdmin() instead, this will be removed in Nextcloud 20' )
setDeprecatedProp ( 'oc_requesttoken' , ( ) => getRequestToken ( ) , 'use OC.requestToken instead, this will be removed in Nextcloud 20' )
setDeprecatedProp ( 'oc_webroot' , ( ) => OC . webroot , 'use OC.getRootPath() instead, this will be removed in Nextcloud 20' )
setDeprecatedProp ( 'OCDialogs' , ( ) => OC . dialogs , 'use OC.dialogs instead, this will be removed in Nextcloud 20' )
2020-07-31 10:40:53 +03:00
window . OCP = OCP
window . OCA = OCA
2019-10-04 12:40:35 +03:00
$ . fn . select2 = deprecate ( $ . fn . select2 , 'select2' , 19 )
2019-01-29 11:28:45 +03:00
/ * *
* 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 }
* /
2019-09-25 19:19:42 +03:00
window . t = _ . bind ( OC . L10N . translate , OC . L10N )
2019-01-29 11:28:45 +03:00
/ * *
* 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
* /
2019-09-25 19:19:42 +03:00
window . n = _ . bind ( OC . L10N . translatePlural , OC . L10N )