forked from pencilblue/pencilblue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
libraries.js
179 lines (163 loc) · 7.55 KB
/
libraries.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/*
Copyright (C) 2015 PencilBlue, LLC
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
//dependencies
var util = require('./util.js');
module.exports = function LibrariesServiceModule(pb) {
/**
* Service for library settings retrieval
*
* @module Services
* @class LibrariesService
* @constructor
*/
function LibrariesService(){}
/**
*
* @private
* @static
* @readonly
* @property LIBRARIES_SETTINGS_REF
* @type {String}
*/
var LIBRARIES_SETTINGS_REF = 'libraries_settings';
/**
*
* @private
* @static
* @readonly
* @property CDN_DEFAULTS
* @type {Object}
*/
var CDN_DEFAULTS = Object.freeze({
jquery: '//code.jquery.com/jquery-1.11.1.min.js',
jquery_ui_js: '//code.jquery.com/ui/1.10.4/jquery-ui.min.js',
jquery_ui_css: '//code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css',
jquery_ui_touch_punch: '//cdnjs.cloudflare.com/ajax/libs/jqueryui-touch-punch/0.2.3/jquery.ui.touch-punch.min.js',
jquery_file_upload_js: '/js/lib/jquery/jquery.fileupload.js',
jquery_file_upload_css: '/css/lib/jquery/jquery.fileupload.css',
jquery_iframe_transport: '/js/lib/jquery/jquery.iframe-transport.js',
jquery_datetime_picker_js: '/js/lib/jquery/jquery.datetimepicker.min.js',
jquery_datetime_picker_css: '/css/lib/jquery/jquery.datetimepicker.min.css',
jquery_validate: '//ajax.aspnetcdn.com/ajax/jquery.validate/1.12.0/jquery.validate.min.js',
bootstrap_js: '//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js',
bootstrap_css: '//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css',
font_awesome: '//netdna.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css',
angular: '//ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js',
angular_route: '//ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular-route.min.js',
angular_sanitize: '//ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular-sanitize.min.js',
spin: '//fgnass.github.io/spin.js/spin.min.js',
jquery_spin: '//fgnass.github.io/spin.js/jquery.spin.js',
he: '/js/lib/he/he.js',
to_markdown: '/js/lib/to_markdown/to-markdown.js',
markdown: '/js/lib/markdown/lib/markdown.js',
angular_upload: '//cdnjs.cloudflare.com/ajax/libs/danialfarid-angular-file-upload/1.6.1/angular-file-upload.min.js',
angular_upload_shim: '//cdnjs.cloudflare.com/ajax/libs/danialfarid-angular-file-upload/1.6.1/angular-file-upload-shim.min.js',
ng_sortable_css: '/css/lib/ng-sortable/ng-sortable.min.css',
ng_sortable_style_css: '/css/lib/ng-sortable/ng-sortable.style.min.css',
ng_sortable_js: '/js/lib/ng-sortable/ng-sortable.min.js'
});
/**
*
* @private
* @static
* @readonly
* @property BOWER_DEFAULTS
* @type {Object}
*/
var BOWER_DEFAULTS = Object.freeze({
jquery: '/bower_components/jquery/dist/jquery.min.js',
jquery_ui_js: '/bower_components/jqueryui/jquery-ui.min.js',
jquery_ui_css: '/bower_components/jqueryui/themes/ui-lightness/jquery-ui.min.css',
jquery_ui_touch_punch: '/bower_components/jqueryui-touch-punch/jquery.ui.touch-punch.min.js',
jquery_file_upload_js: '/bower_components/jquery-file-upload/js/jquery.fileupload.js',
jquery_file_upload_css: '/bower_components/jquery-file-upload/css/jquery.fileupload.css',
jquery_iframe_transport: '/bower_components/jquery.iframe-transport/jquery.iframe-transport.js',
jquery_datetime_picker_js: '/bower_components/datetimepicker/jquery.datetimepicker.js',
jquery_datetime_picker_css: '/bower_components/datetimepicker/jquery.datetimepicker.css',
jquery_validate: '/bower_components/jquery.validation/dist/jquery.validate.min.js',
bootstrap_js: '/bower_components/bootstrap/dist/js/bootstrap.min.js',
bootstrap_css: '/bower_components/bootstrap/dist/css/bootstrap.min.css',
font_awesome: '/bower_components/fontawesome/css/font-awesome.min.css',
angular: '/bower_components/angular/angular.min.js',
angular_route: '/bower_components/angular-route/angular-route.min.js',
angular_sanitize: '/bower_components/angular-sanitize/angular-sanitize.min.js',
spin: '/bower_components/jquery.spinjs/libs/spin/spin.js',
jquery_spin: '/bower_components/jquery.spinjs/dist/jquery.spin.min.js',
he: '/bower_components/he/he.js',
to_markdown: '/bower_components/to-markdown/src/to-markdown.js',
markdown: '/bower_components/markdown/lib/markdown.js',
angular_upload: '/bower_components/danialfarid-angular-file-upload/dist/angular-file-upload.min.js',
angular_upload_shim: '/bower_components/danialfarid-angular-file-upload/dist/angular-file-upload-shim.min.js',
ng_sortable_css: '/bower_components/ng-sortable/dist/ng-sortable.min.css',
ng_sortable_style_css: '/bower_components/ng-sortable/dist/ng-sortable.style.min.css',
ng_sortable_js: '/bower_components/ng-sortable/dist/ng-sortable.min.js'
});
/**
* Retrieves the library settings
*
* @method getSettings
* @param {Function} cb Callback function
*/
LibrariesService.prototype.getSettings = function(cb){
pb.settings.get(LIBRARIES_SETTINGS_REF, function(err, settings){
if (settings) {
return cb(err, settings);
}
//set default settings if they don't exist
settings = LibrariesService.getCDNDefaults();
pb.settings.set(LIBRARIES_SETTINGS_REF, settings, function(err, result) {
cb(err, settings);
});
});
};
/**
* Loads the libraries settings into template service globals. Called on system
* startup
*
* @method init
* @param {Function} cb Callback function
*/
LibrariesService.init = function(cb) {
var instance = new LibrariesService();
instance.getSettings(function(err, settings) {
if(util.isError(err)) {
return cb(err);
}
Object.keys(settings).forEach(function(key) {
pb.TemplateService.registerGlobal(key + '_src', settings[key]);
});
cb(null, true);
});
};
/**
* Retrieves the default library settings for CDNs
*
* @method getCDNDefaults
* @return {Object} CDN defaults
*/
LibrariesService.getCDNDefaults = function() {
return util.clone(CDN_DEFAULTS);
};
/**
* Retrieves the default library settings for Bower
*
* @method getBowerDefaults
* @return {Object} Bower defaults
*/
LibrariesService.getBowerDefaults = function() {
return util.clone(BOWER_DEFAULTS);
};
//exports
return LibrariesService;
};