colly_wyx
2018-05-29 d479d9fbcb37f8b861031c94a83d0e37761210c5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/* ==========================================================
 * sco.message.js
 * http://github.com/terebentina/sco.js
 * ==========================================================
 * Copyright 2013 Dan Caragea.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ========================================================== */
 
/*jshint laxcomma:true, sub:true, browser:true, jquery:true, eqeqeq: false */
 
;(function($, undefined) {
    "use strict";
 
    var pluginName = 'scojs_message';
 
    $[pluginName] = function(message, type) {
        clearTimeout($[pluginName].timeout);
        var $selector = $('#' + $[pluginName].options.id);
        if (!$selector.length) {
            $selector = $('<div/>', {id: $[pluginName].options.id}).appendTo($[pluginName].options.appendTo);
        }
        if ($[pluginName].options.animate) {
            $selector.addClass('page_mess_animate');
        } else {
            $selector.removeClass('page_mess_animate');
        }
        $selector.html(message);
        if (type === undefined || type == $[pluginName].TYPE_ERROR) {
            $selector.removeClass($[pluginName].options.okClass).addClass($[pluginName].options.errClass);
        } else if (type == $[pluginName].TYPE_OK) {
            $selector.removeClass($[pluginName].options.errClass).addClass($[pluginName].options.okClass);
        }
        $selector.slideDown('fast', function() {
            $[pluginName].timeout = setTimeout(function() { $selector.slideUp('fast'); }, $[pluginName].options.delay);
        });
    };
 
 
    $.extend($[pluginName], {
        options: {
             id: 'page_message'
            ,okClass: 'page_mess_ok'
            ,errClass: 'page_mess_error'
            ,animate: true
            ,delay: 4000
            ,appendTo: 'body'    // where should the modal be appended to (default to document.body). Added for unit tests, not really needed in real life.
        },
 
        TYPE_ERROR: 1,
        TYPE_OK: 2
    });
})(jQuery);