mavensmate
Version:
Core APIs that drive MavensMate IDEs for Salesforce1/Force.com
43 lines (40 loc) • 2.9 kB
JavaScript
//if("undefined"==typeof jQuery.aljs)throw new Error("Please include the ALJS initializer file");!function(i){i.fn.notification=function(s){i.extend({assetsLocation:i.aljs.assetsLocation},s);if(1===this.length&&"string"!=typeof s)return this.on("click",'[data-aljs-dismiss="notification"]',function(s){var t=i(this).closest(".slds-notify");t.length>0&&(t.trigger("dismissed.aljs.notification"),t.addClass("slds-hide"))});if("string"==typeof s)return this.each(function(){var t=i(this);if(!t.hasClass("slds-notify"))throw new Error("This method can only be run on a notification with the slds-notify class on it");"show"===s||"toggle"===s&&t.hasClass("slds-hide")?(t.removeClass("slds-hide"),$notification.trigger("dismissed.aljs.notification")):("dismiss"===s||"toggle"===s&&!t.hasClass("slds-hide"))&&(t.addClass("slds-hide"),$notification.trigger("shown.aljs.notification"))});throw new Error("This plugin can only be run with a selector, or with a command")}}(jQuery);
//
(function($) {
$.fn.notification = function(options) {
var settings = $.extend({
assetsLocation: $.aljs.assetsLocation
// These are the defaults
}, options );
if (this.length === 1 && typeof options !== 'string') { // If initializing plugin with options
console.log('initing plugin')
return this.on('click', '[data-aljs-dismiss="notification"]', function(e) {
var $notification = $(this).closest('.slds-notify');
if ($notification.length > 0) {
$notification.trigger('dismissed.aljs.notification'); // Custom aljs event
$notification.addClass('slds-hide');
}
});
} else if (typeof options === 'string') { // If calling a method
console.log('calling method');
console.log(this);
return this.each(function() {
var $node = $(this);
console.log($node);
if (!($node.hasClass('slds-notify'))) {
throw new Error("This method can only be run on a notification with the slds-notify class on it");
} else {
if (options === 'show' || (options === 'toggle' && $node.hasClass('slds-hide'))) {
$node.removeClass('slds-hide');
// $notification.trigger('dismissed.aljs.notification'); // Custom aljs event
} else if (options === 'dismiss' || (options === 'toggle' && !($node.hasClass('slds-hide')))) {
$node.addClass('slds-hide');
// $notification.trigger('shown.aljs.notification'); // Custom aljs event
}
}
});
} else {
throw new Error("This plugin can only be run with a selector, or with a command")
}
};
}(jQuery));