surprise
2023-12-05 6ecef4176f6d9df60cd1a753a36e09cd96bce9b8
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
/** layui-v2.5.4 MIT License By https://www.layui.com */
layui.define("jquery", function (e) {
  "use strict";
  var i = layui.jquery,
    t = {
      config: {},
      index: layui.slider ? layui.slider.index + 1e4 : 0,
      set: function (e) {
        var t = this;
        return (t.config = i.extend({}, t.config, e)), t;
      },
      on: function (e, i) {
        return layui.onevent.call(this, n, e, i);
      },
    },
    a = function () {
      var e = this,
        i = e.config;
      return {
        setValue: function (i, t) {
          return e.slide("set", i, t || 0);
        },
        config: i,
      };
    },
    n = "slider",
    l = "layui-disabled",
    s = "layui-slider",
    r = "layui-slider-bar",
    o = "layui-slider-wrap",
    u = "layui-slider-wrap-btn",
    d = "layui-slider-tips",
    v = "layui-slider-input",
    c = "layui-slider-input-txt",
    m = "layui-slider-input-btn",
    p = "layui-slider-hover",
    f = function (e) {
      var a = this;
      (a.index = ++t.index),
        (a.config = i.extend({}, a.config, t.config, e)),
        a.render();
    };
  (f.prototype.config = {
    type: "default",
    min: 0,
    max: 100,
    value: 0,
    step: 1,
    showstep: !1,
    tips: !0,
    input: !1,
    range: !1,
    height: 200,
    disabled: !1,
    theme: "#009688",
  }),
    (f.prototype.render = function () {
      var e = this,
        t = e.config;
      if (
        (t.step < 1 && (t.step = 1),
        t.max < t.min && (t.max = t.min + t.step),
        t.range)
      ) {
        t.value = "object" == typeof t.value ? t.value : [t.min, t.value];
        var a = Math.min(t.value[0], t.value[1]),
          n = Math.max(t.value[0], t.value[1]);
        (t.value[0] = a > t.min ? a : t.min),
          (t.value[1] = n > t.min ? n : t.min),
          (t.value[0] = t.value[0] > t.max ? t.max : t.value[0]),
          (t.value[1] = t.value[1] > t.max ? t.max : t.value[1]);
        var r = Math.floor(((t.value[0] - t.min) / (t.max - t.min)) * 100),
          v = Math.floor(((t.value[1] - t.min) / (t.max - t.min)) * 100),
          m = v - r + "%";
        (r += "%"), (v += "%");
      } else {
        "object" == typeof t.value && (t.value = Math.min.apply(null, t.value)),
          t.value < t.min && (t.value = t.min),
          t.value > t.max && (t.value = t.max);
        var m = Math.floor(((t.value - t.min) / (t.max - t.min)) * 100) + "%";
      }
      var p = t.disabled ? "#c2c2c2" : t.theme,
        f =
          '<div class="layui-slider ' +
          ("vertical" === t.type ? "layui-slider-vertical" : "") +
          '">' +
          (t.tips ? '<div class="layui-slider-tips"></div>' : "") +
          '<div class="layui-slider-bar" style="background:' +
          p +
          "; " +
          ("vertical" === t.type ? "height" : "width") +
          ":" +
          m +
          ";" +
          ("vertical" === t.type ? "bottom" : "left") +
          ":" +
          (r || 0) +
          ';"></div><div class="layui-slider-wrap" style="' +
          ("vertical" === t.type ? "bottom" : "left") +
          ":" +
          (r || m) +
          ';"><div class="layui-slider-wrap-btn" style="border: 2px solid ' +
          p +
          ';"></div></div>' +
          (t.range
            ? '<div class="layui-slider-wrap" style="' +
              ("vertical" === t.type ? "bottom" : "left") +
              ":" +
              v +
              ';"><div class="layui-slider-wrap-btn" style="border: 2px solid ' +
              p +
              ';"></div></div>'
            : "") +
          "</div>",
        h = i(t.elem),
        y = h.next("." + s);
      if (
        (y[0] && y.remove(),
        (e.elemTemp = i(f)),
        t.range
          ? (e.elemTemp
              .find("." + o)
              .eq(0)
              .data("value", t.value[0]),
            e.elemTemp
              .find("." + o)
              .eq(1)
              .data("value", t.value[1]))
          : e.elemTemp.find("." + o).data("value", t.value),
        h.html(e.elemTemp),
        "vertical" === t.type && e.elemTemp.height(t.height + "px"),
        t.showstep)
      ) {
        for (var g = (t.max - t.min) / t.step, b = "", x = 1; x < g + 1; x++) {
          var T = (100 * x) / g;
          T < 100 &&
            (b +=
              '<div class="layui-slider-step" style="' +
              ("vertical" === t.type ? "bottom" : "left") +
              ":" +
              T +
              '%"></div>');
        }
        e.elemTemp.append(b);
      }
      if (t.input && !t.range) {
        var w = i(
          '<div class="layui-slider-input layui-input"><div class="layui-slider-input-txt"><input type="text" class="layui-input"></div><div class="layui-slider-input-btn"><i class="layui-icon layui-icon-up"></i><i class="layui-icon layui-icon-down"></i></div></div>'
        );
        h.css("position", "relative"),
          h.append(w),
          h
            .find("." + c)
            .children("input")
            .val(t.value),
          "vertical" === t.type
            ? w.css({ left: 0, top: -48 })
            : e.elemTemp.css("margin-right", w.outerWidth() + 15);
      }
      t.disabled
        ? (e.elemTemp.addClass(l), e.elemTemp.find("." + u).addClass(l))
        : e.slide(),
        e.elemTemp
          .find("." + u)
          .on("mouseover", function () {
            var a =
                "vertical" === t.type ? t.height : e.elemTemp[0].offsetWidth,
              n = e.elemTemp.find("." + o),
              l =
                "vertical" === t.type
                  ? a - i(this).parent()[0].offsetTop - n.height()
                  : i(this).parent()[0].offsetLeft,
              s = (l / a) * 100,
              r = i(this).parent().data("value"),
              u = t.setTips ? t.setTips(r) : r;
            e.elemTemp.find("." + d).html(u),
              "vertical" === t.type
                ? e.elemTemp
                    .find("." + d)
                    .css({
                      bottom: s + "%",
                      "margin-bottom": "20px",
                      display: "inline-block",
                    })
                : e.elemTemp
                    .find("." + d)
                    .css({ left: s + "%", display: "inline-block" });
          })
          .on("mouseout", function () {
            e.elemTemp.find("." + d).css("display", "none");
          });
    }),
    (f.prototype.slide = function (e, t, a) {
      var n = this,
        l = n.config,
        s = n.elemTemp,
        f = function () {
          return "vertical" === l.type ? l.height : s[0].offsetWidth;
        },
        h = s.find("." + o),
        y = s.next("." + v),
        g = y
          .children("." + c)
          .children("input")
          .val(),
        b = 100 / ((l.max - l.min) / Math.ceil(l.step)),
        x = function (e, i) {
          (e = Math.ceil(e) * b > 100 ? Math.ceil(e) * b : Math.round(e) * b),
            (e = e > 100 ? 100 : e),
            h.eq(i).css("vertical" === l.type ? "bottom" : "left", e + "%");
          var t = T(h[0].offsetLeft),
            a = l.range ? T(h[1].offsetLeft) : 0;
          "vertical" === l.type
            ? (s
                .find("." + d)
                .css({ bottom: e + "%", "margin-bottom": "20px" }),
              (t = T(f() - h[0].offsetTop - h.height())),
              (a = l.range ? T(f() - h[1].offsetTop - h.height()) : 0))
            : s.find("." + d).css("left", e + "%"),
            (t = t > 100 ? 100 : t),
            (a = a > 100 ? 100 : a);
          var n = Math.min(t, a),
            o = Math.abs(t - a);
          "vertical" === l.type
            ? s.find("." + r).css({ height: o + "%", bottom: n + "%" })
            : s.find("." + r).css({ width: o + "%", left: n + "%" });
          var u = l.min + Math.round(((l.max - l.min) * e) / 100);
          if (
            ((g = u),
            y
              .children("." + c)
              .children("input")
              .val(g),
            h.eq(i).data("value", u),
            (u = l.setTips ? l.setTips(u) : u),
            s.find("." + d).html(u),
            l.range)
          ) {
            var v = [h.eq(0).data("value"), h.eq(1).data("value")];
            v[0] > v[1] && v.reverse();
          }
          l.change && l.change(l.range ? v : u);
        },
        T = function (e) {
          var i = ((e / f()) * 100) / b,
            t = Math.round(i) * b;
          return e == f() && (t = Math.ceil(i) * b), t;
        },
        w = i(
          [
            '<div class="layui-auxiliar-moving" id="LAY-slider-moving"></div',
          ].join("")
        ),
        M = function (e, t) {
          var a = function () {
            t && t(), w.remove();
          };
          i("#LAY-slider-moving")[0] || i("body").append(w),
            w.on("mousemove", e),
            w.on("mouseup", a).on("mouseleave", a);
        };
      if ("set" === e) return x(t, a);
      s.find("." + u).each(function (e) {
        var t = i(this);
        t.on("mousedown", function (i) {
          i = i || window.event;
          var a = t.parent()[0].offsetLeft,
            n = i.clientX;
          "vertical" === l.type &&
            ((a = f() - t.parent()[0].offsetTop - h.height()), (n = i.clientY));
          var r = function (i) {
              i = i || window.event;
              var r =
                a + ("vertical" === l.type ? n - i.clientY : i.clientX - n);
              r < 0 && (r = 0), r > f() && (r = f());
              var o = ((r / f()) * 100) / b;
              x(o, e),
                t.addClass(p),
                s.find("." + d).show(),
                i.preventDefault();
            },
            o = function () {
              t.removeClass(p), s.find("." + d).hide();
            };
          M(r, o);
        });
      }),
        s.on("click", function (e) {
          var t = i("." + u);
          if (
            !t.is(event.target) &&
            0 === t.has(event.target).length &&
            t.length
          ) {
            var a,
              n =
                "vertical" === l.type
                  ? f() - e.clientY + i(this).offset().top
                  : e.clientX - i(this).offset().left;
            n < 0 && (n = 0), n > f() && (n = f());
            var s = ((n / f()) * 100) / b;
            (a = l.range
              ? "vertical" === l.type
                ? Math.abs(n - parseInt(i(h[0]).css("bottom"))) >
                  Math.abs(n - parseInt(i(h[1]).css("bottom")))
                  ? 1
                  : 0
                : Math.abs(n - h[0].offsetLeft) > Math.abs(n - h[1].offsetLeft)
                ? 1
                : 0
              : 0),
              x(s, a),
              e.preventDefault();
          }
        }),
        y.hover(
          function () {
            var e = i(this);
            e.children("." + m).fadeIn("fast");
          },
          function () {
            var e = i(this);
            e.children("." + m).fadeOut("fast");
          }
        ),
        y
          .children("." + m)
          .children("i")
          .each(function (e) {
            i(this).on("click", function () {
              g =
                1 == e
                  ? g - l.step < l.min
                    ? l.min
                    : Number(g) - l.step
                  : Number(g) + l.step > l.max
                  ? l.max
                  : Number(g) + l.step;
              var i = (((g - l.min) / (l.max - l.min)) * 100) / b;
              x(i, 0);
            });
          });
      var q = function () {
        var e = this.value;
        (e = isNaN(e) ? 0 : e),
          (e = e < l.min ? l.min : e),
          (e = e > l.max ? l.max : e),
          (this.value = e);
        var i = (((e - l.min) / (l.max - l.min)) * 100) / b;
        x(i, 0);
      };
      y.children("." + c)
        .children("input")
        .on("keydown", function (e) {
          13 === e.keyCode && (e.preventDefault(), q.call(this));
        })
        .on("change", q);
    }),
    (f.prototype.events = function () {
      var e = this;
      e.config;
    }),
    (t.render = function (e) {
      var i = new f(e);
      return a.call(i);
    }),
    e(n, t);
});