Skip to content

Commit

Permalink
JS cleanup and code style
Browse files Browse the repository at this point in the history
  • Loading branch information
abjerner committed Jun 29, 2018
1 parent 63a7f6f commit 0602a68
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 42 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
angular.module("umbraco").controller("Skybrud.LinkPickerPreValues.Controller", function ($scope) {

var v = Umbraco.Sys.ServerVariables.application.version.split('.');
$scope.umbVersion = parseFloat(v[0] + '.' + v[1]);
var v = Umbraco.Sys.ServerVariables.application.version.split(".");
$scope.umbVersion = parseFloat(v[0] + "." + v[1]);

$scope.views = [
{ alias: 'preview', name: 'Preview' },
{ alias: 'table', name: 'Table' },
{ alias: 'list', name: 'List' }
{ alias: "preview", name: "Preview" },
{ alias: "table", name: "Table" },
{ alias: "list", name: "List" }
];

$scope.view = $scope.views[0];
Expand All @@ -19,7 +19,7 @@
content: true,
media: true
},
view: 'preview',
view: "preview",
columns: {
type: true,
id: true,
Expand All @@ -33,15 +33,15 @@
// Make sure we still support the old "showTable" option
if ($scope.model.value.showTable === true) {
delete $scope.model.value.showTable;
$scope.model.value.view = 'table';
$scope.model.value.view = "table";
} else if ($scope.model.value.showTable === false) {
delete $scope.model.value.showTable;
$scope.model.value.view = 'list';
$scope.model.value.view = "list";
}

// Make sure the selected view is reflected in the UI
angular.forEach($scope.views, function (view) {
if ($scope.model.value.view == view.alias) {
if ($scope.model.value.view === view.alias) {
$scope.view = view;
}
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
angular.module('umbraco').directive('skybrudLinkpicker', ['dialogService', 'skybrudLinkPickerService', function (dialogService, p) {
angular.module("umbraco").directive("skybrudLinkpicker", ["dialogService", "skybrudLinkPickerService", function (dialogService, p) {
return {
scope: {
value: '=',
config: '='
value: "=",
config: "="
},
transclude: true,
restrict: 'E',
restrict: "E",
replace: true,
templateUrl: '/App_Plugins/Skybrud.LinkPicker/Views/LinkPickerDirective.html?v=2',
templateUrl: "/App_Plugins/Skybrud.LinkPicker/Views/LinkPickerDirective.html?v=2",
link: function (scope) {

var v = Umbraco.Sys.ServerVariables.application.version.split('.');
scope.umbVersion = parseFloat(v[0] + '.' + (v[1].length === 1 ? "0" + v[1] : v[1]));
var v = Umbraco.Sys.ServerVariables.application.version.split(".");
scope.umbVersion = parseFloat(v[0] + "." + (v[1].length === 1 ? "0" + v[1] : v[1]));

function initValue() {

// Initialize an empty model if no value at all
if (!scope.value) {
scope.value = {
title: '',
title: "",
items: []
};
}

// Convert the value if an array (legacy)
if (Array.isArray(scope.value)) {
scope.value = {
title: '',
title: "",
items: scope.value
};
}

// Set the "mode" property if not already present
scope.value.items.forEach(function (link) {
if (!link.mode) link.mode = (link.id ? (link.url && link.url.indexOf('/media/') === 0 ? 'media' : 'content') : 'url');
if (!link.mode) link.mode = (link.id ? (link.url && link.url.indexOf("/media/") === 0 ? "media" : "content") : "url");
});

}
Expand All @@ -48,9 +48,9 @@
if (scope.cfg.types.url === undefined) scope.cfg.types.url = true;
if (scope.cfg.types.content === undefined) scope.cfg.types.content = true;
if (scope.cfg.types.media === undefined) scope.cfg.types.media = true;
if (scope.cfg.view == undefined) scope.cfg.view = 'preview';
if (scope.cfg.showTable === true) scope.cfg.view = 'table';
if (scope.cfg.showTable === false) scope.cfg.view = 'list';
if (scope.cfg.view == undefined) scope.cfg.view = "preview";
if (scope.cfg.showTable === true) scope.cfg.view = "table";
if (scope.cfg.showTable === false) scope.cfg.view = "list";
if (!scope.cfg.columns) scope.cfg.columns = {};
if (scope.cfg.columns.type === undefined) scope.cfg.columns.type = true;
if (scope.cfg.columns.content === undefined) scope.cfg.columns.content = true;
Expand Down Expand Up @@ -91,7 +91,7 @@
};

// Set the ID if "mode" is "content"
if (link.id && link.mode == 'content') {
if (link.id && link.mode === "content") {
target.id = link.id;
}

Expand All @@ -112,42 +112,36 @@
}
};




//p.editLink(link, function (newLink) {
// scope.value.items[index] = newLink;
//}, closeAllDialogs);
};

scope.removeLink = function (index) {
var temp = [];
for (var i = 0; i < scope.value.items.length; i++) {
if (index != i) temp.push(scope.value.items[i]);
if (index !== i) temp.push(scope.value.items[i]);
}
scope.value.items = temp;
};

scope.sortableOptions = {
axis: 'y',
cursor: 'move',
handle: '.handle',
tolerance: 'pointer',
placeholder: 'linkpicker-sortable-placeholder',
containment: 'parent'
axis: "y",
cursor: "move",
handle: ".handle",
tolerance: "pointer",
placeholder: "linkpicker-sortable-placeholder",
containment: "parent"
};

scope.sortableOptionsList = {
axis: 'y',
cursor: 'move',
handle: '.handle',
tolerance: 'pointer',
containment: 'parent'
axis: "y",
cursor: "move",
handle: ".handle",
tolerance: "pointer",
containment: "parent"
};

scope.sortableOptionsPreview = {
distance: 10,
tolerance: 'pointer',
tolerance: "pointer",
scroll: true,
zIndex: 6000,
disabled: false
Expand Down

0 comments on commit 0602a68

Please sign in to comment.