質問編集履歴

1

ボタンを押した時のコードを追加

2021/08/17 06:44

投稿

JunYoshida
JunYoshida

スコア20

test CHANGED
File without changes
test CHANGED
@@ -35,3 +35,105 @@
35
35
  </div>
36
36
 
37
37
  ```
38
+
39
+
40
+
41
+ ボタンを押した時のコード(Peepsoというライブラリを使っていて、解読したところの一部抜粋です。)
42
+
43
+ ```JavaScript
44
+
45
+ peepso.npm.objectAssign(
46
+
47
+ PsPostbox.prototype,
48
+
49
+ PsObserver.prototype,
50
+
51
+
52
+
53
+ this.$btns = this.$el.find('.ps-postbox-action');
54
+
55
+ this.$btnSubmit = this.$btns.find('.ps-button-action');
56
+
57
+
58
+
59
+ /**
60
+
61
+ *
62
+
63
+ */
64
+
65
+ getData: function () {
66
+
67
+ var data = this._getData();
68
+
69
+ data = this.applyFilters('data', data);
70
+
71
+ data = peepso.observer.applyFilters('postbox_data', data, this); // deprecated
72
+
73
+ return data;
74
+
75
+ },
76
+
77
+
78
+
79
+ /**
80
+
81
+ * Check whether current postbox state allows user to submit.
82
+
83
+ * @return {boolean}
84
+
85
+ */
86
+
87
+ validate: function () {
88
+
89
+ var data = this._getData(),
90
+
91
+ status = data.content.trim(),
92
+
93
+ valid = status ? true : false;
94
+
95
+
96
+
97
+ return this.applyFilters('data_validate', valid, data);
98
+
99
+ },
100
+
101
+
102
+
103
+ /**
104
+
105
+ * Handle submit action.
106
+
107
+ */
108
+
109
+ submit: function () {
110
+
111
+ if (typeof this.opts.submit === 'function' && this.validate()) {
112
+
113
+ this.$btns.hide();
114
+
115
+ this.$loading.show();
116
+
117
+ this.opts.submit(
118
+
119
+ this,
120
+
121
+ this.getData(),
122
+
123
+ $.proxy(function () {
124
+
125
+ this.$loading.hide();
126
+
127
+ this.$btns.css('display', 'flex');
128
+
129
+ }, this)
130
+
131
+ );
132
+
133
+ }
134
+
135
+ },
136
+
137
+
138
+
139
+ ```