crlf to lf

This commit is contained in:
Cédric Salvador 2013-09-12 14:23:48 +02:00
parent 16e2de1d7b
commit 2ec8720629

View File

@ -1,209 +1,209 @@
/*! /*!
* jNotify jQuery Plug-in * jNotify jQuery Plug-in
* *
* Copyright 2010 Giva, Inc. (http://www.givainc.com/labs/) * Copyright 2010 Giva, Inc. (http://www.givainc.com/labs/)
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
* *
* Date: 2010-09-30 * Date: 2010-09-30
* Rev: 1.1.00 * Rev: 1.1.00
*/ */
;(function($){ ;(function($){
$.jnotify = function (m, o, d){ $.jnotify = function (m, o, d){
return new jNotify(m, o, d); return new jNotify(m, o, d);
}; };
// set the version of the plug-in // set the version of the plug-in
$.jnotify.version = "1.1.00"; $.jnotify.version = "1.1.00";
var $jnotify, queue = [], count = 0, playing = false, paused = false, queuedId, queuedNote, var $jnotify, queue = [], count = 0, playing = false, paused = false, queuedId, queuedNote,
// define default settings // define default settings
defaults = { defaults = {
// define core settings // define core settings
type: "" // if a type is specified, then an additional class of classNotification + type is created for each notification type: "" // if a type is specified, then an additional class of classNotification + type is created for each notification
, delay: 2000 // the default time to show each notification (in milliseconds) , delay: 2000 // the default time to show each notification (in milliseconds)
, sticky: false // determines if the message should be considered "sticky" (user must manually close notification) , sticky: false // determines if the message should be considered "sticky" (user must manually close notification)
, closeLabel: "×" // the HTML to use for the "Close" link , closeLabel: "×" // the HTML to use for the "Close" link
, showClose: true // determines if the "Close" link should be shown if notification is also sticky , showClose: true // determines if the "Close" link should be shown if notification is also sticky
, fadeSpeed: 1000 // the speed to fade messages out (in milliseconds) , fadeSpeed: 1000 // the speed to fade messages out (in milliseconds)
, slideSpeed: 250 // the speed used to slide messages out (in milliseconds) , slideSpeed: 250 // the speed used to slide messages out (in milliseconds)
// define the class statements // define the class statements
, classContainer: "jnotify-container" // className to use for the outer most container--this is where all the notifications appear , classContainer: "jnotify-container" // className to use for the outer most container--this is where all the notifications appear
, classNotification: "jnotify-notification" // className of the individual notification containers , classNotification: "jnotify-notification" // className of the individual notification containers
, classBackground: "jnotify-background" // className of the background layer for each notification container , classBackground: "jnotify-background" // className of the background layer for each notification container
, classClose: "jnotify-close" // className to use for the "Close" link , classClose: "jnotify-close" // className to use for the "Close" link
, classMessage: "jnotify-message" // className to use for the actual notification text container--this is where the message is actually written , classMessage: "jnotify-message" // className to use for the actual notification text container--this is where the message is actually written
// event handlers // event handlers
, init: null // callback that occurs when the main jnotify container is created , init: null // callback that occurs when the main jnotify container is created
, create: null // callback that occurs when when the note is created (occurs just before appearing in DOM) , create: null // callback that occurs when when the note is created (occurs just before appearing in DOM)
, beforeRemove: null // callback that occurs when before the notification starts to fade away , beforeRemove: null // callback that occurs when before the notification starts to fade away
, remove: null // callback that occurs when notification is removed , remove: null // callback that occurs when notification is removed
, transition: null // allows you to overwrite how the transitions between messages are handled , transition: null // allows you to overwrite how the transitions between messages are handled
// receives the following arguments: // receives the following arguments:
// container - jQuery object containing the notification // container - jQuery object containing the notification
// message - jQuery object of the actual message // message - jQuery object of the actual message
// count - the number of items left in queue // count - the number of items left in queue
// callback - a function you must execute once your transition has executed // callback - a function you must execute once your transition has executed
// options - the options used for this jnotify instance // options - the options used for this jnotify instance
}; };
// override the defaults // override the defaults
$.jnotify.setup = function (o){ $.jnotify.setup = function (o){
defaults = $.extend({}, defaults, o) ; defaults = $.extend({}, defaults, o) ;
}; };
$.jnotify.play = function (f, d){ $.jnotify.play = function (f, d){
if( playing && (f !== true ) || (queue.length == 0) ) return; if( playing && (f !== true ) || (queue.length == 0) ) return;
playing = true; playing = true;
// get first note // get first note
var note = queue.shift(); var note = queue.shift();
queuedNote = note; queuedNote = note;
// determine delay to use // determine delay to use
var delay = (arguments.length >= 2) ? parseInt(d, 10) : note.options.delay; var delay = (arguments.length >= 2) ? parseInt(d, 10) : note.options.delay;
// run delay before removing message // run delay before removing message
queuedId = setTimeout(function(){ queuedId = setTimeout(function(){
// clear timeout id // clear timeout id
queuedId = 0; queuedId = 0;
note.remove(function (){ note.remove(function (){
// makr that the queue is empty // makr that the queue is empty
if( queue.length == 0 ) playing = false; if( queue.length == 0 ) playing = false;
// force playing the next item in queue // force playing the next item in queue
else if( !paused ) $.jnotify.play(true); else if( !paused ) $.jnotify.play(true);
}); });
}, delay); }, delay);
}; };
$.jnotify.pause = function(){ $.jnotify.pause = function(){
clearTimeout(queuedId); clearTimeout(queuedId);
// push the item back into the queue // push the item back into the queue
if( queuedId ) queue.unshift(queuedNote); if( queuedId ) queue.unshift(queuedNote);
// mark that we're playing (so it doesn't automatically start playing) // mark that we're playing (so it doesn't automatically start playing)
paused = playing = true; paused = playing = true;
} }
$.jnotify.resume = function(){ $.jnotify.resume = function(){
// mark that we're no longer pause // mark that we're no longer pause
paused = false; paused = false;
// resume playing // resume playing
$.jnotify.play(true, 0); $.jnotify.play(true, 0);
} }
function jNotify(message, options){ function jNotify(message, options){
// a reference to the jNotify object // a reference to the jNotify object
var self = this, TO = typeof options; var self = this, TO = typeof options;
if( TO == "number" ){ if( TO == "number" ){
options = $.extend({}, defaults, {delay: options}); options = $.extend({}, defaults, {delay: options});
} else if( TO == "boolean" ){ } else if( TO == "boolean" ){
options = $.extend({}, defaults, {sticky: true}) ; options = $.extend({}, defaults, {sticky: true}) ;
} else if( TO == "string" ){ } else if( TO == "string" ){
options = $.extend({}, defaults, {type: options, delay: ((arguments.length > 2) && (typeof arguments[2] == "number")) ? arguments[2] : defaults.delay, sticky: ((arguments.length > 2) && (typeof arguments[2] == "boolean")) ? arguments[2] : defaults.sticky}) ; options = $.extend({}, defaults, {type: options, delay: ((arguments.length > 2) && (typeof arguments[2] == "number")) ? arguments[2] : defaults.delay, sticky: ((arguments.length > 2) && (typeof arguments[2] == "boolean")) ? arguments[2] : defaults.sticky}) ;
} else { } else {
options = $.extend({}, defaults, options); options = $.extend({}, defaults, options);
} }
// store the options // store the options
this.options = options; this.options = options;
// if the container doesn't exist, create it // if the container doesn't exist, create it
if( !$jnotify ){ if( !$jnotify ){
// we want to use one single container, so always use the default container class // we want to use one single container, so always use the default container class
$jnotify = $('<div class="' + defaults.classContainer + '" />').appendTo("body"); $jnotify = $('<div class="' + defaults.classContainer + '" />').appendTo("body");
if( $.isFunction(options.init) ) options.init.apply(self, [$jnotify]); if( $.isFunction(options.init) ) options.init.apply(self, [$jnotify]);
} }
// create the notification // create the notification
function create(message){ function create(message){
var html = '<div class="' + options.classNotification + (options.type.length ? (" " + options.classNotification + "-" + options.type) : "") + '">' var html = '<div class="' + options.classNotification + (options.type.length ? (" " + options.classNotification + "-" + options.type) : "") + '">'
+ '<div class="' + options.classBackground + '"></div>' + '<div class="' + options.classBackground + '"></div>'
+ (options.sticky && options.showClose ? ('<a class="' + options.classClose + '">' + options.closeLabel + '</a>') : '') + (options.sticky && options.showClose ? ('<a class="' + options.classClose + '">' + options.closeLabel + '</a>') : '')
+ '<div class="' + options.classMessage + '">' + '<div class="' + options.classMessage + '">'
+ '<div>' + message + '</div>' + '<div>' + message + '</div>'
+ '</div></div>'; + '</div></div>';
// increase the counter tracking the notification instances // increase the counter tracking the notification instances
count++; count++;
// create the note // create the note
var $note = $(html); var $note = $(html);
if( options.sticky ){ if( options.sticky ){
// add click handler to remove the sticky notification // add click handler to remove the sticky notification
$note.find("a." + options.classClose).bind("click.jnotify", function (){ $note.find("a." + options.classClose).bind("click.jnotify", function (){
self.remove(); self.remove();
}); });
} }
// run callback // run callback
if( $.isFunction(options.create) ) options.create.apply(self, [$note]); if( $.isFunction(options.create) ) options.create.apply(self, [$note]);
// return the new note // return the new note
return $note.appendTo($jnotify); return $note.appendTo($jnotify);
} }
// remove the notification // remove the notification
this.remove = function (callback){ this.remove = function (callback){
var $msg = $note.find("." + options.classMessage), $parent = $msg.parent(); var $msg = $note.find("." + options.classMessage), $parent = $msg.parent();
// remove message from counter // remove message from counter
var index = count--; var index = count--;
// run callback // run callback
if( $.isFunction(options.beforeRemove) ) options.beforeRemove.apply(self, [$msg]); if( $.isFunction(options.beforeRemove) ) options.beforeRemove.apply(self, [$msg]);
// cleans up notification // cleans up notification
function finished(){ function finished(){
// remove the parent container // remove the parent container
$parent.remove(); $parent.remove();
// if there's a callback, run it // if there's a callback, run it
if( $.isFunction(callback) ) callback.apply(self, [$msg]); if( $.isFunction(callback) ) callback.apply(self, [$msg]);
if( $.isFunction(options.remove) ) options.remove.apply(self, [$msg]); if( $.isFunction(options.remove) ) options.remove.apply(self, [$msg]);
} }
// check if a custom transition has been specified // check if a custom transition has been specified
if( $.isFunction(options.transition) ) options.transition.apply(self, [$parent, $msg, index, finished, options]); if( $.isFunction(options.transition) ) options.transition.apply(self, [$parent, $msg, index, finished, options]);
else { else {
$msg.fadeTo(options.fadeSpeed, 0.01, function (){ $msg.fadeTo(options.fadeSpeed, 0.01, function (){
// if last item, just remove // if last item, just remove
if( index <= 1 ) finished(); if( index <= 1 ) finished();
// slide the parent closed // slide the parent closed
else $parent.slideUp(options.slideSpeed, finished); else $parent.slideUp(options.slideSpeed, finished);
}); });
// if the last notification, fade out the container // if the last notification, fade out the container
if( count <= 0 ) $parent.fadeOut(options.fadeSpeed); if( count <= 0 ) $parent.fadeOut(options.fadeSpeed);
} }
} }
// create the note // create the note
var $note = create(message); var $note = create(message);
// if not a sticky, add to show queue // if not a sticky, add to show queue
if( !options.sticky ){ if( !options.sticky ){
// add the message to the queue // add the message to the queue
queue.push(this); queue.push(this);
// play queue // play queue
$.jnotify.play(); $.jnotify.play();
} }
return this; return this;
}; };
})(jQuery); })(jQuery);