Skip to content

Commit

Permalink
Wrap in IIFE and add "use strict" statement
Browse files Browse the repository at this point in the history
  • Loading branch information
meyfa committed Dec 23, 2016
1 parent 30e534f commit 9264b24
Showing 1 changed file with 50 additions and 42 deletions.
92 changes: 50 additions & 42 deletions app/app.js
@@ -1,49 +1,57 @@
/*global angular */

angular.module("youtube-thumbnail-preview", ["ngFilemodel"])

.controller("main", ["$scope", function ($scope) {

/** Stores info about the fake video that is displayed. */
$scope.info = {
title: "Title of the video",
uploader: "Channel Name",
time: "12:34",
uploadtime: "42 minutes ago",
views: "123,456",
};

/** FileList model for the thumbnail selection */
$scope.imageFiles = null;
/** The currently displayed data URL */
$scope.image = null;

/**
* Reads the given File object as a data URL and stores it in $scope.image.
*/
function loadFile(file) {
var reader = new FileReader();
reader.onload = function (event) {
$scope.$apply(function () {
$scope.image = event.target.result;
});
(function (angular) {
"use strict";

// -- MODULE DECLARATION
angular.module("youtube-thumbnail-preview", ["ngFilemodel"])

// MAIN CONTROLLER
.controller("main", ["$scope", function ($scope) {

/** Stores info about the fake video that is displayed. */
$scope.info = {
title: "Title of the video",
uploader: "Channel Name",
time: "12:34",
uploadtime: "42 minutes ago",
views: "123,456",
};
reader.readAsDataURL(file);
}

// load thumbnail on file selection
$scope.$watchCollection("imageFiles", function (files) {
if (files && files.length) {
loadFile(files[0]);
/** FileList model for the thumbnail selection */
$scope.imageFiles = null;
/** The currently displayed data URL */
$scope.image = null;

/**
* Reads the given File as a data URL and stores it in $scope.image.
*/
function loadFile(file) {
var reader = new FileReader();
reader.onload = function (event) {
$scope.$apply(function () {
$scope.image = event.target.result;
});
};
reader.readAsDataURL(file);
}
});

}])
// load thumbnail on file selection
$scope.$watchCollection("imageFiles", function (files) {
if (files && files.length) {
loadFile(files[0]);
}
});

}])

// THUMBNAIL DIRECTIVE
.directive("appThumbnail", [function () {
return {
restrict: "E",
scope: true,
templateUrl: "app/thumbnail.html",
};
}]);

.directive("appThumbnail", [function () {
return {
restrict: "E",
scope: true,
templateUrl: "app/thumbnail.html",
};
}]);
})(angular);

0 comments on commit 9264b24

Please sign in to comment.