From f0a973a8cbfee14ba9a1447fe8d88470ee1904ad Mon Sep 17 00:00:00 2001 From: RogerHo Date: Thu, 4 Aug 2016 16:59:58 +0800 Subject: [PATCH] Fix --- dist/browser.min.js | 33 +++++++++++++++++++++------------ dist/directive.js | 33 +++++++++++++++++++++------------ src/directive.js | 37 +++++++++++++++++++++++-------------- 3 files changed, 65 insertions(+), 38 deletions(-) diff --git a/dist/browser.min.js b/dist/browser.min.js index 3bdf715..e7e2707 100644 --- a/dist/browser.min.js +++ b/dist/browser.min.js @@ -16,27 +16,36 @@ var link = function link(scope, element, attrs) { var tooltipInstance = void 0, config = {}; + var getOpt = function getOpt() { + opt = { + target: element[0], + content: config[PROPS.tooltip] || config[PROPS.content] + }; + if (config[PROPS.classes]) { + opt.classes = config[PROPS.classes]; + } + if (config[PROPS.position]) { + opt.position = config[PROPS.position]; + } + return opt; + }; + angular.forEach(PROPS, function (prop) { - return attrs.$observe(prop, function (data) { + attrs.$observe(prop, function (data) { return config[prop] = data; }); + + if (tooltipInstance) { + tooltipInstance.setOptions(getOpt()); + } }); scope.$watch('tooltipEnabled', function (enabled) { if (enabled === undefined || enabled) { - var opt = { - target: element[0], - content: config[PROPS.tooltip] || config[PROPS.content] - }; - if (config[PROPS.classes]) { - opt.classes = config[PROPS.classes]; - } - if (config[PROPS.position]) { - opt.position = config[PROPS.position]; - } - tooltipInstance = new Tooltip(opt); + tooltipInstance = new Tooltip(getOpt()); } else if (tooltipInstance) { tooltipInstance.destroy(); + tooltipInstance = null; } }); diff --git a/dist/directive.js b/dist/directive.js index 1542839..08f14aa 100644 --- a/dist/directive.js +++ b/dist/directive.js @@ -15,27 +15,36 @@ var link = function link(scope, element, attrs) { var tooltipInstance = void 0, config = {}; + var getOpt = function getOpt() { + opt = { + target: element[0], + content: config[PROPS.tooltip] || config[PROPS.content] + }; + if (config[PROPS.classes]) { + opt.classes = config[PROPS.classes]; + } + if (config[PROPS.position]) { + opt.position = config[PROPS.position]; + } + return opt; + }; + angular.forEach(PROPS, function (prop) { - return attrs.$observe(prop, function (data) { + attrs.$observe(prop, function (data) { return config[prop] = data; }); + + if (tooltipInstance) { + tooltipInstance.setOptions(getOpt()); + } }); scope.$watch('tooltipEnabled', function (enabled) { if (enabled === undefined || enabled) { - var opt = { - target: element[0], - content: config[PROPS.tooltip] || config[PROPS.content] - }; - if (config[PROPS.classes]) { - opt.classes = config[PROPS.classes]; - } - if (config[PROPS.position]) { - opt.position = config[PROPS.position]; - } - tooltipInstance = new Tooltip(opt); + tooltipInstance = new Tooltip(getOpt()); } else if (tooltipInstance) { tooltipInstance.destroy(); + tooltipInstance = null; } }); diff --git a/src/directive.js b/src/directive.js index a0d9576..1ada2c7 100644 --- a/src/directive.js +++ b/src/directive.js @@ -9,25 +9,34 @@ const PROPS = { const link = (scope, element, attrs) => { let tooltipInstance, config = {}; - angular.forEach(PROPS, prop => - attrs.$observe(prop, data => config[prop] = data) - ); + const getOpt = () => { + opt = { + target: element[0], + content: config[PROPS.tooltip] || config[PROPS.content] + }; + if (config[PROPS.classes]) { + opt.classes = config[PROPS.classes]; + } + if (config[PROPS.position]) { + opt.position = config[PROPS.position]; + } + return opt; + } + + angular.forEach(PROPS, prop => { + attrs.$observe(prop, data => config[prop] = data); + + if (tooltipInstance) { + tooltipInstance.setOptions(getOpt()) + } + }); scope.$watch('tooltipEnabled', enabled => { if (enabled === undefined || enabled) { - let opt = { - target: element[0], - content: config[PROPS.tooltip] || config[PROPS.content] - }; - if (config[PROPS.classes]) { - opt.classes = config[PROPS.classes]; - } - if (config[PROPS.position]) { - opt.position = config[PROPS.position]; - } - tooltipInstance = new Tooltip(opt); + tooltipInstance = new Tooltip(getOpt()); } else if (tooltipInstance) { tooltipInstance.destroy(); + tooltipInstance = null; } });