Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Wrap in IIFE and add "use strict" statement
- Loading branch information
Showing
1 changed file
with
50 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); |