PDA

View Full Version : is it possible ? Manipulation of the dom



dme69
18 Oct 2010, 11:45 AM
Hello all,

I tried many things but i'm asking for your help because i'm doing stupid things now !
here is what i want to do. I want to transform a html file (i'm not composing) to another. I want to move some parts of the body to div.
Here is the original one :
<body>
text+images part 1
<div class="sep">some text</div>
tex+images part2
<div class="sep">some text</div>
text+images part3
</body>


and here is what i want :
<body>
<div id="div_1">
text+images part 1
</div>
<div id="div_2">
tex+images part2
</div>
<div id="div_3">
text+images part3
</div>
...
</body>

In fact the div with class="sep" will be used as separator and won't appear in the final result.

I hope i am clear and someone could help me.
Best regards.
Dominique.

dme69
19 Oct 2010, 5:10 AM
I'm sad, nobody can't help me. ;-(
Maybe i'm not clear for what i want to do ?
To solve my problem i'm working on how works the dom traversal. I mean, i want to "read" the body line by line and copy each line into a new div until i find a div with class=sep or the end of body.
Is this kind of things possible ?

dme69
19 Oct 2010, 6:38 AM
Someone help me to do it with jquery. Can someone help me here with ext-core ?
here is the code with jquery :

i = 0;
$("body").contents().filter(function() {
return this.nodeType == 3; // text node
})
.wrap(function() {
i++;
return $("<div />").addClass("text").attr("id", "div_"+i);
});
//$(".sep").hide(); // or remove()

dme69
19 Oct 2010, 11:47 PM
Hello,
Well nobody could help me ;-(
That's not a problem i can understand.
After some big search, i found this and this is the solution for me :


// Add a filter function to CompositeElement (Why it not there already?) Ext.override(Ext.CompositeElementLite, {
filter : function(fn){
var els = [];
this.each(function(el){
if(fn(el.dom)){
els[els.length] = el.dom;
}
});
this.elements = [];
this.add(els);
return this;
} });


Hope it will help somebody else in the future.

Thanks to Animal (http://www.sencha.com/forum/member.php?10-Animal) for this solution on another thread.

Dominique.