main.default.js 6.2 KB

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