Sweetalert: μž…λ ₯κ³Ό κ²°ν•©λœ λ§Žμ€ λ²„νŠΌμ€ λ²„νŠΌμ˜ κ°’λ§Œ λ°˜ν™˜ν•©λ‹ˆλ‹€.

에 λ§Œλ“  2017λ…„ 10μ›” 31일  Β·  6μ½”λ©˜νŠΈ  Β·  좜처: t4t5/sweetalert

λ¬Έμ„œμ—μ„œ λˆ„λ½λœ 것이 μ—†λŠ” ν•œ μž…λ ₯ ν•„λ“œμ™€ κ²°ν•©λœ λ‹€λ₯Έ 값을 가진 μ—¬λŸ¬ λ²„νŠΌμ΄ μžˆλŠ” swal을 λ§Œλ“€λ©΄ μž…λ ₯ 값이 κΈ°λ³Έ swal μ½”λ“œλ₯Ό μ‚¬μš©ν•˜μ—¬ λ°˜ν™˜λ˜μ§€ μ•ŠλŠ”λ‹€λŠ” 것이 어리석은 μΌμž…λ‹ˆλ‹€. 이것은 μ‹€μ œλ‘œ SweetAlertκ°€ μ œκ³΅ν•΄μ•Ό ν•˜λŠ” 잠재적 κ°€λŠ₯성을 μ—†μ• μ€λ‹ˆλ‹€.

κ°€μž₯ μœ μš©ν•œ λŒ“κΈ€

@t4t5 λͺ¨λ“  λ²„νŠΌμ€ μž…λ ₯ κ°’κ³Ό λ²„νŠΌ 값을 λ°˜ν™˜ν•΄μ•Ό ν•©λ‹ˆλ‹€. 특히 λ‚΄ μ‚¬μš© μ‚¬λ‘€μ˜ 경우 μ›Ή 기반 μ„œλ²„ 관리 도ꡬ에 SweetAlertλ₯Ό μ‚¬μš©ν•˜κ³  있으며 보닀 κ΅¬μ²΄μ μœΌλ‘œλŠ” μ‚¬μš©μžκ°€ "κΈˆμ§€" λ²„νŠΌμ„ 클릭할 λ•Œ κ΄€λ¦¬μžμ—κ²Œ ν”„λ‘¬ν”„νŠΈλ₯Ό ν‘œμ‹œν•©λ‹ˆλ‹€. 그런 λ‹€μŒ κ²½κ³ μ—λŠ” μ‹œκ°„ 길이λ₯Ό λ‚˜νƒ€λ‚΄κΈ° μœ„ν•΄ ("1d", "1w" λ˜λŠ” "forever") 값을 λ°˜ν™˜ν•΄μ•Ό ν•˜λŠ” μ„Έ 개의 λ²„νŠΌμ΄ μžˆμŠ΅λ‹ˆλ‹€. λ˜ν•œ μ‚¬μš©μžκ°€ κΈˆμ§€λœ μ΄μœ μ— λŒ€ν•œ 이유λ₯Ό μ œκ³΅ν•˜κΈ° μœ„ν•΄ μž…λ ₯ ν…μŠ€νŠΈ ν•„λ“œκ°€ ν•„μš”ν•©λ‹ˆλ‹€. 이 λ²„νŠΌ 쀑 ν•˜λ‚˜λ₯Ό ν΄λ¦­ν•˜λ©΄ λ‚΄ 콜백이 ν΄λ¦­ν•œ λ²„νŠΌμ˜ κ°’κ³Ό μž…λ ₯ 값을 쌍으둜 λ§Œλ“€μ–΄ λ‚΄ μ„œλ²„μ— API 쿼리λ₯Ό μƒμ„±ν•˜μ—¬ 차단 μ΄μœ μ™€ 차단 기간을 μ„€μ •ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

이 μ‚¬μš© 사둀가 두 값을 λͺ¨λ‘ λ°˜ν™˜ν•˜λŠ” κ²ƒμ˜ μ€‘μš”μ„±μ„ λͺ…ν™•νžˆ ν•˜κΈ°λ₯Ό λ°”λžλ‹ˆλ‹€. 이λ₯Ό 톡해 κ°œλ°œμžλŠ” 1단계 ν”„λ‘œμ„ΈμŠ€μ—¬μ•Ό ν•˜λŠ” μž‘μ—…μ„ μˆ˜ν–‰ν•˜κΈ° μœ„ν•΄ 사물을 ν•΄ν‚Ήν•˜κ±°λ‚˜ 두 개의 κ²½κ³ λ₯Ό 생성할 ν•„μš”κ°€ μ—†μŠ΅λ‹ˆλ‹€.

example

        banPlayer: function (data) {
            var swalField = document.createElement('input');
            swalField.setAttribute("placeholder", "Reason for ban");
            swal({
                title: 'Banning: ' + data.name,
                buttons: {
                    cancel: "Go back!",
                    day: {
                      text: "24hr",
                      visible: true,
                      closeModal: true
                    },
                    week: {
                      text: "1w",
                      visible: true,
                      closeModal: true
                    },
                    perm: {
                      text: "Forever",
                      visible: true,
                      closeModal: true
                    }
                  },
                  content: swalField,
                dangerMode: true
            }).then( value => {
                let reason = swalField.value;
                // build API query request and submit it
            });

μœ„μ˜ μŠ€λ‹ˆνŽ«μ€ μ½˜ν…μΈ μ™€ λ²„νŠΌ 값을 κ°€μ Έμ˜€λŠ” "ν•΄ν‚€" λ°©μ‹μž…λ‹ˆλ‹€. κ·ΈλŸ¬λ‚˜ 이 μŠ€λ ˆλ“œμ˜ μ•žλΆ€λΆ„μ—μ„œ ν‘œν˜„ν•œ κ²ƒμ²˜λŸΌ 두 값을 λͺ¨λ‘ λ°˜ν™˜ν•˜λ„λ‘ ν•˜λŠ” 것이 훨씬 μ’‹μŠ΅λ‹ˆλ‹€.

λͺ¨λ“  6 λŒ“κΈ€

확인 λ²„νŠΌκ³Ό λ‹€λ₯Έ λ²„νŠΌμ΄ λͺ¨λ‘ μž…λ ₯ 값을 λ°˜ν™˜ν•˜κΈ°λ₯Ό μ›ν•˜μ‹­λ‹ˆκΉŒ? μ‚¬μš© 사둀가 μ •ν™•νžˆ 무엇인지 μžμ„Ένžˆ μ„€λͺ…ν•΄ μ£Όμ‹œκ² μŠ΅λ‹ˆκΉŒ? :)

@t4t5 μ•„λ§ˆλ„ 이 FIXME 와 κ΄€λ ¨ .

swal({
    buttons: {
        cancel: "Go back!",
        one: {
          text: "Button One",
          value: 1
        },
        two: {
          text: "Button Two",
          value: 2
        },
        three: {
          text: "Button Three",
          value: 3
        }
      },
      content: {
        element: "input",
        attributes: {
          placeholder: "What's your favorite food?",
          type: "text",
        },
      }
/*
 * Only returns one value, because input is overridden by buttons
 * so you never get the input's value and the button's value
 * just the button's value.
 */
}).then( value => {
    switch (value) {                  
        case 1:
            swal("You pressed one!")
            break;
        case 2:
            swal("You pressed two!")
            break;
        case 3:
            swal("You pressed three!")
            break;
        default:
            swal("Phew, got outta there.");
    }
});

λ²„νŠΌ 값을 μ‚¬μš©ν•  수 μžˆλŠ” κΈ°λŠ₯κ³Ό μž…λ ₯ 값이 무엇이든 간에 쀑첩 κ²½κ³  λŒ€μ‹  논리λ₯Ό μˆ˜ν–‰ν•˜κ³  λ²„νŠΌμ— μ˜ν•΄ μž¬μ •μ˜λ˜κΈ° λ•Œλ¬Έμ— μ“Έλͺ¨μ—†λŠ” μž…λ ₯이 있으면 맀우 μœ μš©ν•©λ‹ˆλ‹€.

button κ°’κ³Ό content 값을 λͺ¨λ‘ ν¬ν•¨ν•˜λ €λ©΄ +1

λ²„νŠΌμ˜ ν‚€ 쀑 ν•˜λ‚˜λ₯Ό "확인"으둜 μ„€μ •ν•˜λ©΄ μž…λ ₯ 값이 λ°˜ν™˜λ©λ‹ˆλ‹€. 예:

swal({
  buttons: {
    cancel: "Go back!",
    one: {
      text: "Button One",
      value: 1
    },
    two: {
      text: "Button Two",
      value: 2
    },
    confirm: {
      text: "Button Three",
    }
  },
  content: {
    element: "input",
    attributes: {
      placeholder: "What's your favorite food?",
      type: "text",
    },
  }
})

μ‚¬μš© 사둀에 μΆ©λΆ„ν•©λ‹ˆκΉŒ, μ•„λ‹ˆλ©΄ λͺ¨λ“  λ²„νŠΌμ΄ μž…λ ₯ κ°’κ³Ό λ²„νŠΌ 값을 λͺ¨λ‘ λ°˜ν™˜ν•΄μ•Ό ν•œλ‹€λŠ” μ˜λ―Έμž…λ‹ˆκΉŒ?

@t4t5 λͺ¨λ“  λ²„νŠΌμ€ μž…λ ₯ κ°’κ³Ό λ²„νŠΌ 값을 λ°˜ν™˜ν•΄μ•Ό ν•©λ‹ˆλ‹€. 특히 λ‚΄ μ‚¬μš© μ‚¬λ‘€μ˜ 경우 μ›Ή 기반 μ„œλ²„ 관리 도ꡬ에 SweetAlertλ₯Ό μ‚¬μš©ν•˜κ³  있으며 보닀 κ΅¬μ²΄μ μœΌλ‘œλŠ” μ‚¬μš©μžκ°€ "κΈˆμ§€" λ²„νŠΌμ„ 클릭할 λ•Œ κ΄€λ¦¬μžμ—κ²Œ ν”„λ‘¬ν”„νŠΈλ₯Ό ν‘œμ‹œν•©λ‹ˆλ‹€. 그런 λ‹€μŒ κ²½κ³ μ—λŠ” μ‹œκ°„ 길이λ₯Ό λ‚˜νƒ€λ‚΄κΈ° μœ„ν•΄ ("1d", "1w" λ˜λŠ” "forever") 값을 λ°˜ν™˜ν•΄μ•Ό ν•˜λŠ” μ„Έ 개의 λ²„νŠΌμ΄ μžˆμŠ΅λ‹ˆλ‹€. λ˜ν•œ μ‚¬μš©μžκ°€ κΈˆμ§€λœ μ΄μœ μ— λŒ€ν•œ 이유λ₯Ό μ œκ³΅ν•˜κΈ° μœ„ν•΄ μž…λ ₯ ν…μŠ€νŠΈ ν•„λ“œκ°€ ν•„μš”ν•©λ‹ˆλ‹€. 이 λ²„νŠΌ 쀑 ν•˜λ‚˜λ₯Ό ν΄λ¦­ν•˜λ©΄ λ‚΄ 콜백이 ν΄λ¦­ν•œ λ²„νŠΌμ˜ κ°’κ³Ό μž…λ ₯ 값을 쌍으둜 λ§Œλ“€μ–΄ λ‚΄ μ„œλ²„μ— API 쿼리λ₯Ό μƒμ„±ν•˜μ—¬ 차단 μ΄μœ μ™€ 차단 기간을 μ„€μ •ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

이 μ‚¬μš© 사둀가 두 값을 λͺ¨λ‘ λ°˜ν™˜ν•˜λŠ” κ²ƒμ˜ μ€‘μš”μ„±μ„ λͺ…ν™•νžˆ ν•˜κΈ°λ₯Ό λ°”λžλ‹ˆλ‹€. 이λ₯Ό 톡해 κ°œλ°œμžλŠ” 1단계 ν”„λ‘œμ„ΈμŠ€μ—¬μ•Ό ν•˜λŠ” μž‘μ—…μ„ μˆ˜ν–‰ν•˜κΈ° μœ„ν•΄ 사물을 ν•΄ν‚Ήν•˜κ±°λ‚˜ 두 개의 κ²½κ³ λ₯Ό 생성할 ν•„μš”κ°€ μ—†μŠ΅λ‹ˆλ‹€.

example

        banPlayer: function (data) {
            var swalField = document.createElement('input');
            swalField.setAttribute("placeholder", "Reason for ban");
            swal({
                title: 'Banning: ' + data.name,
                buttons: {
                    cancel: "Go back!",
                    day: {
                      text: "24hr",
                      visible: true,
                      closeModal: true
                    },
                    week: {
                      text: "1w",
                      visible: true,
                      closeModal: true
                    },
                    perm: {
                      text: "Forever",
                      visible: true,
                      closeModal: true
                    }
                  },
                  content: swalField,
                dangerMode: true
            }).then( value => {
                let reason = swalField.value;
                // build API query request and submit it
            });

μœ„μ˜ μŠ€λ‹ˆνŽ«μ€ μ½˜ν…μΈ μ™€ λ²„νŠΌ 값을 κ°€μ Έμ˜€λŠ” "ν•΄ν‚€" λ°©μ‹μž…λ‹ˆλ‹€. κ·ΈλŸ¬λ‚˜ 이 μŠ€λ ˆλ“œμ˜ μ•žλΆ€λΆ„μ—μ„œ ν‘œν˜„ν•œ κ²ƒμ²˜λŸΌ 두 값을 λͺ¨λ‘ λ°˜ν™˜ν•˜λ„λ‘ ν•˜λŠ” 것이 훨씬 μ’‹μŠ΅λ‹ˆλ‹€.

또 λ‹€λ₯Έ μ˜ˆλŠ” μž…λ ₯ ν•„λ“œμ™€ 두 개의 λ²„νŠΌμΈ 확인 + μ·¨μ†Œκ°€ μžˆλŠ” λͺ¨λ‹¬( closeOnEsc: false, closeOnClickOutside: false )μž…λ‹ˆλ‹€. μ§€κΈˆμ€ @JayHerlth μ†”λ£¨μ…˜μ„ μ‚¬μš©

이 νŽ˜μ΄μ§€κ°€ 도움이 λ˜μ—ˆλ‚˜μš”?
0 / 5 - 0 λ“±κΈ‰

κ΄€λ ¨ 문제

vmitchell85 picture vmitchell85  Β·  6μ½”λ©˜νŠΈ

daftspunk picture daftspunk  Β·  4μ½”λ©˜νŠΈ

jamieson99 picture jamieson99  Β·  3μ½”λ©˜νŠΈ

adiwithadidas picture adiwithadidas  Β·  4μ½”λ©˜νŠΈ

rafatux picture rafatux  Β·  5μ½”λ©˜νŠΈ