-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/Meligy/jQuery-Notification
Conflicts: .gitignore jQueryNotification.suo jQueryNotification/bin/jQueryNotification.dll jQueryNotification/bin/jQueryNotification.pdb jQueryNotification/obj/Debug/jQueryNotification.dll jQueryNotification/obj/Debug/jQueryNotification.pdb
- Loading branch information
Showing
19 changed files
with
226 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
A fork of Emad Mokhtar(<a href="http://twitter/EmadMokhtar">@EmadMokhtar</a>)'s blog post on ASP.NET webforms use of jQuery notification. | ||
|
||
**Enad's original blog post:** | ||
http://www.emadmokhtar.com/2012/02/using-notification-in-asp-net-webforms/ | ||
|
||
**Emad's original github repository:** | ||
https://github.com/EmadMokhtar/jQuery-Notification | ||
|
||
**jQuery Plugin used in both original and forked code:** | ||
http://www.givainc.com/labs/jnotify_jquery_plugin.htm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,83 +1,73 @@ | ||
using System.Web.UI; | ||
using System; | ||
using System.Globalization; | ||
using System.Web; | ||
using System.Web.UI; | ||
using System.Web.UI.WebControls; | ||
|
||
namespace jQueryNotification.Helper | ||
namespace JqueryNotification | ||
{ | ||
public static class NotificationHelper | ||
public static class NotificationExtensions | ||
{ | ||
/// <summary> | ||
/// Shows the successful notification. | ||
/// </summary> | ||
/// <param name="page">The page.</param> | ||
/// <param name="message">The message.</param> | ||
public static void ShowSuccessfulNotification(this Page page, string message) | ||
public static void ShowNotification(this Control control, NotificationType notificationType, string message, TimeSpan timeBeforeHiding) | ||
{ | ||
page.ClientScript.RegisterStartupScript(page.GetType(), "notificationScript", | ||
"<script type='text/javascript'> $(document).ready(function () { $.jnotify('" + | ||
message + "'); });</script>"); | ||
var totalNotificationShowingMilliseconds = timeBeforeHiding.TotalMilliseconds; | ||
var jNotifyDelay = totalNotificationShowingMilliseconds > 0 | ||
? totalNotificationShowingMilliseconds.ToString(CultureInfo.InvariantCulture) | ||
: "undefined"; // equal to not adding anything | ||
|
||
var notificationScript = | ||
string.Format( | ||
"$( function () {{ if(typeof $.jnotify === 'function') {{ $.jnotify('{0}', '{1}', {2}); }} }} );", | ||
HttpUtility.JavaScriptStringEncode(message), notificationType.ScriptKey, jNotifyDelay); | ||
|
||
// Allow adding multiple notifications by making the key unique | ||
var scriptKey = Guid.NewGuid().ToString(); | ||
|
||
// Adding the call to the pre-render event of the page, so that multiple notification calls | ||
// are added in the same order they are rendered in the page, not the order the calls are processed in page life cycle | ||
control.PreRender += new EventHandler | ||
((sender, e) => | ||
// Note that we need to use ScriptManager to be UpdatePanel friendly | ||
// This will still work even if there is no ScriptManager on the page | ||
ScriptManager.RegisterStartupScript(control, control.GetType(), scriptKey, | ||
notificationScript, | ||
// saves us from adding <script> in string and making it harder to re | ||
addScriptTags: true)); | ||
} | ||
|
||
public static void ShowNotification(this Control currentControl, NotificationType notificationType, string message) | ||
{ | ||
ShowNotification(currentControl, notificationType, message, TimeSpan.FromMilliseconds(0)); | ||
} | ||
|
||
public static void ShowSuccessfulNotification(this Control currentControl, string notificationMessage) | ||
{ | ||
ShowNotification(currentControl, NotificationType.Success, notificationMessage); | ||
} | ||
|
||
/// <summary> | ||
/// Shows the warning notification. | ||
/// </summary> | ||
/// <param name="page">The page.</param> | ||
/// <param name="message">The message.</param> | ||
public static void ShowWarningNotification(this Page page, string message) | ||
public static void ShowWarningNotification(this Control currentControl, string notificationMessage) | ||
{ | ||
page.ClientScript.RegisterStartupScript(page.GetType(), "notificationScript", | ||
"<script type='text/javascript'> $(document).ready(function () { $.jnotify('" + | ||
message + "', 'warning'); });</script>"); | ||
ShowNotification(currentControl, NotificationType.Warning, notificationMessage); | ||
} | ||
|
||
/// <summary> | ||
/// Shows the error notification. | ||
/// </summary> | ||
/// <param name="page">The page.</param> | ||
/// <param name="message">The message.</param> | ||
public static void ShowErrorNotification(this Page page, string message) | ||
public static void ShowErrorNotification(this Control currentControl, string notificationMessage) | ||
{ | ||
page.ClientScript.RegisterStartupScript(page.GetType(), "notificationScript", | ||
"<script type='text/javascript'> $(document).ready(function () { $.jnotify('" + | ||
message + "', 'error'); });</script>"); | ||
ShowNotification(currentControl, NotificationType.Error, notificationMessage); | ||
} | ||
|
||
/// <summary> | ||
/// Shows the successful notification. | ||
/// </summary> | ||
/// <param name="page">The page.</param> | ||
/// <param name="message">The message.</param> | ||
/// <param name="delayTimeSpan">The delay time span in millisecond.</param> | ||
public static void ShowSuccessfulNotification(this Page page, string message, int delayTimeSpan) | ||
public static void ShowSuccessfulNotification(this Control currentControl, string notificationMessage, int milliseondsBeforeHiding) | ||
{ | ||
page.ClientScript.RegisterStartupScript(page.GetType(), "notificationScript", | ||
"<script type='text/javascript'> $(document).ready(function () { $.jnotify('" + | ||
message + "', " + delayTimeSpan + " ); });</script>"); | ||
ShowNotification(currentControl, NotificationType.Success, notificationMessage, TimeSpan.FromMilliseconds(milliseondsBeforeHiding)); | ||
} | ||
|
||
/// <summary> | ||
/// Shows the warning notification. | ||
/// </summary> | ||
/// <param name="page">The page.</param> | ||
/// <param name="message">The message.</param> | ||
/// <param name="delayTimeSpan">The delay time span in millisecond.</param> | ||
public static void ShowWarningNotification(this Page page, string message, int delayTimeSpan) | ||
public static void ShowWarningNotification(this Control currentControl, string notificationMessage, int milliseondsBeforeHiding) | ||
{ | ||
page.ClientScript.RegisterStartupScript(page.GetType(), "notificationScript", | ||
"<script type='text/javascript'> $(document).ready(function () { $.jnotify('" + | ||
message + "', 'warning', " + delayTimeSpan + " ); });</script>"); | ||
ShowNotification(currentControl, NotificationType.Warning, notificationMessage, TimeSpan.FromMilliseconds(milliseondsBeforeHiding)); | ||
} | ||
|
||
/// <summary> | ||
/// Shows the error notification. | ||
/// </summary> | ||
/// <param name="page">The page.</param> | ||
/// <param name="message">The message.</param> | ||
/// <param name="delayTimeSpan">The delay time span in millisecond.</param> | ||
public static void ShowErrorNotification(this Page page, string message, int delayTimeSpan) | ||
public static void ShowErrorNotification(this Control currentControl, string notificationMessage, int milliseondsBeforeHiding) | ||
{ | ||
page.ClientScript.RegisterStartupScript(page.GetType(), "notificationScript", | ||
"<script type='text/javascript'> $(document).ready(function () { $.jnotify('" + | ||
message + "', 'error', " + delayTimeSpan + " ); });</script>"); | ||
ShowNotification(currentControl, NotificationType.Error, notificationMessage, TimeSpan.FromMilliseconds(milliseondsBeforeHiding)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
namespace JqueryNotification | ||
{ | ||
public sealed class NotificationType | ||
{ | ||
public string ScriptKey { get; private set; } | ||
|
||
private NotificationType(string scriptKey) | ||
{ | ||
ScriptKey = scriptKey; | ||
} | ||
|
||
public static NotificationType Success = new NotificationType(""); | ||
public static NotificationType Error = new NotificationType("error"); | ||
public static NotificationType Warning = new NotificationType("warning"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="SampleUserControl.ascx.cs" Inherits="jQueryNotification.SampleUserControl" %> | ||
<div> | ||
<asp:Button ID="btnShowUserControlNotification" runat="server" | ||
Text="Two notifications from user control" onclick="btnShowUserControlNotification_Click" /> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Web; | ||
using System.Web.UI; | ||
using System.Web.UI.WebControls; | ||
using JqueryNotification; | ||
|
||
namespace jQueryNotification | ||
{ | ||
public partial class SampleUserControl : System.Web.UI.UserControl | ||
{ | ||
protected void Page_Load(object sender, EventArgs e) | ||
{ | ||
|
||
} | ||
|
||
protected void btnShowUserControlNotification_Click(object sender, EventArgs e) | ||
{ | ||
// Note using <br /> in the message to show you can use HTML in there | ||
// Of course if you are using HTML in real cases, avoid creating it by using strings like this | ||
|
||
// Note using 'this' indicating the call belongs to the user control | ||
this.ShowSuccessfulNotification("Called first, but shown second<br />As I belong to some control on the page"); | ||
// Note using 'Page' indicating the call belongs to the Page itself | ||
Page.ShowWarningNotification("Called second, but shown first<br />As I belong to the page itself"); | ||
} | ||
} | ||
} |
Oops, something went wrong.