Comparing version 1.2.0 to 1.2.1
{ | ||
"name": "coachmarks", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"description": "On-board new users to your app and introduce new features with SVG sketches (coachmarks)", | ||
@@ -5,0 +5,0 @@ "source": "src/index.js", |
@@ -15,3 +15,3 @@ function cache(...args) { | ||
cache.addOrGet = (name, obj) => { | ||
cache.init(); | ||
// cache.init(); | ||
if (typeof obj === 'undefined') { | ||
@@ -29,3 +29,3 @@ // Get | ||
cache.get = name => { | ||
cache.init(); | ||
// cache.init(); | ||
return cache.cache[name]; | ||
@@ -35,3 +35,3 @@ }; | ||
cache.add = (name, obj) => { | ||
cache.init(); | ||
// cache.init(); | ||
cache.cache[name] = obj; | ||
@@ -43,3 +43,3 @@ return obj; | ||
cache.remove = name => { | ||
cache.init(); | ||
// cache.init(); | ||
if (name) delete cache.cache[name]; | ||
@@ -49,3 +49,3 @@ }; | ||
cache.clear = () => { | ||
cache.init(); | ||
// cache.init(); | ||
for (const c of cache.cache) { | ||
@@ -64,3 +64,3 @@ cache.cache[c] = undefined; | ||
cache.all = () => { | ||
cache.init(); | ||
// cache.init(); | ||
return cache.cache; | ||
@@ -70,5 +70,5 @@ }; | ||
cache.allArray = () => { | ||
cache.init(); | ||
// cache.init(); | ||
const elms = []; | ||
for (const key in cache) { | ||
for (const key in cache.cache) { | ||
if (Object.prototype.hasOwnProperty.call(cache.cache, key)) { | ||
@@ -75,0 +75,0 @@ elms.push({ key: cache.cache[key] }); |
@@ -48,3 +48,3 @@ 'use strict'; | ||
Object.values(cache.all()).forEach(val => { | ||
if (val.showing) val.showing = false; | ||
if (val && val.showing) val.showing = false; | ||
}); | ||
@@ -57,3 +57,7 @@ } | ||
const mark = cache(name); | ||
if (!mark) throw new Error(`Coachmark with name '${name}' not found`); | ||
if (!mark) { | ||
console.error(`Coachmark with name '${name}' not found`); | ||
return; | ||
} | ||
mark.showing = true; | ||
@@ -70,5 +74,13 @@ mark.name = name; | ||
function coach(mark) { | ||
if (!mark) throw new Error(`Coachmark with name '${name}' not found`); | ||
if (!mark) { | ||
console.error(`No mark specified`); | ||
return; | ||
} | ||
const elm = document.querySelector(mark.target); | ||
if (!elm) { | ||
console.error(`Couldn't find element '${mark.target}' for mark ${mark.name}`); | ||
return; | ||
} | ||
cache.set('elm', elm); | ||
@@ -79,3 +91,3 @@ | ||
// elm.style.position = 'absolute'; | ||
elm.style['z-index'] = 102; | ||
// elm.style['z-index'] = 102; | ||
@@ -85,6 +97,8 @@ const borderRadius = window.getComputedStyle(elm).getPropertyValue('border-radius'); | ||
const top = elm.offsetTop; | ||
const left = elm.offsetLeft; | ||
const width = elm.offsetWidth; | ||
const height = elm.offsetHeight; | ||
const rect = elm.getBoundingClientRect(); | ||
const top = rect.top; | ||
const left = rect.left; | ||
const width = rect.width; | ||
const height = rect.height; | ||
const right = left + width; | ||
@@ -150,7 +164,7 @@ const bottom = top + height; | ||
export function addText(textStr) { | ||
const elm = cache('elm'); | ||
if (!elm) return; | ||
const text = cache.default('text', () => document.createElement('div')); | ||
const elm = cache('elm'); | ||
if (!elm) throw new Error('Could not get element from cache'); | ||
const [box1, box2] = splitScreen(); | ||
@@ -171,6 +185,6 @@ | ||
textContainer.className = 'coachmark-text-container'; | ||
textContainer.style.top = box.top; | ||
textContainer.style.left = box.left; | ||
textContainer.style.width = box.width; | ||
textContainer.style.height = box.height; | ||
textContainer.style.top = box.top + 'px'; | ||
textContainer.style.left = box.left + 'px'; | ||
textContainer.style.width = box.width + 'px'; | ||
textContainer.style.height = box.height + 'px'; | ||
@@ -188,2 +202,4 @@ textContainer.appendChild(text); | ||
function leaderLine(from, to) { | ||
if (!from || !to) return; | ||
let line = cache.get('leaderLine'); | ||
@@ -305,4 +321,7 @@ if (line) { | ||
if (mark.flow) { | ||
const next = mark.flow.getNext(mark.name); | ||
let flow = cache('flow'); | ||
if (mark.flow) flow = cache.set('flow', mark.flow); | ||
if (flow) { | ||
const next = flow.getNext(mark.name); | ||
if (next) { | ||
@@ -313,3 +332,3 @@ icon = nextButtonHTML(); | ||
}; | ||
} | ||
} else cache.remove('flow'); | ||
} | ||
@@ -316,0 +335,0 @@ |
@@ -14,2 +14,4 @@ function clean(name) { | ||
this.flow.push(name); | ||
return this; | ||
} | ||
@@ -16,0 +18,0 @@ |
@@ -10,3 +10,3 @@ import cache from './cache'; | ||
window.CoachmarkCache = cache.cache; | ||
window.CoachmarkCache = cache; | ||
@@ -21,2 +21,7 @@ export default { | ||
if (!config.text) { | ||
console.log('No text specified'); | ||
return; | ||
} | ||
cache(`mark.${name}`, config); | ||
@@ -23,0 +28,0 @@ }, |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
402889
3032