1

Topic: Very EASY BBcode ?!

Hummmm ... in fact since I have seen minmax.js I suppose JavaScript becomes our "friend" (and cool smile)
...

So I have found a BBcode really easy ...

<script language="Javascript">
var isMozilla = (navigator.userAgent.toLowerCase().indexOf('gecko')!=-1) ? true : false;
var regexp = new RegExp("[\r]","gi");

function storeCaret(selec)
{
    if (isMozilla) 
    {
    // Si on est sur Mozilla

        oField = document.forms['news'].elements['newst'];

        objectValue = oField.value;

        deb = oField.selectionStart;
        fin = oField.selectionEnd;

        objectValueDeb = objectValue.substring( 0 , oField.selectionStart );
        objectValueFin = objectValue.substring( oField.selectionEnd , oField.textLength );
        objectSelected = objectValue.substring( oField.selectionStart ,oField.selectionEnd );

    //    alert("Debut:'"+objectValueDeb+"' ("+deb+")\nFin:'"+objectValueFin+"' ("+fin+")\n\nSelectionné:'"+objectSelected+"'("+(fin-deb)+")");
            
        oField.value = objectValueDeb + "[" + selec + "]" + objectSelected + "[/" + selec + "]" + objectValueFin;
        oField.selectionStart = strlen(objectValueDeb);
        oField.selectionEnd = strlen(objectValueDeb + "[" + selec + "]" + objectSelected + "[/" + selec + "]");
        oField.focus();
        oField.setSelectionRange(
            objectValueDeb.length + selec.length + 2,
            objectValueDeb.length + selec.length + 2);
    }
    else
    {
    // Si on est sur IE
        
        oField = document.forms['news'].elements['newst'];
        var str = document.selection.createRange().text;

        if (str.length>0)
        {
        // Si on a selectionné du texte
            var sel = document.selection.createRange();
            sel.text = "[" + selec + "]" + str + "[/" + selec + "]";
            sel.collapse();
            sel.select();
        }
        else
        {
            oField.focus(oField.caretPos);
        //    alert(oField.caretPos+"\n"+oField.value.length+"\n")
            oField.focus(oField.value.length);
            oField.caretPos = document.selection.createRange().duplicate();
            
            var bidon = "%~%";
            var orig = oField.value;
            oField.caretPos.text = bidon;
            var i = oField.value.search(bidon);
            oField.value = orig.substr(0,i) + "[" + selec + "][/" + selec + "]" + orig.substr(i, oField.value.length);
            var r = 0;
            for(n = 0; n < i; n++)
            {if(regexp.test(oField.value.substr(n,2)) == true){r++;}};
            pos = i + 2 + selec.length - r;
            //placer(document.forms['news'].elements['newst'], pos);
            var r = oField.createTextRange();
            r.moveStart('character', pos);
            r.collapse();
            r.select();

        }
    }
}

</script>

In text Area ...


<form name="news">
<input type="button" value="b" style="width:50px;font-weight:bold" onclick="storeCaret('b')">
<input type="button" value="i" style="width:50px;font-style:italic" onclick="storeCaret('i')">
<input type="button" value="u" style="width:50px;text-decoration:underline" onclick="storeCaret('u')">
<input type="button" value="quote"style="width:50px" onclick="storeCaret('quote')">
<input type="button" value="code"style="width:50px" onclick="storeCaret('code')">
<input type="button" value="url"style="width:50px" onclick="storeCaret('url')">
<input type="button" value="img"style="width:50px" onclick="storeCaret('img')"><br>
<textarea name="newst" id="newst" rows="10" wrap="virtual" cols="45"></textarea>
</form>

Works perfectly under IE et Mozilla ... Are Paul and Rickard OK to include it on future versions ? A lot of people will thanx you smile

Re: Very EASY BBcode ?!

I see specific Gecko/IE code, I'm actually using Safari.
Specific browser code is the worst, JS is lame because it always need different code for each browser.

I vote no.

Re: Very EASY BBcode ?!

I agree with analogue, since it's for specific browser code it wouldn't be a good idea to use it.

So I also vote no (even though I use Mozilla Firefox).

Re: Very EASY BBcode ?!

Any demo?

Digital photography news, reviews, discussions and more!
http://www.shuttertalk.com

The online bible for all
http://www.publicbible.com

5

Re: Very EASY BBcode ?!

mmmmmmmmm how to explain ... do you want this code compatible with Mozaic or Lynx too ?!

mmmmmmmm I see my stats ... Ohhhhhhhhhhh incredible !

IE = 82%

Mozilla / Firefox / Gecko Browser = 14%

ALL OTHER BROWSERS = 4%

Safari = 0,5%


In this case, the SCALING image in 1.2.1 is a problem for you too no ?

SAFARI = minority of the web.

Firefox is on all plateforms ...

Re: Very EASY BBcode ?!

Rod wrote:

Hummmm ... in fact since I have seen minmax.js I suppose JavaScript becomes our "friend" (and cool smile)

not really they only used it because of IEs poor css support

Re: Very EASY BBcode ?!

I've done something similar for a "client". Perhaps I'll throw together a mod. Was it mindplay that had been tinkering with this as well? His Javascript was a bit more ambitious though.

"Programming is like sex: one mistake and you have to support it for the rest of your life."

8 (edited by analogue 2005-02-05 13:29)

Re: Very EASY BBcode ?!

Rod, you are acting exactly the same as those webmasters doing crappy MS-HTML, except you are doing it for Gecko. The purpose of the web is to be usable on any platform and browser, and by any I'm even talking about web clients not running on computers or browsers which event out yet.

Re: Very EASY BBcode ?!

http://punbb.org/forums/viewtopic.php?id=6217

There you go smile

"Programming is like sex: one mistake and you have to support it for the rest of your life."

Re: Very EASY BBcode ?!

analogue wrote:

Rod, you are acting exactly the same as those webmasters doing crappy MS-HTML, except you are doing it for Gecko. The purpose of the web is to be usable on any platform and browser, and by any I'm even talking about web clients not running on computers or browsers which event out yet.

True, but since there aren't any browsers out there that support the standards properly (and there probably never will be), what you do is to design the page according to the standards and then, make tweaks to make it look allright in all the various browsers. There's just no way around that. You can't just ignore browser bugs. You HAVE TO deal with them.

"Programming is like sex: one mistake and you have to support it for the rest of your life."

11 (edited by Mako 2005-02-05 14:54)

Re: Very EASY BBcode ?!

Rod wrote:

mmmmmmmmm how to explain ... do you want this code compatible with Mozaic or Lynx too ?!

mmmmmmmm I see my stats ... Ohhhhhhhhhhh incredible !

IE = 82%

Mozilla / Firefox / Gecko Browser = 14%

ALL OTHER BROWSERS = 4%

Safari = 0,5%


In this case, the SCALING image in 1.2.1 is a problem for you too no ?

SAFARI = minority of the web.

Firefox is on all plateforms ...

Even if it is a minority, you still should make everything work with it.

"You start coding. I'll go find out what they want." - Computer Analyst to Programmer

12

Re: Very EASY BBcode ?!

Hummmmmmmmmmmm

I don't know where is the "bug"

If a user has safari, the BUTTONS don't work ... but TEXTAREA WORKS in Safari no ? (hahahahaa).

So ... This feature is not a nuisance about compatibility. Only this future doesn't work on Safari, but don't prevent user from posting anyway. Right ?

I'm on the web since 1998 ... and you remember me people who wanted to claim "NETSCAPE 4 IS BETTER THAN IE"

Let me laugh, today.

The ONLY browsers which are perfect today are Gecko and Opera. If you want to use an "original" browser, don't cry. Simply.

Re: Very EASY BBcode ?!

Rod wrote:

The ONLY browsers which are perfect today are Gecko and Opera. If you want to use an "original" browser, don't cry. Simply.

no browser is perfect

Re: Very EASY BBcode ?!

Rod wrote:

The ONLY browsers which are perfect today are Gecko and Opera.

I have a feeling Paul wouldn't agree with you on that smile

"Programming is like sex: one mistake and you have to support it for the rest of your life."

15 (edited by alastc 2005-02-05 16:00)

Re: Very EASY BBcode ?!

Whilst agreeing with Analogue, I'd suggest that a similar effect could be used without browser specific code, but detecting for support of the required features.

I.e. detect a modern browser by using something like:

if(mostComplicateFeatureNeeded) {
(stuff here)
} 
else return false;

My JavaScript knowledge is v. hazy and this is off the cuff, but I'm fairly sure about the principle.

16

Re: Very EASY BBcode ?!

To damn right. Firefox maybe pretty standards compliant but its broken. IE is not standards compliant but once you have applied the relevant hacks it actually renders pages better than Firefox. As for Opera, its getting better but its amazing how many times I have seen pages render different in Firefox and Opera, both can't be right. Oh, and the way form elements are rendered in IE is better than all the others.

As for minmax, I hate it but it's a necessary evil. It's only function is to make IE emulate {max-width: 100%} which Gecko, Opera and, I think, Safari 1.2 get anway. The only people who are screwed by it will be those using IE5 Mac but they are screwed by just about everything.

17

Re: Very EASY BBcode ?!

Paul wrote:

it will be those using IE5 Mac but they are screwed by just about everything

Too funny smile but you touch ONE point : why peole accept this about MAC and not about SAFARI ? In 2 cases, they are VERY VERY VERY FAR from a standard utilisation.

Some people use electricity for their car. But everyone uses gazoil. Is all done for the one who has electricity ? It's the same case here. If there is no javascript error, I don't see where is the problem to use EASY things like this script (which is very practice) for 95% of users of the NET and they are, SOMEWHERE, compatible with all browsers (degrading well : don't work, but no errors)

18

Re: Very EASY BBcode ?!

Rod: IE5 Mac is old technology and will soon be dead technology, thats why it's legitimate to take the decision to ignore it. Safari is current generation technology on the Mac platform. The fact that only a small proportion of internet users are using Safari is not the point. On a Mac orientated site 90% of members might be using Safari. Plus of course Safari is pretty standards compliant so any up-to-date site ought to work on Safari.

If webmasters want to modify PunBB to work better for their particular audience thats fine, in fact it's a very sensible way to go about things. Equally, it's fine to have mods which will only work on particular platforms or in particular browsers provided it's made clear in the mods release information.

P.S. It's no using asking if I'm OK with something, I take my instructions from PunBB World Wide HQ, I'm just the British branch office.

Re: Very EASY BBcode ?!

Rod wrote:

If a user has safari, the BUTTONS don't work ... but TEXTAREA WORKS in Safari no ? (hahahahaa).

What's so funny ? And what's your point ? Safari is a very cool browser, and I'm not a Mac addict, I just own an iBook. My point here is to not bloat PunBB, you can do what you want in a mod, or you can use BB extensions for firefox, but it's wrong to ask Rickard to put it in the core release.