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 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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 GNU AGPL version 3 or any later version
  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'
  27. import _ from 'underscore'
  28. import $ from 'jquery'
  29. import 'jquery-migrate/dist/jquery-migrate.min'
  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'
  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 'bootstrap/js/dist/tooltip'
  39. import './Polyfill/tooltip'
  40. import ClipboardJS from 'clipboard'
  41. import { dav } from 'davclient.js'
  42. import Handlebars from 'handlebars'
  43. import 'jcrop/js/jquery.Jcrop'
  44. import 'jcrop/css/jquery.Jcrop.css'
  45. import md5 from 'blueimp-md5'
  46. import moment from 'moment'
  47. import 'select2'
  48. import 'select2/select2.css'
  49. import 'snap.js/dist/snap'
  50. import 'strengthify'
  51. import 'strengthify/strengthify.css'
  52. import OC from './OC/index'
  53. import OCP from './OCP/index'
  54. import OCA from './OCA/index'
  55. import { getToken as getRequestToken } from './OC/requesttoken'
  56. const warnIfNotTesting = function() {
  57. if (window.TESTING === undefined) {
  58. console.warn.apply(console, arguments)
  59. }
  60. }
  61. /**
  62. * Mark a function as deprecated and automatically
  63. * warn if used!
  64. *
  65. * @param {Function} func the library to deprecate
  66. * @param {String} funcName the name of the library
  67. * @param {Int} version the version this gets removed
  68. * @returns {function}
  69. */
  70. const deprecate = (func, funcName, version) => {
  71. const oldFunc = func
  72. const newFunc = function() {
  73. warnIfNotTesting(`The ${funcName} library is deprecated! It will be removed in nextcloud ${version}.`)
  74. return oldFunc.apply(this, arguments)
  75. }
  76. Object.assign(newFunc, oldFunc)
  77. return newFunc
  78. }
  79. const setDeprecatedProp = (global, cb, msg) => {
  80. (Array.isArray(global) ? global : [global]).forEach(global => {
  81. if (window[global] !== undefined) {
  82. delete window[global]
  83. }
  84. Object.defineProperty(window, global, {
  85. get: () => {
  86. if (msg) {
  87. warnIfNotTesting(`${global} is deprecated: ${msg}`)
  88. } else {
  89. warnIfNotTesting(`${global} is deprecated`)
  90. }
  91. return cb()
  92. },
  93. })
  94. })
  95. }
  96. window._ = _
  97. setDeprecatedProp(['$', 'jQuery'], () => $, 'The global jQuery is deprecated. It will be removed in a later versions without another warning. Please ship your own.')
  98. setDeprecatedProp('autosize', () => autosize, 'please ship your own, this will be removed in Nextcloud 20')
  99. setDeprecatedProp('Backbone', () => Backbone, 'please ship your own, this will be removed in Nextcloud 20')
  100. setDeprecatedProp(['Clipboard', 'ClipboardJS'], () => ClipboardJS, 'please ship your own, this will be removed in Nextcloud 20')
  101. window.dav = dav
  102. setDeprecatedProp('Handlebars', () => Handlebars, 'please ship your own, this will be removed in Nextcloud 20')
  103. setDeprecatedProp('md5', () => md5, 'please ship your own, this will be removed in Nextcloud 20')
  104. setDeprecatedProp('moment', () => moment, 'please ship your own, this will be removed in Nextcloud 20')
  105. window.OC = OC
  106. setDeprecatedProp('initCore', () => initCore, 'this is an internal function')
  107. setDeprecatedProp('oc_appswebroots', () => OC.appswebroots, 'use OC.appswebroots instead, this will be removed in Nextcloud 20')
  108. setDeprecatedProp('oc_config', () => OC.config, 'use OC.config instead, this will be removed in Nextcloud 20')
  109. setDeprecatedProp('oc_current_user', () => OC.getCurrentUser().uid, 'use OC.getCurrentUser().uid instead, this will be removed in Nextcloud 20')
  110. setDeprecatedProp('oc_debug', () => OC.debug, 'use OC.debug instead, this will be removed in Nextcloud 20')
  111. setDeprecatedProp('oc_defaults', () => OC.theme, 'use OC.theme instead, this will be removed in Nextcloud 20')
  112. setDeprecatedProp('oc_isadmin', OC.isUserAdmin, 'use OC.isUserAdmin() instead, this will be removed in Nextcloud 20')
  113. setDeprecatedProp('oc_requesttoken', () => getRequestToken(), 'use OC.requestToken instead, this will be removed in Nextcloud 20')
  114. setDeprecatedProp('oc_webroot', () => OC.webroot, 'use OC.getRootPath() instead, this will be removed in Nextcloud 20')
  115. setDeprecatedProp('OCDialogs', () => OC.dialogs, 'use OC.dialogs instead, this will be removed in Nextcloud 20')
  116. window.OCP = OCP
  117. window.OCA = OCA
  118. $.fn.select2 = deprecate($.fn.select2, 'select2', 19)
  119. /**
  120. * translate a string
  121. * @param {string} app the id of the app for which to translate the string
  122. * @param {string} text the string to translate
  123. * @param [vars] map of placeholder key to value
  124. * @param {number} [count] number to replace %n with
  125. * @return {string}
  126. */
  127. window.t = _.bind(OC.L10N.translate, OC.L10N)
  128. /**
  129. * translate a string
  130. * @param {string} app the id of the app for which to translate the string
  131. * @param {string} text_singular the string to translate for exactly one object
  132. * @param {string} text_plural the string to translate for n objects
  133. * @param {number} count number to determine whether to use singular or plural
  134. * @param [vars] map of placeholder key to value
  135. * @return {string} Translated string
  136. */
  137. window.n = _.bind(OC.L10N.translatePlural, OC.L10N)