2018-12-27 11:54:16 +00:00
|
|
|
import {ng, ngDeps} from './vendor';
|
2019-10-26 23:30:01 +00:00
|
|
|
import {camelToKebab} from './lib/string';
|
2017-01-31 13:13:06 +00:00
|
|
|
|
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
|
2019-10-24 22:53:53 +00:00
|
|
|
* same function. If any of the options (template, transclude, bindings...) is
|
|
|
|
* redeclared in the child component, the last has preference.
|
2019-10-08 21:57:02 +00:00
|
|
|
*
|
|
|
|
* @param {String} name Coponent name in camelCase
|
|
|
|
* @param {Object} options The component options
|
|
|
|
* @return {angularModule} The same angular module
|
|
|
|
*/
|
2019-11-10 10:08:44 +00:00
|
|
|
function vnComponent(name, options) {
|
2019-10-08 21:57:02 +00:00
|
|
|
let controller = options.controller;
|
|
|
|
let parent = Object.getPrototypeOf(controller);
|
|
|
|
let parentOptions = parent.$options || {};
|
|
|
|
|
2019-10-26 23:30:01 +00:00
|
|
|
let parentTransclude = parentOptions.transclude;
|
|
|
|
let transclude = parentTransclude instanceof Object
|
|
|
|
? Object.assign({}, parentTransclude)
|
|
|
|
: parentTransclude;
|
|
|
|
|
|
|
|
if (options.transclude instanceof Object) {
|
|
|
|
if (transclude instanceof Object)
|
|
|
|
Object.assign(transclude, options.transclude);
|
|
|
|
else
|
|
|
|
transclude = options.transclude;
|
|
|
|
} else if (options.transclude !== undefined)
|
|
|
|
transclude = options.transclude;
|
|
|
|
|
2019-10-08 21:57:02 +00:00
|
|
|
let mergedOptions = Object.assign({},
|
|
|
|
parentOptions,
|
|
|
|
options,
|
|
|
|
{
|
2019-10-26 23:30:01 +00:00
|
|
|
transclude,
|
2019-10-08 21:57:02 +00:00
|
|
|
bindings: Object.assign({},
|
|
|
|
parentOptions.bindings,
|
|
|
|
options.bindings
|
2019-10-24 22:53:53 +00:00
|
|
|
),
|
|
|
|
require: Object.assign({},
|
|
|
|
parentOptions.require,
|
|
|
|
options.require
|
2019-10-08 21:57:02 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
);
|
|
|
|
controller.$options = mergedOptions;
|
|
|
|
|
2019-10-26 23:30:01 +00:00
|
|
|
let classNames = [camelToKebab(name)];
|
|
|
|
if (parent.$classNames) classNames = classNames.concat(parent.$classNames);
|
|
|
|
controller.$classNames = classNames;
|
|
|
|
|
2019-10-08 21:57:02 +00:00
|
|
|
return this.component(name, mergedOptions);
|
2019-11-10 10:08:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const ngModuleFn = ng.module;
|
|
|
|
|
|
|
|
ng.module = function(...args) {
|
|
|
|
let ngModule = ngModuleFn.apply(this, args);
|
|
|
|
ngModule.vnComponent = vnComponent;
|
|
|
|
return ngModule;
|
2019-10-08 21:57:02 +00:00
|
|
|
};
|
|
|
|
|
2019-11-10 10:08:44 +00:00
|
|
|
const ngModule = ng.module('vnCore', ngDeps);
|
|
|
|
export default ngModule;
|
|
|
|
|
|
|
|
config.$inject = ['$translateProvider', '$translatePartialLoaderProvider', '$animateProvider'];
|
|
|
|
export function config($translateProvider, $translatePartialLoaderProvider, $animateProvider) {
|
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',
|
2020-02-12 13:36:05 +00:00
|
|
|
en_GB: 'en',
|
2018-02-10 15:18:01 +00:00
|
|
|
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;
|
|
|
|
});
|
2019-11-10 10:08:44 +00:00
|
|
|
|
|
|
|
$animateProvider.customFilter(
|
|
|
|
node => node.tagName == 'UI-VIEW');
|
2018-02-10 15:18:01 +00:00
|
|
|
}
|
|
|
|
ngModule.config(config);
|