Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * jQuery insertAtCaret
- * Allows inserting text where the caret is in a textarea
- * Copyright (c) 2003-2010 phpMyAdmin devel team
- * Version: 1.0
- * Developed by the phpMyAdmin devel team. Modified by Alex King and variaas
- * http://alexking.org/blog/2003/06/02/inserting-at-the-cursor-using-javascript
- * http://www.mail-archive.com/jquery-en@googlegroups.com/msg08708.html
- * Licensed under the GPL license:
- * http://www.gnu.org/licenses/gpl.html
- */
- (function(a){a.fn.insertAtCaret=function(b){return this.each(function(){if(document.selection){this.focus();sel=document.selection.createRange();sel.text=b;this.focus();}else{if(this.selectionStart||this.selectionStart=="0"){var d=this.selectionStart;var c=this.selectionEnd;var e=this.scrollTop;this.value=this.value.substring(0,d)+b+this.value.substring(c,this.value.length);this.focus();this.selectionStart=d+b.length;this.selectionEnd=d+b.length;this.scrollTop=e;}else{this.value+=b;this.focus();}}});};})(jQuery);
- /* ------------------ */
- http://valums.com/ajax-upload/
- /* ------------------ */
- // dodawanie, _UPLOAD_ACTION i _UPLOAD_DIR, żeby działało przy url rewrite gdy przeniosę z dev na produkcję
- // skrypt zwraca JSONem listę plików przez json_encode(array('files' => array('nazwapliku', 'nazwapliku', 'nazwapliku'))), żeby dało się dodać w razie czego multiupload plików i tylko zmodyfikować JS ;)
- $("textarea.addUpload").each(function()
- {
- var e = $(this);
- e.before("<div class='upload_button' id='upload_" + e.attr('name') + "'>Dodaj zdjęcie</div>");
- new AjaxUpload('upload_' + e.attr('name'),
- {
- action: _UPLOAD_ACTION,
- name: 'filename',
- responseType: 'json',
- onComplete: function(file, response)
- {
- if(typeof response.error != "undefined")
- {
- alert("Wystąpił błąd podczas dodawania pliku.");
- }
- else
- {
- var textarea = $("textarea[name='" + this._button.id.replace(/^upload_/,'') + "']");
- for(i=0, l=response.files.length; i < l; i++)
- {
- textarea.insertAtCaret('<img src="' + _UPLOAD_DIR + "/" + response.files[i] + '">');
- }
- }
- }
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement