-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathverifyImageSrc.js
More file actions
executable file
·236 lines (191 loc) · 6.53 KB
/
verifyImageSrc.js
File metadata and controls
executable file
·236 lines (191 loc) · 6.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
angular.module('app')
.directive('verifyImageSrc',['$timeout', '$compile', 'utilitiesService', function($timeout, $compile, utilitiesService) {
var directive = {
restrict: 'A'
, link: function(scope, element, attrs) {
/**
* This will get the image from the attribute and verify if the image exist
* onload, onerror
*
* If the image onload, it will place the image within the dom of the
* parent container, add new class to element 'ng-valid'
*
* onerror, add class to element 'ng-invalid'
*
* Acceptable attributes
* data-true, place the image within the css of the parent element
*
* default 'NONE', inject new $childNode
*
* @type {Image}
*/
var image = new Image();
var icon = false
,imageSource = attrs.verifyImageSrc;
//create a source element, only to be use during video integration
var source = angular.element( '<source>' );
//load the image src to the image object
image.src = imageSource;
//load source to video source object, only to be used during video integration
source[0].src = imageSource
//watch for changes due to js timing on dom load
var getImageSrc = scope.$watch
( function(){
return attrs.verifyImageSrc;
}
, function( imageSource ){
//continue watchin
if( ! imageSource){
return;
}
imageSource = imageSource;
image.src = imageSource;
//incase of changes
source[0].src = imageSource
// Remove watch now that we have what we need.
getImageSrc();
}
);
for(var i in scope.menuItems){
if(scope.menuItems[i].selected){
icon = scope.menuItems[i].icon
}
}
/**
* Allow for implementation of HTML5 Video,
* The supported image format for web, example http://v4e.thewikies.com/
* Example on control hooks
* http://blog.teamtreehouse.com/building-custom-controls-for-html5-videos
*
* Note: http://diveintohtml5.info/detect.html#video
* "probably" if the browser is fairly confident it can play this format
* "maybe" if the browser thinks it might be able to play this format
* "" (an empty string) if the browser is certain it can’t play this format
*
* Chrome - webm, ogg, ogv, mp4
* Firefox - webm, ogg, ogv
* Safari - mp4
* IE - mp4
* Opera - webm, ogg, ogv
*/
var supportedVideoFormats = ['webm','ogg','ogv','mp4']
var extension = imageSource.split('.').pop()
var supportVideo = utilitiesService.supports_video()
//checks if the browsers supports video and its a supported format the file
//TODO:currently this is false
if(false && supportVideo && utilitiesService.inArray(extension,supportedVideoFormats)){
/*<div class="video-container" >
<video controls=false preload >
<source src="{{assetsPath}}/{{packageDetails.shop_image_v4}}" type=''/>
</video>
<div class="video-controls"></div>
</div>*/
var container = angular.element( '<div>' ).addClass( 'video-container');
//Video element and controls
var video = angular.element( '<video>' );
video[0].setAttribute("preload","auto");
video[0].setAttribute("controls","false");
video[0].setAttribute("id","video");
video.wrap(container)
switch(extension){
case 'webm':
if(utilitiesService.supports_webm_video()){
source[0].type = "video/webm"
}
break;
case 'ogg':
case 'ogv':
if(utilitiesService.supports_ogg_theora_video()){
source[0].type = "video/ogg"
}
break;
case 'mp4':
if(utilitiesService.supports_h264_baseline_video()){
source[0].type = "video/mp4"
}
break;
/*default:
//if we have to do fallback to flash, used for desktop
var source = null;
source = angular.element( '<object >' );
source[0].setAttribute("type","application/x-shockwave-flash");
source[0].setAttribute("data","http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf");
source.css({ 'width': '100%' });
image.wrap(source)
break;*/
}
//add the video to source
source.wrap(video)
//creating some custom controls
var controls = angular.element( '<div>' ).addClass( 'video-controls');
var icon = angular.element( '<span>' ).addClass( 'icon-bulletarrow');
icon.wrap(controls)
//Event listener for the play/pause button
controls.bind("click", function() {
if (video[0].paused == true) {
videoContainer.css({'display':'none'});
// Play the video
video[0].play();
} else {
// Pause the video
video[0].pause();
}
});
//detect when the video ended
video.bind("ended", function() {
videoContainer.css({'display':'block'});
});
//add the video to the video-container
container.append(controls)
container.prepend(video)
//finally lets push what we just build to document
element.append(container)
/*
* Styling the video-control to obtain the poster
* TODO://need to load the image dinamically
*/
var videoContainer = utilitiesService.getObject('.video-controls')
videoContainer.css({
'background-image': 'url(https://assets.accesso.com/demo/images/v5seasonpass.png)'
,'background-size':'100% 100%'
});
setClassesOnload()
}else{
image.onload = function(){
setClassesOnload()
/**
* this is an additional style to verify-image-scr attribute,
* if it contails data-true it will set the within the css
* of the parent container
*
*/
if(attrs.$attr.true ? true : false){
element.css({
'background-image': 'url('+attrs.verifyImageSrc+')'
});
}else{
//append the new image
element.append(image)
}
return
}
image.onerror = function() {
element.addClass('ng-invalid')
//set the height of missing image ui feel
element.find('img' ).css({'height':'187px'});
//append the new image, if there is an image
if(icon)
element.append('<span class="'+icon+'"></span>')
}
}
function setClassesOnload(){
//hide any images within the children of the element, this is mainly for placeholders
element.find('img' ).addClass('hide');
//add success class to manipulate
element.removeClass('ng-invalid')
element.addClass('ng-valid')
}
}
};
return directive;
}]);