You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

globals.js 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /**
  2. * @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
  3. *
  4. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  5. * @author John Molakvoæ <skjnldsv@protonmail.com>
  6. * @author Julius Härtl <jus@bitgrid.net>
  7. * @author Roeland Jago Douma <roeland@famdouma.nl>
  8. *
  9. * @license AGPL-3.0-or-later
  10. *
  11. * This program is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License as
  13. * published by the Free Software Foundation, either version 3 of the
  14. * License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. *
  24. */
  25. /* eslint-disable @nextcloud/no-deprecations */
  26. import { initCore } from './init.js'
  27. import _ from 'underscore'
  28. import $ from 'jquery'
  29. import 'jquery-migrate/dist/jquery-migrate.min.js'
  30. // TODO: switch to `jquery-ui` package and import widgets and effects individually
  31. // `jquery-ui-dist` is used as a workaround for the issue of missing effects
  32. import 'jquery-ui-dist/jquery-ui.js'
  33. import 'jquery-ui-dist/jquery-ui.css'
  34. import 'jquery-ui-dist/jquery-ui.theme.css'
  35. // END TODO
  36. import autosize from 'autosize'
  37. import Backbone from 'backbone'
  38. import './Polyfill/tooltip.js'
  39. import ClipboardJS from 'clipboard'
  40. import { dav } from 'davclient.js'
  41. import Handlebars from 'handlebars'
  42. import md5 from 'blueimp-md5'
  43. import moment from 'moment'
  44. import 'select2'
  45. import 'select2/select2.css'
  46. import 'snap.js/dist/snap.js'
  47. import 'strengthify'
  48. import 'strengthify/strengthify.css'
  49. import OC from './OC/index.js'
  50. import OCP from './OCP/index.js'
  51. import OCA from './OCA/index.js'
  52. import { getToken as getRequestToken } from './OC/requesttoken.js'
  53. const warnIfNotTesting = function() {
  54. if (window.TESTING === undefined) {
  55. OC.debug && console.warn.apply(console, arguments)
  56. }
  57. }
  58. /**
  59. * Mark a function as deprecated and automatically
  60. * warn if used!
  61. *
  62. * @param {Function} func the library to deprecate
  63. * @param {string} funcName the name of the library
  64. * @param {number} version the version this gets removed
  65. * @return {Function}
  66. */
  67. const deprecate = (func, funcName, version) => {
  68. const oldFunc = func
  69. const newFunc = function() {
  70. warnIfNotTesting(`The ${funcName} library is deprecated! It will be removed in nextcloud ${version}.`)
  71. return oldFunc.apply(this, arguments)
  72. }
  73. Object.assign(newFunc, oldFunc)
  74. return newFunc
  75. }
  76. const setDeprecatedProp = (global, cb, msg) => {
  77. (Array.isArray(global) ? global : [global]).forEach(global => {
  78. if (window[global] !== undefined) {
  79. delete window[global]
  80. }
  81. Object.defineProperty(window, global, {
  82. get: () => {
  83. if (msg) {
  84. warnIfNotTesting(`${global} is deprecated: ${msg}`)
  85. } else {
  86. warnIfNotTesting(`${global} is deprecated`)
  87. }
  88. return cb()
  89. },
  90. })
  91. })
  92. }
  93. window._ = _
  94. setDeprecatedProp(['$', 'jQuery'], () => $, 'The global jQuery is deprecated. It will be removed in a later versions without another warning. Please ship your own.')
  95. setDeprecatedProp('autosize', () => autosize, 'please ship your own, this will be removed in Nextcloud 20')
  96. setDeprecatedProp('Backbone', () => Backbone, 'please ship your own, this will be removed in Nextcloud 20')
  97. setDeprecatedProp(['Clipboard', 'ClipboardJS'], () => ClipboardJS, 'please ship your own, this will be removed in Nextcloud 20')
  98. window.dav = dav
  99. setDeprecatedProp('Handlebars', () => Handlebars, 'please ship your own, this will be removed in Nextcloud 20')
  100. setDeprecatedProp('md5', () => md5, 'please ship your own, this will be removed in Nextcloud 20')
  101. setDeprecatedProp('moment', () => moment, 'please ship your own, this will be removed in Nextcloud 20')
  102. window.OC = OC
  103. setDeprecatedProp('initCore', () => initCore, 'this is an internal function')
  104. setDeprecatedProp('oc_appswebroots', () => OC.appswebroots, 'use OC.appswebroots instead, this will be removed in Nextcloud 20')
  105. setDeprecatedProp('oc_config', () => OC.config, 'use OC.config instead, this will be removed in Nextcloud 20')
  106. setDeprecatedProp('oc_current_user', () => OC.getCurrentUser().uid, 'use OC.getCurrentUser().uid instead, this will be removed in Nextcloud 20')
  107. setDeprecatedProp('oc_debug', () => OC.debug, 'use OC.debug instead, this will be removed in Nextcloud 20')
  108. setDeprecatedProp('oc_defaults', () => OC.theme, 'use OC.theme instead, this will be removed in Nextcloud 20')
  109. setDeprecatedProp('oc_isadmin', OC.isUserAdmin, 'use OC.isUserAdmin() instead, this will be removed in Nextcloud 20')
  110. setDeprecatedProp('oc_requesttoken', () => getRequestToken(), 'use OC.requestToken instead, this will be removed in Nextcloud 20')
  111. setDeprecatedProp('oc_webroot', () => OC.webroot, 'use OC.getRootPath() instead, this will be removed in Nextcloud 20')
  112. setDeprecatedProp('OCDialogs', () => OC.dialogs, 'use OC.dialogs instead, this will be removed in Nextcloud 20')
  113. window.OCP = OCP
  114. window.OCA = OCA
  115. $.fn.select2 = deprecate($.fn.select2, 'select2', 19)
  116. /**
  117. * translate a string
  118. *
  119. * @param {string} app the id of the app for which to translate the string
  120. * @param {string} text the string to translate
  121. * @param [vars] map of placeholder key to value
  122. * @param {number} [count] number to replace %n with
  123. * @return {string}
  124. */
  125. window.t = _.bind(OC.L10N.translate, OC.L10N)
  126. /**
  127. * translate a string
  128. *
  129. * @param {string} app the id of the app for which to translate the string
  130. * @param {string} text_singular the string to translate for exactly one object
  131. * @param {string} text_plural the string to translate for n objects
  132. * @param {number} count number to determine whether to use singular or plural
  133. * @param [vars] map of placeholder key to value
  134. * @return {string} Translated string
  135. */
  136. window.n = _.bind(OC.L10N.translatePlural, OC.L10N)