Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Inline Editor Close Button #5443

Merged
merged 8 commits into from
Oct 10, 2013
Merged

Inline Editor Close Button #5443

merged 8 commits into from
Oct 10, 2013

Conversation

VizuaaLOG
Copy link
Contributor

I have added a close button to the inline editor as was requested here #5441. The unit test was successful. Please review the work and leave any feedback.

@marcelgerber
Copy link
Contributor

Works fine for me, unit tests were successful.

@larz0
Copy link
Member

larz0 commented Oct 9, 2013

Thanks @VizuaaLOG, looks good.

@njx we should do the same for color editor as well right?

(Tagging @redmunds for the upcoming bezier editor.)

screen shot 2013-10-08 at 8 51 57 pm

@marcelgerber
Copy link
Contributor

If we do this in the color editor, we should also do this in WebDocs.
But I wonder if there is a way to ingegrate this in every inline editor, also if it is called ba an extension. That would maybe be a better solution.

@VizuaaLOG
Copy link
Contributor Author

@larz0 Thanks :).

@SAplayer I could look into if the inline editors have any classes in common and then add it in that way.

@njx
Copy link

njx commented Oct 9, 2013

@VizuaaLOG Take a look at InlineWidget (which is the base class for all the inline editors) and see if you can put it in there in a reasonable way.

@marcelgerber
Copy link
Contributor

@njx I tried this (b25fd99890ffcae5ecf3ed305a6ed6c78aaa70aa) - the result works for WebDocs, but not for the Inline Editor, because it is would be underneath the scrollbar (not visible). The problem is, we haven't got a default way/element for the InlineWidget. Every (default) extension has its own way to create an InlineWidget.

@VizuaaLOG
Copy link
Contributor Author

@SAplayer @njx I think it will work on all inline widgets. I moved the code into InlineWidgets.js and changed it slightly. I also edited the styles in brackets.less so that it should always be positioned in the same place.

// create the close button
var $closeBtn = this.$htmlContent.append("<a href='#'' class='close' id='inline-close'>&times;</a>");

$closeBtn .on("mouseup", function(e) {
Copy link
Contributor

Choose a reason for hiding this comment

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

@VizuaaLOG
Please edit your code in Brackets with the default JSLint on. You will see some JSLint errors on this line telling you to have exactly one space after function and should not have extra white spaces before .on.

@VizuaaLOG
Copy link
Contributor Author

@RaymondLim Fixed the jslint errors.

@RaymondLim
Copy link
Contributor

@VizuaaLOG Your close button works, but focus gets lost after clicking on it though. If you start typing after using the close button, nothing shows up in the editor.



// create the close button
var $closeBtn = this.$htmlContent.append("<a href='#'' class='close' id='inline-close'>&times;</a>");
Copy link
Contributor

Choose a reason for hiding this comment

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

You have an extra single quote after href='#' and this extra quote is causing it to be an invalid element (at least for some jQuery apis). This is why focus gets lost after using the close button.

@ghost ghost assigned RaymondLim Oct 10, 2013
@VizuaaLOG
Copy link
Contributor Author

I fixed the extra quote problem however the focus is still lost when clicking the close button. I thought about doing editor.focus() however the only way i can do this is by requiring the editor.js file in InlineWidget.js. If you have any other solutions please say. I am still currently looking for another way.

@larz0
Copy link
Member

larz0 commented Oct 10, 2013

@VizuaaLOG just letting you know we've decided to move the close button to the left so that it can be more consistent with other inline editors and quick doc. Thanks for you help!

4deb3b76-3096-11e3-82d1-3127cb78e806

@VizuaaLOG
Copy link
Contributor Author

@larz0 Ok, i fixed the focus problem. Also did you want me to commit it on the left or has it already been done?



// create the close button
this.$closeBtn = this.$htmlContent.append("<a href='#' class='close' id='inline-close'>&times;</a>");
Copy link
Contributor

Choose a reason for hiding this comment

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

This assignment is wrong. You're assigning the entire inline widget as close button. What you want is create an element with your "a" tag and assign it to the close button before appending it to $htmlContent.

Now with this code you can close the inline editor just clicking anywhere inside the inline.

@RaymondLim
Copy link
Contributor

@VizuaaLOG Larz is informing you to move the button to the left since you're working on it. So we're waiting for your commit.

@larz0
Copy link
Member

larz0 commented Oct 10, 2013

@VizuaaLOG yes please :)

@VizuaaLOG
Copy link
Contributor Author

Ok no problem will fix the problem with the entire widget being a close button then will commit the new changes

@VizuaaLOG
Copy link
Contributor Author

Just wondering if someone could help me :). I have changed the close button code to this

// create the close button
var closeBtn = "<a href='#' class='close' id='inline-widget'>&times;</a>";
closeBtn.click(function (e) {
    self.close();
    e.stopImmediatePropagation();
});
this.$htmlContent.append(closeBtn);

However i get the following error in dev tools Uncaught TypeError: Object <a href='#' class='close' id='inline-widget'>&times;</a> has no method 'click'. Am i missing something or have i misunderstood what @RaymondLim said?

@RaymondLim
Copy link
Contributor

You need to wrap your link element with $() and create an jQuery object and also prefix your variable with $ to indicate that it's a jQuery object.

@VizuaaLOG
Copy link
Contributor Author

Thanks it worked :) Just about to commit the changes

@marcelgerber
Copy link
Contributor

I think you missunderstood him again (perhaps your method works, but it isn't nice). Maybe take a look at 0523bc6.



// create the close button
var closeBtn = $("<a href='#' class='close' id='inline-close'>&times;</a>");
Copy link
Contributor

Choose a reason for hiding this comment

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

It's better to keep it as this.$closeBtn instead of a local variable. Also it is important to prefix with a $ if it is a jQuery object and not a regular HTML element.

@VizuaaLOG
Copy link
Contributor Author

@RaymondLim ok will change it now also is @SAplayer's method better because i think it looks cleaner so i will change it to that.

@RaymondLim
Copy link
Contributor

Yes, @SAplayer's code is better as you're chaining to the existing code with the new close button first.

// create the close button
this.$closeBtn = this.$htmlContent.find("#inline-close");
this.$closeBtn.click(function (e) {
console.log("Clicked");
Copy link
Contributor

Choose a reason for hiding this comment

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

No, please don't leave your debugging code in.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes sorry i noticed it after i committed it so i'm just undoing it then re committing

@VizuaaLOG
Copy link
Contributor Author

I think that is everything. I had to re commit the style because i undid the commits too far :(. But it all works again.

.append("<div class='shadow bottom' />");

.append("<div class='shadow bottom' />")
.append("<a href='#' class='close' id='inline-close'>&times;</a>");
Copy link
Member

Choose a reason for hiding this comment

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

We can't use an id here because there can be multiple inline editors open at once. If you change this to a class it should work fine.

But it seems like you could just use the existing .close class on this node -- the find() call below should still work since it's scoped, and the CSS rule below is already nested under a .inline-widget selector as well.

@VizuaaLOG
Copy link
Contributor Author

I have changed it to use the class and removed the ID and it all still works.

.append("<a href='#' class='close'>&times;</a>");

// create the close button
this.$closeBtn = this.$htmlContent.find('.close');
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Please use double quote for strings as this is our coding convention.

@VizuaaLOG
Copy link
Contributor Author

@RaymondLim Sorry i changed it, need to get used to that because i usually use single quotes.

@RaymondLim
Copy link
Contributor

Looks good now. Merging.

@VizuaaLOG
Copy link
Contributor Author

Ok thanks.

RaymondLim added a commit that referenced this pull request Oct 10, 2013
@RaymondLim RaymondLim merged commit 8b7d501 into adobe:master Oct 10, 2013
@VizuaaLOG VizuaaLOG deleted the inline-editor-close-button branch October 10, 2013 20:57
@larz0
Copy link
Member

larz0 commented Oct 10, 2013

🍻

@RaymondLim
Copy link
Contributor

Oops... Looks like this breaks one of the WebPlatformDocs extensions unit tests. File a new issue #5473 for the unit test failure.

@njx
Copy link

njx commented Oct 10, 2013

I just checked this out and it looks fine everywhere except Quick Docs, where it seems to be causing the content in the right column to shift downward. Filed as #5472.

@VizuaaLOG
Copy link
Contributor Author

I just looked at the problem and it is the margin right to move the content away from the close button. However, i cant think of another way to move the content away from the button. Any ideas?

@larz0
Copy link
Member

larz0 commented Oct 10, 2013

@VizuaaLOG I'll take a look.

@VizuaaLOG
Copy link
Contributor Author

Found the problem and will make a branch to fix it

@njx
Copy link

njx commented Oct 10, 2013

See comments in #5472. I don't think it's necessarily the margin's fault--it might be the fact that we're adding a float into the top level.

@VizuaaLOG
Copy link
Contributor Author

i tried getting rid of the float and it didn't change. The fix i had was changing the left columns's width to 26% which fixes the problem. However i'm new to git and am having some teething troubles with it so i cant fix it :). Will get my git fixed tomorrow then try then

@larz0
Copy link
Member

larz0 commented Oct 10, 2013

@VizuaaLOG sounds good :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants