buli
2023-06-05 e9b970ea36eea5dcf93fd5b965bf13d7010ce0ad
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
<apex:component >
<script>
;
'use strict';
angular.module("alDirective", [])
// INPUT タグ 用 ディレクティブ 単一ファイル選択 or カメラ
.directive("fileModel", ["$parse", function ($parse) {
    return {
        restrict: "A",
        link: function (scope, element, attrs) {
            var model = $parse(attrs.fileModel);
            element.bind("change", function () {
                scope.$apply(function () {
                    console.log("input file ");
                    model.assign(scope, element[0].files[0]);
                });
            });
        }
    };
}])
// NPUT タグ 用 ディレクティブ 複数ファイル選択
.directive("multifileModel", ["$parse", function ($parse) {
    return {
        restrict: "A",
        link: function (scope, element, attrs) {
            var model = $parse(attrs.multifileModel);
            element.bind("change", function () {
                scope.$apply(function () {
                    console.log("input file ");
                    model.assign(scope, element[0].files);
                });
            });
        }
    };
}])
// ロングタップを拾う用
// https://gist.github.com/BobNisco/9885852
.directive('onLongPress', ['$timeout', '$parse', function($timeout, $parse) {
    return {
        restrict: 'A',
        link: function ($scope, $elm, $attrs) {
            // スマホ用 ロングタップ判定
            $elm.bind('touchstart', function (evt) {
                // Locally scoped variable that will keep track of the long press
                $scope.longPress = true;
                var functionHandler = $parse($attrs.onLongPress);
                // We'll set a timeout for 600 ms for a long press
                $timeout(function () {
                    if ($scope.longPress) {
                        // If the touchend event hasn't fired,
                        // apply the function given in on the element's on-long-press attribute
                        $scope.$apply(function () {
                            functionHandler($scope, {$event: evt});
                        });
                    }
                }, 600);
            });
            // スマホ用 タッチ終了
            $elm.bind('touchend', function (evt) {
                // Prevent the onLongPress event from firing
                $scope.longPress = false;
                var functionHandler = $parse($attrs.onTouchEnd);
                // If there is an on-touch-end function attached to this element, apply it
                if ($attrs.onTouchEnd) {
                    $scope.$apply(function () {
                        functionHandler($scope, {$event: evt});
                    });
                }
            });
            // PC用 ロングタップ判定
            $elm.bind('mousedown', function (evt) {
                // Locally scoped variable that will keep track of the long press
                $scope.longPress = true;
                var functionHandler = $parse($attrs.onLongPress);
                // We'll set a timeout for 600 ms for a long press
                $timeout(function () {
                    if ($scope.longPress) {
                        // If the touchend event hasn't fired,
                        // apply the function given in on the element's on-long-press attribute
                        $scope.$apply(function () {
                            functionHandler($scope, {$event: evt});
                        });
                    }
                }, 600);
            });
            // PC用 タッチ終了
            $elm.bind('mouseup', function (evt) {
                // Prevent the onLongPress event from firing
                $scope.longPress = false;
                var functionHandler = $parse($attrs.onTouchEnd);
                // If there is an on-touch-end function attached to this element, apply it
                if ($attrs.onTouchEnd) {
                    $scope.$apply(function () {
                        functionHandler($scope, {$event: evt});
                    });
                }
            });
        }
    };
}])
;
 
</script>
</apex:component>