Wer kann Plugin für Link Peview bauen?

02.04.2021 15:39 (zuletzt bearbeitet: 02.04.2021 15:51)
avatar  dirk_71
#1 Wer kann Plugin für Link Peview bauen?
avatar
Mitglied

Hi,

ich habe in meinem Forum ein Preview für Links eingebaut.
Kann jemand daraus ein Plugin machen? Ich habe noch nie ein Plugin entwickelt.
Ich brauche es für das mobile Template V6.
Der Code ansich ist recht einfach und besteht aus 2 Teilen.

Einmal CSS

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
 

.mini-preview-anchor {
display: inline-block;
position: relative;
white-space: nowrap;
}
 
.mini-preview-wrapper {
-moz-box-sizing: content-box;
box-sizing: content-box;
position: relative;
overflow: hidden;
z-index: 9999;
opacity: 0;
margin-top: -4px;
border: solid 1px #000;
box-shadow: 4px 4px 6px rgba(0, 0, 0, .3);
transition: z-index steps(1) .3s, opacity .3s, margin-top .3s;
}
 
.mini-preview-anchor:hover .mini-preview-wrapper {
z-index: 2;
opacity: 1;
margin-top: 6px;
transition: opacity .3s, margin-top .3s;
}
 
.mini-preview-loading, .mini-preview-cover {
position: absolute;
top: 0;
bottom: 0;
right: 0;
left: 0;
}
 
.mini-preview-loading {
display: table;
height: 100%;
width: 100%;
font-size: 1.25rem;
text-align: center;
color: #f5ead4;
background-color: #59513f;
}
 
.mini-preview-loading::before {
content: 'Loading...';
display: table-cell;
text-align: center;
vertical-align: middle;
}
 
.mini-preview-cover {
background-color: rgba(0, 0, 0, 0); /* IE fix */
}
 
.mini-preview-frame {
border: none;
-webkit-transform-origin: 0 0;
transform-origin: 0 0;
}
 
 



Und dieses Javascript

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
 

(function($) {
var PREFIX = 'mini-preview';

// implemented as a jQuery plugin
$.fn.miniPreview = function(options) {
return this.each(function() {
var $this = $(this);
var miniPreview = $this.data(PREFIX);
if (miniPreview) {
miniPreview.destroy();
}
 
miniPreview = new MiniPreview($this, options);
miniPreview.generate();
$this.data(PREFIX, miniPreview);
});
};

var MiniPreview = function($el, options) {
this.$el = $el;
this.$el.addClass(PREFIX + '-anchor');
this.options = $.extend({}, this.defaultOptions, options);
this.counter = MiniPreview.prototype.sharedCounter++;
};

MiniPreview.prototype = {
sharedCounter: 0,

defaultOptions: {
width: 379,
height: 216,
scale: .45,
prefetch: 'parenthover'
},

generate: function() {
this.createElements();
this.setPrefetch();
},
 
createElements: function() {
var $wrapper = $('<div>', { class: PREFIX + '-wrapper' });
var $loading = $('<div>', { class: PREFIX + '-loading' });
var $frame = $('<iframe>', { class: PREFIX + '-frame' });
var $cover = $('<div>', { class: PREFIX + '-cover' });
$wrapper.appendTo(this.$el).append($loading, $frame, $cover);

// sizing
$wrapper.css({
width: this.options.width + 'px',
height: this.options.height + 'px'
});

// scaling
var inversePercent = 100 / this.options.scale;
$frame.css({
width: inversePercent + '%',
height: inversePercent + '%',
transform: 'scale(' + this.options.scale + ')'
});
 
// positioning
var fontSize = parseInt(this.$el.css('font-size').replace('px', ''), 10)
var top = (this.$el.height() + fontSize) / 10;
var left = (this.$el.width() - $wrapper.outerWidth()) / 10 + 400;
$wrapper.css({
top: top + 'px',
left: left + 'px'
});
},

setPrefetch: function() {
switch (this.options.prefetch) {
case 'pageload':
this.loadPreview();
break;
case 'parenthover':
this.$el.parent().one(this.getNamespacedEvent('mouseenter'),
this.loadPreview.bind(this));
break;
case 'none':
this.$el.one(this.getNamespacedEvent('mouseenter'),
this.loadPreview.bind(this));
break;
default:
throw 'Prefetch setting not recognized: ' + this.options.prefetch;
break;
}
},

loadPreview: function() {
this.$el.find('.' + PREFIX + '-frame')
.attr('src', this.$el.attr('href'))
.on('load', function() {
// some sites don't set their background color
$(this).css('background-color', '#fff');
});
},

getNamespacedEvent: function(event) {
return event + '.' + PREFIX + '_' + this.counter;
},
 
destroy: function() {
this.$el.removeClass(PREFIX + '-anchor');
this.$el.parent().off(this.getNamespacedEvent('mouseenter'));
this.$el.off(this.getNamespacedEvent('mouseenter'));
this.$el.find('.' + PREFIX + '-wrapper').remove();
}
};
})(jQuery);
$(function() {
$('.xquoteable a[target*="blank"]').miniPreview({ prefetch: 'none' });
 
});
 
 



Bisher habe ich es nur im eigenen CCS und JS Teil des Forum eingebunden.

Es wird im Moment bei allen Links automatisch generiert wenn sie als target blank haben, also alle externen Links
Siehe Beispiel


 Antworten

 Beitrag melden
Bereits Mitglied?
Jetzt anmelden!
Mitglied werden?
Jetzt registrieren!