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.8KB

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