1
0
mirror of https://github.com/e107inc/e107.git synced 2025-04-14 01:22:13 +02:00

Issue #87 - Media-Manager insert should now work correctly. (text selection/replacement does not at the moment)

This commit is contained in:
Cameron 2013-04-20 18:09:33 -07:00
parent cff013c5e5
commit e6c7cc420f
3 changed files with 18 additions and 14 deletions

View File

@ -65,6 +65,7 @@ function loadJSAddons()
e107::js('core', 'jquery.elastic.js', 'jquery', 2);
e107::js('core', 'jquery.at.caret.min.js', 'jquery', 2);
// e107::js('core', 'jquery-ui-timepicker-addon.js', 'jquery', 2);

View File

@ -2,24 +2,21 @@ $(document).ready(function()
{
$(".e-dialog-save").live("click", function(){// FIXME TODO missing caret , text selection overwrite etc.
var newval = $('#bbcode_holder').val();
// alert(newval);
var target = $(this).attr('data-target');
if(!target){ return true; }
$('#' + target, window.top.document).atCaret('insert', newval); // http://code.google.com/p/jquery-at-caret/wiki/GettingStarted
//var cursorIndex = $('#' + target, window.top.document).attr("selectionStart");
//var lStr = $('#' + target, window.top.document).attr('value').substr(0,cursorIndex) + " " + newval + " ";
//var rStr = $('#' + target, window.top.document).attr('value').substr(cursorIndex);
//alert('hello');
if(!target){return true; }
//console.log($('#' + target, window.top.document).attr('value'));
var cursorIndex = $('#' + target, window.top.document).attr("selectionStart");
var lStr = $('#' + target, window.top.document).attr('value').substr(0,cursorIndex) + " " + newval + " ";
var rStr = $('#' + target, window.top.document).attr('value').substr(cursorIndex);
$('#' + target, window.top.document).attr('value',lStr+rStr);
$('#' + target, window.top.document).attr("selectionStart",lStr.length);
//$('#' + target, window.top.document).attr('value',lStr+rStr);
//$('#' + target, window.top.document).attr("selectionStart",lStr.length);
//('#' + target, window.top.document).insertAtCaret(newVal);
@ -41,6 +38,9 @@ $(document).ready(function()
eMediaAttribute();
});
function eMediaAttribute(e)
{
var style = '';

3
e107_web/js/jquery.at.caret.min.js vendored Normal file
View File

@ -0,0 +1,3 @@
(function(){var $,methods;$=jQuery;methods={insert:function(value){var after,before,o,pos;o=this[0];pos=methods['getCaretPosition'].apply(this);before=o.value.substring(0,pos);after=o.value.substring(pos,o.value.length);$(o).val(before+value+after);pos+=value.length;return methods['setCaretPosition'].apply(this,[pos]);},backspace:function(){var after,before,o,pos;o=this[0];pos=methods['getCaretPosition'].apply(this);before=o.value.substring(0,pos-1);after=o.value.substring(pos,o.value.length);$(o).val(before+after);pos-=1;return methods['setCaretPosition'].apply(this,[pos]);},"delete":function(){var after,before,o,pos;o=this[0];pos=methods['getCaretPosition'].apply(this);before=o.value.substring(0,pos);after=o.value.substring(pos+1,o.value.length);$(o).val(before+after);return methods['setCaretPosition'].apply(this,[pos]);},getCaretPosition:function(){var caretPos,o,sel;o=this[0];caretPos=0;if(document.selection){o.focus();sel=document.selection.createRange();sel.moveStart('character',-o.value.length);caretPos=sel.text.length;}else if(o.selectionStart||o.selectionStart==='0'){caretPos=o.selectionStart;}
return caretPos;},setCaretPosition:function(pos){var f,o;o=this[0];if(o.setSelectionRange){o.focus();return o.setSelectionRange(pos,pos);}else if(o.createTextRange){f=function(){return o.focus();};setTimeout(f,10);f=function(o,pos){var range;range=o.createTextRange();range.collapse(true);range.moveEnd('character',pos);range.moveStart('character',pos);return range.select();};setTimeout("f(o, pos)",20);return pos;}}};$.fn.atCaret=function(method){if(methods[method]){return methods[method].apply(this,Array.prototype.slice.call(arguments,1));}else if(typeof method==='object'||!method){return methods.init.apply(this,arguments);}else{return $.error('Method '+method+' does not exist on jQuery.atCaret');}};}).call(this);