2018-12-27 11:54:16 +00:00
|
|
|
import {ng, ngDeps} from './vendor';
|
2017-01-31 13:13:06 +00:00
|
|
|
|
2018-12-27 11:54:16 +00:00
|
|
|
const ngModule = ng.module('vnCore', ngDeps);
|
2018-02-10 15:18:01 +00:00
|
|
|
export default ngModule;
|
|
|
|
|
2019-10-08 21:57:02 +00:00
|
|
|
/**
|
|
|
|
* Acts like native Module.component() function but merging component options
|
|
|
|
* with parent component options. This method establishes the $options property
|
|
|
|
* to the component controller class with the merged component options. To
|
|
|
|
* retrieve parent options, it reads the same property of the parent class, so
|
|
|
|
* for the parent options to be copied, it must have been declared using this
|
|
|
|
* same function. If any of the options (template, transclude, bindings ...) is
|
|
|
|
* redeclared in the child component, it has preference.
|
|
|
|
*
|
|
|
|
* @param {String} name Coponent name in camelCase
|
|
|
|
* @param {Object} options The component options
|
|
|
|
* @return {angularModule} The same angular module
|
|
|
|
*/
|
|
|
|
ngModule.vnComponent = function(name, options) {
|
|
|
|
let controller = options.controller;
|
|
|
|
let parent = Object.getPrototypeOf(controller);
|
|
|
|
let parentOptions = parent.$options || {};
|
|
|
|
|
|
|
|
let mergedOptions = Object.assign({},
|
|
|
|
parentOptions,
|
|
|
|
options,
|
|
|
|
{
|
|
|
|
transclude: Object.assign({},
|
|
|
|
parentOptions.transclude,
|
|
|
|
options.transclude
|
|
|
|
),
|
|
|
|
bindings: Object.assign({},
|
|
|
|
parentOptions.bindings,
|
|
|
|
options.bindings
|
|
|
|
)
|
|
|
|
}
|
|
|
|
);
|
|
|
|
controller.$options = mergedOptions;
|
|
|
|
|
|
|
|
return this.component(name, mergedOptions);
|
|
|
|
};
|
|
|
|
|
2018-02-10 15:18:01 +00:00
|
|
|
config.$inject = ['$translateProvider', '$translatePartialLoaderProvider'];
|
|
|
|
export function config($translateProvider, $translatePartialLoaderProvider) {
|
2019-10-18 19:36:30 +00:00
|
|
|
// For CSS browser targeting
|
|
|
|
document.documentElement.setAttribute('data-browser', navigator.userAgent);
|
|
|
|
|
2018-02-10 15:18:01 +00:00
|
|
|
$translatePartialLoaderProvider.addPart('core');
|
|
|
|
|
2019-01-25 22:02:29 +00:00
|
|
|
let conf = {urlTemplate: '/locale/{part}/{lang}.json'};
|
2018-02-10 15:18:01 +00:00
|
|
|
|
|
|
|
let fallbackLang = 'es';
|
|
|
|
let langs = ['en', 'es'];
|
|
|
|
let langAliases = {
|
|
|
|
en_US: 'en',
|
|
|
|
en_UK: 'en',
|
|
|
|
es_ES: 'es',
|
|
|
|
es_AR: 'es'
|
|
|
|
};
|
|
|
|
|
|
|
|
$translateProvider
|
|
|
|
.useSanitizeValueStrategy('escape')
|
|
|
|
.useLoader('$translatePartialLoader', conf)
|
|
|
|
.registerAvailableLanguageKeys(langs, langAliases)
|
|
|
|
// FIXME: Circular dependency due to vnInterceptor
|
|
|
|
// .fallbackLanguage(fallbackLang)
|
|
|
|
.determinePreferredLanguage(() => {
|
|
|
|
let locale = $translateProvider.resolveClientLocale();
|
|
|
|
if (langs.indexOf(locale) !== -1)
|
|
|
|
return locale;
|
|
|
|
if (langAliases[locale])
|
|
|
|
return langAliases[locale];
|
|
|
|
return fallbackLang;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
ngModule.config(config);
|