소스 검색

Added possibility to paste an image from the clipboard

thororm 9 년 전
부모
커밋
24aea957b3
4개의 변경된 파일23개의 추가작업 그리고 5개의 파일을 삭제
  1. 1 1
      i18n/de.json
  2. 18 0
      js/privatebin.js
  3. 2 2
      tpl/bootstrap.php
  4. 2 2
      tpl/page.php

+ 1 - 1
i18n/de.json

@@ -132,7 +132,7 @@
     "Cloned: '%s'": "Geklont: '%s'",
     "Cloned: '%s'": "Geklont: '%s'",
     "The cloned file '%s' was attached to this paste.": "Die geklonte Datei '%s' wurde angehängt.",
     "The cloned file '%s' was attached to this paste.": "Die geklonte Datei '%s' wurde angehängt.",
     "Attach a file": "Datei anhängen",
     "Attach a file": "Datei anhängen",
-    "or drag & drop file": "oder per Drag & Drop einfügen",
+    "alternatively drag & drop a file or paste an image from the clipboard": "Alternativ Drag & Drop einer Datei oder einfügen eines Bildes aus der Zwischenablage",
     "File too large, to display a preview. Please download the attachment.": "Datei zu groß, um als Vorschau angezeigt zu werden. Bitte Anhang herunterladen.",
     "File too large, to display a preview. Please download the attachment.": "Datei zu groß, um als Vorschau angezeigt zu werden. Bitte Anhang herunterladen.",
     "Remove attachment": "Anhang entfernen",
     "Remove attachment": "Anhang entfernen",
     "Your browser does not support uploading encrypted files. Please use a newer browser.":
     "Your browser does not support uploading encrypted files. Please use a newer browser.":

+ 18 - 0
js/privatebin.js

@@ -2298,6 +2298,23 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
             });
             });
         };
         };
 
 
+        /**
+         * Attaches the clipboard attachment handler to the page.
+         * @returns {undefined}
+         */
+        me.addClipboardEventHandler = function () {
+            document.addEventListener("paste",
+                    function (event) {
+                        var items = (event.clipboardData || event.originalEvent.clipboardData).items;
+                        for (var i in items) {
+                            var item = items[i];
+                            if (item.kind === 'file') {
+                                me.readFileData(item.getAsFile());
+                            }
+                        }
+                    }, false);
+        };
+
         /**
         /**
          * initiate
          * initiate
          *
          *
@@ -2315,6 +2332,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
 
 
                 me.$fileInput = $('#file');
                 me.$fileInput = $('#file');
                 me.addDragDropHandler();
                 me.addDragDropHandler();
+                me.addClipboardEventHandler();
             }
             }
         }
         }
 
 

+ 2 - 2
tpl/bootstrap.php

@@ -69,7 +69,7 @@ if ($MARKDOWN):
 <?php
 <?php
 endif;
 endif;
 ?>
 ?>
-		<script type="text/javascript" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-pOe2H/Z6no88ilmHnSzSPrN5jYaj4B0VrxeVKHZ728CwUxNKwI8xIAUH+B/UPnKXgT33IV2EHbBIXYJERQxinA==" crossorigin="anonymous"></script>
+		<script type="text/javascript" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-wrGlxXZ5UYLGd+2CJB2I4xXJXoG632WaqM+glL2g669ta/mDwPgDhB+mhoXGdD7PWLpZ9JIgcjovMou/wrPtRg==" crossorigin="anonymous"></script>
 		<!--[if lt IE 10]>
 		<!--[if lt IE 10]>
 		<style type="text/css">body {padding-left:60px;padding-right:60px;} #ienotice {display:block;} #oldienotice {display:block;}</style>
 		<style type="text/css">body {padding-left:60px;padding-right:60px;} #ienotice {display:block;} #oldienotice {display:block;}</style>
 		<![endif]-->
 		<![endif]-->
@@ -283,7 +283,7 @@ if ($FILEUPLOAD):
 								<div>
 								<div>
 									<input type="file" id="file" name="file"/>
 									<input type="file" id="file" name="file"/>
 								</div>
 								</div>
-								<div id="dragAndDropFileName" class="dragAndDropFile"><?php echo I18n::_('or drag & drop file'); ?></div>
+								<div id="dragAndDropFileName" class="dragAndDropFile"><?php echo I18n::_('alternatively drag & drop a file or paste an image from the clipboard'); ?></div>
 							</li>
 							</li>
 							<li id="customattachment" class="hidden"></li>
 							<li id="customattachment" class="hidden"></li>
 							<li>
 							<li>

+ 2 - 2
tpl/page.php

@@ -47,7 +47,7 @@ if ($MARKDOWN):
 <?php
 <?php
 endif;
 endif;
 ?>
 ?>
-		<script type="text/javascript" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-pOe2H/Z6no88ilmHnSzSPrN5jYaj4B0VrxeVKHZ728CwUxNKwI8xIAUH+B/UPnKXgT33IV2EHbBIXYJERQxinA==" crossorigin="anonymous"></script>
+		<script type="text/javascript" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-wrGlxXZ5UYLGd+2CJB2I4xXJXoG632WaqM+glL2g669ta/mDwPgDhB+mhoXGdD7PWLpZ9JIgcjovMou/wrPtRg==" crossorigin="anonymous"></script>
 		<!--[if lt IE 10]>
 		<!--[if lt IE 10]>
 		<style type="text/css">body {padding-left:60px;padding-right:60px;} #ienotice {display:block;} #oldienotice {display:block;}</style>
 		<style type="text/css">body {padding-left:60px;padding-right:60px;} #ienotice {display:block;} #oldienotice {display:block;}</style>
 		<![endif]-->
 		<![endif]-->
@@ -203,7 +203,7 @@ if ($FILEUPLOAD):
 				<div id="attach" class="hidden">
 				<div id="attach" class="hidden">
 					<span id="clonedfile" class="hidden"><?php echo I18n::_('Cloned file attached.'); ?></span>
 					<span id="clonedfile" class="hidden"><?php echo I18n::_('Cloned file attached.'); ?></span>
 					<span id="filewrap"><?php echo I18n::_('Attach a file'); ?>: <input type="file" id="file" name="file" /></span>
 					<span id="filewrap"><?php echo I18n::_('Attach a file'); ?>: <input type="file" id="file" name="file" /></span>
-					<span id="dragAndDropFileName" class="dragAndDropFile"><?php echo I18n::_('or drag & drop file'); ?></span>
+					<span id="dragAndDropFileName" class="dragAndDropFile"><?php echo I18n::_('alternatively drag & drop a file or paste an image from the clipboard'); ?></span>
 					<button id="fileremovebutton"><?php echo I18n::_('Remove attachment'); ?></button>
 					<button id="fileremovebutton"><?php echo I18n::_('Remove attachment'); ?></button>
 				</div>
 				</div>
 <?php
 <?php