From 03e1c2d60c0dcd401d335e2b5f630e136e811e2c Mon Sep 17 00:00:00 2001 From: shibafu Date: Sun, 10 Feb 2019 20:48:16 +0900 Subject: [PATCH] =?UTF-8?q?=E3=82=AB=E3=83=BC=E3=83=89=E6=83=85=E5=A0=B1?= =?UTF-8?q?=E3=81=AE=E3=83=AA=E3=82=AF=E3=82=A8=E3=82=B9=E3=83=88=E5=87=A6?= =?UTF-8?q?=E7=90=86=E3=82=92=E5=85=B1=E9=80=9A=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/js/tissue.js | 49 ++++++++++++++++++++++ resources/views/ejaculation/show.blade.php | 38 +---------------- resources/views/home.blade.php | 38 +---------------- resources/views/layouts/base.blade.php | 1 + resources/views/search/index.blade.php | 38 +---------------- resources/views/user/profile.blade.php | 38 +---------------- 6 files changed, 58 insertions(+), 144 deletions(-) create mode 100644 public/js/tissue.js 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