カード情報のリクエスト処理を共通化
This commit is contained in:
		
							
								
								
									
										49
									
								
								public/js/tissue.js
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										49
									
								
								public/js/tissue.js
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,49 @@
 | 
			
		||||
// app.jsの名はモジュールバンドラーを投入する日まで予約しておく。CSSも同じ。
 | 
			
		||||
 | 
			
		||||
(function ($) {
 | 
			
		||||
 | 
			
		||||
    $.fn.linkCard = function (options) {
 | 
			
		||||
        var settings = $.extend({
 | 
			
		||||
            endpoint: '/api/checkin/card'
 | 
			
		||||
        }, options);
 | 
			
		||||
 | 
			
		||||
        return this.each(function () {
 | 
			
		||||
            var $this = $(this);
 | 
			
		||||
            $.ajax({
 | 
			
		||||
                url: settings.endpoint,
 | 
			
		||||
                method: 'get',
 | 
			
		||||
                type: 'json',
 | 
			
		||||
                data: {
 | 
			
		||||
                    url: $this.find('a').attr('href')
 | 
			
		||||
                }
 | 
			
		||||
            }).then(function (data) {
 | 
			
		||||
                var $title = $this.find('.card-title');
 | 
			
		||||
                var $desc = $this.find('.card-text');
 | 
			
		||||
                var $image = $this.find('img');
 | 
			
		||||
 | 
			
		||||
                if (data.title === '') {
 | 
			
		||||
                    $title.hide();
 | 
			
		||||
                } else {
 | 
			
		||||
                    $title.text(data.title);
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                if (data.description === '') {
 | 
			
		||||
                    $desc.hide();
 | 
			
		||||
                } else {
 | 
			
		||||
                    $desc.text(data.description);
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                if (data.image === '') {
 | 
			
		||||
                    $image.hide();
 | 
			
		||||
                } else {
 | 
			
		||||
                    $image.attr('src', data.image);
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                if (data.title !== '' || data.description !== '' || data.image !== '') {
 | 
			
		||||
                    $this.removeClass('d-none');
 | 
			
		||||
                }
 | 
			
		||||
            });
 | 
			
		||||
        });
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
})(jQuery);
 | 
			
		||||
@@ -112,42 +112,8 @@
 | 
			
		||||
            form.submit();
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
        $('.link-card').each(function () {
 | 
			
		||||
            var $this = $(this);
 | 
			
		||||
            $.ajax({
 | 
			
		||||
                url: '{{ url('/api/checkin/card') }}',
 | 
			
		||||
                method: 'get',
 | 
			
		||||
                type: 'json',
 | 
			
		||||
                data: {
 | 
			
		||||
                    url: $this.find('a').attr('href')
 | 
			
		||||
                }
 | 
			
		||||
            }).then(function (data) {
 | 
			
		||||
                var $title = $this.find('.card-title');
 | 
			
		||||
                var $desc = $this.find('.card-text');
 | 
			
		||||
                var $image = $this.find('img');
 | 
			
		||||
 | 
			
		||||
                if (data.title === '') {
 | 
			
		||||
                    $title.hide();
 | 
			
		||||
                } else {
 | 
			
		||||
                    $title.text(data.title);
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                if (data.description === '') {
 | 
			
		||||
                    $desc.hide();
 | 
			
		||||
                } else {
 | 
			
		||||
                    $desc.text(data.description);
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                if (data.image === '') {
 | 
			
		||||
                    $image.hide();
 | 
			
		||||
                } else {
 | 
			
		||||
                    $image.attr('src', data.image);
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                if (data.title !== '' || data.description !== '' || data.image !== '') {
 | 
			
		||||
                    $this.removeClass('d-none');
 | 
			
		||||
                }
 | 
			
		||||
            });
 | 
			
		||||
        $('.link-card').linkCard({
 | 
			
		||||
            endpoint: '{{ url('/api/checkin/card') }}'
 | 
			
		||||
        });
 | 
			
		||||
    </script>
 | 
			
		||||
@endpush
 | 
			
		||||
@@ -108,42 +108,8 @@
 | 
			
		||||
@push('script')
 | 
			
		||||
    <script type="text/javascript" src="//cdn.jsdelivr.net/npm/chart.js@2.7.1/dist/Chart.min.js"></script>
 | 
			
		||||
    <script>
 | 
			
		||||
        $('.link-card').each(function () {
 | 
			
		||||
            var $this = $(this);
 | 
			
		||||
            $.ajax({
 | 
			
		||||
                url: '{{ url('/api/checkin/card') }}',
 | 
			
		||||
                method: 'get',
 | 
			
		||||
                type: 'json',
 | 
			
		||||
                data: {
 | 
			
		||||
                    url: $this.find('a').attr('href')
 | 
			
		||||
                }
 | 
			
		||||
            }).then(function (data) {
 | 
			
		||||
                var $title = $this.find('.card-title');
 | 
			
		||||
                var $desc = $this.find('.card-text');
 | 
			
		||||
                var $image = $this.find('img');
 | 
			
		||||
 | 
			
		||||
                if (data.title === '') {
 | 
			
		||||
                    $title.hide();
 | 
			
		||||
                } else {
 | 
			
		||||
                    $title.text(data.title);
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                if (data.description === '') {
 | 
			
		||||
                    $desc.hide();
 | 
			
		||||
                } else {
 | 
			
		||||
                    $desc.text(data.description);
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                if (data.image === '') {
 | 
			
		||||
                    $image.hide();
 | 
			
		||||
                } else {
 | 
			
		||||
                    $image.attr('src', data.image);
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                if (data.title !== '' || data.description !== '' || data.image !== '') {
 | 
			
		||||
                    $this.removeClass('d-none');
 | 
			
		||||
                }
 | 
			
		||||
            });
 | 
			
		||||
        $('.link-card').linkCard({
 | 
			
		||||
            endpoint: '{{ url('/api/checkin/card') }}'
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
        new Chart(document.getElementById('global-count-graph').getContext('2d'), {
 | 
			
		||||
 
 | 
			
		||||
@@ -134,6 +134,7 @@
 | 
			
		||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.11.0/umd/popper.min.js"></script>
 | 
			
		||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-cookie/2.2.0/js.cookie.js"></script>
 | 
			
		||||
<script type="text/javascript" src="{{ asset('js/bootstrap.min.js') }}"></script>
 | 
			
		||||
<script type="text/javascript" src="{{ asset('js/tissue.js') }}"></script>
 | 
			
		||||
<script>
 | 
			
		||||
    $(function(){
 | 
			
		||||
        @guest
 | 
			
		||||
 
 | 
			
		||||
@@ -80,42 +80,8 @@
 | 
			
		||||
 | 
			
		||||
@push('script')
 | 
			
		||||
    <script>
 | 
			
		||||
        $('.link-card').each(function () {
 | 
			
		||||
            var $this = $(this);
 | 
			
		||||
            $.ajax({
 | 
			
		||||
                url: '{{ url('/api/checkin/card') }}',
 | 
			
		||||
                method: 'get',
 | 
			
		||||
                type: 'json',
 | 
			
		||||
                data: {
 | 
			
		||||
                    url: $this.find('a').attr('href')
 | 
			
		||||
                }
 | 
			
		||||
            }).then(function (data) {
 | 
			
		||||
                var $title = $this.find('.card-title');
 | 
			
		||||
                var $desc = $this.find('.card-text');
 | 
			
		||||
                var $image = $this.find('img');
 | 
			
		||||
 | 
			
		||||
                if (data.title === '') {
 | 
			
		||||
                    $title.hide();
 | 
			
		||||
                } else {
 | 
			
		||||
                    $title.text(data.title);
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                if (data.description === '') {
 | 
			
		||||
                    $desc.hide();
 | 
			
		||||
                } else {
 | 
			
		||||
                    $desc.text(data.description);
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                if (data.image === '') {
 | 
			
		||||
                    $image.hide();
 | 
			
		||||
                } else {
 | 
			
		||||
                    $image.attr('src', data.image);
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                if (data.title !== '' || data.description !== '' || data.image !== '') {
 | 
			
		||||
                    $this.removeClass('d-none');
 | 
			
		||||
                }
 | 
			
		||||
            });
 | 
			
		||||
        $('.link-card').linkCard({
 | 
			
		||||
            endpoint: '{{ url('/api/checkin/card') }}'
 | 
			
		||||
        });
 | 
			
		||||
    </script>
 | 
			
		||||
@endpush
 | 
			
		||||
@@ -136,42 +136,8 @@
 | 
			
		||||
            form.submit();
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
        $('.link-card').each(function () {
 | 
			
		||||
            var $this = $(this);
 | 
			
		||||
            $.ajax({
 | 
			
		||||
                url: '{{ url('/api/checkin/card') }}',
 | 
			
		||||
                method: 'get',
 | 
			
		||||
                type: 'json',
 | 
			
		||||
                data: {
 | 
			
		||||
                    url: $this.find('a').attr('href')
 | 
			
		||||
                }
 | 
			
		||||
            }).then(function (data) {
 | 
			
		||||
                var $title = $this.find('.card-title');
 | 
			
		||||
                var $desc = $this.find('.card-text');
 | 
			
		||||
                var $image = $this.find('img');
 | 
			
		||||
 | 
			
		||||
                if (data.title === '') {
 | 
			
		||||
                    $title.hide();
 | 
			
		||||
                } else {
 | 
			
		||||
                    $title.text(data.title);
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                if (data.description === '') {
 | 
			
		||||
                    $desc.hide();
 | 
			
		||||
                } else {
 | 
			
		||||
                    $desc.text(data.description);
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                if (data.image === '') {
 | 
			
		||||
                    $image.hide();
 | 
			
		||||
                } else {
 | 
			
		||||
                    $image.attr('src', data.image);
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                if (data.title !== '' || data.description !== '' || data.image !== '') {
 | 
			
		||||
                    $this.removeClass('d-none');
 | 
			
		||||
                }
 | 
			
		||||
            });
 | 
			
		||||
        $('.link-card').linkCard({
 | 
			
		||||
            endpoint: '{{ url('/api/checkin/card') }}'
 | 
			
		||||
        });
 | 
			
		||||
    </script>
 | 
			
		||||
@endpush
 | 
			
		||||
		Reference in New Issue
	
	Block a user