Forum code listings : folding + quick selection

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Blue
Addict
Addict
Posts: 868
Joined: Fri Oct 06, 2006 4:41 am
Location: Canada

Forum code listings : folding + quick selection

Post by Blue »

I would very much appreciate having a button to fold code sections in forum postings.
It would make following discussions a lot easier, especially where participants offer very long code examples; it would as well seriously diminish all the scrollling required to follow topics.

Additionally, having a button to select the code in one shot would be quite practical, especially when the code is lengthy.
"That's not a bug..." said the programmer. "it's a feature! "
"Oh! I see..." replied the blind man.
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: Forum code listings : folding + quick selection

Post by davido »

@Blue,
I was advised, in answer to a similar question, to use the Prosilver Board Style.
The code section is placed in a small scrollable window with the ability to easily highlight all the code with a single click to Select All.
DE AA EB
User avatar
Blue
Addict
Addict
Posts: 868
Joined: Fri Oct 06, 2006 4:41 am
Location: Canada

Re: Forum code listings : folding + quick selection

Post by Blue »

Major thanks for that tip, Davido.
I did change the board style and I do love the Select All feature in code boxes.
But i'm surprised. I had no idea that different board styles offered different functionalities.
I thought styles were purely about looks and colours.

But my wishes still stand:
+ a folding function for code sections
+ a select function for code sections in all board styles
"That's not a bug..." said the programmer. "it's a feature! "
"Oh! I see..." replied the blind man.
User avatar
skywalk
Addict
Addict
Posts: 3972
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Forum code listings : folding + quick selection

Post by skywalk »

+1.

I requested this before since subsilverPlus is my preferred skin.
For now I assign this javascript to a bookmark and click it for pages with Code tags.
It's an extra step, but still saves time.

Code: Select all

javascript:var hoch="95px",select="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAAANCAMAAABIK2QJAAAAB3RJTUUH2AYGEg8u3H74gAAAABd0RVh0U29mdHdhcmUAR0xEUE5HIHZlciAzLjRxhaThAAAACHRwTkdHTEQzAAAAAEqAKR8AAAAEZ0FNQQAAsY8L/GEFAAADAFBMVEVFRUWA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0T/pQfyxQAAADZJREFUeJyNjEEKADAMwvz/h+fNWdeOHRekSJCCjSTUMUT6MqKQLqdm4zM7PrP2t+fRvx+Ihw1yH39YLwn1QAAAAABJRU5ErkJggg==",minus="data:image/gif;base64,R0lGODlhCgAKAKIAADMzM//M/93d3WZmZv///wAAAAAAAAAAACH5BAEHAAEALAAAAAAKAAoAAAMVGLrc/mrISQe5+ErBOx9AKI5QaS4JADs=",plus="data:image/gif;base64,R0lGODlhCgAKAKIAADMzM//M/93d3WZmZv///wAAAAAAAAAAACH5BAEHAAEALAAAAAAKAAoAAAMgGDo8+mEQ4mAUosaGG5sEBjJYWQ5ACmAq8AyddWVy+yQAOw==",expandfunc="\n";expandfunc+="function expand_code(img_id)\n",expandfunc+="{\n",expandfunc+=" var node = document.getElementById(img_id);\n",expandfunc+=' node.src = "'+minus+'" ;\n',expandfunc+=" node.onclick = function() { collapse_code(img_id); };\n",expandfunc+=' var node = document.getElementById("c"+img_id);\n',expandfunc+=' node.style.overflow = "visible";\n',expandfunc+=' node.style.height = "100%";\n',expandfunc+="}\n";var collapsefunc="\n";collapsefunc+="function collapse_code(img_id)\n",collapsefunc+="{\n",collapsefunc+=" var node = document.getElementById(img_id);\n",collapsefunc+=' node.src = "'+plus+'" ;\n',collapsefunc+=" node.onclick = function() { expand_code(img_id); };\n",collapsefunc+=' var node = document.getElementById("c"+img_id);\n',collapsefunc+=' node.style.height = "'+hoch+'";\n',collapsefunc+=' node.style.overflow = "scroll";\n',collapsefunc+="}\n";var selectfunc="\n";selectfunc+="function select_code ( img_id )\n",selectfunc+="{\n",selectfunc+=" if ( window.getSelection() && window.getSelection().removeAllRanges() ) {\n",selectfunc+=" window.getSelection().removeAllRanges();\n",selectfunc+=" }\n",selectfunc+=" div_id = img_id - 1000;\n",selectfunc+=' var node = document.getElementById ( "c" + div_id );\n',selectfunc+=" if ( document.createRange() ){;\n",selectfunc+=" range = document.createRange();\n",selectfunc+=" if ( range.selectNode(node) ){;\n",selectfunc+=" range.selectNode(node);\n",selectfunc+=" };\n",selectfunc+=" };\n",selectfunc+=" if ( window.getSelection() && window.getSelection().addRange( range ) ){\n",selectfunc+=" window.getSelection().addRange( range );\n",selectfunc+=" };\n",selectfunc+="}\n";for(var img_id=0,len=document.getElementsByTagName("div").length,script,i=0;len>i;i++)if("codetitle"==document.getElementsByTagName("div")[i].className){var node=document.getElementsByTagName("div")[i],html=node.innerHTML,count=0,code=0;node.innerHTML="<b>Code :</b>",img_id+=1,select_id=img_id+1e3,code=node.nextSibling,code.innerHTML.split("<br>").length-1>=10&&(node.innerHTML+='&nbsp;<img id="'+img_id+'" src="'+plus+'" onclick="expand_code('+img_id+')" />',code.style.height=hoch,code.style.overflow="scroll"),code.id="c"+img_id,node.innerHTML+='&nbsp;<img id="'+select_id+'" src="'+select+'" onclick="select_code('+select_id+')" />'}script=document.createElement("script"),script.innerHTML=expandfunc,script.innerHTML+=collapsefunc,script.innerHTML+=selectfunc,document.body.appendChild(script);
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
User avatar
Blue
Addict
Addict
Posts: 868
Joined: Fri Oct 06, 2006 4:41 am
Location: Canada

Re: Forum code listings : folding + quick selection

Post by Blue »

skywalk wrote:[...]I requested this before since subsilverPlus is my preferred skin.
That was my style of choice until tonight as well.
I only changed it, because of the information provided by Davido.
skywalk wrote:[...]I assign this javascript to a bookmark and click it for pages with Code tags.

Code: Select all

javascript:var [etc...]
Seems like a very smart solution.
And I'd like to be smart too ! 8)
However, i have no clue how to use that with Chrome (Windows 10 x64). :cry:
Any extra information would be appreciated... and much required :oops:

Thank you, Skywalk.
"That's not a bug..." said the programmer. "it's a feature! "
"Oh! I see..." replied the blind man.
User avatar
skywalk
Addict
Addict
Posts: 3972
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Forum code listings : folding + quick selection

Post by skywalk »

Ha, that is the URL of my bookmark in Chrome on Windows 10 x64. Make a bookmark of some site and edit its properties.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Post Reply