Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
128 additions
and
2 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
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
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
namespace common.directives.markdownEditor { | ||
|
||
interface TestScope extends ng.IRootScopeService { | ||
testModel: any; | ||
} | ||
|
||
describe('Markdown editor directive', () => { | ||
|
||
let $compile:ng.ICompileService, | ||
$rootScope:TestScope | ||
; | ||
|
||
beforeEach(()=> { | ||
|
||
module('app'); | ||
|
||
inject((_$compile_, _$rootScope_) => { | ||
$compile = _$compile_; | ||
$rootScope = _$rootScope_; | ||
}); | ||
|
||
}); | ||
|
||
it('should initialise the directive and change the model', () => { | ||
|
||
let testText = "Some **markdown** text"; | ||
|
||
$rootScope.testModel = testText; | ||
|
||
let element = $compile(`<markdown-editor ng-model="testModel" spell-checker="false"></markdown-editor>`)($rootScope); | ||
|
||
$rootScope.$digest(); | ||
|
||
$(element).find('.editor-toolbar > a').first().click(); | ||
|
||
$rootScope.$digest(); | ||
|
||
expect($rootScope.testModel).not.to.equal(testText); | ||
}); | ||
|
||
|
||
}); | ||
|
||
} |
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<div class="video-embed" ng-switch="provider"> | ||
|
||
<iframe | ||
ng-switch-when="youtube" | ||
width="420" | ||
height="315" | ||
src="{{url}}" | ||
frameborder="0" | ||
allowfullscreen | ||
></iframe> | ||
|
||
<iframe | ||
ng-switch-when="vimeo" | ||
src="{{url}}" | ||
width="500" | ||
height="281" | ||
frameborder="0" | ||
allowfullscreen> | ||
</iframe> | ||
|
||
</div> |
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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
namespace common.directives.videoEmbed { | ||
|
||
export const namespace = 'common.directives.videoEmbed'; | ||
|
||
export interface IVideoEmbedScope extends ng.IScope { | ||
provider: string; | ||
videoId: string; | ||
url: string; | ||
} | ||
|
||
class VideoEmbedDirective implements ng.IDirective { | ||
|
||
public restrict = 'E'; | ||
public templateUrl = 'templates/common/directives/videoEmbed/videoEmbed.tpl.html'; | ||
public replace = false; | ||
public scope = { | ||
provider: '@', | ||
videoId: '@', | ||
}; | ||
|
||
constructor(private $sce:ng.ISCEService) { | ||
} | ||
|
||
public link = ($scope: IVideoEmbedScope, $element: ng.IAugmentedJQuery, $attrs: ng.IAttributes) => { | ||
|
||
//@todo detect when scope property changes and force redraw of the iframe | ||
|
||
switch($scope.provider){ | ||
case 'youtube': | ||
$scope.url = this.$sce.trustAsResourceUrl(`https://www.youtube.com/embed/${$scope.videoId}?modestbranding=1`); | ||
break; | ||
|
||
case 'vimeo': | ||
$scope.url = this.$sce.trustAsResourceUrl(`https://player.vimeo.com/video/${$scope.videoId}`); | ||
break; | ||
|
||
} | ||
|
||
}; | ||
|
||
static factory(): ng.IDirectiveFactory { | ||
const directive = ($sce) => new VideoEmbedDirective($sce); | ||
directive.$inject = ['$sce']; | ||
return directive; | ||
} | ||
} | ||
|
||
angular.module(namespace, [ | ||
]) | ||
.directive('videoEmbed', VideoEmbedDirective.factory()) | ||
; | ||
|
||
|
||
} |
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