added text new line to <br> conversion option

This commit is contained in:
Jaime Pillora
2013-06-14 16:54:40 +10:00
parent 9275312b03
commit 70f18f4be5
5 changed files with 43 additions and 11 deletions
+15 -3
View File
@@ -1,11 +1,11 @@
/** Notify.js - v0.0.1 - 2013/06/12
/** Notify.js - v0.0.1 - 2013/06/14
* http://notifyjs.com/
* Copyright (c) 2013 Jaime Pillora - MIT
*/
(function(window,document,undefined) {
'use strict';
var Notification, addStyle, coreStyle, createElem, defaults, getAnchorElement, getStyle, globalAnchors, hAligns, incr, inherit, insertCSS, mainPositions, opposites, parsePosition, pluginClassName, pluginName, pluginOptions, positions, realign, stylePrefixes, styles, vAligns,
var Notification, addStyle, coreStyle, createElem, defaults, encode, getAnchorElement, getStyle, globalAnchors, hAligns, incr, inherit, insertCSS, mainPositions, opposites, parsePosition, pluginClassName, pluginName, pluginOptions, positions, realign, stylePrefixes, styles, vAligns,
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
pluginName = 'notify';
@@ -125,6 +125,7 @@ pluginOptions = {
autoHideDelay: 5000,
arrowShow: true,
arrowSize: 5,
breakNewLines: true,
elementPosition: 'bottom',
globalPosition: 'top right',
style: 'bootstrap',
@@ -199,6 +200,11 @@ realign = function(alignment, inner, outer) {
throw "Invalid alignment";
};
encode = function(text) {
encode.e = encode.e || createElem("div");
return encode.e.text(text).html();
};
Notification = (function() {
function Notification(elem, data, options) {
@@ -427,7 +433,13 @@ Notification = (function() {
} else if (!this.container && !data) {
return;
}
this.text[this.rawHTML ? 'html' : 'text'](data);
if (!this.rawHTML) {
data = encode(data);
if (this.options.breakNewLines) {
data = data.replace(/\n/, '<br/>');
}
}
this.text.html(data);
this.updateClasses();
if (this.elem) {
this.setElementPosition();
+2 -2
View File
File diff suppressed because one or more lines are too long
+15 -3
View File
@@ -1,11 +1,11 @@
/** Notify.js - v0.0.1 - 2013/06/12
/** Notify.js - v0.0.1 - 2013/06/14
* http://notifyjs.com/
* Copyright (c) 2013 Jaime Pillora - MIT
*/
(function(window,document,undefined) {
'use strict';
var Notification, addStyle, coreStyle, createElem, defaults, getAnchorElement, getStyle, globalAnchors, hAligns, incr, inherit, insertCSS, mainPositions, opposites, parsePosition, pluginClassName, pluginName, pluginOptions, positions, realign, stylePrefixes, styles, vAligns,
var Notification, addStyle, coreStyle, createElem, defaults, encode, getAnchorElement, getStyle, globalAnchors, hAligns, incr, inherit, insertCSS, mainPositions, opposites, parsePosition, pluginClassName, pluginName, pluginOptions, positions, realign, stylePrefixes, styles, vAligns,
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
pluginName = 'notify';
@@ -125,6 +125,7 @@ pluginOptions = {
autoHideDelay: 5000,
arrowShow: true,
arrowSize: 5,
breakNewLines: true,
elementPosition: 'bottom',
globalPosition: 'top right',
style: 'bootstrap',
@@ -199,6 +200,11 @@ realign = function(alignment, inner, outer) {
throw "Invalid alignment";
};
encode = function(text) {
encode.e = encode.e || createElem("div");
return encode.e.text(text).html();
};
Notification = (function() {
function Notification(elem, data, options) {
@@ -427,7 +433,13 @@ Notification = (function() {
} else if (!this.container && !data) {
return;
}
this.text[this.rawHTML ? 'html' : 'text'](data);
if (!this.rawHTML) {
data = encode(data);
if (this.options.breakNewLines) {
data = data.replace(/\n/, '<br/>');
}
}
this.text.html(data);
this.updateClasses();
if (this.elem) {
this.setElementPosition();
+2 -2
View File
File diff suppressed because one or more lines are too long
+9 -1
View File
@@ -164,6 +164,7 @@ pluginOptions =
autoHideDelay: 5000
arrowShow: true
arrowSize: 5
breakNewLines: true
elementPosition: 'bottom'
globalPosition: 'top right'
style: 'bootstrap'
@@ -236,6 +237,9 @@ realign = (alignment, inner, outer) ->
outer - inner
throw "Invalid alignment"
encode = (text) ->
encode.e = encode.e or createElem "div"
encode.e.text(text).html()
# ================================
# NOTIFY CLASS
@@ -471,8 +475,12 @@ class Notification
else if not @container and not data
return
#escape
unless @rawHTML
data = encode(data)
data = data.replace(/\n/,'<br/>') if @options.breakNewLines
#update content
@text[if @rawHTML then 'html' else 'text'](data)
@text.html(data)
#set styles
@updateClasses()