@stratusjs/angularjs
Version:
This is the AngularJS package for StratusJS.
146 lines (144 loc) • 6.51 kB
JavaScript
System.register(["lodash", "@stratusjs/runtime/stratus", "@stratusjs/core/environment", "angular", "angular-sanitize", "../services/collection", "@stratusjs/core/misc"], function (exports_1, context_1) {
"use strict";
var lodash_1, stratus_1, environment_1, collection_1, misc_1;
var __moduleName = context_1 && context_1.id;
return {
setters: [
function (lodash_1_1) {
lodash_1 = lodash_1_1;
},
function (stratus_1_1) {
stratus_1 = stratus_1_1;
},
function (environment_1_1) {
environment_1 = environment_1_1;
},
function (_1) {
},
function (_2) {
},
function (collection_1_1) {
collection_1 = collection_1_1;
},
function (misc_1_1) {
misc_1 = misc_1_1;
}
],
execute: function () {
stratus_1.Stratus.Modules.ngSanitize = true;
stratus_1.Stratus.Controllers.Generic = [
'$scope',
'$element',
'$log',
'$sce',
'$parse',
'$window',
'Registry',
async ($scope, $element, $log, $sce, $parse, $window, R) => {
$scope.uid = misc_1.safeUniqueId('controller_generic_');
stratus_1.Stratus.Instances[$scope.uid] = $scope;
await R.fetch($element, $scope);
$scope.ctrlParent = $scope.$parent;
$scope.Stratus = stratus_1.Stratus;
$scope._ = lodash_1.default;
$scope.cookie = environment_1.cookie;
$scope.$window = $window;
$scope.getUrlParams = misc_1.getUrlParams;
$scope.setUrlParams = misc_1.setUrlParams;
$scope.$log = $log;
$scope.Math = Math;
$scope.isArray = lodash_1.isArray;
$scope.isDate = lodash_1.isDate;
$scope.isDefined = (value) => !lodash_1.isUndefined(value);
$scope.isElement = lodash_1.isElement;
$scope.isFunction = lodash_1.isFunction;
$scope.isNumber = lodash_1.isNumber;
$scope.isObject = lodash_1.isObject;
$scope.isString = lodash_1.isString;
$scope.isUndefined = lodash_1.isUndefined;
$scope.getHTML = $sce.trustAsHtml;
$scope.getURL = $sce.trustAsResourceUrl;
$scope.getAnchor = () => {
const url = window.location.href;
if (!url || !url.length) {
return false;
}
const anchor = url.indexOf('#');
if (anchor < 0) {
return false;
}
if ((anchor + 1) >= url.length) {
return false;
}
return url.substring(anchor + 1, url.length);
};
$scope.scrollToAnchor = (anchor, inUrl, delay) => {
if (!anchor || lodash_1.isEmpty(anchor)) {
$log.warn('anchor id not set!');
return false;
}
if (lodash_1.isUndefined(inUrl)) {
inUrl = false;
}
if (inUrl && anchor !== $scope.getAnchor()) {
return false;
}
const el = $window.document.getElementById(anchor);
if (!el) {
$log.warn(`element not found: ${anchor}`);
return false;
}
if (!delay) {
el.scrollIntoView({ behavior: 'smooth' });
return true;
}
return setTimeout(() => {
$scope.scrollToAnchor(anchor, inUrl, --delay);
}, 1);
};
if ($scope.data && lodash_1.isFunction($scope.data.on)) {
$scope.data.on('change', () => $scope.$applyAsync());
}
if (!$scope.collection || !($scope.collection instanceof collection_1.Collection)) {
return;
}
const selected = {
id: $element.attr('data-selected'),
raw: $element.attr('data-raw')
};
if (!selected.id || !lodash_1.isString(selected.id)) {
return;
}
if (misc_1.isJSON(selected.id)) {
selected.id = JSON.parse(selected.id);
$scope.$watch('collection.models', (models) => {
if ($scope.selected || $scope.selectedInit) {
return;
}
lodash_1.forEach(models, (model) => {
if (selected.id !== model.getIdentifier()) {
return;
}
$scope.selected = selected.raw ? model.data : model;
$scope.selectedInit = true;
});
});
}
else {
selected.model = $parse(selected.id);
selected.value = selected.model($scope.$parent);
if (!lodash_1.isArray(selected.value)) {
return;
}
selected.value = selected.value.filter((n) => n);
if (selected.value.length) {
return;
}
$scope.selected = lodash_1.head(selected.value);
}
}
];
}
};
});
//# sourceMappingURL=generic.js.map