Skip to content
This repository was archived by the owner on Jul 12, 2020. It is now read-only.

Commit 8484add

Browse files
authored
Merge pull request #88 from yamgent/383-fix-seamless-panel-caret
Fix seamless panel caret
2 parents 433c7d0 + 93515d4 commit 8484add

File tree

1 file changed

+25
-55
lines changed

1 file changed

+25
-55
lines changed

src/Panel.vue

Lines changed: 25 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@
1616
<div :class="['card-header',{'header-toggle':isExpandableCard}, cardType, borderType]"
1717
@click.prevent.stop="isExpandableCard && toggle()"
1818
@mouseover="onHeaderHover = true" @mouseleave="onHeaderHover = false">
19-
<div class="header-wrapper" ref="headerWrapper">
19+
<div class="caret-wrapper">
20+
<span :class="['glyphicon', localExpanded ? 'glyphicon-chevron-down' : 'glyphicon-chevron-right']" v-if="showCaret"></span>
21+
</div>
22+
<div class="header-wrapper">
2023
<slot name="header">
2124
<div :class="['card-title', cardType, {'text-white':!isLightBg}]" v-html="headerContent"></div>
2225
</slot>
@@ -204,38 +207,10 @@
204207
return this.cardType === 'bg-light' || this.cardType === 'bg-white' || this.cardType === 'bg-warning';
205208
},
206209
headerContent () {
207-
return this.renderedHeader;
210+
return md.render(this.header);
208211
},
209212
altContent () {
210-
return this.alt && md.render(this.alt) || this.renderedHeader;
211-
},
212-
renderedHeader () {
213-
if (!this.header) {
214-
return '';
215-
}
216-
217-
let htmlRenderedHeader = md.render(this.header).trim();
218-
219-
if (this.isSeamless) {
220-
// insert the caret to the header content
221-
let caretAdded = false;
222-
223-
// if the header content is wrapped by a <p> or any <h1>, <h2>, ...
224-
// then it must be inserted inside these HTML tags, otherwise the
225-
// header content will not be in the same line as caret
226-
const tags = ['<p>', '<h1>', '<h2>', '<h3>', '<h4>', '<h5>', '<h6>'];
227-
tags.forEach(tag => {
228-
if (!caretAdded && htmlRenderedHeader.startsWith(tag)) {
229-
htmlRenderedHeader = this.insertCaretInsideHeader(htmlRenderedHeader);
230-
caretAdded = true;
231-
}
232-
});
233-
234-
if (!caretAdded) {
235-
htmlRenderedHeader = this.caretHtml + ' ' + htmlRenderedHeader;
236-
}
237-
}
238-
return htmlRenderedHeader;
213+
return this.alt && md.render(this.alt) || md.render(this.header);
239214
},
240215
hasSrc () {
241216
return this.src && this.src.length > 0;
@@ -246,16 +221,6 @@
246221
} else {
247222
return onHeaderHover;
248223
}
249-
},
250-
caretHtml () {
251-
if (this.localExpanded) {
252-
return '<span class="glyphicon glyphicon-chevron-down" aria-hidden="true"></span>'
253-
} else {
254-
return '<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>'
255-
}
256-
},
257-
hasCustomHeader () {
258-
return this.$slots.header !== undefined;
259224
}
260225
},
261226
data () {
@@ -299,11 +264,6 @@
299264
if (isOpen && this.hasSrc) {
300265
this.$refs.retriever.fetch()
301266
}
302-
},
303-
insertCaretInsideHeader(originalHeaderHTML) {
304-
const wrappedElementName = jQuery(originalHeaderHTML).attr("name");
305-
return jQuery(originalHeaderHTML).unwrap().prepend(this.caretHtml + ' ')
306-
.wrap(`<${wrappedElementName}></${wrappedElementName}>`).parent().html();
307267
}
308268
},
309269
watch: {
@@ -332,11 +292,6 @@
332292
if (this.hasSrc && (this.preloadBool || this.expandedBool)) {
333293
this.$refs.retriever.fetch()
334294
}
335-
336-
if (this.hasCustomHeader) {
337-
this.$refs.headerWrapper.innerHTML =
338-
this.insertCaretInsideHeader(this.$refs.headerWrapper.innerHTML);
339-
}
340295
});
341296
const panelHeader = this.$slots.header ? this.$refs.headerWrapper.innerHTML : this.headerContent;
342297
const panelHeaderText = jQuery(panelHeader).wrap('<div></div>').parent().find(':header').text();
@@ -363,15 +318,21 @@
363318
margin: 0px !important;
364319
}
365320
321+
.caret-wrapper {
322+
float: left;
323+
display: inline-block;
324+
width: 32px;
325+
}
326+
366327
.header-wrapper {
367328
display: inline-block;
368-
width: 72%;
329+
width: calc(100% - 32px - 96px);
369330
}
370331
371332
.button-wrapper {
372333
float: right;
373334
display: inline-block;
374-
width: 28%;
335+
width: 96px;
375336
}
376337
377338
.header-toggle {
@@ -450,12 +411,21 @@
450411
/* Bootstrap extra small(xs) responsive breakpoint */
451412
@media (max-width: 575.98px) {
452413
414+
.caret-wrapper {
415+
float: left;
416+
display: inline-block;
417+
width: 32px;
418+
}
419+
453420
.header-wrapper {
454-
width: 88%;
421+
display: inline-block;
422+
width: calc(100% - 32px - 32px);
455423
}
456424
457425
.button-wrapper {
458-
width: 12%;
426+
float: right;
427+
display: inline-block;
428+
width: 32px;
459429
}
460430
461431
.card-body {

0 commit comments

Comments
 (0)