04: FINDing your Way Around

This is a temporary forum setup for the purpose of discussing the EMC standards
Locked
User avatar
markus_petrux
Registered User
Posts: 376
Joined: Fri Jun 18, 2004 10:58 pm
Location: Girona, Catalunya (Spain)
Contact:

Re: 04: FINDing your Way Around

Post by markus_petrux » Thu Nov 25, 2004 8:31 pm

...or you can do something like:

Code: Select all

#
# ---[ OPEN ]----------
#
templates/subSilver/overall_header.tpl
#
# ---[ FIND ]----------
#
<body
#
# ---[ BEFORE ADD ]----------
#
<script language="javascript" type="text/javascript">
<!--
function doOnLoad()
{
	if( oldOnLoad )
	{
		oldOnLoad();
		oldOnLoad = null;
	}
	// my onload stuff goes here...
	// ...
	// ...
}
var	oldOnLoad = window.onload;
window.onload = doOnLoad;
// -->
</script>
#
# ---[ SAVE ]----------
#

spooky2280
Registered User
Posts: 4
Joined: Mon Nov 15, 2004 3:15 am
Contact:

Re: 04: FINDing your Way Around

Post by spooky2280 » Fri Nov 26, 2004 3:44 am

It works... and not.

I forgot to mention in my previous post that window.onload and an onload event in the body tag are the same event, and the last one to appear in the document will override any handler previously called by window.onload or even <body onload=...> if there is a window.onload later in the document. Play to comment and uncomment this and you'll see what I mean:

Code: Select all

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>_</title>

<!-- START not my MOD -->
<script>
window.onload = a; // 1
function a()
{
	document.title+='1';
}
</script>
<!-- FIN not my MOD -->

<!-- START my MOD -->
<script>
function b()
{
	if (c)
	{
		c();
		c = null;
	}
	document.title+='2';
}
var c = window.onload;
window.onload = b; // 2
</script>
<!-- FIN my MOD -->

</head>
<!-- 3 and 4 -->
<body onload="document.title+='3'" onload="document.title+='4'">
&nbsp;
</body>
</html>

<!-- START not my MOD -->
<script>
window.onload = cc; // 5 (overrides the onload event of the body tag)
function cc()
{
	document.title+='5';
}
</script>
<!-- FIN not my MOD -->

<!-- START my MOD -->
<script>
function d()
{
	if (e)
	{
		e();
		e = null;
	}
	if (f)
	{
		f();
		f = null;
	}
	document.title+='6';
}
var e = document.body.getAttribute('onload'); // 3 a second time
document.body.onload = null; // cancel the first 3 so it fires only once
var f = window.onload;
window.onload = d; // 6
document.title+='fired :';
</script>
<!-- FIN my MOD -->

Quite the conundrum if you don't want to screw up any other Javascript MOD...

User avatar
markus_petrux
Registered User
Posts: 376
Joined: Fri Jun 18, 2004 10:58 pm
Location: Girona, Catalunya (Spain)
Contact:

Re: 04: FINDing your Way Around

Post by markus_petrux » Fri Nov 26, 2004 4:18 am

If you are concerned about other MODs breaking your onload event, you can place your javascript just before the </body> tag.

However, you can't control if other javascripts running on the same page are badly coded or buggy.

There's a correct way to code an onload event. I mean, it should take care of other scripts running on the same page possibly using their own onload events as well. IMHO, if you do it correctly and your script is broken by another one, then that's not your problem.

If you want to see an example on how I use the onload event, take a look at the Select Expand BBCodes MOD:
http://www.phpbb.com/phpBB/viewtopic.php?t=229348" target="_blank

I have not had any similar problem... yet! ;)

spooky2280
Registered User
Posts: 4
Joined: Mon Nov 15, 2004 3:15 am
Contact:

Re: 04: FINDing your Way Around

Post by spooky2280 » Fri Nov 26, 2004 6:38 am

The question still remains: Does EasyMod allow some kind of "if else" for these sticky situations?
If you are concerned about other MODs breaking your onload event
I'm also concerned about my MOD not breaking other onload events. Right now, I've found a way to not use onload event at all for window and body:
http://www.phpbb.com/phpBB/viewtopic.ph ... 29#1329229" target="_blank


I've looked at your MOD. Very interesting scripting indeed. You don't code like me at all. I have a lot a things to learn from your code. Would you care eventually to answer my questions? Don't worry, I usually google my way to knowledge. ;)

Things I have to dig about your code:
  • this.T = [];
    (shortcut for new Object ???)
  • this.size = this.min = 40;
    (2 equals??)
  • _SXBB.prototype.genCmd = function(cmd, txt)
    (never experienced with prototype and this way to create a function. What's the pros and cons?)
  • else if( document.createRange && (document.getSelection || window.getSelection) )
    {
    // Works on: Netscape/Mozilla/Konqueror/Safari
    // To be confirmed: Konqueror/Safari use window.getSelection ?
    r = document.createRange();
    r.selectNodeContents(o);
    s = window.getSelection ? window.getSelection() : document.getSelection();
    s.removeAllRanges();
    s.addRange(r);
    }
    (thought only IE supported selection)
  • if( window.addEventListener )
    Didn't know about this W3C way to attach an event
  • // The 'legacy' method
    (what is Legacy?)
  • for( var id in SXBB )
    (I'm clueless about this syntax)
  • moveToElementText
    (an IE method I haven't noticed before?)
If you care to comment these, let's do it by PM so this thread won't go off topic. Anyways, now I have a great day ahead of me with all these new things to learn :)
// Any better way to detect IEMac?
I don't know about better, but here's mine:

Code: Select all

var IsIEMac = (!window.showModelessDialog && window.ActiveXObject && document.getElementById);
And here's Peter-Paul Koch's way,
http://www.quirksmode.org/index.js" target="_blank

Code: Select all

var bugRiddenCrashPronePieceOfJunk = (
	navigator.userAgent.indexOf('MSIE 5') != -1
	&&
	navigator.userAgent.indexOf('Mac') != -1
);

User avatar
markus_petrux
Registered User
Posts: 376
Joined: Fri Jun 18, 2004 10:58 pm
Location: Girona, Catalunya (Spain)
Contact:

Re: 04: FINDing your Way Around

Post by markus_petrux » Sat Nov 27, 2004 2:01 am

spooky2280 wrote:The question still remains: Does EasyMod allow some kind of "if else" for these sticky situations?
Short answer: Nope.


Offtopic follows: :?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  • this.T = [];

    This is the as:
    this.T = new Array();
  • this.size = this.min = 40;

    This is the same as:
    this.size = 40;
    this.min = 40;
  • _SXBB.prototype.genCmd = function(cmd, txt)
    This syntax allows to extend the base definition of the object (supported since javascript 1.2, I believe).

    This is the same effect as this syntax:

    Code: Select all

    function foo(id)
    {
       this.id = id;
       this.bar = bar;  // <-- attach method bar to object foo
       return this;
    }
    function bar()
    {
       return this.id;
    }
    Pros: It allows to dessign a cleaner object constructor.
    Cons: AFAIK, None. Javascript 1.2 was introduced by NS4 I believe. Who cares about javascript enabled browsers older than NS4/IE4 these days?
  • (thought only IE supported selection)
    Well, Netscape introduced its own way too. None of them supported by the DOM. Opera tries to follow the DOM to the letter, so it does support any kind of text selection.
  • for( var id in SXBB )

    This allows to walk through the elements of "named arrays". Example of a named array:
    var a = [];
    a['foo'] = 1;
    a['bar'] = 2;
Thanks for the tip on IEMac detection. :)

spooky2280
Registered User
Posts: 4
Joined: Mon Nov 15, 2004 3:15 am
Contact:

Re: 04: FINDing your Way Around

Post by spooky2280 » Sat Jan 15, 2005 9:47 pm

Is there a built-in function in EasyMod to FIND the end of the file, whatever is at the end? OPEN (file) FIND (end???) AFTER, ADD (...)

I need it for viewtopic_body.tpl

User avatar
Nux
Registered User
Posts: 943
Joined: Tue Jun 14, 2005 5:09 pm
Location: 3cities, Poland
Contact:

Re: 04: FINDing your Way Around

Post by Nux » Fri Dec 09, 2005 2:23 pm

I installed 2.0.18 manually and saw that the MOD for it is using FIND in ways I didn't know of... So I want to straighten things up a bit.

Let's assume that we work on the following file:

Code: Select all

This is the first line.
This is the second line.
This is the third line.
This is the fouth line.
Examples/Questions
  1. I use:

    Code: Select all

    #-----[ OPEN ]------
    input
    
    #-----[ FIND ]------
    This
    This
    
    #-----[ REPLACE WITH ]------
    blah
    
    The output file is:

    Code: Select all

    blah
    This is the third line.
    This is the fouth line.
    
    correct?
  2. Code: Select all

    #-----[ OPEN ]------
    input
    
    #-----[ FIND ]------
    This
    This
    
    #-----[ IN-LINE FIND ]------
    This
    
    #-----[ IN-LINE FIND ]------
    This
    
    #-----[ IN-LINE REPLACE WITH ]------
    blah
    
    The output file is:

    Code: Select all

    This is the first line.
    blah is the second line.
    This is the third line.
    This is the fouth line.
    
    correct?
  3. Code: Select all

    #-----[ OPEN ]------
    input
    
    #-----[ FIND ]------
    the
    #-----[ IN-LINE FIND ]------
    the
    #-----[ IN-LINE REPLACE WITH ]------
    a
    
    #-----[ FIND ]------
    the
    #-----[ IN-LINE FIND ]------
    the
    #-----[ IN-LINE REPLACE WITH ]------
    a
    
    #-----[ FIND ]------
    the
    #-----[ IN-LINE FIND ]------
    the
    #-----[ IN-LINE REPLACE WITH ]------
    a
    
    #-----[ FIND ]------
    the
    #-----[ IN-LINE FIND ]------
    the
    #-----[ IN-LINE REPLACE WITH ]------
    a
    #-----[ IN-LINE FIND ]------
    fouth
    #-----[ IN-LINE REPLACE WITH ]------
    fourth
    
    The output file is:

    Code: Select all

    This is a first line.
    This is a second line.
    This is a third line.
    This is a fourth line.
    
    correct?
I'm just wondering if it's all correct and intended?

User avatar
Nux
Registered User
Posts: 943
Joined: Tue Jun 14, 2005 5:09 pm
Location: 3cities, Poland
Contact:

Re: 04: FINDing your Way Around

Post by Nux » Fri Dec 09, 2005 2:32 pm

On a side note:
markus_petrux wrote:
  • (thought only IE supported selection)
    Well, Netscape introduced its own way too. None of them supported by the DOM. Opera tries to follow the DOM to the letter, so it does support any kind of text selection.
Now Opera 8 also supports the selection - it's even better then Mozilla - places the cursor close to the inserted tag (unfortunately it doesn't support shortcut keys).

wGEric
Registered User
Posts: 521
Joined: Wed Jun 11, 2003 2:07 am
Contact:

Re: 04: FINDing your Way Around

Post by wGEric » Fri Dec 09, 2005 10:55 pm

Yes, those are correct. You can use partial FINDs and you can do more than one action on each FIND.
Eric

User avatar
Nux
Registered User
Posts: 943
Joined: Tue Jun 14, 2005 5:09 pm
Location: 3cities, Poland
Contact:

Re: 04: FINDing your Way Around

Post by Nux » Sat Dec 10, 2005 3:38 am

Hm... So the second one should work too? I'm wondering because it searches IN-LINE in multiple (found) lines. It's a nice feature if it's intended, but I don't know if it is.

Locked