-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
110 lines (99 loc) · 5.08 KB
/
main.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
$(function() {
//toggleの代替
$.fn.clickToggle = function(a, b) {
return this.each(function() {
var clicked = false;
$(this).on('click', function() {
clicked = !clicked;
if (clicked) {
return a.apply(this, arguments);
}
return b.apply(this, arguments);
});
});
};
//いいね→ストックの変更
var isStock = $(".col-sm-9 .StockButton__unstock");
if (isStock.length) {
var stock = $('<button class="p-button liked"><span class="fa fa-fw fa-check"></span><span>ストック</span></button>');
stock.clickToggle(
function() {
$(".ArticleMainHeader .LikeButton .p-button.liked").attr("class", "p-button");
$(".ArticleMainHeader .LikeButton .p-button .fa.fa-fw.fa-check").attr("style", "display:none");
},
function() {
$(".ArticleMainHeader .LikeButton .p-button").attr("class", "p-button liked");
$(".ArticleMainHeader .LikeButton .p-button .fa.fa-fw.fa-check").removeAttr("style", "display:none");
});
} else {
var stock = $('<button class="p-button"><span class="fa fa-fw fa-check" style = "display:none"></span><span>ストック</span></button>');
stock.clickToggle(
function() {
$(".ArticleMainHeader .LikeButton .p-button").attr("class", "p-button liked");
$(".ArticleMainHeader .LikeButton .p-button .fa.fa-fw.fa-check").removeAttr("style", "display:none");
},
function() {
$(".ArticleMainHeader .LikeButton .p-button.liked").attr("class", "p-button");
$(".ArticleMainHeader .LikeButton .p-button .fa.fa-fw.fa-check").attr("style", "display:none");
});
}
$(".col-sm-9 .StockButton__stock").on("click",
function() {
$(".ArticleMainHeader .LikeButton .p-button").attr("class", "p-button liked");
$(".ArticleMainHeader .LikeButton .p-button .fa.fa-fw.fa-check").removeAttr("style", "display:none");
});
$(".col-sm-9 .StockButton__unstock").on("click",
function() {
$(".ArticleMainHeader .LikeButton .p-button.liked").attr("class", "p-button");
$(".ArticleMainHeader .LikeButton .p-button .fa.fa-fw.fa-check").attr("style", "display:none");
});
stock.on("click", function() {
$($(".StockButton__stock")[0]).click();
});
$(".ArticleMainHeader .LikeButton .p-button").attr("style", "display:none");
$(".ArticleMainHeader .LikeButton").append(stock);
//ストック→いいねの変更
var isIine = $(".col-sm-9 .p-button.liked");
if (isIine.length) {
var iine = $('<div class="StockButton"><button class="StockButton__stock" type="submit"><div class="fa-stack fa-lg"><span class="fa fa-fw fa-check""></span></div><span class="StockButton__label">いいね</span></button><div>');
iine.attr("style", "color:#79b74a");
iine.clickToggle(
function() {
$(".u-flex.u-space-between .fa.fa-fw.fa-check").attr("class", "fa fa-fw fa-thumbs-up");
iine.removeAttr("style", "color:#79b74a");
},
function() {
$(".u-flex.u-space-between .fa.fa-fw.fa-thumbs-up").attr("class", "fa fa-fw fa-check");
iine.attr("style", "color:#79b74a");
});
} else {
var iine = $('<div class="StockButton"><button class="StockButton__stock" type="submit"><div class="fa-stack fa-lg"><span class="fa fa-fw fa-thumbs-up"></span></div><span class="StockButton__label">いいね</span></button><div>');
iine.clickToggle(
function() {
$(".u-flex.u-space-between .fa.fa-fw.fa-thumbs-up").attr("class", "fa fa-fw fa-check");
iine.attr("style", "color:#79b74a");
},
function() {
$(".u-flex.u-space-between .fa.fa-fw.fa-check").attr("class", "fa fa-fw fa-thumbs-up");
iine.removeAttr("style", "color:#79b74a");
});
}
iine.on("click", function() {
$($(".p-button")[0]).click();
});
$(".col-sm-9 .LikeButton .p-button").on("click",
function() {
if ($(this).hasClass("liked")) {
$(".u-flex.u-space-between .fa.fa-fw.fa-check").attr("class", "fa fa-fw fa-thumbs-up");
iine.removeAttr("style", "color:#79b74a");
} else {
$(".u-flex.u-space-between .fa.fa-fw.fa-thumbs-up").attr("class", "fa fa-fw fa-check");
iine.attr("style", "color:#79b74a");
}
});
$('.u-flex.u-space-between .StockButton__stock').attr("style", "display:none");
$('.u-flex.u-space-between .StockButton__unstock').attr("style", "display:none");
$('.u-flex.u-space-between .StockButton.StockButton--stocked').attr("style", "display:none");
$('.u-flex.u-space-between .StockButton').attr("style", "display:none");
$('.u-flex.u-space-between .ArticleAsideHeader__stock').append(iine);
});