-
Notifications
You must be signed in to change notification settings - Fork 100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improved placement, individual duration, events and minor refactorings #15
base: master
Are you sure you want to change the base?
Changes from 7 commits
7d41d2f
8359649
c97a352
33ef747
c31754d
16c79e1
e24b6a9
96030e0
4e0a4b4
5801135
9caa66a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
.cg-notify-message { | ||
position:fixed; | ||
left:50%; | ||
top:0px; | ||
z-index: 9999; | ||
max-width:400px; | ||
|
@@ -23,6 +22,18 @@ | |
box-shadow: 0 6px 12px rgba(0,0,0,.175); | ||
} | ||
|
||
.cg-notify-message-center { | ||
left:50%; | ||
} | ||
|
||
.cg-notify-message-left { | ||
left:1%; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can both this and the right class use a px left and right. 10 or15px most likely? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, I will fix that as soon as possible. |
||
} | ||
|
||
.cg-notify-message-right { | ||
right:1%; | ||
} | ||
|
||
.cg-notify-message a { | ||
font-weight:bold; | ||
color:inherit; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,21 +16,30 @@ angular.module('cgNotify', []).factory('notify',['$timeout','$http','$compile',' | |
args = {message:args}; | ||
} | ||
|
||
args.templateUrl = args.templateUrl ? args.templateUrl : defaultTemplateUrl; | ||
args.position = args.position ? args.position : position; | ||
args.container = args.container ? args.container : container; | ||
args.classes = args.classes ? args.classes : ''; | ||
|
||
var scope = args.scope ? args.scope.$new() : $rootScope.$new(); | ||
args.templateUrl = angular.isString(args.templateUrl) && args.templateUrl.length > 0 ? args.templateUrl : defaultTemplateUrl; | ||
args.position = angular.isString(args.position) ? args.position : position; | ||
args.container = angular.isObject(args.container) ? args.container : container; | ||
args.classes = angular.isString(args.classes) ? args.classes : ''; | ||
args.duration = angular.isNumber(args.duration) ? args.duration : duration; | ||
args.onOpen = angular.isFunction(args.onOpen) ? args.onOpen : undefined; | ||
args.onClose = angular.isFunction(args.onClose) ? args.onClose : undefined; | ||
|
||
var scope = angular.isDefined(args.scope) ? args.scope.$new() : $rootScope.$new(); | ||
scope.$message = args.message; | ||
scope.$classes = args.classes; | ||
scope.$messageTemplate = args.messageTemplate; | ||
scope.$messageTemplate = args.messageTemplate; | ||
|
||
if(angular.isFunction(args.onClick)){ | ||
scope.$click = function(){ | ||
args.onClick(scope.$message); | ||
}; | ||
} | ||
|
||
$http.get(args.templateUrl,{cache: $templateCache}).success(function(template){ | ||
|
||
var templateElement = $compile(template)(scope); | ||
templateElement.bind('webkitTransitionEnd oTransitionEnd otransitionend transitionend msTransitionEnd', function(e){ | ||
if (e.propertyName === 'opacity' || | ||
if (e.propertyName === 'opacity' || e.currentTarget.style.opacity === '0' || | ||
(e.originalEvent && e.originalEvent.propertyName === 'opacity')){ | ||
|
||
templateElement.remove(); | ||
|
@@ -57,19 +66,26 @@ angular.module('cgNotify', []).factory('notify',['$timeout','$http','$compile',' | |
angular.element(args.container).append(templateElement); | ||
messageElements.push(templateElement); | ||
|
||
if (args.position === 'center'){ | ||
$timeout(function(){ | ||
templateElement.css('margin-left','-' + (templateElement[0].offsetWidth /2) + 'px'); | ||
}); | ||
switch (args.position){ | ||
case 'center': templateElement.addClass('cg-notify-message-center'); | ||
templateElement.css('margin-left','-' + (templateElement[0].offsetWidth /2) + 'px'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, I will take a look into that! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, and thanks for this PR! I'm using it primarily because of the custom duration feature, but I certainly don't mind getting the other improvements for free as well :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, fixed that part. Thanks for testing my PR! Please keep me up to date about other insufficiencies :) |
||
break; | ||
case 'left': templateElement.addClass('cg-notify-message-left'); | ||
break; | ||
case 'right': templateElement.addClass('cg-notify-message-right'); | ||
break; | ||
} | ||
|
||
scope.$close = function(){ | ||
templateElement.css('opacity',0).attr('data-closing','true'); | ||
layoutMessages(); | ||
|
||
if(angular.isDefined(args.onClose)){ | ||
args.onClose(scope.$message); | ||
} | ||
}; | ||
|
||
var layoutMessages = function(){ | ||
var j = 0; | ||
var currentY = startTop; | ||
for(var i = messageElements.length - 1; i >= 0; i --){ | ||
var shadowHeight = 10; | ||
|
@@ -82,18 +98,21 @@ angular.module('cgNotify', []).factory('notify',['$timeout','$http','$compile',' | |
currentY += height + verticalSpacing; | ||
} | ||
element.css('top',top + 'px').css('margin-top','-' + (height+shadowHeight) + 'px').css('visibility','visible'); | ||
j ++; | ||
} | ||
}; | ||
|
||
$timeout(function(){ | ||
layoutMessages(); | ||
}); | ||
|
||
if (duration > 0){ | ||
if (args.duration > 0){ | ||
$timeout(function(){ | ||
scope.$close(); | ||
},duration); | ||
},args.duration); | ||
} | ||
|
||
if(angular.isDefined(args.onOpen)){ | ||
args.onOpen(scope.$message); | ||
} | ||
|
||
}).error(function(data){ | ||
|
@@ -122,12 +141,12 @@ angular.module('cgNotify', []).factory('notify',['$timeout','$http','$compile',' | |
}; | ||
|
||
notify.config = function(args){ | ||
startTop = !angular.isUndefined(args.startTop) ? args.startTop : startTop; | ||
verticalSpacing = !angular.isUndefined(args.verticalSpacing) ? args.verticalSpacing : verticalSpacing; | ||
duration = !angular.isUndefined(args.duration) ? args.duration : duration; | ||
defaultTemplateUrl = args.templateUrl ? args.templateUrl : defaultTemplateUrl; | ||
position = !angular.isUndefined(args.position) ? args.position : position; | ||
container = args.container ? args.container : container; | ||
startTop = angular.isNumber(args.startTop) ? args.startTop : startTop; | ||
verticalSpacing = angular.isNumber(args.verticalSpacing) ? args.verticalSpacing : verticalSpacing; | ||
duration = angular.isNumber(args.duration) ? args.duration : duration; | ||
defaultTemplateUrl = angular.isString(args.templateUrl) && args.templateUrl.length > 0 ? args.templateUrl : defaultTemplateUrl; | ||
position = angular.isString(args.position) ? args.position : position; | ||
container = angular.isObject(args.container) ? args.container : container; | ||
}; | ||
|
||
notify.closeAll = function(){ | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think all 3 events need to take a better argument than the message string. I would think the actual return value (which is an object that contains a modifiable message property as well as a close method) would be more appropriate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are absolutely right, that would make way more sense than just the message.