diff --git a/public/js/tissue.js b/public/js/tissue.js new file mode 100644 index 0000000..dab7c34 --- /dev/null +++ b/public/js/tissue.js @@ -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); \ No newline at end of file diff --git a/resources/views/ejaculation/show.blade.php b/resources/views/ejaculation/show.blade.php index 4a55930..b61cf00 100644 --- a/resources/views/ejaculation/show.blade.php +++ b/resources/views/ejaculation/show.blade.php @@ -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') }}' }); @endpush \ No newline at end of file diff --git a/resources/views/home.blade.php b/resources/views/home.blade.php index 730818c..eb55241 100644 --- a/resources/views/home.blade.php +++ b/resources/views/home.blade.php @@ -108,42 +108,8 @@ @push('script') + @endpush \ No newline at end of file diff --git a/resources/views/user/profile.blade.php b/resources/views/user/profile.blade.php index 5a674fc..4e442ca 100644 --- a/resources/views/user/profile.blade.php +++ b/resources/views/user/profile.blade.php @@ -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') }}' }); @endpush \ No newline at end of file