?
Solved

modifying specific selected text in a textarea field

Posted on 2005-04-04
52
Medium Priority
?
865 Views
Last Modified: 2008-01-09
I need some more details related to a topic I previously posted, please visit the link below for the details:

http://www.experts-exchange.com/Web/Web_Languages/JavaScript/Q_21264558.html

Just to recap I have a textarea field used as part of a Content management System.  I want the user to be able to highlight a piece of text, then click on a button, after which a popup window with a list of external files is rendered. Clicking on a file name in the popup closes the popup and surrounds the selected text from the parent window with a link to the external file.

Now all of this I have working thanks to John Bricci’s help.  I only have one problem.
If a user enters the following example code:
<ul>
<li>Report One</li>
<li>Report Two</li>
<li>Report Three</li>
</ul>

If I highlight the second instance of “Report” and try to generate a link, the code places the link around the first instance of  “Report”.  How do I isolate specific instances of words?
0
Comment
Question by:xamian
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 19
  • 17
  • 8
  • +3
52 Comments
 
LVL 25

Expert Comment

by:archrajan
ID: 13701325
where will the user enter this?
<ul>
<li>Report One</li>
<li>Report Two</li>
<li>Report Three</li>
</ul>

in the text box??
0
 
LVL 5

Expert Comment

by:jpontani
ID: 13701636
Here's the code I use to get the selected text:

function getSelectionRange() {
      cbox.focus();
      var range;
      if (document.selection) {
            range = document.selection.createRange();
      } else {
            return;
      }
      return range;
}

A sample of how to use that function that I use is:
function Code(myCode) {
      if(document.selection) {
            var range = getSelectionRange();
            var newRange = cbox.createTextRange();
            newRange = range.duplicate();
            var newtext = "[" + myCode + "]" + range.text + "[/" + myCode + "]";
            newRange.text = newtext;
      } else if (cbox.selectionEnd && (cbox.selectionEnd - cbox.selectionStart > 0)) {
            var start_selection = cbox.selectionStart;
            var end_selection = cbox.selectionEnd;
            if (end_selection <= 2)      {
                  end_selection = cbox.textLength;
            }
            var start = (cbox.value).substring(0, start_selection);
            var middle = (cbox.value).substring(start_selection, end_selection);
            var end = (cbox.value).substring(end_selection, cbox.textLength);
            middle = "[" + myCode + "]" + middle + "[/" + myCode + "]";
            cbox.value = start + middle + end;
      } else {
            cbox.value += "[" + myCode + "][/" + myCode + "]"
      }
}

I have a BBCode style editor, so the Code() function would put something like:   [b][/b] around text.  In my functions you need to have the item 'cbox' set before you can use it, or you could just replace it with document.getElementById('inserttextboxIDhere')

- Joe
0
 
LVL 15

Expert Comment

by:SnowFlake
ID: 13701946
I dont know what you are currently using
but if IE only is good for you then
you might want to look at
document.execCommand('CreateLink',false,'http://yourdomain.com/url')
if you know what url you want for the link
or just document.execCommand("CreateLink"); if you want the standard GUI.

you can see an example here:
http://msdn.microsoft.com/workshop/samples/author/dhtml/refs/execCommand_CreateLink.htm

or read more about execCommand here (It can do other stuff as well,
most active on the current selection):

http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/methods/execcommand.asp

If you like this you will probably need to read about the "unselectable" and "contentEditable" Attributes as well.

SnowFlake

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:xamian
ID: 13702484
I'll try these out tomorrow and let you know.

Thanks
0
 
LVL 1

Author Comment

by:xamian
ID: 13710394
Hmm... Joe Pontani's code looked the most promising, but it looks like some of those methods aren't supported by IE.  I'm setting this up for my intranet, so all of the users are required to access the application using an IE browser 5.5 or higher.
0
 
LVL 5

Expert Comment

by:jpontani
ID: 13710497
It works fine for me in IE6.  Paste the code of your page and maybe I can help you work through the problem.

- Joe
0
 
LVL 1

Author Comment

by:xamian
ID: 13710911
OK, The following block of code is on the form page which use's a WYSIWYG  editor as the textarea field, the function is invoked via an onClick Event:

function aeapi_custom_link_to_object2(aeNum)
{
//This stores the instance of the ActiveEdit Object
DHTMLSafe = aeObjects[aeNum];
//This stores the text the user highlighted from the textarea field, this value will be passed as a URL variable
var SelectedText = DHTMLSafe.DOM.selection.createRange().text;
//This opens a popup that lists all of the available files for the user to link to
if(SelectedText != '')
{
   var W = 548;
   var H = 324;
      var wX = (screen.width-W)/2;
   var wY = (screen.height-H)/2;
   var loader = window.open('InsertObject.cfm?SelectedText='+SelectedText+'&bt='+SelectedBt, 'content', 'height='+H+',width='+W+',scrollbars=1,location=1,status=1,menubar=0,toolbar=0,resizable=1,left='+wX+',top='+wY);
}
return;
}

*******************************************


OK, now below is the code on the popup:

<html>
<head>
<title>Insert Object</title>
<script type='text/javascript' language='JavaScript 1.1'>
//This takes the text the user highlighted,which was passed as a URL variable and stores it as a form variable
function get_replace()
{
var hold = location.search.substr(location.search.indexOf("=")+1);
var obj = document.getElementById('main');
obj.value = hold;
return;
}
//This creates a link to the file the user wants to link to
function do_link(val)
{
//This goes and gets all of the current content that is inside the parent's textarea field
var FormContent = parent.opener.aeObject.DOM.body.innerHTML;
//This retrieves the selected that we stored in the form variable
var SelectedText = document.getElementById('main').value;
//This creates a link to the file
var NewText = '<a href="'+val+'" target="_blank">'+unescape(SelectedText)+'</a>';
//This modifies the content from the original textarea field by swapping the highlighted text with the new link
NewContent = FormContent.replace(SelectedText, NewText);
//This takes the modified content and inserts it into the original textarea field on the parent window
parent.opener.aeObject.DOM.body.innerHTML = NewContent;
//This closes the popup
this.window.close();
//This returns us back to the parent window
return;
}
         
</script>
</head>
<body onload='get_replace();'>
<form name='hold'>
<input type='hidden' id='main' name='main'>
</form>
<ul>
<li>
2004 Annual Report <a href="javascript:void(do_link('/myfiles/Annual Report 2004.pdf'))">INSERT</a></li>
</ul>
</body>
</html>

Like I said, this works perfectly, except that if for example the end-user enters the word "Report" three times inside the text area field, and then highlights the second instance of the word "Report", so that the link is made soley on that word, my function screws up and adds the link to the first instance of the word "Report".

I know it's because I used the replace function without setting the start point, but how do you isolate the damn start and end points?

Any assistance would be most appreciated.  Thanks





0
 
LVL 1

Author Comment

by:xamian
ID: 13711092
Oops, just ignore the code:

&bt='+SelectedBt

I was experimenting with trying to pass the insertion point using the boundingTop method.
0
 
LVL 5

Expert Comment

by:jpontani
ID: 13711305
DHTMLSafe.DOM

What is that?  Try changing that to 'document' to get the selected text.

- Joe
0
 
LVL 15

Expert Comment

by:SnowFlake
ID: 13714142
OBSERVATION:
It looks like its not the whole picture yet,
and as if aeObjects[]
is an array of some representation of an "active editor" that probably has a DOM property.

SUGGESTION:
xamian,
In perticular if you intend to have this for IE5.5 only
you should consider execCommand again as it is Very easy to implement
and very powerfull.

CURRENT SITUATION:
currently your function does not know and has no way of knowing
which instance of the word to replace so it replaces the first one.

CURRENT SITUATION SOLUTION:
To be able to replace the right instance you have to work with the object returned by selection.createRange()
and not with the value of it's .text property.

before calling on your popup I would save the current user selection object
on aeObjects[aeNum]
aeObjects[aeNum].LastUserSelection = DHTMLSafe.DOM.selection.createRange();

then on the "callback"
instead of
     parent.opener.aeObject.DOM.body.innerHTML = NewContent
use parent.opener.aeObject.DOM.body.innerHTML = NewContent

then

parent.opener.aeObject.DOM.body.innerHTML = NewContent
you can do something like:
parent.opener.aeObject.LastUserSelection.htmlText = NewContent;

I hope you can glue all of this up,
I didn't  give full code fix as some parts are missing and I was guessing
like where is parent.opener.aeObject actually defined ? ( I guessed it is the active editor object
that opened the popup)


0
 
LVL 1

Author Comment

by:xamian
ID: 13716245
The problem with using execCommand is that it assumes the end-user knows the URL to the external file they want to link to.  This is all basically for a low-end content management system.  To make a long story short, every user may have access to many web page "collections" and each collection has it's own directory for storing external files.  My clients don't want to have to remember the URL path for every collection they have access to.  The example of my code that I posted only shows a sample of a hard coded link.  In reality the database is spitting out the list of links with their individual directory locations dynamically.  I need to be able to insert these dynamic links into the textarea field of the ActiveEdit Object.

I'll play around with your other suggestions and see where it takes me.

Thanks

0
 
LVL 1

Author Comment

by:xamian
ID: 13716461
Snowflake,

Why did you repeat the following three times?

parent.opener.aeObject.DOM.body.innerHTML = NewContent
0
 
LVL 5

Expert Comment

by:jpontani
ID: 13716604
Ah, I think I understand your dilemma now.  What you could do is have an onload event of the popup window.  When it loads, focus the opener, get the selected range (get it in the popup though), and focus back on the popup.

Something like:

function GetParentWindowSelection() {
      opener.focus();
      var pRange;
      if(opener.document.selection)
            pRange = opener.document.selection.createRange();
      if(pRange) {
            window.focus();
            return pRange;
      } else {
            window.focus();
            return;
      }
}

That would be in your popup window, and it will get the selected text from the parent window.  You can change the text in that range by setting pRange.text.  So if you wanted a link, you would do:

function Link() {
      var myRange = GetParentWindowSelection();
      myRange.text = "<a href=\"" + link + "\">" + myRange.text + "</a>"
}
0
 
LVL 5

Expert Comment

by:jpontani
ID: 13717228
Ack, bad code, I forgot some important stuff:

function Link() {
      var myRange = GetParentWindowSelection();
      var newRange;
      if(opener.document.getElementById({textareaIDHere})) {
            newRange = opener.document.getElementById({textareaIDHere}).createTextRange();
            newRange = myRange.duplicate;
            newRange.text = LinkTextHere;
      }
}

- Joe
0
 
LVL 1

Author Comment

by:xamian
ID: 13718032
Hi Joe,

I tried this but I keep getting and error of "Object Expected".


<script type='text/javascript' language='JavaScript 1.1'>
function GetParentWindowSelection() {
     opener.focus();
     var pRange;
     if(opener.document.selection)
          pRange = opener.document.selection.createRange();
     if(pRange) {
          window.focus();
          return pRange;
     } else {
          window.focus();
          return;
     }
}
//***************************************************

function do_link(val) {
     var newRange;
       var myRange = GetParentWindowSelection();
     myRange.text = "<a href="+val+" target="_blank">" + myRange.text + "</a>"
     if(opener.document.getElementById({content})) {
          newRange = opener.document.getElementById({content}).createTextRange();
          newRange = myRange.duplicate;
          newRange.text = myRange.text;
              this.window.close();
              return;
     }
}    
</script>

Plus the ActiveEdit Object does not have the "Id" attribute available to it.  I tried "getElementByName" but that crapped out too.

Any other ideas?
0
 
LVL 5

Expert Comment

by:jpontani
ID: 13718326
Try this:

function do_link(val) {
     var newRange;
     var myRange = GetParentWindowSelection();
     var myObj;
     var Objects = opener.document.getElementsByTag({tag});
     for(var i=0; i<Objects.length; i++) {
          if(Objects[i].name == "{itemnamehere}")
                myObj = Objects[i];
     }
     if(myObj) {
          newRange = myObj.createTextRange();
          newRange = myRange.duplicate;
          newRange.text = "<a href="+val+" target="_blank">" + myRange.text + "</a>";
          this.window.close();
          return;
     }
}

- Joe
0
 
LVL 5

Expert Comment

by:jpontani
ID: 13718334
Gah, change:
var Objects = opener.document.getElementsByTag({tag});

to
var Objects = opener.document.getElementsByTagName({tag});

- Joe
0
 
LVL 15

Expert Comment

by:SnowFlake
ID: 13720072
I seem to be on a different time zone from the rest of the participants of the Q :)

O.K.
xamian,
you said that "The problem with using execCommand is that it assumes the end-user knows the URL to the external file they want to link to"
this is not true, it is only if you choose to use the GUI.
You can just as well use it without its GUI as a way to wrap the selection with a link,
quoting (more or less) from:
http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/methods/execcommand.asp

SYNTAX:

bSuccess = object.execCommand(sCommand [, bUserInterface] [, vValue])

Parameters
-------------
sCommand : Required. String that specifies the command to execute. This command can be any of the command identifiers that can be executed in script.
bUserInterface Optional. Boolean that specifies one of the following values. false Default. Does not display a user interface.
true Displays a user interface, if the command supports one.
 
vValue Optional. Variant that specifies the string, number, or other value to assign. Possible values depend on sCommand .

Return Value

Returns True if the command is successful."

The documentation of the CreateLink command
( http://msdn.microsoft.com/workshop/author/dhtml/reference/constants/createlink.asp )

says:
CreateLink command Inserts a hyperlink on the current selection, ***or*** displays a dialog box enabling the user to specify a URL to insert as a hyperlink on the current selection.

Scripting Information

Command CreateLink  
User interface Optional. This command displays a dialogue box if the bUserInterface argument of execCommand is set to true or omitted. ****It does not display a dialogue box if the argument is set to false or null and the vValue parameter is present (even if it's null)****.
execCommand vValue Optional. String that specifies a URL.



i.e. if you use for example document.execCommand('CreateLink',false,'http://www.dreamhouse.co.il')
if will wrap the current selection with a link to http://www.dreamhouse.co.il without asking the user for any information.

the reason I think execCommand is so good for you is that I am guessing that your active editor has more functions like
bold italic color etc. (Or such would be nice to have).
all thos actions are accomplished in a very similar and simple way
e.g.
document.execCommand("ForeColor",false,"#FF0033");
document.execCommand("Bold");

not only that but you get complex behavior like the one you get in word
where if you have some chars Bold ans some not it will first turn them all to be nonbold and only then bold them all together.

for additional command identifires look at:
http://msdn.microsoft.com/workshop/author/dhtml/reference/commandids.asp

Next issue in Next POST :)
0
 
LVL 15

Expert Comment

by:SnowFlake
ID: 13720128
xamian:
on your next post you wrote
"Why did you repeat the following three times? ..."

It was an edditing error,
only the last set should have been there
where it said:

"instead of
parent.opener.aeObject.DOM.body.innerHTML = NewContent
you can do something like:
parent.opener.aeObject.LastUserSelection.htmlText = NewContent;
"


0
 
LVL 1

Author Comment

by:xamian
ID: 13720130
Still getting "Object Expected".

OK Let me submit this again.

Here's the code on the parent page:
**********************************************

function aeapi_custom_link_to_object2(aeNum)
{
DHTMLSafe = aeObjects[aeNum];
      
var SelectedText = DHTMLSafe.DOM.selection.createRange().text;

          if(SelectedText != '')
          {
               var W = 548;
               var H = 324;
                var wX = (screen.width-W)/2;
               var wY = (screen.height-H)/2;
               var loader = window.open('InsertObject.cfm?SelectedText='+SelectedText, 'content', 'height='+H+',width='+W+',scrollbars=1,location=1,status=1,menubar=0,toolbar=0,resizable=1,left='+wX+',top='+wY);
          }

          return;
     }
********************************************

OK here's the code on the popup:



<script type='text/javascript' language='JavaScript 1.1'>
function GetParentWindowSelection() {
     opener.focus();
     var pRange;
     if(opener.document.selection)
          pRange = opener.document.selection.createRange();
     if(pRange) {
          window.focus();
          return pRange;
     } else {
          window.focus();
          return;
     }
}

function do_link(val) {
     var newRange;
     var myRange = GetParentWindowSelection();
     var myObj;
     var Objects = opener.document.getElementsByTagName(content);
      
     for(var i=0; i<Objects.length; i++) {
          if(Objects[i].name == "content")
                myObj = Objects[i];
     }
     if(myObj) {
          newRange = myObj.createTextRange();
          newRange = myRange.duplicate;
          newRange.text = "<a href="+val+" target="_blank">" + myRange.text + "</a>";
          this.window.close();
          return;
     }
}
         
</script>
0
 
LVL 5

Expert Comment

by:jpontani
ID: 13720202
var Objects = opener.document.getElementsByTagName(content);

Replace 'content' with the tag name of the object.  You are using textarea, right?  If so do:

var Objects = opener.document.getElementsByTagName("textarea");

Then on this line:
if(Objects[i].name == "content")

Change "content" to the name of your textarea, so if you have:

<textarea name="myHTMLBox"></textarea>

You would do:

if(Objects[i].name == "myHTMLBox")

If you still need help you can contact me on MSN @ jpontani[[at]]gmail.com (change the [[at]] to @)

- Joe
0
 
LVL 15

Expert Comment

by:SnowFlake
ID: 13720832
I belive that you should try and avoid as much as possible
the syntax of opener.document.{a_very.long.list_of_qualifiers.assuming.you_know.
exactly_how.the_caller_is.structured}

A much better pattern would be that of a preset (or even configurable) callback function.
In your case that would translate to thinking of your popup as a URL selector, therefore
defineing a function in the opener called URLSelectedCallback(sURL)
inside that function you should have something like:

function URLSelectedCallback(sURL){
   var rng=document.selection.createRange();
   if (rng.text.length>0) {
       rng.execCommand('CreateLink',false,sURL);
       // or if you wish
      // rng.text='<a href='+sURL+' target='_blank'>' + rng.text + '</a>';
   }
}

on the popup you should have
function do_link(val) {
    if (typeof(opener.length)!='unknown') {  // avoid an error if the opener window has been closed
       if (typeof(opener.URLSelectedCallback)=='function') {
            opener.URLSelectedCallback(val);
       }
    }
}

This way You have a small interface and your popup can be reusable in other
systems if relevant.
On more generic and or complex systems you could have more then one callback function
and In some cases you can pass thair names as parameters to the popup window.

Please tell us if any of this helps you.

If you still can't get it to work it would be nice if you paste the entire code or
have it on a site where we can see you current code in action.

SnowFlake

0
 
LVL 15

Expert Comment

by:SnowFlake
ID: 13720934
Implementing my idea's into your code :)


Here's the code on the parent page:
**********************************************

function aeapi_custom_link_to_object2(aeNum)
{
DHTMLSafe = aeObjects[aeNum];

DHTMLSafe.rng=DHTMLSafe.DOM.selection.createRange();  // Use expando property to store the selected range

var SelectedText = DHTMLSafe.rng.text;

          if(SelectedText != '')
          {
               var W = 548;
               var H = 324;
                var wX = (screen.width-W)/2;
               var wY = (screen.height-H)/2;

               var loader = window.open('InsertObject.cfm?SelectedText='+SelectedText, 'content', 'height='+H+',width='+W+',scrollbars=1,location=1,status=1,menubar=0,toolbar=0,resizable=1,left='+wX+',top='+wY);
          }

          return;
     }

function URLSelectedCallback(sURL){
   DHTMLSafe = aeObjects[aeNum];  // I assume aeNum is global enough to be recognized in this function as well.
   var DHTMLSafe.rng;
   if (rng.text.length>0) {
       rng.execCommand('CreateLink',false,sURL);
       // or if you wish
      // rng.text='<a href='+sURL+' target='_blank'>' + rng.text + '</a>';
   }
}
********************************************

OK here's the code on the popup:

<script type='text/javascript' language='JavaScript 1.1'>

function do_link(val) {
    if (typeof(opener.length)!='unknown') {  // avoid an error if the opener window has been closed
       if (typeof(opener.URLSelectedCallback)=='function') {
            opener.URLSelectedCallback(val);
       }
    }

}
         
</script>
0
 
LVL 1

Author Comment

by:xamian
ID: 13727210
SnowFlake,

I would post a sample but it's on our intranet and I don't have a license for the ActiveEdit object on my personal server.
I tried your code but I'm getting the following error on the main parent window:

Expected';'

I can't tell where the colon is missing, it looks good to me, but obviously there's an error.
0
 
LVL 15

Expert Comment

by:SnowFlake
ID: 13730266
var DHTMLSafe.rng;

should have been

 var rng=DHTMLSafe.rng;

sorry ...
0
 
LVL 1

Author Comment

by:xamian
ID: 13730366
Hi SnowFlake,

Well I'm not generating any javascript errors, but when I click on the link in the popup, nothing happens at all.  Any Ideas?
0
 
LVL 1

Author Comment

by:xamian
ID: 13730467
Wow, I just realized how long this message is getting.  Can anyone just show me the code for a working example like Joe Bricci did for me?
http://www.experts-exchange.com/Web/Web_Languages/JavaScript/Q_21264558.html

Then maybe I can take the example, reverse-engineer it and extrapolate what I need to do, like I did the last time.
0
 
LVL 15

Expert Comment

by:SnowFlake
ID: 13730911
lets try to add some alerts to see what are we missing:
make the changes to those two functions and tell me what alerts are showing

function URLSelectedCallback(sURL){
   alert('URLSelectedCallback called');
   DHTMLSafe = aeObjects[aeNum];  // I assume aeNum is global enough to be recognized in this function as well.
   var DHTMLSafe.rng;
   if (rng.text.length>0) {
       alert('running execCommand');
       rng.execCommand('CreateLink',false,sURL);
       // or if you wish
      // rng.text='<a href='+sURL+' target='_blank'>' + rng.text + '</a>';
   }
}
********************************************

OK here's the code on the popup:

<script type='text/javascript' language='JavaScript 1.1'>

function do_link(val) {
    alert('do_link called');
    if (typeof(opener.length)!='unknown') {  // avoid an error if the opener window has been closed
       if (typeof(opener.URLSelectedCallback)=='function') {
            opener.URLSelectedCallback(val);
       }
       else {
           alert('the typeof(opener.URLSelectedCallback) was ' + typeof(opener.URLSelectedCallback));
       }
    }
    else {
           alert('the typeof(opener.length) was ' + typeof(opener.length));
    }

}

ALSO:
you said "I don't have a license for the ActiveEdit object "
is this an activex ??
I was under the impression that this is a text area And I belive so where the rest of the experts.
Thinking about It I am not sure it can even be done.

When using execCommand you usualy work on html elements.

standard usage (working tested example) would be something like:
<html>
<body>

<span unselectable="on" style="cursor:hand" onclick="document.selection.createRange().execCommand('Bold');">bold</span>
<div id="edt" border=1 contentEditable="true">Try editing this text, select some of it and click bold</div>

</body>
</html>

note two things:
1) the attribute contentEditable="true" on the div that makes it possible to edit its content
2) the attribute unselectable="on" on the span so that when clicking on it you will not lose the selection in the div

I hope this helps

0
 
LVL 1

Author Comment

by:xamian
ID: 13735869
SnowFlake,

OK....  When I click on "Insert Link" an alert opens up that reads:

"do_link called"

When I click on the OK button on the alert, another alert opens that reads:

"the typeof (opener.URLSelectedCallback) was object"

So what does this mean?

To confirm your theory, yes this is an ActiveX Control, but I believe this can be done because I'm 90% there.  Like I said before, the code I have works, with the exception that it creates a link out of the first instance of the highlighted text.
0
 
LVL 15

Expert Comment

by:SnowFlake
ID: 13738668
o.k.
The second alert told us that
typeof(opener.URLSelectedCallback) was 'object'
and not 'function' as  I exected it to be.

try changeing the if to be:

       if (typeof(opener.URLSelectedCallback)!='undefined') {

and letes see where it gets us this round.
0
 
LVL 17

Expert Comment

by:Cem Türk
ID: 15638211
No comment has been added to this question in more than 21 days, so it is now classified as abandoned..
I will leave the following recommendation for this question in the Cleanup topic area:

DELETE - No Refund

Any objections should be posted here in the next 4 days. After that time, the question will be closed.

cem_turk

EE Cleanup Volunteer
0
 
LVL 15

Expert Comment

by:SnowFlake
ID: 15639109
Yes please,
I object  for a few reasons:

1) There is tons of information here.
2) both myself and jpontani put lots of time into this.
3) IMHO and unless the OP will say other wise - the Q was answered.

I would PAQ and split points between myself an jpontani
unlerr the OP has another opinion on this.

SnowFlake
   
0
 
LVL 17

Expert Comment

by:Cem Türk
ID: 15639234
i've reviewed the question again.

it's ok to PAQ this question,  i appreciate your work here. but i'm in doubt if your comments lead to solution.

cem_turk
0
 
LVL 15

Expert Comment

by:SnowFlake
ID: 15640637
and your doubt is based on .... ?

things ended (so far) with a debugging procces in place,
found an error in code I expected to be a complete solution,
then I told the OP what to change and he disapeared (so far)
without either saying thank you and grading
or stateing that he lost intrest and explaining why (note however that the OP
was on EE after that and did ask a few other Q's).

SnowFlake.
0
 
LVL 17

Expert Comment

by:Cem Türk
ID: 15640677
my doubt is based on "things ended (so far) with a debugging procces in place" .
you expect your code to be a complete solution by yourself, if you were to act according to http://www.experts-exchange.com/help.jsp#hi89
which option would you select as recommendation as a third person? (i am not very sure, thats why i am asking for your suggestion).

cem_turk

0
 
LVL 15

Expert Comment

by:SnowFlake
ID: 15640757
I would
allow for 21 days for the OP to comment on this as he still seems to come to EE from time to time,
if he fails to response,
accept with a grade B and a split between myself and jpontani.
This is although I think my solution is probably working for xamian.

the reasoning is:
main reason for a B is that there is no way for us to make 100% sure it does work without the OP
because this is not a JS only Q.

It is my opinion that if the OP would have remained on the Q he could have completed what he need
with either my own or jpontani' code.

as a searcher - I would be content getting all those comments and probably found them useful.

SnowFlake

Note however that I never was a CV and maybe someone else would have another opinion on this.
0
 
LVL 17

Expert Comment

by:Cem Türk
ID: 15640776
http://www.experts-exchange.com/help.jsp#hi89

Accept a comment
"if there is doubt that this is a solution, or if it is only a partial solution, then it should NOT be the recommendation."

>>main reason for a B is that there is no way for us to make 100% sure it does work without the OP

Since we cant make 100% sure that it works, we cant recommend to accept a comment.
the information you provided is valuable so its ok to PAQ.
OP didnt responded all your comments so we have to choose option PAQ - Refund

cem_turk

0
 
LVL 1

Author Comment

by:xamian
ID: 15642176
Hi guys,

I'm back.  I'm sorry I never got back to this.  I was working on a major project and didn't have time.  I swear I will devote an entire day to this sometime this coming week.  I have to say that one of the reasons I droped this was because none of the suggestions were working, so I'm sorry, but I wouldn't give points to either of you.  This is still very important to me and I will definitely spend a day revisiting this item.  I will probably get back to you on this on Thursday Jan 12, 2006. I have some fires to put out earlier this week but I will get back to you.  I really do appreciate and value your assistance.
Thanks, talk to you soon.
0
 
LVL 15

Expert Comment

by:SnowFlake
ID: 15642859
well, I for one am happy that xamian is still around
and I will try and do my best to help him with his problem
(hopefully to a solution worthy of an A grade :)).

xamian - I am awaiting a response on my last comment from 04/08/2005.

0
 
LVL 1

Author Comment

by:xamian
ID: 15675490
OK, so I picked up from where we left off on 4/8/05.  Wow, how time flies.  Anyway.

The same situation exists, when I click on "Insert Link" on the popup, an alert opens up that reads:

"do_link called"

When I click on the OK button on the alert, another alert opens that reads:

"the typeof(opener.URLSelectedCallback) was undefined"

What next?


0
 
LVL 15

Expert Comment

by:SnowFlake
ID: 15675988
sorry, its midnight here - I saw your comment,
and I will get back to you about it tommorow.

but as long as I am here -

just so that we will be talking about the same thing - what browser are you using ?
and did you make sure the name of the function in the opener window is spelled exactly like the one we are
testing in the opened window ? (i.e. URLSelectedCallback is spelled exactly the same on all places)

SnowFlake
0
 
LVL 15

Expert Comment

by:SnowFlake
ID: 15679996
thanks.
0
 
LVL 1

Author Comment

by:xamian
ID: 15681544
OK I'm using IE 6.0.  Since the Content Management system is Intranet based I can rely on my customers to be using the same browser, at the very least version 5.0 or higher.

The following was on the opener, the name of the function is different, I should note that the developer of the ActiveX control documented that custom functions must be prefixed with "aeapi_custom_", I have to admit I'm not sure why:

function aeapi_custom_link_to_object2(aeNum)
{
DHTMLSafe = aeObjects[aeNum];
      
var SelectedText = DHTMLSafe.DOM.selection.createRange().text;

          if(SelectedText != '')
          {
               var W = 548;
               var H = 324;
                var wX = (screen.width-W)/2;
               var wY = (screen.height-H)/2;
               var loader = window.open('InsertObject.cfm?SelectedText='+SelectedText, 'content', 'height='+H+',width='+W+',scrollbars=1,location=1,status=1,menubar=0,toolbar=0,resizable=1,left='+wX+',top='+wY);
          }

          return;
     }
0
 
LVL 15

Expert Comment

by:SnowFlake
ID: 15686195
well, no point in trying to call a function that does not exist is there ?

change the do_link function in the opend page to the following and tell me what happens now.


function do_link(val) {
    alert('do_link called');
    if (typeof(opener.length)!='unknown') {  // avoid an error if the opener window has been closed
       if (typeof(opener.aeapi_custom_link_to_object2)=='function') {
            opener.aeapi_custom_link_to_object2(val);
       }
       else {
           alert('the typeof(opener.aeapi_custom_link_to_object2) was ' + typeof(opener.aeapi_custom_link_to_object2));
       }
    }
    else {
           alert('the typeof(opener.length) was ' + typeof(opener.length));
    }

}

0
 
LVL 15

Expert Comment

by:SnowFlake
ID: 15686218
b.t.w.
the only reason I can think for why he would require such a naming convention
would be if the component (active editor) has some callbacks of its own
and he expects them  to use this naming scheme.

You might want to re-read the documentation of that component.

but any way I have a feeling we are going to be much closer now.

SnowFlake
0
 
LVL 1

Author Comment

by:xamian
ID: 15691401
OK, pretty much the same thing.  I get an alert that reads "do_link called",

When I click on the OK button on the alert, another alert opens that reads:

"the typeof(opener.aeapi_custom_link_to_object2) was object"

What now?
0
 
LVL 15

Expert Comment

by:SnowFlake
ID: 15697018
now we are getting threre.

change where it says
if (typeof(opener.aeapi_custom_link_to_object2)=='function') {
to
if (typeof(opener.aeapi_custom_link_to_object2)!='undefined') {

this time we know that the condition will be true because we know that "the typeof(opener.aeapi_custom_link_to_object2) was object"

to the function of the opener should be called.

you can also add after
var SelectedText = DHTMLSafe.DOM.selection.createRange().text;
in the aeapi_custom_link_to_object2 function another line that will have
alert(SelectedText);

this will also let us know that we actually successfuly called this function.

SnowFlake
0
 
LVL 1

Author Comment

by:xamian
ID: 15786711
OK, now when I click on the button that invokes the function I get an alert that renders whatever word I highlighted.

Once I click the "OK" button my popup shows up with my list of items to link to.

When I click on an item to create the link back in the opener page, I get another alert that reads "do_link called".  When I click on the "OK" button nothing happens.  The popup just stays up there.
0
 
LVL 15

Expert Comment

by:SnowFlake
ID: 15787719
now we have two issues if I understand you corectly -
1. the function aeapi_custom_link_to_object2 does not do what you wanted it to do.
   (to create the link)
2. you expect the popup to close.

but because of the timespan between posts here I am loosing sync.
lets align ourselves:
IMHO we should have now 3 functions
one called from the main windows and has the window.open statement
a second function on the popup which is the one calling back to the main window
a third function again on the main window which is the one that is actually supposed to do the work.

could you please post all three of them at their current state.

SnowFlake
0
 
LVL 1

Accepted Solution

by:
DarthMod earned 0 total points
ID: 16173043
PAQed with no points refunded (of 500)

DarthMod
Community Support Moderator
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question