main.default.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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? for determine the jQuery version to use (optional)
  98. ie8 = (typeof window.addEventListener === 'undefined' && typeof document.getElementsByClassName === 'undefined');
  99. // config of RequireJS (REQUIRED)
  100. require.config({
  101. baseUrl : '../vendor/elfinder/js',
  102. paths : {
  103. 'jquery' : '//cdnjs.cloudflare.com/ajax/libs/jquery/'+(ie8? '1.12.4' : jqver)+'/jquery.min',
  104. 'jquery-ui': '//cdnjs.cloudflare.com/ajax/libs/jqueryui/'+uiver+'/jquery-ui.min',
  105. 'elfinder' : 'elfinder.min',
  106. 'encoding-japanese': '//cdn.rawgit.com/polygonplanet/encoding.js/1.0.26/encoding.min'
  107. },
  108. waitSeconds : 10 // optional
  109. });
  110. // check elFinderConfig and fallback
  111. if (! require.defined('elFinderConfig')) {
  112. define('elFinderConfig', {
  113. // elFinder options (REQUIRED)
  114. // Documentation for client options:
  115. // https://github.com/Studio-42/elFinder/wiki/Client-configuration-options
  116. defaultOpts : {
  117. url : 'php/connector.minimal.php' // connector URL (REQUIRED)
  118. ,commandsOptions : {
  119. edit : {
  120. extraOptions : {
  121. // set API key to enable Creative Cloud image editor
  122. // see https://console.adobe.io/
  123. creativeCloudApiKey : '',
  124. // browsing manager URL for CKEditor, TinyMCE
  125. // uses self location with the empty value
  126. managerUrl : ''
  127. }
  128. }
  129. ,quicklook : {
  130. // to enable preview with Google Docs Viewer
  131. 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']
  132. }
  133. }
  134. },
  135. managers : {
  136. 'elfinder': {},
  137. }
  138. });
  139. }
  140. // load JavaScripts (REQUIRED)
  141. load();
  142. })();