List Info

Thread: Including other JS files and using "class" and custom styles




Including other JS files and using "class" and custom styles
user name
2006-08-04 08:18:51
Hi all
 I hope that, even if these are very basic questions,
someone could give 
me some hints.

   1. Does it work including an external Javascript script
inside a GM
      script?
      For instance, if I want to include some "AJAX
effects" and want to
      use one of the Open Source javascript libraries out
there...
   2. In my GM script I am programmatically creating ALL the
widgets
      that I need.
      Is there a way where I could use some "static
HTML" to shortcut
      the development time? If yes, does someone have an
example?
   3. one of the issues related to my poor knowledge of JS
is that, when
      programmatically creating my widgets, I do not know
how to set a
      custom CSS class (the equivalent of saying <div
class="myclass">
      ..... how can I specify in Javascript this?)
   4. associated to the latter. If I create my own CSS
classes, can I
      store their definition in a CSS style sheet file and
"import" it
      in the GM script? If yes, how?

   5. Final one. Can I use XUL inside a GM script?

Thanks a lot for your help and patience
/Stefano

_______________________________________________
Greasemonkey mailing list
Greasemonkeymozdev.org
http:
//mozdev.org/mailman/listinfo/greasemonkey
Including other JS files and using "class" and custom styles
user name
2006-08-04 13:32:43
On 8/4/2006 4:18 AM, Stefano POGLIANI wrote:
>   1. Does it work including an external Javascript
script inside a GM
>      script?

The only straightforward way is to copy and paste the source
in. 
There's no "include" statement like in some
other languages.

>   2. Is there a way where I could use some
"static HTML" to shortcut
>      the development time? If yes, does someone have an
example?

There's a number of ways.  For example:
http://www.a
rantius.com/article/dollar-e

>   3. one of the issues related to my poor knowledge of
JS is that, when
>      programmatically creating my widgets, I do not
know how to set a
>      custom CSS class (the equivalent of saying <div
class="myclass">
>      ..... how can I specify in Javascript this?)

Since "class" is a reserved word in JavaScript,
you have to use 
something else.  In this case, className.

>   4. associated to the latter. If I create my own CSS
classes, can I
>      store their definition in a CSS style sheet file
and "import" it
>      in the GM script? If yes, how?

Yes.
http://diveintogreasemonkey.org/patterns/add-css.html

>   5. Final one. Can I use XUL inside a GM script?

That question is a bit too open ended for me to understand
fully; I 
can't be sure, because I don't know what you're really
trying to do, but 
I suspect the answer is no.
_______________________________________________
Greasemonkey mailing list
Greasemonkeymozdev.org
http:
//mozdev.org/mailman/listinfo/greasemonkey
Including other JS files and using "class" and custom styles
user name
2006-08-04 13:42:17
Thanks Anthony!

Do you have an example of use of "className" in
Javascript?

also, as I read the "Dive into GM" page, it
seems that if the newly 
defined "class" gets added an  "!
important;" at the end, the definition 
overrides the previous one.
Could this approach be used to "sort of" RESET
any stylesheet attribute 
that would apply to the elements I am defining in my page?
The issue here is to avoid that page-specific stylesheets
affect the 
display of my widgets in the page (so that on one page my
DIV will paint 
in one way and, on a different page, it will paint in  a
different way).


As to the XUL question. I was wondering if, for instance,
with GM I 
could create a little XUL container which could, then, be
embedded in 
soething like the "All-in-One Sidebar"
extension.

Thanks
/Stefano

Anthony Lieuallen wrote:
> On 8/4/2006 4:18 AM, Stefano POGLIANI wrote:
>>   1. Does it work including an external Javascript
script inside a GM
>>      script?
>
> The only straightforward way is to copy and paste the
source in. 
> There's no "include" statement like in
some other languages.
>
>>   2. Is there a way where I could use some
"static HTML" to shortcut
>>      the development time? If yes, does someone
have an example?
>
> There's a number of ways.  For example:
> http://www.a
rantius.com/article/dollar-e
>
>>   3. one of the issues related to my poor knowledge
of JS is that, when
>>      programmatically creating my widgets, I do not
know how to set a
>>      custom CSS class (the equivalent of saying
<div class="myclass">
>>      ..... how can I specify in Javascript this?)
>
> Since "class" is a reserved word in
JavaScript, you have to use 
> something else.  In this case, className.
>
>>   4. associated to the latter. If I create my own
CSS classes, can I
>>      store their definition in a CSS style sheet
file and "import" it
>>      in the GM script? If yes, how?
>
> Yes.
> http://diveintogreasemonkey.org/patterns/add-css.html
>
>>   5. Final one. Can I use XUL inside a GM script?
>
> That question is a bit too open ended for me to
understand fully; I 
> can't be sure, because I don't know what you're
really trying to do, 
> but I suspect the answer is no.
> _______________________________________________
> Greasemonkey mailing list
> Greasemonkeymozdev.org
> http:
//mozdev.org/mailman/listinfo/greasemonkey


_______________________________________________
Greasemonkey mailing list
Greasemonkeymozdev.org
http:
//mozdev.org/mailman/listinfo/greasemonkey
Including other JS files and using "class" and custom styles
user name
2006-08-04 13:50:12
On 8/4/2006 9:42 AM, Stefano POGLIANI wrote:
> Do you have an example of use of
"className" in Javascript?

Uh..
var div=document.createElement('div');
div.className='foo';

> also, as I read the "Dive into GM" page, it
seems that if the newly 
> defined "class" gets added an  "!
important;" at the end, the definition 
> overrides the previous one.

The "! important" clause relates to specificity:
h
ttp://www.w3.org/TR/CSS21/cascade.html#specificity
It makes that rule "more specific" than anything
else.

> Could this approach be used to "sort of"
RESET any stylesheet attribute 
> that would apply to the elements I am defining in my
page?

There's a GM api to do this .. I think it's only in CVS
versions at this 
point.  I can't remember its name, but someone will come up
with it.

> As to the XUL question. I was wondering if, for
instance, with GM I 
> could create a little XUL container which could, then,
be embedded in 
> soething like the "All-in-One Sidebar"
extension.

Can't say, for sure.
_______________________________________________
Greasemonkey mailing list
Greasemonkeymozdev.org
http:
//mozdev.org/mailman/listinfo/greasemonkey
Including other JS files and using "class" and custom styles
user name
2006-08-04 22:19:32
I can't remember what the status of this whole discussion
is anymore.

Has anyone suggested another metadata statement, like
"library 
userscript_library.user.js".
(since include is already defined; the
".user.js" could be implied and 
auto-appended if absent)
The desired file could be in the standard user script
directory.
This would be fairly easy to do and support. (relatively, I
think)
You could just "install" the library 'module',
but not include it to 
anything, just to get
it into the directory for reference with the library
meta statement.

As for XUL, no, that is chrome-only, which you could do if
you compiled 
your GmScript
into an extension and then added the XUL stuff.

_______________________________________________
Greasemonkey mailing list
Greasemonkeymozdev.org
http:
//mozdev.org/mailman/listinfo/greasemonkey
Including other JS files and using "class" and custom styles
user name
2006-08-05 22:53:25
> I can't remember what the status of this whole
discussion is anymore.
>
> Has anyone suggested another metadata statement, like
"library
> userscript_library.user.js".

It has been suggested, and there has even been floating
around some
code to implement it. Unfortunately it still has not made it
into a
released Greasemonkey version, for reasons I don't remember
(they may
not have been aired publicly yet, for instance).

-- 
 / Johan Sundström, http://ecmanaut.blogspo
t.com/
_______________________________________________
Greasemonkey mailing list
Greasemonkeymozdev.org
http:
//mozdev.org/mailman/listinfo/greasemonkey
Including other JS files and using "class" and custom styles
user name
2006-08-05 23:44:44
On 8/5/06, Johan Sundström <oyasumigmail.com> wrote:
> It has been suggested, and there has even been floating
around some
> code to implement it. Unfortunately it still has not
made it into a
> released Greasemonkey version, for reasons I don't
remember (they may
> not have been aired publicly yet, for instance).

No particular reason, except that nobody has had time to do
it. We
should not be adding random code (no offense) to GM just
because a
patch exists.

Anyway, yes I know this is a very popular request. It's
near the top
of the list of things to do.

- a
_______________________________________________
Greasemonkey mailing list
Greasemonkeymozdev.org
http:
//mozdev.org/mailman/listinfo/greasemonkey
Including other JS files and using "class" and custom styles
user name
2006-08-06 12:17:03
On 8/6/06, Aaron Boodman <zboogsgmail.com> wrote:
> On 8/5/06, Johan Sundström <oyasumigmail.com> wrote:
> > It has been suggested, and there has even been
floating around some
> > code to implement it. Unfortunately it still has
not made it into a
> > released Greasemonkey version, for reasons I
don't remember
> > (they may not have been aired publicly yet, for
instance).
>
> No particular reason, except that nobody has had time
to do it. We
> should not be adding random code (no offense) to GM
just because
> a patch exists.

Certainly not; code review and working it in the right way
is never optional.

Is there anything one can do as a non-committer to help the
cause?
(It's a very high up wishlist item of mine, too, since it
would reduce
most of my everyday GM scripting code payloads to fewer
lines than the
GM script documentation and header itself.)

-- 
 / Johan Sundström, http://ecmanaut.blogspo
t.com/
_______________________________________________
Greasemonkey mailing list
Greasemonkeymozdev.org
http:
//mozdev.org/mailman/listinfo/greasemonkey
Including other JS files and using "class" and custom styles
user name
2006-08-07 07:28:41
The easiest way to do it without having to worry about any
complexity and
such would be to just read the library file and insert it
into the injected
script right before injection. The only
"problem" with this is that the
code would have multiple instances, which is only a
"memory space thing".
They would all be sandboxed, so it wouldn't matter that
there were multiple
instances of the library code. (not optimal, but it would be
easy, and 
would work)

Alternately, I was thinking on a way to treat each library
as an object, 
with
each function a method of that object, with Gm being the
(initial) link 
between
the scripts and calls to the object methods, since there
would be a 
timing issue
of when the library was injected itself and available for
calls.

So, initially, when you make a call to the object method,
you might actually
get "caught" by Gm, which would finish the call
once the library code 
(object)
was available, and would then modify the calling script's
object value 
so that
calls to the methods would be direct after that. This may or
may not work or
be viable or optimal, I was just mulling it over.

I think with anything other than my first idea, you have to
be careful 
because
of security concerns and the like, which makes
implementation more complex.

Unless someone has already worked out something better that
I don't 
remember.

_______________________________________________
Greasemonkey mailing list
Greasemonkeymozdev.org
http:
//mozdev.org/mailman/listinfo/greasemonkey
Including other JS files and using "class" and custom styles
user name
2006-08-10 20:36:18
Bill

    how would you do for the first suggestion? Is this
"pasting" the
external script code inside the current GM script or is
there a coolest
way to do?

I just tried the GM_xmlhttpRequest approach from Philip but
in my case
it did not work as the "eval" seems not to
return.

Thanks
Best regards
/Stefano

Bill Donnelly wrote:
> The easiest way to do it without having to worry about
any complexity and
> such would be to just read the library file and insert
it into the 
> injected
> script right before injection. The only
"problem" with this is that the
> code would have multiple instances, which is only a
"memory space thing".
> They would all be sandboxed, so it wouldn't matter
that there were 
> multiple
> instances of the library code. (not optimal, but it
would be easy, and 
> would work)
>
> Alternately, I was thinking on a way to treat each
library as an 
> object, with
> each function a method of that object, with Gm being
the (initial) 
> link between
> the scripts and calls to the object methods, since
there would be a 
> timing issue
> of when the library was injected itself and available
for calls.
>
> So, initially, when you make a call to the object
method, you might 
> actually
> get "caught" by Gm, which would finish the
call once the library code 
> (object)
> was available, and would then modify the calling
script's object value 
> so that
> calls to the methods would be direct after that. This
may or may not 
> work or
> be viable or optimal, I was just mulling it over.
>
> I think with anything other than my first idea, you
have to be careful 
> because
> of security concerns and the like, which makes
implementation more 
> complex.
>
> Unless someone has already worked out something better
that I don't 
> remember.
>
> _______________________________________________
> Greasemonkey mailing list
> Greasemonkeymozdev.org
> http:
//mozdev.org/mailman/listinfo/greasemonkey




_______________________________________________
Greasemonkey mailing list
Greasemonkeymozdev.org
http:
//mozdev.org/mailman/listinfo/greasemonkey
[1-10] [11]

about | contact  Other archives ( Real Estate discussion Medical topics )