The insert in the text does not work in Opera.

Comments

hutch’s picture

That's right, it did work in earlier versions of Opera, very annoying ;-(

Tarsjusz’s picture

is any solution known already? or coming...

hutch’s picture

This is AFAIK beyond the control of imagepicker, unless anyone knows of a javascript fix/hack for Opera

arkhnchul’s picture

Status: Active » Patch (to be ported)

in imagepicker.module, function isertAtCursor (line 976) insert code for opera before final else:

if (window.selection){
	sel=window.selection.createRange();
	sel.text=myValue;
}
hutch’s picture

Doesn't work for me ;-(

I stuck some alerts in to see which method Opera is using, it's using document.selection mode
I put window.selection at the top so it was tested first, no joy.

Now, I have just tried moving the netscape method to the top, bingo!

  function insertAtCursor(myField, myValue) {
    //Mozilla/Firefox/Netscape 7+ support
    if (myField.selectionStart || myField.selectionStart == '0') {
      var startPos = myField.selectionStart;
      var endPos = myField.selectionEnd;
      myField.value = myField.value.substring(0, startPos)+ myValue + myField.value.substring(endPos, myField.value.length);
    }
    //IE support
    else if (document.selection) {
      myField.focus();
      sel = document.selection.createRange();
      sel.text = myValue;
    }
    else {
      myField.value += myValue;
    }
  }

Can anyone replace function insertAtCursor at line 976 in imagepicker.module and test in Opera as well as IE.
I don't have easy access to IE and it needs to be supported.

arkhnchul’s picture

Status: Patch (to be ported) » Reviewed & tested by the community

opera 10.00, 10.01, 10.10 (linux buids)
IE7
it works.

hutch’s picture

Good news, so far. I would still like a confirmation for IE8
I am also thinking that the insertAtCursor function is asking the wrong question, surely it should be detecting the browser and deciding which method to use on that basis.
more later.....

hutch’s picture

Here is another version of insertAtCursor()
it uses Jquery browser detection function

  function insertAtCursor(myField, myValue) {
    browser = imagepicker_browser_detect();
    if (browser == 'msie') {
      if (document.selection) {
        myField.focus();
        sel = document.selection.createRange();
        sel.text = myValue;
      }
    }
    else if (browser == 'opera' || browser == 'mozilla' || browser == 'safari' ) {
      if (myField.selectionStart || myField.selectionStart == '0') {
        var startPos = myField.selectionStart;
        var endPos = myField.selectionEnd;
        myField.value = myField.value.substring(0, startPos)+ myValue + myField.value.substring(endPos, myField.value.length);
      }
    }
    else {
      myField.value += myValue;
    }
  }

  function imagepicker_browser_detect() {
    if ($.browser.msie) {
      return 'msie';
    }
    else if ($.browser.safari) {
      return 'safari';
    }
    else if ($.browser.opera) {
      return 'opera';
    }
    else if ($.browser.mozilla) {
      return 'mozilla';
    }
    else {
      return 'unknown';
    }
  }

I have tested this with firefox 2 and 3, Opera 9 and 10 and safari version 4.

Please test and report back folks!

hutch’s picture

Version: 6.x-2.2 » 6.x-2.x-dev

Please try the latest development snapshot for this issue.

hutch’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.