- Timestamp:
- Nov 25, 2015 7:29:35 PM (8 years ago)
- Location:
- trunk/js
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/js/Msg.js
r551 r552 45 45 --------------------------------------------------------------------- 46 46 */ 47 Strangecode.Msg = function (options) {47 Strangecode.Msg = function (options) { 48 48 // Merge options with defaults 49 49 this.o = $.extend({ 50 container: ' #sc-msg:last',50 container: '.sc-msg:last', 51 51 above_msg: '', 52 52 gotohash: true … … 64 64 * @since 18 Mar 2014 23:24:15 65 65 */ 66 Strangecode.Msg.prototype.raise = function (message, msg_class) {66 Strangecode.Msg.prototype.raise = function (message, msg_class) { 67 67 // If an "above msg" is provided, and one doesn't already exist, add it to the message box. 68 68 if (this.o.above_msg.length && !$(this.o.container).find('.sc-above').length) { … … 73 73 // Append this raised message to the sc-msg stack, if it doesn't exist already. 74 74 if (!$(this.o.container).find(':contains("' + message + '")').length) { 75 $(this.o.container).append($('<div class="sc-js-msg ' + msg_class + '"></div>').text(message)).show(); 76 // $(this.o.container).append($('<div data-alert class="alert-box sc-js-msg ' + msg_class + '"></div>').hide().text(message).append('<a href="#" class="close">Ã</a>')); 77 // $('.sc-js-msg').slideDown('fast'); 75 $(this.o.container).append($('<div data-alert class="alert-box sc-js-msg ' + msg_class + '"></div>').hide().html(message).append('<a href="#" class="close">Ã</a>')); 76 $('.sc-js-msg').slideDown('fast'); 77 if ($.fn.foundation) { 78 $(document).foundation('reflow'); 79 } 78 80 } 79 81 … … 86 88 87 89 /* 88 * Removes all messages previously created by Msg.raise. 90 * Removes all previously raised messages. By default, only messages raised by this JS class 91 * are cleared (matching class="sc-js-msg"), but you can clear *all* messages by assigning a more general 92 * class (e.g., "sc-msg-error"). 89 93 * 90 94 * @access public 91 95 * @param string message The message to display. 92 * @param string class The class to apply to the message div (when using codebase CSS, it is useful touse one of: sc-msg-success, sc-msg-notice, sc-msg-warning, sc-msg-error)96 * @param string class Remove message divs matching this class (default: sc-js-msg; or use one of: sc-msg-success, sc-msg-notice, sc-msg-warning, sc-msg-error) 93 97 * @author Quinn Comendant <quinn@strangecode.com> 94 * @version 1. 098 * @version 1.1 95 99 * @since 18 Mar 2014 23:24:15 96 100 */ 97 Strangecode.Msg.prototype.clear = function() { 98 // Append this raised message to the sc-msg stack. 99 var msg_class = (typeof msg_class === 'undefined') ? 'sc-msg-error' : msg_class; 100 $(this.o.container).find('.sc-js-msg').remove(); 101 Strangecode.Msg.prototype.clear = function (msg_class) { 102 var msg_class = (typeof msg_class === 'undefined') ? 'sc-js-msg' : msg_class; 103 $(this.o.container).find('.' + msg_class).remove(); 101 104 }; -
trunk/js/Utilities.js
r527 r552 70 70 71 71 /* 72 * Encode/decode HTML by proxying content via an in-memory div, setting its inner text which jQuery automatically encodes. 72 * Encode html entities by specific mapping table. 73 * Decode HTML by proxying content via an in-memory div, setting its inner text which jQuery automatically encodes. 73 74 Then we pull the encoded contents back out. The div never exists on the page. 74 75 --------------------------------------------------------------------- 75 $('select').append($('<option>', { 76 value: value, 77 text: Strangecode.htmlEncode(text) 78 })); 76 $('input').val(Strangecode.htmlEncode(string)); 79 77 --------------------------------------------------------------------- 80 * 81 *@access public82 * @version 1.1 83 *@since 30 Jun 201378 79 @access public 80 @version 2.0 81 @since 30 Jun 2013 84 82 */ 85 Strangecode.htmlEncode = function(text) { 86 return $('<div/>').text(text).html(); 83 Strangecode.htmlEncode = function (str) { 84 var entityMap = { 85 '&': '&', 86 '<': '<', 87 '>': '>', 88 '"': '"', 89 "'": ''', 90 '/': '/', 91 '`': '`' 92 }; 93 return String(str).replace(/[&<>"'\/`]/g, function (s) { 94 return entityMap[s]; 95 }); 87 96 }; 88 Strangecode.htmlDecode = function (text) {89 return $('<div />').html(value).text();97 Strangecode.htmlDecode = function (str) { 98 return $('<div>').html(str).text(); 90 99 }; 91 100 92 101 93 102 /* 94 *Returns a string with URL-unsafe characters removed.103 Returns a string with URL-unsafe characters removed. 95 104 --------------------------------------------------------------------- 96 105 var urlslug = $('.url').val().slug(); … … 109 118 return str.replace(/[^a-z0-9 -]/g, '').replace(/\s+/g, '-').replace(/-+/g, '-'); 110 119 }; 120 121 122 123 /* 124 Remove rounding errors caused by representation of finite binary floating point numbers. 125 --------------------------------------------------------------------- 126 > (.1*.2) 127 0.020000000000000004 128 > (.1*.2).trim() 129 0.02 130 --------------------------------------------------------------------- 131 * @access public 132 * @version 1.0 133 * @since 24 Nov 2015 134 */ 135 if (!Number.prototype.trim) { 136 Number.prototype.trim = function (precision) { 137 var precision = precision || 11; 138 return Math.round(this * Math.pow(10, precision)) / Math.pow(10, precision); 139 }; 140 } 141 142 /* 143 Uppercase the first letter of string. 144 --------------------------------------------------------------------- 145 > 'hello world'.trim() 146 Hello world 147 --------------------------------------------------------------------- 148 * @access public 149 * @version 1.0 150 * @since 24 Nov 2015 151 */ 152 if (!String.prototype.ucfirst) { 153 String.prototype.ucfirst = function() { 154 return this.charAt(0).toUpperCase() + this.slice(1); 155 }; 156 } 157
Note: See TracChangeset
for help on using the changeset viewer.