Changeset 552 for trunk/js


Ignore:
Timestamp:
Nov 25, 2015 7:29:35 PM (8 years ago)
Author:
anonymous
Message:

Updated js.

Location:
trunk/js
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/js/Msg.js

    r551 r552  
    4545---------------------------------------------------------------------
    4646*/
    47 Strangecode.Msg = function(options) {
     47Strangecode.Msg = function (options) {
    4848    // Merge options with defaults
    4949    this.o = $.extend({
    50         container: '#sc-msg:last',
     50        container: '.sc-msg:last',
    5151        above_msg: '',
    5252        gotohash: true
     
    6464* @since    18 Mar 2014 23:24:15
    6565*/
    66 Strangecode.Msg.prototype.raise = function(message, msg_class) {
     66Strangecode.Msg.prototype.raise = function (message, msg_class) {
    6767    // If an "above msg" is provided, and one doesn't already exist, add it to the message box.
    6868    if (this.o.above_msg.length && !$(this.o.container).find('.sc-above').length) {
     
    7373    // Append this raised message to the sc-msg stack, if it doesn't exist already.
    7474    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        }
    7880    }
    7981
     
    8688
    8789/*
    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").
    8993*
    9094* @access   public
    9195* @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 to use 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)
    9397* @author   Quinn Comendant <quinn@strangecode.com>
    94 * @version  1.0
     98* @version  1.1
    9599* @since    18 Mar 2014 23:24:15
    96100*/
    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();
     101Strangecode.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();
    101104};
  • trunk/js/Utilities.js

    r527 r552  
    7070
    7171/*
    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.
    7374Then we pull the encoded contents back out. The div never exists on the page.
    7475---------------------------------------------------------------------
    75 $('select').append($('<option>', {
    76     value: value,
    77     text: Strangecode.htmlEncode(text)
    78 }));
     76$('input').val(Strangecode.htmlEncode(string));
    7977---------------------------------------------------------------------
    80 *
    81 * @access   public
    82 * @version  1.1
    83 * @since    30 Jun 2013
     78
     79@access   public
     80@version  2.0
     81@since    30 Jun 2013
    8482*/
    85 Strangecode.htmlEncode = function(text) {
    86     return $('<div/>').text(text).html();
     83Strangecode.htmlEncode = function (str) {
     84    var entityMap = {
     85        '&': '&amp;',
     86        '<': '&lt;',
     87        '>': '&gt;',
     88        '"': '&quot;',
     89        "'": '&#39;',
     90        '/': '&#x2F;',
     91        '`': '&DiacriticalGrave;'
     92    };
     93    return String(str).replace(/[&<>"'\/`]/g, function (s) {
     94        return entityMap[s];
     95    });
    8796};
    88 Strangecode.htmlDecode = function(text) {
    89     return $('<div/>').html(value).text();
     97Strangecode.htmlDecode = function (str) {
     98    return $('<div>').html(str).text();
    9099};
    91100
    92101
    93102/*
    94 * Returns a string with URL-unsafe characters removed.
     103Returns a string with URL-unsafe characters removed.
    95104---------------------------------------------------------------------
    96105var urlslug = $('.url').val().slug();
     
    109118    return str.replace(/[^a-z0-9 -]/g, '').replace(/\s+/g, '-').replace(/-+/g, '-');
    110119};
     120
     121
     122
     123/*
     124Remove rounding errors caused by representation of finite binary floating point numbers.
     125---------------------------------------------------------------------
     126> (.1*.2)
     1270.020000000000000004
     128> (.1*.2).trim()
     1290.02
     130---------------------------------------------------------------------
     131* @access   public
     132* @version  1.0
     133* @since    24 Nov 2015
     134*/
     135if (!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/*
     143Uppercase the first letter of string.
     144---------------------------------------------------------------------
     145> 'hello world'.trim()
     146Hello world
     147---------------------------------------------------------------------
     148* @access   public
     149* @version  1.0
     150* @since    24 Nov 2015
     151*/
     152if (!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.