A replacement for JavaScript's “alert”
github.com
github.com
If something is that important then you'll usually want to give the user a choice from a set of options - e.g. if the user is doing something that can destroy data without the possibility of undoing their actions then you'll want a dialogue that asks them if they're sure. That should block all other interaction because it really is important. When the user has no input though, and there's nothing they can do but click 'ok', there's no need to use an alert. Just put a message on the screen that's high enough up the page's information hierarchy that they've very likely to see it. Make it sticky (so it's there until the user dismisses it, but doesn't block other actions) if it's something that they need to confirm that they've seen.
Don't force the user to do things your way. Guide the user, sure, but let them do things their way.
So alerts are pretty much a must for us, and the obnoxious interruptions help us make the regulators happy. Getting a nicer alert like this will make our customers a bit happier while still keeping us in compliance.
But our use case is of course not standard. Usually alerts are like Satan.
> if the user is doing something that can destroy data without the possibility of undoing their actions then you'll want a dialogue that asks them if they're sure
if(confirm(....)) { doStuff() } else { cleanup() }
This should at least have a callbacks for the different buttons.In terms of design, I don't like absolute vertical centering. It should be higher on the page. I use 1:2, or 1:1.6 for the top/bottom margin as my "default" modal centering.
http://tristanedwards.me/sweetalert
Unfortunately, there's only one function so this isn't useful if you want to run code when the user cancels the dialog:
https://github.com/t4t5/sweetalert/blob/750a0fd72c3beaa6d4d7...
So, if I click OK am I acknowledging the alert to dismiss it or is performing an action? If I hit cancel am I canceling the alert or canceling the action?
Its still terrible UI. Limiting the options to things like "ok" and "cancel" can be very confusing to the end user.
Don't you agree? {OK} {Cancel}
Are you sure you want to delete? {Yes, delete thing X} {No, keep it}
Would you still find that insufficient communication with the user? No sarcasm, genuinely interested to get your opinion.
sweetAlert('hello')With that said, I think it looks great
1. It's less than 5KB.
2. It overrides the existing alert function.
3. It extends the existing alert function.
What I don't like about Sweet Alert:
1. It's bloated for what it does... > 30KB
2. The short-hand swal doesn't make sense or read well.
That is an absolutely terrible idea. It overrides alert() but doesn't - and can't - duplicate its blocking behavior.
I'm not criticizing you for liking the idea! I can see its appeal myself. I'm criticizing Wow Alert for letting a nifty idea result in bad sofware design.
https://github.com/al0p/wow-alert/blob/b3224bc34fea6a49aac2d...
Their version of window.alert() returns immediately after setting up the alert window and actions - because that's all it is capable of.
If you just drop this into existing code without inspecting each and every alert() call to make sure it doesn't rely on the blocking - both in your own code and every library you use - you will definitely break things.
Far better to leave alert() alone and make this a separate function with its own name.
If you really wanted to, I think you could set up an endpoint on your server to be long polled with synchronous XHR in a while loop, while you set up the popup in an iframe. When the popup is clicked, you send a notification to the server so the next synchronous request returns 200 and you dispose of the iframe.
On searching, I discover someone else has had this crazy idea already - http://stackoverflow.com/questions/16934667/what-methods-are...
I'm surprised that the SO poster got the synchronous XHR approach to work. When I did some tests with Chromium last year they seemed to show that an iframe runs in the same thread as its parent window. I wasn't testing XHR though, just animation.
So if you ever do try this out, I would be interested to hear the results. Thanks!
So I fail to see how using $('#...").foo() in your large project is going to be harder to maintain than rolling your own DOM manipulating library.
So yeah, in my opinion if you opt to use your own solution or a lesser known one, I'd say you're at least a bit of an asshole because 1.) you're assuming you know better than the majority of people (who don't have a problem with using jQuery) or 2.) you're wasting everyone's time by forcing them to learn something new when there's a perfectly fine solution already available.
I can think of ways to not use jQuery, like using d3 instead, but somehow, I don't think that's what you're talking about.
That said, it does everything jQuery does, and more, and in a very nice way IMHO. If you're used to the jQuery syntax sugar, you probably don't like it, but I never liked sugar.
So yeah, a jQuery dependency is a killer for me.
Now this isn't a great use but its one maybe acceptable use if my browser really didn't work on their site.
Confirm dialogs particularly around destructive actions are decent use cases for UI blocking.
Deleted comment
https://camo.githubusercontent.com/3144fa643139adee4eb7d01e2...
We'll be nice and give the author the benefit of the doubt and say it's juxtaposition :P
- Unexpected behavior on mobile devices. (since they usually implement their own alerts)
Just make it backwards-compatible and it will be pretty sweet. Until then it's not serious.
https://github.com/t4t5/sweetalert/commit/2413e5cbcd1fe3d6e1...
- Heavy use of Javascript for what CSS is designed for: https://github.com/t4t5/sweetalert/blob/master/lib/sweet-ale...
- Inconsistent between function spacing followed by mixed tabs and spaces
- Odd use of DOM based attributes to pass configuration options
- Colourspace manipulation on each call where SASS would be effective https://github.com/t4t5/sweetalert/blob/master/lib/sweet-ale...
- Includes jquery, but uses it very little, instead opting to re-invent the wheel in most cases.
- Strange click event firing, gratuitous use of magic key code numbers https://github.com/t4t5/sweetalert/blob/master/lib/sweet-ale...
etc...
(As you can probably tell, I do not like this style at all)
If so, there's a slight typo on the "See it in action!" page (http://tristanedwards.me/sweetalert). For the "A warning message, with a function attached to the "Confirm"-button" demo, the code displayed says 'alert("Booyah!");' but the alert being displayed says 'Deleted!'
edit: Ah, fair enough. The project's github page has issues enabled though.
I recommend using the content in the link itself: it's described as 'awesome' not 'beautiful'.
What's funny is that since this doesn't actually work like a JS Alert, it's actually quite 'ugly'. ;)
Hopefully very few JS developers are using alerts in their production code (or dev for that matter!), and if they are they're probably not interested enough in user-friendly design to seek out this replacement.
I notice that even large apps like gmail and google calendar use native alerts (and I've been using them a bit more under certain circumstances—something has gone terribly wrong). What about native alerts in all situations equals unfriendly design—esp. when trying to mimic mobile native apps, but needing to span the gap from OS to OS?
I actually think SweetAlerts looks pretty nice for those kind of in-app notifications, which was the point I was trying to make. (Though seeing comments from people who have dug in further it seems like it has some issues)
The only issue I see with doing it that way is if you are in another Window and click to get focus, but you should deal with the alert when it appears since it is a part of completing a task.
Usually people only switch windows when they have completed a task.
Click the Confirm example: Click "cancel" to clear the dialogue.
Click the button again: Click "delete me" and you don't get the deleted alert that you normally get.
Also, I suggest optionally only blocking a portion of the DOM and centering over it. This would allow a component to lock without locking the application.
Finished your sentence for you.
But needs more callback functions...
Chrome supports the <dialog> element which is guaranteed to appear on top of whatever page its injected on.
Javsacript's Alert, prompt, also guarantee it will appear on top.