Skip to content

Instantly share code, notes, and snippets.

@konsultaner
Last active December 18, 2015 04:49
Show Gist options
  • Save konsultaner/5728234 to your computer and use it in GitHub Desktop.
Save konsultaner/5728234 to your computer and use it in GitHub Desktop.
This is an angularjs directive for jsMovie
/* Directive for jsMovie */
/* USAGE: <div jsmovie='' play-on-load='true' folder='img/seq/' sequence='mySeq####.png' from='1' to='32'></div> */
module.directive('jsmovie',function(){
return {
restrict:"A",
link:function(scope,element,attrs){
var possibleSettings = [
{name:'images', type:'array'},
{name:'clipQueue', type:'array'},
{name:'grid', type:'object'},
{name:'loader', type:'object'},
{name:'sequence', type:'string'},
{name:'folder', type:'string'},
{name:'folder', type:'string'},
{name:'from', type:'int'},
{name:'to', type:'int'},
{name:'step', type:'int'},
{name:'fps', type:'int'},
{name:'width', type:'int'},
{name:'height', type:'int'},
{name:'loadParallel', type:'int'},
{name:'repeat', type:'bool'},
{name:'playOnLoad', type:'bool'},
{name:'performStop', type:'bool'},
{name:'playBackwards', type:'bool'},
{name:'showPreLoader', type:'bool'},
{name:'verbose', type:'bool'}
];
var settings = {};
for(var i in possibleSettings){
if(!possibleSettings.hasOwnProperty(i))continue;
if(typeof attrs[possibleSettings[i].name] != 'undefined'){
if(possibleSettings[i].type == 'bool'){
settings[possibleSettings[i].name] = (attrs[possibleSettings[i].name] == 'true' || attrs[possibleSettings[i].name] == '1');
}else if(possibleSettings[i].type == 'int'){
settings[possibleSettings[i].name] = parseInt(attrs[possibleSettings[i].name]);
}else if(possibleSettings[i].type == 'array' || possibleSettings[i].type == 'object'){
settings[possibleSettings[i].name] = scope.$eval(attrs[possibleSettings[i].name]);
}else{
settings[possibleSettings[i].name] = attrs[possibleSettings[i].name];
}
}
}
if($(element).data('jsMovie')){
//$(element).jsMovie('destroy');
}
$(element).jsMovie(settings);
/* allow to play clips from the settings*/
if(typeof attrs.playClipOnLoad != 'undefined' && attrs.playClipOnLoad == 'true' || attrs.playClipOnLoad == '1'){
$(element).jsMovie("playClips");
}
/* stop all scripts on site change to prevent a never ending error list */
scope.$on("$routeChangeStart",function(){
$(element).jsMovie('destroy');
})
}
}
})
/* Directive for the play button */
/* USAGE <div jsmovie-play='#my-movie' ></div>*/
.directive('jsmoviePlay',function($parse){
return {
restrict: "A",
link: function (scope, element, attrs) {
$(element).on("click",function(){
$(attrs.jsmoviePlay).jsMovie('play',attrs.fromFrame,attrs.toFrame,attrs.repeat,attrs.performStop);
});
}
}
})
/* Directive for the stop button */
/* USAGE <div jsmovie-stop='#my-movie' ></div>*/
.directive('jsmovieStop',function($parse){
return {
restrict: "A",
link: function (scope, element, attrs) {
$(element).on("click",function(){
$(attrs.jsmovieStop).jsMovie('stop');
});
}
}
})
/* Directive for the pause button */
/* USAGE <div jsmovie-pause='#my-movie' ></div>*/
.directive('jsmoviePause',function($parse){
return {
restrict: "A",
link: function (scope, element, attrs) {
$(element).on("click",function(){
$(attrs.jsmoviePause).jsMovie('pause');
});
}
}
})
/* Directive for the reverse button */
/* USAGE <div jsmovie-reverse='#my-movie' ></div>*/
.directive('jsmovieReverse',function($parse){
return {
restrict: "A",
link: function (scope, element, attrs) {
$(element).on("click",function(){
$(attrs.jsmovieReverse).jsMovie('option','playBackwards',!$(attrs.jsmovieReverse).jsMovie('option','playBackwards'));
});
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment