config.service.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. angular.module('kityminderEditor')
  2. .provider('config', function() {
  3. this.config = {
  4. // 右侧面板最小宽度
  5. ctrlPanelMin: 250,
  6. // 右侧面板宽度
  7. ctrlPanelWidth: parseInt(window.localStorage.__dev_minder_ctrlPanelWidth) || 250,
  8. // 分割线宽度
  9. dividerWidth: 3,
  10. // 默认语言
  11. defaultLang: 'zh-cn',
  12. // 放大缩小比例
  13. zoom: [10, 20, 30, 50, 80, 100, 120, 150, 200],
  14. // 图片上传接口
  15. imageUpload: 'server/imageUpload.php'
  16. };
  17. this.set = function(key, value) {
  18. var supported = Object.keys(this.config);
  19. var configObj = {};
  20. // 支持全配置
  21. if (typeof key === 'object') {
  22. configObj = key;
  23. }
  24. else {
  25. configObj[key] = value;
  26. }
  27. for (var i in configObj) {
  28. if (configObj.hasOwnProperty(i) && supported.indexOf(i) !== -1) {
  29. this.config[i] = configObj[i];
  30. }
  31. else {
  32. console.error('Unsupported config key: ', key, ', please choose in :', supported.join(', '));
  33. return false;
  34. }
  35. }
  36. return true;
  37. };
  38. this.$get = function () {
  39. var me = this;
  40. return {
  41. get: function (key) {
  42. if (arguments.length === 0) {
  43. return me.config;
  44. }
  45. if (me.config.hasOwnProperty(key)) {
  46. return me.config[key];
  47. }
  48. console.warn('Missing config key pair for : ', key);
  49. return '';
  50. }
  51. };
  52. }
  53. });