5 Replies Latest reply on Feb 21, 2011 8:08 AM by BeriliaTubul

    [js] select the previous word

    BeriliaTubul

      Hi,

       

      I have a xml like this (well... this is just a part of my xml):

      "<p>This is some text<note>This will be a footnote</note></p>"

       

      I made a xml rules who find the "note" to make a footnote with it.

      So, I need the word before "note" to apply the footnote to it (in the case, "text")

       

       

      this.xpath = "//note";

      this.apply = function(myElement, myRuleProcessor){

       

        var myStory =  myElement.insertionPoints[0].parentStory.contents;

      }

       

      how can i know which item (of words in myStory) is myElement?

       

      I tried to use index but I don't know how :

      myElement.words.item(0).index;

       

       

      Please help me this is so much frustrating!

        • 1. Re: [js] select the previous word
          Harbs. Level 6

          Try someting like this:

           

           var myStory =  myElement.insertionPoints[0].parentStory;
          var myInsertionPoint = myStory.insertionPoints.item(myElement.insertionPoints[0].index-1);
          //add the footnote to myInsertionPoint...
          
          

           

          Harbs

          • 2. Re: [js] select the previous word
            BeriliaTubul Level 1

            Hi,

             

            It doesn't work : myInsertionPoint is the number of the character (at least it's what I understood) but I need the number of the word :

             

            myWord = myTextFrame.parentStory.words.item(myInsertionPoint);

            var myFootnote = myWord.insertionPoints.item(-1).footnotes.add();

            myFootnote.insertionPoints.item(-1).contents = myElement.contents;

             

            Maybe I can do otherwise but I don't know how.

            • 3. Re: [js] select the previous word
              Harbs. Level 6

              That's not right...

              I don't know why you don't just use the insertionPoint, but it should be something like this:

               

              myWord = myTextFrame.parentStory.characters.item(myInsertionPoint).words.item(0);
              

               

              Harbs

              1 person found this helpful
              • 4. Re: [js] select the previous word
                BeriliaTubul Level 1

                When I do that I have an error in Indesign something like "incorrect parameter" (my messages are in french). It appends when I declare myWord

                var myTextFrame = myElement.insertionPoints[0].parentTextFrames[0]; var myStory =  myElement.insertionPoints[0].parentStory; var myInsertionPoint = myStory.insertionPoints.item(myElement.insertionPoints[0].index-1); var myWord = myTextFrame.parentStory.characters.item(myInsertionPoint).words.item(0);

                 

                When I do

                alert(myInsertionPoint.contents);

                the alert is empty.

                • 5. Re: [js] select the previous word
                  BeriliaTubul Level 1

                  That's ok with this code :

                   

                  var myTextFrame = myElement.insertionPoints[0].parentTextFrames[0]; var myStory =  myElement.insertionPoints[0].parentStory; var myInsertionPoint = myStory.insertionPoints.item(myElement.insertionPoints[0].index-3); var myWord = myTextFrame.parentStory.characters.item(myElement.insertionPoints[0].index-3).words.item( 0);               

                   

                  I forgot that I have a return to line. This explain why I couldn't find any word at index-1.

                   

                  Thank you very much Harbs