mirror of
https://github.com/chenasraf/ng-qtip2.git
synced 2026-05-17 17:58:05 +00:00
Some reorganizing
+ method reordering + scaling watchable options for future additions
This commit is contained in:
@@ -1,3 +1,12 @@
|
|||||||
|
str2bool = (str) -> String(str).toLowerCase() not in ['false', '0', 'null', '']
|
||||||
|
|
||||||
|
removeEmpties = (obj, deep = true) ->
|
||||||
|
for k, v of obj
|
||||||
|
if v? and typeof v is 'object' and deep
|
||||||
|
removeEmpties obj[k], deep
|
||||||
|
else if not v?
|
||||||
|
delete obj[k]
|
||||||
|
|
||||||
NgQtip2 = ($timeout, $compile, $http, $templateCache, qtipDefaults, $q) ->
|
NgQtip2 = ($timeout, $compile, $http, $templateCache, qtipDefaults, $q) ->
|
||||||
restrict: 'A'
|
restrict: 'A'
|
||||||
scope:
|
scope:
|
||||||
@@ -30,18 +39,20 @@ NgQtip2 = ($timeout, $compile, $http, $templateCache, qtipDefaults, $q) ->
|
|||||||
object: '=qtipTemplateObject'
|
object: '=qtipTemplateObject'
|
||||||
|
|
||||||
link: (scope, el, attrs) ->
|
link: (scope, el, attrs) ->
|
||||||
|
# these link attrs to qtip props (el.qtip(prop, val))
|
||||||
|
watchProps =
|
||||||
|
qtipVisible: 'toggle'
|
||||||
|
qtipDisable: 'disable'
|
||||||
|
|
||||||
|
# these link attrs to qtip options (el.qtip('option', name, val))
|
||||||
|
watchOptions =
|
||||||
|
qtipTitle: 'content.title'
|
||||||
|
qtipClass: 'style.classes'
|
||||||
|
qtip: 'content.text'
|
||||||
|
|
||||||
scope.qtipOptions ?= {}
|
scope.qtipOptions ?= {}
|
||||||
|
|
||||||
str2bool = (str) -> String(str).toLowerCase() not in ['false', '0', 'null', '']
|
|
||||||
|
|
||||||
scope.apiPromise = $q.defer()
|
scope.apiPromise = $q.defer()
|
||||||
|
|
||||||
scope.getQtipId = ->
|
|
||||||
el.data('hasqtip')
|
|
||||||
|
|
||||||
scope.getQtipElement = (id = scope.getQtipId()) ->
|
|
||||||
($ "#qtip-#{id}")
|
|
||||||
|
|
||||||
scope.closeQtip = (e, id = scope.getQtipId(), {rendered = yes} = {}) ->
|
scope.closeQtip = (e, id = scope.getQtipId(), {rendered = yes} = {}) ->
|
||||||
e?.preventDefault?()
|
e?.preventDefault?()
|
||||||
qtEl = ($ "#qtip-#{id}")
|
qtEl = ($ "#qtip-#{id}")
|
||||||
@@ -49,13 +60,14 @@ NgQtip2 = ($timeout, $compile, $http, $templateCache, qtipDefaults, $q) ->
|
|||||||
qtEl.qtip().rendered = scope.qtipPersistent ? rendered
|
qtEl.qtip().rendered = scope.qtipPersistent ? rendered
|
||||||
return
|
return
|
||||||
|
|
||||||
removeEmpties = (obj, deep = true) ->
|
# Generic methods
|
||||||
for k, v of obj
|
scope.getQtipId = ->
|
||||||
if v? and typeof v is 'object' and deep
|
el.data('hasqtip')
|
||||||
removeEmpties obj[k], deep
|
|
||||||
else if not v?
|
|
||||||
delete obj[k]
|
|
||||||
|
|
||||||
|
scope.getQtipElement = (id = scope.getQtipId()) ->
|
||||||
|
($ "#qtip-#{id}")
|
||||||
|
|
||||||
|
# qTip API
|
||||||
scope.api = (e, id = scope.getQtipId()) ->
|
scope.api = (e, id = scope.getQtipId()) ->
|
||||||
qtEl = ($ "#qtip-#{id}")
|
qtEl = ($ "#qtip-#{id}")
|
||||||
return qtEl.qtip "api"
|
return qtEl.qtip "api"
|
||||||
@@ -74,7 +86,9 @@ NgQtip2 = ($timeout, $compile, $http, $templateCache, qtipDefaults, $q) ->
|
|||||||
before?(arguments...)
|
before?(arguments...)
|
||||||
fn?(arguments...)
|
fn?(arguments...)
|
||||||
|
|
||||||
|
# Main init method
|
||||||
generateQtip = (content) ->
|
generateQtip = (content) ->
|
||||||
|
# Default options
|
||||||
attrOptions =
|
attrOptions =
|
||||||
position:
|
position:
|
||||||
my: scope.qtipMy
|
my: scope.qtipMy
|
||||||
@@ -96,40 +110,36 @@ NgQtip2 = ($timeout, $compile, $http, $templateCache, qtipDefaults, $q) ->
|
|||||||
tip: scope.qtipTipStyle
|
tip: scope.qtipTipStyle
|
||||||
content: if content? then content else text: scope.qtipContent ? scope.qtip
|
content: if content? then content else text: scope.qtipContent ? scope.qtip
|
||||||
|
|
||||||
|
# Clear empty values to use defaults
|
||||||
angular.merge attrOptions.hide, scope.qtipHide if scope.qtipHide?
|
angular.merge attrOptions.hide, scope.qtipHide if scope.qtipHide?
|
||||||
angular.merge attrOptions.show, scope.qtipShow if scope.qtipShow?
|
angular.merge attrOptions.show, scope.qtipShow if scope.qtipShow?
|
||||||
removeEmpties options
|
removeEmpties options
|
||||||
removeEmpties attrOptions
|
removeEmpties attrOptions
|
||||||
removeEmpties scope.qtipOptions
|
removeEmpties scope.qtipOptions
|
||||||
|
|
||||||
|
# Merge final opts
|
||||||
options = angular.merge {}, qtipDefaults, attrOptions, scope.qtipOptions
|
options = angular.merge {}, qtipDefaults, attrOptions, scope.qtipOptions
|
||||||
|
|
||||||
|
# qTip API
|
||||||
if options.events?.render?
|
if options.events?.render?
|
||||||
options.events.render = scope._before(scope.resolveApiPromise, options.events.render)
|
options.events.render = scope._before(scope.resolveApiPromise, options.events.render)
|
||||||
else
|
else
|
||||||
options.events ?= {}
|
options.events ?= {}
|
||||||
options.events.render = scope.resolveApiPromise
|
options.events.render = scope.resolveApiPromise
|
||||||
|
|
||||||
|
# Create qtip
|
||||||
($ el).qtip options
|
($ el).qtip options
|
||||||
|
|
||||||
if attrs.qtipVisible?
|
# Assign watch props/options pairs
|
||||||
scope.$watch 'qtipVisible', (newVal) ->
|
for k, v of watchProps
|
||||||
($ el).qtip 'toggle', newVal
|
scope.$watch k, (newVal) ->
|
||||||
|
el.qtip v, newVal
|
||||||
|
|
||||||
if attrs.qtipDisable?
|
for k, v of watchOptions
|
||||||
scope.$watch 'qtipDisable', (newVal) ->
|
scope.$watch k, (newVal) ->
|
||||||
($ el).qtip 'disable', newVal
|
el.qtip 'option', v, newVal
|
||||||
|
|
||||||
if scope.qtipTitle?
|
|
||||||
scope.$watch 'qtipTitle', (newVal) ->
|
|
||||||
($ el).qtip 'option', 'content.title', newVal
|
|
||||||
|
|
||||||
if scope.qtipClass?
|
|
||||||
scope.$watch 'qtipClass', (cls) ->
|
|
||||||
($ el).qtip 'option', 'style.class', cls
|
|
||||||
|
|
||||||
scope.$watch 'qtip', (newVal, oldVal) ->
|
|
||||||
($ el).qtip 'option', 'content.text', newVal if newVal isnt oldVal
|
|
||||||
|
|
||||||
|
# Switch for triggering init by different types of main content/position
|
||||||
if attrs.qtipSelector
|
if attrs.qtipSelector
|
||||||
$timeout ->
|
$timeout ->
|
||||||
generateQtip ($ scope.qtipSelector).html()
|
generateQtip ($ scope.qtipSelector).html()
|
||||||
|
|||||||
108
ng-qtip2.js
108
ng-qtip2.js
@@ -1,6 +1,30 @@
|
|||||||
// Generated by CoffeeScript 1.10.0
|
// Generated by CoffeeScript 1.10.0
|
||||||
(function() {
|
(function() {
|
||||||
var NgQtip2;
|
var NgQtip2, removeEmpties, str2bool;
|
||||||
|
|
||||||
|
str2bool = function(str) {
|
||||||
|
var ref;
|
||||||
|
return (ref = String(str).toLowerCase()) !== 'false' && ref !== '0' && ref !== 'null' && ref !== '';
|
||||||
|
};
|
||||||
|
|
||||||
|
removeEmpties = function(obj, deep) {
|
||||||
|
var k, results, v;
|
||||||
|
if (deep == null) {
|
||||||
|
deep = true;
|
||||||
|
}
|
||||||
|
results = [];
|
||||||
|
for (k in obj) {
|
||||||
|
v = obj[k];
|
||||||
|
if ((v != null) && typeof v === 'object' && deep) {
|
||||||
|
results.push(removeEmpties(obj[k], deep));
|
||||||
|
} else if (v == null) {
|
||||||
|
results.push(delete obj[k]);
|
||||||
|
} else {
|
||||||
|
results.push(void 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return results;
|
||||||
|
};
|
||||||
|
|
||||||
NgQtip2 = function($timeout, $compile, $http, $templateCache, qtipDefaults, $q) {
|
NgQtip2 = function($timeout, $compile, $http, $templateCache, qtipDefaults, $q) {
|
||||||
return {
|
return {
|
||||||
@@ -35,24 +59,20 @@
|
|||||||
object: '=qtipTemplateObject'
|
object: '=qtipTemplateObject'
|
||||||
},
|
},
|
||||||
link: function(scope, el, attrs) {
|
link: function(scope, el, attrs) {
|
||||||
var content, generateQtip, ref, removeEmpties, str2bool;
|
var content, generateQtip, ref, watchOptions, watchProps;
|
||||||
|
watchProps = {
|
||||||
|
qtipVisible: 'toggle',
|
||||||
|
qtipDisable: 'disable'
|
||||||
|
};
|
||||||
|
watchOptions = {
|
||||||
|
qtipTitle: 'content.title',
|
||||||
|
qtipClass: 'style.classes',
|
||||||
|
qtip: 'content.text'
|
||||||
|
};
|
||||||
if (scope.qtipOptions == null) {
|
if (scope.qtipOptions == null) {
|
||||||
scope.qtipOptions = {};
|
scope.qtipOptions = {};
|
||||||
}
|
}
|
||||||
str2bool = function(str) {
|
|
||||||
var ref;
|
|
||||||
return (ref = String(str).toLowerCase()) !== 'false' && ref !== '0' && ref !== 'null' && ref !== '';
|
|
||||||
};
|
|
||||||
scope.apiPromise = $q.defer();
|
scope.apiPromise = $q.defer();
|
||||||
scope.getQtipId = function() {
|
|
||||||
return el.data('hasqtip');
|
|
||||||
};
|
|
||||||
scope.getQtipElement = function(id) {
|
|
||||||
if (id == null) {
|
|
||||||
id = scope.getQtipId();
|
|
||||||
}
|
|
||||||
return $("#qtip-" + id);
|
|
||||||
};
|
|
||||||
scope.closeQtip = function(e, id, arg) {
|
scope.closeQtip = function(e, id, arg) {
|
||||||
var qtEl, ref, ref1, rendered;
|
var qtEl, ref, ref1, rendered;
|
||||||
if (id == null) {
|
if (id == null) {
|
||||||
@@ -68,23 +88,14 @@
|
|||||||
qtEl.qtip('hide');
|
qtEl.qtip('hide');
|
||||||
qtEl.qtip().rendered = (ref1 = scope.qtipPersistent) != null ? ref1 : rendered;
|
qtEl.qtip().rendered = (ref1 = scope.qtipPersistent) != null ? ref1 : rendered;
|
||||||
};
|
};
|
||||||
removeEmpties = function(obj, deep) {
|
scope.getQtipId = function() {
|
||||||
var k, results, v;
|
return el.data('hasqtip');
|
||||||
if (deep == null) {
|
};
|
||||||
deep = true;
|
scope.getQtipElement = function(id) {
|
||||||
|
if (id == null) {
|
||||||
|
id = scope.getQtipId();
|
||||||
}
|
}
|
||||||
results = [];
|
return $("#qtip-" + id);
|
||||||
for (k in obj) {
|
|
||||||
v = obj[k];
|
|
||||||
if ((v != null) && typeof v === 'object' && deep) {
|
|
||||||
results.push(removeEmpties(obj[k], deep));
|
|
||||||
} else if (v == null) {
|
|
||||||
results.push(delete obj[k]);
|
|
||||||
} else {
|
|
||||||
results.push(void 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return results;
|
|
||||||
};
|
};
|
||||||
scope.api = function(e, id) {
|
scope.api = function(e, id) {
|
||||||
var qtEl;
|
var qtEl;
|
||||||
@@ -114,7 +125,7 @@
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
generateQtip = function(content) {
|
generateQtip = function(content) {
|
||||||
var attrOptions, options, ref, ref1;
|
var attrOptions, k, options, ref, ref1, results, v;
|
||||||
attrOptions = {
|
attrOptions = {
|
||||||
position: {
|
position: {
|
||||||
my: scope.qtipMy,
|
my: scope.qtipMy,
|
||||||
@@ -162,31 +173,20 @@
|
|||||||
options.events.render = scope.resolveApiPromise;
|
options.events.render = scope.resolveApiPromise;
|
||||||
}
|
}
|
||||||
($(el)).qtip(options);
|
($(el)).qtip(options);
|
||||||
if (attrs.qtipVisible != null) {
|
for (k in watchProps) {
|
||||||
scope.$watch('qtipVisible', function(newVal) {
|
v = watchProps[k];
|
||||||
return ($(el)).qtip('toggle', newVal);
|
scope.$watch(k, function(newVal) {
|
||||||
|
return el.qtip(v, newVal);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (attrs.qtipDisable != null) {
|
results = [];
|
||||||
scope.$watch('qtipDisable', function(newVal) {
|
for (k in watchOptions) {
|
||||||
return ($(el)).qtip('disable', newVal);
|
v = watchOptions[k];
|
||||||
});
|
results.push(scope.$watch(k, function(newVal) {
|
||||||
|
return el.qtip('option', v, newVal);
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
if (scope.qtipTitle != null) {
|
return results;
|
||||||
scope.$watch('qtipTitle', function(newVal) {
|
|
||||||
return ($(el)).qtip('option', 'content.title', newVal);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
if (scope.qtipClass != null) {
|
|
||||||
scope.$watch('qtipClass', function(cls) {
|
|
||||||
return ($(el)).qtip('option', 'style.class', cls);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return scope.$watch('qtip', function(newVal, oldVal) {
|
|
||||||
if (newVal !== oldVal) {
|
|
||||||
return ($(el)).qtip('option', 'content.text', newVal);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
if (attrs.qtipSelector) {
|
if (attrs.qtipSelector) {
|
||||||
$timeout(function() {
|
$timeout(function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user