I have a whole bunch of pages that I need to parse through and add calculated 
IDs to each image, based on the ID of its ancestor (might be parent, 
grandparent or more) div which has the class of "page".

So that, for instance, this...

<div class="page" id="p_27">
        ... blah, blah ...
        <img ... />
        <img ... />
.       .. blah, blah ...
        <div ...>
                <img ... />
        </div>
</div>
<div class="page" id="p_28">
        ... blah, blah ...
        <img ... />
        <img ... />
.       .. blah, blah ...
        <div ...>
                <img ... />
        </div>
</div>

...would become this...

<div class="page" id="p_27">
        ... blah, blah ...
        <img ... id="p_27-01 />
        <img ... id="p_27-02 />
.       .. blah, blah ...
        <div ...>
                <img ... id="p_27-03 />
        </div>
</div>
<div class="page" id="p_28">
        ... blah, blah ...
        <img ... id="p_28-01 />
        <img ... id="p_28-02 />
.       .. blah, blah ...
        <div ...>
                <img ... id="p_28-03 />
        </div>
</div>

... etc., with the particulars having no regularity.


I've written a jQuery script that can do this dynamically with less code than 
it takes to comment it.

$(function() {
        $('div.page').each(function() { 
                //GET REFS TO ALL div.page ELEMENTS, WITH EACH ONE:

                var theID = $(this).attr('id'); 
                        //GET THE ID OF THE DIV

                var counter = 1; 
                        //SET COUNTER TO ONE FOR FRESH INCREMENTATION

                var imageID; 
                        //DECLARE ImageID VARIABLE

                $(this).find('img').each(function(counter) { 
                        //GET REFS TO EACH DESCENDENT img OF THE DIV; WITH EACH 
ONE:

                        imageID = (theID + "-" + (((counter += 1) < 10) ? 
counter = "0" + counter : true)); 
                                //CONCATENATE THE DIV ID WITH THE COUNTER, 
SEPARATED BY A HYPHEN, 
                                WITH A LEADING ZERO IF NECESSARY, 
                                SET THE VALUE OF imageID TO THE RESULT,  
                                AND INCREMENT THE COUNTER.

                        $(this).attr('id', imageID); 
                                //SET THE ID OF THE IMAGE TO imageID
     });
  });
});


But how might I go about getting the generated code for it into my source files?

I can write regular expressions, and I can AppleScript, but it's so much more 
complex to deal with this sort of thing via string parsing than it is to 
directly alter objects in the DOM.

Your suggestions are much appreciated.
-- 
___________________________________________________

RICK GORDON
EMERALD VALLEY GRAPHICS AND CONSULTING
___________________________________________________

WWW:   http://www.shelterpub.com

-- 
-- 
You received this message because you are subscribed to the 
"BBEdit Talk" discussion group on Google Groups.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
<http://groups.google.com/group/bbedit?hl=en>
If you have a feature request or would like to report a problem, 
please email "[email protected]" rather than posting to the group.
Follow @bbedit on Twitter: <http://www.twitter.com/bbedit>



Reply via email to