main.default.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /**
  2. * elFinder client options and main script for RequireJS
  3. *
  4. * Rename "main.default.js" to "main.js" and edit it if you need configure elFInder options or any things. And use that in elfinder.html.
  5. * e.g. `<script data-main="./main.js" src="./require.js"></script>`
  6. **/
  7. (function(){
  8. "use strict";
  9. var // jQuery and jQueryUI version
  10. jqver = '3.4.1',
  11. uiver = '1.12.1',
  12. // Detect language (optional)
  13. lang = (function() {
  14. var locq = window.location.search,
  15. map = {
  16. 'pt' : 'pt_BR',
  17. 'ug' : 'ug_CN',
  18. 'zh' : 'zh_CN'
  19. },
  20. full = {
  21. 'zh_tw' : 'zh_TW',
  22. 'zh_cn' : 'zh_CN',
  23. 'fr_ca' : 'fr_CA'
  24. },
  25. fullLang, locm, lang;
  26. if (locq && (locm = locq.match(/lang=([a-zA-Z_-]+)/))) {
  27. // detection by url query (?lang=xx)
  28. fullLang = locm[1];
  29. } else {
  30. // detection by browser language
  31. fullLang = (navigator.browserLanguage || navigator.language || navigator.userLanguage || '');
  32. }
  33. fullLang = fullLang.replace('-', '_').substr(0,5).toLowerCase();
  34. if (full[fullLang]) {
  35. lang = full[fullLang];
  36. } else {
  37. lang = (fullLang || 'en').substr(0,2);
  38. if (map[lang]) {
  39. lang = map[lang];
  40. }
  41. }
  42. return lang;
  43. })(),
  44. // Start elFinder (REQUIRED)
  45. start = function(elFinder, editors, config) {
  46. // load jQueryUI CSS
  47. elFinder.prototype.loadCss('//cdnjs.cloudflare.com/ajax/libs/jqueryui/'+uiver+'/themes/smoothness/jquery-ui.css');
  48. $(function() {
  49. var optEditors = {
  50. commandsOptions: {
  51. edit: {
  52. editors: Array.isArray(editors)? editors : []
  53. }
  54. }
  55. },
  56. opts = {};
  57. // Interpretation of "elFinderConfig"
  58. if (config && config.managers) {
  59. $.each(config.managers, function(id, mOpts) {
  60. opts = Object.assign(opts, config.defaultOpts || {});
  61. // editors marges to opts.commandOptions.edit
  62. try {
  63. mOpts.commandsOptions.edit.editors = mOpts.commandsOptions.edit.editors.concat(editors || []);
  64. } catch(e) {
  65. Object.assign(mOpts, optEditors);
  66. }
  67. // Make elFinder
  68. $('#' + id).elfinder(
  69. // 1st Arg - options
  70. $.extend(true, { lang: lang }, opts, mOpts || {}),
  71. // 2nd Arg - before boot up function
  72. function(fm, extraObj) {
  73. // `init` event callback function
  74. fm.bind('init', function() {
  75. // Optional for Japanese decoder "encoding-japanese"
  76. if (fm.lang === 'ja') {
  77. require(
  78. [ 'encoding-japanese' ],
  79. function(Encoding) {
  80. if (Encoding && Encoding.convert) {
  81. fm.registRawStringDecoder(function(s) {
  82. return Encoding.convert(s, {to:'UNICODE',type:'string'});
  83. });
  84. }
  85. }
  86. );
  87. }
  88. });
  89. }
  90. );
  91. });
  92. } else {
  93. alert('"elFinderConfig" object is wrong.');
  94. }
  95. });
  96. },
  97. // JavaScript loader (REQUIRED)
  98. load = function() {
  99. require(
  100. [
  101. 'elfinder'
  102. , 'extras/editors.default.min' // load text, image editors
  103. , 'elFinderConfig'
  104. // , 'extras/quicklook.googledocs.min' // optional preview for GoogleApps contents on the GoogleDrive volume
  105. ],
  106. start,
  107. function(error) {
  108. alert(error.message);
  109. }
  110. );
  111. },
  112. // is IE8 or :? for determine the jQuery version to use (optional)
  113. old = (typeof window.addEventListener === 'undefined' && typeof document.getElementsByClassName === 'undefined')
  114. ||
  115. (!window.chrome && !document.unqueID && !window.opera && !window.sidebar && 'WebkitAppearance' in document.documentElement.style && document.body.style && typeof document.body.style.webkitFilter === 'undefined');
  116. // config of RequireJS (REQUIRED)
  117. require.config({
  118. baseUrl : 'js',
  119. paths : {
  120. 'jquery' : '//cdnjs.cloudflare.com/ajax/libs/jquery/'+(old? '1.12.4' : jqver)+'/jquery.min',
  121. 'jquery-ui': '//cdnjs.cloudflare.com/ajax/libs/jqueryui/'+uiver+'/jquery-ui.min',
  122. 'elfinder' : 'elfinder.min',
  123. 'encoding-japanese': '//cdn.rawgit.com/polygonplanet/encoding.js/1.0.26/encoding.min'
  124. },
  125. waitSeconds : 10 // optional
  126. });
  127. // check elFinderConfig and fallback
  128. // This part don't used if you are using elfinder.html, see elfinder.html
  129. if (! require.defined('elFinderConfig')) {
  130. define('elFinderConfig', {
  131. // elFinder options (REQUIRED)
  132. // Documentation for client options:
  133. // https://github.com/Studio-42/elFinder/wiki/Client-configuration-options
  134. defaultOpts : {
  135. url : 'php/connector.minimal.php' // connector URL (REQUIRED)
  136. ,commandsOptions : {
  137. edit : {
  138. extraOptions : {
  139. // set API key to enable Creative Cloud image editor
  140. // see https://console.adobe.io/
  141. creativeCloudApiKey : '',
  142. // browsing manager URL for CKEditor, TinyMCE
  143. // uses self location with the empty value
  144. managerUrl : ''
  145. }
  146. }
  147. ,quicklook : {
  148. // to enable CAD-Files and 3D-Models preview with sharecad.org
  149. sharecadMimes : ['image/vnd.dwg', 'image/vnd.dxf', 'model/vnd.dwf', 'application/vnd.hp-hpgl', 'application/plt', 'application/step', 'model/iges', 'application/vnd.ms-pki.stl', 'application/sat', 'image/cgm', 'application/x-msmetafile'],
  150. // to enable preview with Google Docs Viewer
  151. googleDocsMimes : ['application/pdf', 'image/tiff', 'application/vnd.ms-office', 'application/msword', 'application/vnd.ms-word', 'application/vnd.ms-excel', 'application/vnd.ms-powerpoint', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/vnd.openxmlformats-officedocument.presentationml.presentation', 'application/postscript', 'application/rtf'],
  152. // to enable preview with Microsoft Office Online Viewer
  153. // these MIME types override "googleDocsMimes"
  154. officeOnlineMimes : ['application/vnd.ms-office', 'application/msword', 'application/vnd.ms-word', 'application/vnd.ms-excel', 'application/vnd.ms-powerpoint', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/vnd.openxmlformats-officedocument.presentationml.presentation', 'application/vnd.oasis.opendocument.text', 'application/vnd.oasis.opendocument.spreadsheet', 'application/vnd.oasis.opendocument.presentation']
  155. }
  156. }
  157. },
  158. managers : {
  159. 'elfinder': {},
  160. }
  161. });
  162. }
  163. // load JavaScripts (REQUIRED)
  164. load();
  165. })();