Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ticket/10811 AJAX callback "alt_text" insufficiently changes links #759

Merged
merged 4 commits into from Jul 5, 2012

Conversation

nickvergessen
Copy link
Contributor

el.attr('title', alt_text);
el.text(alt_text);
});

/**
* This callback is based on the callback above.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Specify which callback please, I'm sure at some point someone will add another function above this one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@p
Copy link
Contributor

p commented Apr 18, 2012

What should probably be done here is toggle_subscribe callback should call alt_text callback and then perform additional actions needed. Implementing this will necessitate turning anonymous callback functions into named ones.

@nickvergessen
Copy link
Contributor Author

I changed it, now the new callback calls the old one.

@@ -436,14 +436,40 @@ phpbb.add_ajax_callback = function(id, callback)
* the alt-text data attribute, and replaces the text in the attribute with the
* current text so that the process can be repeated.
*/
phpbb.add_ajax_callback('alt_text', function(data) {
phpbb.add_ajax_callback('alt_text', function() {
var el = $(this),
alt_text;

alt_text = el.attr('data-alt-text');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For data attributes you should use .data('alt-text') jQuery method I believe...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was changed from data() to attr() while the jquery PullRequest was made.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, callumacrae already explained it to me. Ignore this note, please.

@callumacrae
Copy link
Contributor

Looks good, except for toogle


phpbb.ajax_callbacks['alt_text'].call(this);

if (el.attr('href').indexOf('unwatch') > 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While this will probably always work, it should really either be >= 0 or > -1 or !== -1

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed

@callumacrae
Copy link
Contributor

Looks good.

@p
Copy link
Contributor

p commented May 1, 2012

The usage of "alt" here is not ideal as "alt text" can be taken to mean "value of alt attribute".

*/
phpbb.add_ajax_callback('toggle_subscribe', function() {
var el = $(this),
alt_text;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I think I said in the original ajax pr, each line should have its own var. I do see that you copy pasted this from elsewhere.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Massive -1 to that. It is harder to read and uses considerably more resources.

There was an interesting talk in an IRC channel ages ago (I'll see if
I can find it later), where it was described as being almost like the
following:

var stuff = ['one'];
stuff.push('two');
stuff.push('three');

Instead of var stuff = ['one', 'two', 'three'];.

Yes, mods can edit the last line, but it looks horrific and is inefficient.

On 1 May 2012, at 03:50, Oleg Pudeyev
reply@reply.github.com
wrote:

el.attr('title', alt_text);
el.text(alt_text);
});

+/**

  • * This callback is based on the alt_text callback.
  • * It replaces the current text with the text in the alt-text data attribute,
  • * and replaces the text in the attribute with the current text so that the
  • * process can be repeated.
  • * Additionally it replaces the icon of the link and changes the link itself.
  • */
    +phpbb.add_ajax_callback('toggle_subscribe', function() {
  • var el = $(this),
  •    alt_text;
    

As I think I said in the original ajax pr, each line should have its own var. I do see that you copy pasted this from elsewhere.


Reply to this email directly or view it on GitHub:
https://github.com/phpbb/phpbb3/pull/759/files#r754507

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I copied it form the callback above

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, it was wrong there and it is wrong here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is it wrong?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the previous pr.

@callumacrae
Copy link
Contributor

I can't see a problem with "alt_text". Most native English speakers
will think alternative, and "alternative_text" is too long, with
nothing else being as descriptive.

On 1 May 2012, at 03:49, Oleg Pudeyev
reply@reply.github.com
wrote:

The usage of "alt" here is not ideal as "alt text" can be taken to mean "value of alt attribute".


Reply to this email directly or view it on GitHub:
#759 (comment)

@travisbot
Copy link

This pull request fails (merged fc3a195 into 2a92fee).


phpbb.ajax_callbacks['alt_text'].call(this);

if (el.attr('href').indexOf('unwatch') !== -1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is rather fragile. I would possibly prefer tracking the state in a data attribute instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as we need to change the value in the link aswell, it doesn't really matter, whether its fragile?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You would then switch between two server-side generated urls rather than assuming you know their contents on the client side.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to rephrase what I said. There should be no url manipulation on the client side. Generate all urls on the server side and switch between them on the client side. To the client side urls should be opaque.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed everything

@travisbot
Copy link

This pull request fails (merged 0ca7295f into 2a92fee).

@travisbot
Copy link

This pull request passes (merged f1056a9 into d998ad4).

p added a commit to p/phpbb3 that referenced this pull request Jul 5, 2012
* nickvergessen/ticket/10811:
  [ticket/10811] Make toogle_subscribe more generic so it can toogle all links
  [ticket/10811] Make it easier for MODs/Extensions to define the alt-text
  [ticket/10811] Make subscribe/unsubscribe repeatable with AJAX
  [ticket/10811] Fix AJAX callback alt_text so it can be repeated.
@p p merged commit f1056a9 into phpbb:develop Jul 5, 2012
@nickvergessen nickvergessen deleted the ticket/10811 branch April 10, 2014 11:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants