This repository has been archived by the owner on May 27, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 40
/
ionic.contrib.frostedGlass.js
83 lines (67 loc) · 2.44 KB
/
ionic.contrib.frostedGlass.js
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
(function() {
'use strict';
/**
* The ionic-contrib-frosted-glass is a fun frosted-glass effect
* that can be used in iOS apps to give an iOS 7 frosted-glass effect
*/
angular.module('ionic.contrib.frostedGlass', ['ionic'])
.factory('$ionicFrostedDelegate', ['$rootScope', function($rootScope) {
return {
update: function() {
$rootScope.$emit('ionicFrosted.update');
}
}
}])
.directive('frostedBar', ['$timeout', '$rootScope', '$ionicScrollDelegate', function($timeout, $rootScope, $ionicScrollDelegate) {
var clone = function($element) {
var el = $element[0];
var content = $element.parent()[0].querySelector('.scroll');
if(!content) {
return;
}
var scrollStart = content.style[ionic.CSS.TRANSFORM];
var startY = parseFloat(scrollStart.replace('translate3d(', '').split(',')[1]) || 0;
// Get the top offset position for headers, etc. on this content area
var contentOffset = content.parentNode.offsetTop;
// Get the height of the header to know how much to offset the content blur
var elHeight = el.offsetHeight;
// Clone the content
var contentCloned = content.cloneNode(true);
// Append the cloned content into the blur box
var blurContent = document.createElement('div');
blurContent.className = 'ionic-contrib-blur';
blurContent.style.overflow = 'hidden';
blurContent.style.height = elHeight + 'px';
blurContent.appendChild(contentCloned);
content.parentNode.addEventListener('scroll', function(e) {
// Move the clone up as we scroll
contentCloned.style[ionic.CSS.TRANSFORM] = 'translate3d(0,' + (-e.detail.scrollTop + contentOffset) + 'px, 0)';
});
contentCloned.style[ionic.CSS.TRANSFORM] = 'translate3d(0,' + (startY + contentOffset) + 'px, 0)';
// Append the blur box into this element
$element.append(blurContent);
return blurContent;
};
return {
restrict: 'AC',
link: function($scope, $element, $attr, frosted) {
var blurContent = null;
$rootScope.$on('ionicFrosted.update', function() {
ionic.requestAnimationFrame(function() {
if(blurContent) {
blurContent.remove();
blurContent = clone($element);
}
});
});
// timeout so we allow child directives to
// render children
$timeout(function() {
ionic.requestAnimationFrame(function() {
blurContent = clone($element);
});
});
}
}
}]);
})();