Hi,

See subject.
Javascript strings are not translated, which is not nice. ALSO, variables are set the "ugly" way at the moment, rather than through teh Drupal.* namespace.

Bye,

Merc.

CommentFileSizeAuthor
#13 drigg-js.patch6.15 KBcedricfontaine

Comments

mercmobily’s picture

Title: Javascript strings are not tanslated, PLUS variables should be passed in a much nicer way » PLUS variables should be passed to JS in a much nicer way

H,

Translations can't happen till D6. So, cancelling the issue (since it will be part of the port).
However, the variables should still be passed nicely to Javascript.

Merc.

mercmobily’s picture

Title: PLUS variables should be passed to JS in a much nicer way » Variables should be passed to JS in a much nicer way

Hi,

Wooops fixed the title.

Merc.

sikjoy’s picture

Hi mercmobily:

Just to be clear: do you mean using drupal_add_js(array()) to pass in the variables? How is it currently being done?

--sicjoy

mercmobily’s picture

Hi,

Yeah, that's what I want to do. Feel free to send a patch... Right now, the module does a rather ugly thing: spits out javascript assigns which is not the best...

Bye!

Merc.

sikjoy’s picture

Assigned: Unassigned » sikjoy
mercmobily’s picture

Hi,

One note: just look at the DRULPAL-5 version of extra_voting_forms -- I've just received a patch that, amongst other things, does that too!

Merc.

sikjoy’s picture

Hi Merc:

I see that in extra_voting_forms you passed in the variables in the hook_init function.

Is there any reason the drupal_add_js call shouldn't be in the hook_menu function under !may_cache?

--sicjoy

mercmobily’s picture

Hi,

I prefer to use hook_menu myself. init() may be dangerous, because in aggressive caching it's not called.
If you test it, and notice that it works fine in hook_menu, please change extra_voting_forms as well!

Merc,

mercmobily’s picture

Category: bug » feature
mercmobily’s picture

Hi,

To clarify what should be done about this issue...
Right now, in drigg.module we have:

function drigg_form(&$node, &$param)

Javascript variables are defined this way:

 if ($node->nid) {
    $editing_var = 'var drigg_editing_node = '. $node->nid .';';
  }
  else {
    $editing_var = 'var drigg_editing_node = 0;';
  }

Then, in drigg.js:

var DriggValidateURL = function(elem, prefix, errtype, check) {
        var entry = $(elem);
        var args = {};
        args.operation = 'validate_url';
        args.url = entry.val();

        if(drigg_editing_node){
          args.editing_node=drigg_editing_node;
        }

This is immensely ugly.

On the other hand, extra_voting_forms does this right:


  // Add our JavaScript variables:
    drupal_add_js(array(
      'extra_voting_forms' => array(
        // Set the right javascript to see of only one vote is allowed:
        'only_one_vote' => variable_get('extra_voting_forms_only_one_vote', FALSE) && ! user_access('voting administrator') ? 1 : 0,
        // Set the anonymous URL:
        'login_page' => extra_voting_forms_anonymous_url(),
        // Get the base path:
        'base_path' => base_path()
       )
      ), 'setting'
    );

And then for example to get the only_one_vote variable, in extra_voting_forms.js:

if (Drupal.settings.extra_voting_forms.only_one_vote) {
    // Disable the drop-down select elements by setting their "disabled" attribute

MUCH neater!
This is a VERY simple patch. However, the catch is in the _careful_ testing it requires.

Does this make sense?

Merc.

cedricfontaine’s picture

I'm working on it. Just a problem : We do initialize var drigg_do_validation = 1; but I can't find anywhere in code where it's been used.

Any help would be appreciated.

Also, could we pass the 6 non translated strings also ? It would help to translate...

mercmobily’s picture

Hi,

About drigg_do_validation: I think it was used i n the past, and got zapped later.
I think you're right: it's not used and can (should) go.

About the string translation: I want to be careful about it. I read something about a translation architecture for Javascript strings for Drupal 6. I don't think they were backporting it. So, I think i would much rather do it "the drupal way" when the D6 port happens, rather than doing it now. It's sort of a separate issue -- let's keep it separate.

I might be wrong. There might be a neat, proper way to translate things right now. But again, it's a separate issue...!

Merc.

cedricfontaine’s picture

StatusFileSize
new6.15 KB

Here is a patch tested and running

mercmobily’s picture

Status: Active » Fixed

Hi,

Another long term task fixed -- THANK YOU cedric!

Merc.

mercmobily’s picture

Status: Fixed » Closed (fixed)