{"version":3,"sources":["webpack:///./app/javascript/public/multi_images.js"],"names":["$","document","ready","click","nextFileFieldIndex","length","trigger","change","extName","allowedExtension","sizeExceeded","extError","each","this","files","i","file","size","name","split","pop","inArray","window","alert","val","fileReader","FileReader","num","readAsDataURL","css","onloadend","src","result","html","before","attr","on","target_image","parent","target_name","data","targetFileFieldIndex","index","$targetFileField","hasClass","newValue","remove","show","console","log","isGameCoach"],"mappings":"gFAAAA,cAAGC,UAAWC,OAAM,WAClBF,EAAE,oBAAoBG,OAAM,WAC1B,IAAIC,EAAqBJ,EAAE,eAAeK,OACrBL,EAAE,gCAAkCI,EAAqB,UAC/DE,QAAQ,QACzB,IAGAN,EAAE,aAAaO,QAAO,WACpB,IAIIC,EAFAC,EAAmB,CAAC,MAAO,OAAQ,MAAO,OAI1CC,GAAe,EACfC,GAAW,EAOf,GALAX,EAAEY,KAAKC,KAAKC,OAAO,SAASC,EAAGC,GACzBA,EAAKC,MAAuBD,EAAKC,KAAK,KAAK,KAL/B,KAKoDP,GAAa,GACjFF,EAAUQ,EAAKE,KAAKC,MAAM,KAAKC,OACc,GAAzCpB,EAAEqB,QAAQb,EAASC,KAA0BE,GAAS,EAC5D,IACID,EAGF,OAFAY,OAAOC,MAfgB,+HAgBvBvB,EAAEgB,MAAMQ,IAAI,IAIdxB,EAAEY,KAAKC,KAAKC,OAAO,SAASC,EAAGC,GAE7B,IAAIS,EAAa,IAAIC,WACjBC,EAAM3B,EAAE,eAAeK,OAAS,EAAIU,EACxCU,EAAWG,cAAcZ,GAGd,GAAPW,GAAW3B,EAAE,yBAAyB6B,IAAI,UAAW,QAGzDJ,EAAWK,UAAY,WACrB,IAAIC,EAAMN,EAAWO,OACjBC,EAAM,uCAAuCjB,EAAKE,6JAE8Ba,+QAQpF/B,EAAE,yBAAyBkC,OAAOD,EACpC,EAEAjC,EAAE,yBAAyBmC,KAAK,QAAS,YAAYR,IACvD,IACIhB,GACFW,OAAOC,MA/Ca,2PAiDxB,IAGAvB,EAAE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PvB,GAAW3B,EAAE,gCAAgC6B,IAAI,UAAW,QAGrD,GAAPF,GAAW3B,EAAE,gCAAgC6B,IAAI,UAAW,QAIlEJ,EAAWK,UAAY,WACrB,IAAIC,EAAMN,EAAWO,OACjBC,EAAM,8CAA8CjB,EAAKE,0KAE8Ba,6RAQ3F/B,EAAE,gCAAgCkC,OAAOD,EAC3C,EAEAjC,EAAE,gCAAgCmC,KAAK,QAAS,mBAAmBR,IACrE,IACIhB,GACFW,OAAOC,MApDa,2PAsDxB,IAGAvB,EAAEC,UAAUmC,GAAG,QAAS,kCAAkC,WAExD,IAAIC,EAAerC,EAAEa,MAAMyB,SAASA,SAChCC,EAAcvC,EAAEqC,GAAcG,KAAK,SACnCC,EAAuBzC,EAAE,sBAAsB0C,MAAOL,GACtDM,EAAmB3C,EAAE,0CAA4CyC,EAAuB,UAG5F,GAAGJ,EAAaO,SAAS,kBAAkB,CACzC,IACIC,EADW7C,EAAE,+BAA+BwB,MACtB,IAAMe,EAChCvC,EAAE,+BAA+BwB,IAAIqB,EACvC,CAGIR,EAAaO,SAAS,0BACxBD,EAAiBnB,IAAI,MAIvBa,EAAaS,SAEb,IAAInB,EAAM3B,EAAE,sBAAsBK,OAClCL,EAAE,gCAAgC+C,OAClC/C,EAAE,gCAAgCmC,KAAK,QAAS,mBAAmBR,IACrE,GACF,G","file":"js/117-65485218eb2dae59a73c.chunk.js","sourcesContent":["$( document ).ready(function(){\n $(\".upload-more-btn\").click(function(){\n var nextFileFieldIndex = $(\".item-image\").length\n var $nextFileField = $(\"#user_user_images_attributes_\" + nextFileFieldIndex + \"_image\")\n $nextFileField.trigger('click');\n });\n\n //fileが選択された時に発火するイベント\n $('.img-file').change(function(){\n var maxExceededMessage = \"10MB以下の画像をアップロードしてください。\";\n var extErrorMessage = \"推奨されている画像形式はjpg, jpeg, pngです。それ以外の場合、正しく保存されないことがあります\";\n var allowedExtension = [\"jpg\", \"jpeg\", \"gif\", \"png\"];\n\n var extName;\n var maxFileSize = 10;\n var sizeExceeded = false;\n var extError = false;\n\n $.each(this.files, function(i, file){\n if (file.size && maxFileSize && file.size/1024/1024 > maxFileSize) {sizeExceeded=true;};\n extName = file.name.split('.').pop();\n if ($.inArray(extName, allowedExtension) == -1) {extError=true;};\n });\n if (sizeExceeded) {\n window.alert(maxExceededMessage);\n $(file).val('');\n return\n }; \n\n $.each(this.files, function(i, file){\n //FileReaderのreadAsDataURLで指定したFileオブジェクトを読み込む\n var fileReader = new FileReader();\n var num = $('.item-image').length + 1 + i\n fileReader.readAsDataURL(file);\n\n    //画像が10枚になったら超えたらドロップボックスを削除する\n if (num == 5){ $('#image-box__container').css('display', 'none') }\n\n //読み込みが完了すると、srcにfileのURLを格納\n fileReader.onloadend = function() {\n var src = fileReader.result\n var html= `
\n
\n
\n
\n
\n
\n
\n
\n
`\n //image_box__container要素の前にhtmlを差し込む\n $('#image-box__container').before(html);\n };\n //image-box__containerのクラスを変更し、CSSでドロップボックスの大きさを変えてやる。\n $('#image-box__container').attr('class', `item-num-${num}`)\n });\n if (extError) {\n window.alert(extErrorMessage);\n };\n });\n\n //削除ボタンをクリックすると発火するイベント\n $(document).on(\"click\", '.item-image__delete-btn', function(){\n\n var target_image = $(this).parent().parent()\n var target_name = $(target_image).data('image')\n var targetFileFieldIndex = $(\".item-image\").index( target_image )\n var $targetFileField = $(\"#user_user_images_attributes_\" + targetFileFieldIndex + \"_image\")\n\n // DB保存済み画像の場合、削除したいファイル名の一覧を送信して、コントラーラー側で画像を削除\n if(target_image.hasClass(\"existing-image\")){\n var oldValue = $(\"#deleted-image-names\").val()\n var newValue = oldValue + \" \" + target_name\n $(\"#deleted-image-names\").val(newValue)\n }\n\n // DB未保存画像の場合、file inputから削除\n if(!target_image.hasClass(\"existing-image\")){\n $targetFileField.val(null)\n }\n\n //プレビューを削除\n target_image.remove()\n //image-box__containerクラスをもつdivタグのクラスを削除のたびに変更\n var num = $('.item-image').length\n $('#image-box__container').show()\n $('#image-box__container').attr('class', `item-num-${num}`)\n })\n\n\n // 出品画像用の記述\n $(\".sample-upload-more-btn\").click(function(){\n console.log(\"ddafda\")\n var nextFileFieldIndex = $(\".sample-item-image\").length\n var $nextFileField = $(\"#user_session_sample_images_attributes_\" + nextFileFieldIndex + \"_image\")\n $nextFileField.trigger('click');\n });\n\n //fileが選択された時に発火するイベント\n $('.sample-img-file').change(function(){\n var maxExceededMessage = \"10MB以下の画像をアップロードしてください。\";\n var extErrorMessage = \"推奨されている画像形式はjpg, jpeg, pngです。それ以外の場合、正しく保存されないことがあります\";\n var allowedExtension = [\"jpg\", \"jpeg\", \"gif\", \"png\"];\n\n var extName;\n var maxFileSize = 10;\n var sizeExceeded = false;\n var extError = false;\n var isGameCoach = $(this).hasClass(\"sample-img-file--game-coach\")\n\n $.each(this.files, function(i, file){\n if (file.size && maxFileSize && file.size/1024/1024 > maxFileSize) {sizeExceeded=true;};\n extName = file.name.split('.').pop();\n if ($.inArray(extName, allowedExtension) == -1) {extError=true;};\n });\n if (sizeExceeded) {\n window.alert(maxExceededMessage);\n $(file).val('');\n return\n }; \n\n $.each(this.files, function(i, file){\n //FileReaderのreadAsDataURLで指定したFileオブジェクトを読み込む\n var fileReader = new FileReader();\n var num = $('.sample-item-image').length + 1 + i\n fileReader.readAsDataURL(file);\n\n if(isGameCoach){\n if (num == 9){ $('#sample-image-box__container').css('display', 'none') }\n }else{\n //画像が10枚になったら超えたらドロップボックスを削除する\n if (num == 6){ $('#sample-image-box__container').css('display', 'none') }\n }\n\n //読み込みが完了すると、srcにfileのURLを格納\n fileReader.onloadend = function() {\n var src = fileReader.result\n var html= `
\n
\n
\n
\n
\n
\n
\n
\n
`\n //image_box__container要素の前にhtmlを差し込む\n $('#sample-image-box__container').before(html);\n };\n //image-box__containerのクラスを変更し、CSSでドロップボックスの大きさを変えてやる。\n $('#sample-image-box__container').attr('class', `sample-item-num-${num}`)\n });\n if (extError) {\n window.alert(extErrorMessage);\n };\n });\n\n //削除ボタンをクリックすると発火するイベント\n $(document).on(\"click\", '.sample-item-image__delete-btn', function(){\n\n var target_image = $(this).parent().parent()\n var target_name = $(target_image).data('image')\n var targetFileFieldIndex = $(\".sample-item-image\").index( target_image )\n var $targetFileField = $(\"#user_session_sample_images_attributes_\" + targetFileFieldIndex + \"_image\")\n\n // DB保存済み画像の場合、削除したいファイル名の一覧を送信して、コントラーラー側で画像を削除\n if(target_image.hasClass(\"existing-image\")){\n var oldValue = $(\"#sample-deleted-image-names\").val()\n var newValue = oldValue + \" \" + target_name\n $(\"#sample-deleted-image-names\").val(newValue)\n }\n\n // DB未保存画像の場合、file inputから削除\n if(!target_image.hasClass(\"sample-existing-image\")){\n $targetFileField.val(null)\n }\n\n //プレビューを削除\n target_image.remove()\n //image-box__containerクラスをもつdivタグのクラスを削除のたびに変更\n var num = $('.sample-item-image').length\n $('#sample-image-box__container').show()\n $('#sample-image-box__container').attr('class', `sample-item-num-${num}`)\n })\n});\n"],"sourceRoot":""}