tag:blogger.com,1999:blog-8640596986273216089.post3503811589554011893..comments2023-08-15T06:10:51.086-03:00Comments on Ariel Flesler: Textnode translator for JavascriptAriel Fleslerhttp://www.blogger.com/profile/17700414222186772120noreply@blogger.comBlogger14125tag:blogger.com,1999:blog-8640596986273216089.post-57284194139427718952009-02-26T04:13:00.000-02:002009-02-26T04:13:00.000-02:00Hithat can happen but i worked it out myself here ...Hi<BR/><BR/>that can happen but i worked it out myself here is the solution<BR/> var BlockP = new Translator(function( text ){<BR/> var data = text.replace( this.block, '*$3*' ).split('*');<BR/> if( data.length == 1 ) // <BR/> return data[0];<BR/> for( var i = 1; i < data.length; i += 2 ){<BR/> var block = data[i];<BR/> data[i] = document.createElement('p');<BR/> data[i].className='padded';<BR/> data[i].appendChild( document.createTextNode(block) );<BR/> }<BR/> return data;<BR/> }, function( node ){ // filter out links<BR/> return node.nodeName != 'A';<BR/> });<BR/> BlockP.block = /(\[(p)\])((?:.+))(\[\/(p)\])/g; // matchUnknownhttps://www.blogger.com/profile/10836328237025388485noreply@blogger.comtag:blogger.com,1999:blog-8640596986273216089.post-50058429229660678532009-02-26T00:58:00.000-02:002009-02-26T00:58:00.000-02:00Hi ArmandI'm not sure I follow, can you make some ...Hi Armand<BR/><BR/>I'm not sure I follow, can you make some kind of demo of what you need ?<BR/>Sorry for the delay :(Ariel Fleslerhttps://www.blogger.com/profile/17700414222186772120noreply@blogger.comtag:blogger.com,1999:blog-8640596986273216089.post-71325271438835001352009-02-17T11:55:00.000-02:002009-02-17T11:55:00.000-02:00Hihow would i go about this I have a block of te...Hi<BR/>how would i go about this I have a block of text and some parts of the text is in [p] [/p]<BR/><BR/>now i want to injectthe content in here back in the page in real paragraps. <BR/><BR/>Search and replace just shows the html as text and I would like it as html so that the page looks nice with paragraphs instead of one bulk of textUnknownhttps://www.blogger.com/profile/10836328237025388485noreply@blogger.comtag:blogger.com,1999:blog-8640596986273216089.post-33933918050340452422008-10-24T17:25:00.000-02:002008-10-24T17:25:00.000-02:00HiSet the option 'jump' to false. I think that sho...Hi<BR/><BR/>Set the option 'jump' to false. I think that should do.Ariel Fleslerhttps://www.blogger.com/profile/17700414222186772120noreply@blogger.comtag:blogger.com,1999:blog-8640596986273216089.post-71123796243900193782008-10-24T16:12:00.000-02:002008-10-24T16:12:00.000-02:00I have a problem, and I really need some tips to g...I have a problem, and I really need some tips to get it done.<BR/><BR/>My serialScroll works well, but my slides are html blocks with clickable links to go to specific pages, THE PROBLEM IS IF A CLICK ON THOSE LINKS THE ONLY THINK THAT HAPPENS IS THAT THE CONTENT SCROLLS BUT THE LINK DOES NOT SEND THE USER TO THAT PAGE.<BR/><BR/>Any ideas?<BR/><BR/>Thanks in advance!X-MGhttps://www.blogger.com/profile/15759502524282188223noreply@blogger.comtag:blogger.com,1999:blog-8640596986273216089.post-9909380372760533322008-08-28T14:30:00.000-03:002008-08-28T14:30:00.000-03:00It's doable... but note that the Translator instan...It's doable... but note that the Translator instance accepts a 2nd argument that is a filter function.<BR/><BR/>Using that function, you can simply achieve what you mean, you return:<BR/><BR/>node.parentNode == your_root_nodeAriel Fleslerhttps://www.blogger.com/profile/17700414222186772120noreply@blogger.comtag:blogger.com,1999:blog-8640596986273216089.post-81611207740432609092008-08-28T14:22:00.000-03:002008-08-28T14:22:00.000-03:00yes. not terribly important, but would allow mani...yes. not terribly important, but would allow manipulating content from a more generic parent selector that may have other children we don't want to touch.amirhttps://www.blogger.com/profile/13445444925766070474noreply@blogger.comtag:blogger.com,1999:blog-8640596986273216089.post-48671329964250383962008-08-28T11:03:00.000-03:002008-08-28T11:03:00.000-03:00Hi Amir, thanks for letting me know about the impl...Hi Amir, thanks for letting me know about the implementation.<BR/><BR/>The 'deep' argument you mention is to <B>avoid</B> making the traversing recursive ?Ariel Fleslerhttps://www.blogger.com/profile/17700414222186772120noreply@blogger.comtag:blogger.com,1999:blog-8640596986273216089.post-63907392484299068142008-08-27T20:40:00.000-03:002008-08-27T20:40:00.000-03:00this was quite useful, thank you. i needed to wri...this was quite useful, thank you. i needed to write an incrementor plugin to increment all numbers within a set, but getting at the text nodes was challenging which your routine solved for me.<BR/><BR/>jQuery.fn.incr = function(amount, fn) {<BR/>amount = typeof amount == 'undefined' ? 1 : Number(amount);<BR/>var fn = fn || function(a){return amount + Number(a);}<BR/>var tr = new Translator(function( text ){<BR/> return text.replace(/(-?\d+)/g, fn );<BR/> });<BR/>this.each(function() {<BR/> tr.traverse(this);<BR/>})<BR/>return this;<BR/>}<BR/><BR/>Also added:<BR/><BR/>jQuery.fn.incrTo = function(amount, fn) {<BR/> return $(this).incr(amount, fn || amount);<BR/>}<BR/><BR/><BR/>Now I can just say $('.votes').incr(1);<BR/>$('.votes').incr(-2);<BR/>$('.votes').incrTo(0);<BR/><BR/>Thanks!<BR/><BR/>(Would be nice if .traverse could be passed a 'deep' argument!)amirhttps://www.blogger.com/profile/13445444925766070474noreply@blogger.comtag:blogger.com,1999:blog-8640596986273216089.post-60437080971171422642008-05-26T20:03:00.000-03:002008-05-26T20:03:00.000-03:00Added a new release!Check the docs, changelog and ...Added a new release!<BR/>Check the docs, changelog and demo to learn more about the update.<BR/><BR/>Added the filtering feature.<BR/><BR/>@1: You can now return an array, it'll solve that problem.<BR/><BR/>@2: Will consider it for 1.0.2.<BR/><BR/>Thanks!Ariel Fleslerhttps://www.blogger.com/profile/17700414222186772120noreply@blogger.comtag:blogger.com,1999:blog-8640596986273216089.post-33035738863978800202008-05-26T19:01:00.000-03:002008-05-26T19:01:00.000-03:00ad 1) an object-based design seems more forward lo...ad 1) an object-based design seems more forward looking as it would keep the signature of the constructor identical as you add more functionality to your translator. For instance, your current code assumes that "parse" returns text that's then transformed into a text node.... but what if I'd like to, say, highlight a word? That would split the text node into multiple text nodes and elements.<BR/><BR/>ad 2) Instead of using recursion, you could use an array as a stack. Then pass the array to the continuation function. In each call, process n array elements.Godmar Backhttps://www.blogger.com/profile/05064247891002006433noreply@blogger.comtag:blogger.com,1999:blog-8640596986273216089.post-31644105569020376642008-05-26T18:27:00.000-03:002008-05-26T18:27:00.000-03:00Hi GodmarThanks for the suggestions:@1: You can ad...Hi Godmar<BR/><BR/>Thanks for the suggestions:<BR/><BR/>@1: You can add the custom data to each translator instance. They will be the scope (this) of the parsing function.<BR/><BR/>@2: I need to think about it a bit. As it's recursive, it's not a straight forward change.<BR/>Note that you can call the translator many times, on different roots, using a delay between each call.<BR/><BR/>@3: I like it, I just saw the place to inject it with just a few more bytes.<BR/>Will add it asap.<BR/><BR/>ThanksAriel Fleslerhttps://www.blogger.com/profile/17700414222186772120noreply@blogger.comtag:blogger.com,1999:blog-8640596986273216089.post-20182491999595412922008-05-26T09:44:00.000-03:002008-05-26T09:44:00.000-03:00Very nice. Three ideas for improvements:- instead...Very nice. Three ideas for improvements:<BR/><BR/>- instead of having take Translator take a function, have it take an object and use a property of the object as callback function. This way, callers can add custom data to receive in the callback. (Use the same technique as in jQuery.ajax).<BR/><BR/>- for large pages, when this script is applied to the root node, it will freeze the page. To avoid this, split the processing into a configurable chunks that are processing in each configurable interval.<BR/><BR/>- finally, a feature that would exclude subtrees that are root in certain elements (such as <a>) would be nice.<BR/><BR/>These three features would significantly simplify the implementation of such functionality as autolinking (for a Firefox script that implements items #2 and #3, see <A HREF="https://www.squarefree.com/userscripts/autolink.user.js " REL="nofollow">Ruderman's autolinking script</A> )Godmar Backhttps://www.blogger.com/profile/05064247891002006433noreply@blogger.comtag:blogger.com,1999:blog-8640596986273216089.post-28101156275189317722008-05-08T09:32:00.000-03:002008-05-08T09:32:00.000-03:00Nice Ariel! Will test against my own script I dev...Nice Ariel! Will test against my own script I developed for this. Well done!<BR/><BR/>Cheers.<BR/><BR/>Joe<BR/><BR/>www.subprint.comJoe McCannhttps://www.blogger.com/profile/08357345760436471708noreply@blogger.com