-
Notifications
You must be signed in to change notification settings - Fork 1
/
bootstrap4-ui-components.js
155 lines (154 loc) · 8.16 KB
/
bootstrap4-ui-components.js
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
( function( $ ) {
window.$bs = {
$body : $( document.body ),
prompt : function( message, callback, type, title, button ) {
var me = this;
callback = callback || $.noop;
title = title || 'Alert';
type = type || 'default';
button = button || 'Ok';
return $( '<div class="modal fade" data-backdrop="static"><div class="modal-dialog"><div class="modal-content"><div class="card card-inverse pt-1 pl-1 pb-1 pr-1 card-' + type + '" style="margin-bottom: 0;"><div class="card-title"><button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button><h3>' + title + '</h3></div><div class="card-text"><p>' + message + '</p><textarea class="form-control" rows="5"></textarea></div><div class="card-footer"><div class="btn-group btn-group-lg btn-group-justified" role="group"><button type="button" class="btn btn-default" data-dismiss="modal">' + button + '</button></div></div></div></div></div></div>' ).appendTo( this.$body ).modal().on( 'hidden.bs.modal', function() {
callback( $( 'textarea', this ).val() );
$( this ).remove();
$( window ).trigger( 'resize' );
}).on( 'shown.bs.modal', function() {
$( 'textarea', this ).focus();
}).modal( 'show' );
}, alert : function( message, callback, type, title, button ) {
var me = this;
callback = callback || $.noop;
title = title || 'Alert';
type = type || 'info';
button = button || 'Ok';
return $( '<div class="modal fade" data-backdrop="static"><div class="modal-dialog" role="document"><div class="modal-content"><div class="card card-inverse pt-1 pl-1 pb-1 pr-1 card-' + type + '" style="margin-bottom: 0;"><div class="card-title"><button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button><h3>' + title + '</h3></div><div class="card-text"><p style="word-break: break-all;">' + message + '</p></div><div class="card-footer"><div class="btn-group btn-group-lg btn-group-justified" role="group"><button type="button" class="btn btn-default" data-dismiss="modal">' + button + '</button></div></div></div></div></div></div>' ).appendTo( this.$body ).modal().on( 'hidden.bs.modal', function() {
callback.call( me );
$( this ).remove();
$( window ).trigger( 'resize' );
}).modal( 'show' );
}, confirm : function( message, callback, type, title, buttons ) {
var me = this;
callback = callback || $.noop;
title = title || 'Confirm';
type = type || 'default';
buttons = buttons || [ 'Ok', 'Cancel' ];
return $confirmModal = $( '<div class="modal fade" data-backdrop="static"><div class="modal-dialog"><div class="modal-content"><div class="card card-inverse pt-1 pl-1 pb-1 pr-1 card-' + type + '" style="margin-bottom: 0;"><div class="card-title"><button type="button" rel="0" class="close" data-dismiss="modal" aria-hidden="true">×</button><h3>' + title + '</h3></div><div class="card-text"><p style="word-break: break-all;">' + message + '</p></div><div class="card-footer"><div class="btn-group btn-group-lg btn-group-justified" role="group">' + buttons.map( function( b, i ) {
return '<button type="button" rel="' + ( i + 1 ) + '" class="btn btn-default">' + b + '</button>';
}).join( '' ) + '</div></div></div></div></div></div>' ).appendTo( this.$body ).modal().on( 'click', 'button', function() {
$confirmModal.modal( 'hide' );
callback.call( me, this.getAttribute( 'rel' ) );
}).modal( 'show' ).on( 'hidden.bs.modal', function() {
$( this ).remove();
$( window ).trigger( 'resize' );
});
}, popup : function( url, type, title, callback, backdrop ) {
type = type || 'default';
backdrop = backdrop || 'static';
return $( '<div class="modal fade" data-backdrop="' + backdrop + '"><div class="modal-dialog modal-lg"><div class="modal-content"><div class="card card-inverse pt-1 pl-1 pb-1 pr-1 card-' + type + '" style="margin-bottom: 0;"><div class="card-title"><button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button><h3>' + ( title ? title : '<i class="fa fa-gear fa-spin"></i> Loading ...' ) + '</h3></div><div class="card-text"><div class="embed-responsive embed-responsive-4by3"><iframe class="embed-responsive-item" style="width: 100%;min-height: 200px;border: none;" src="javascript:;"></iframe></div></div></div></div></div></div>' ).appendTo( this.$body ).modal().on( 'hidden.bs.modal', function() {
$( this ).remove();
$( window ).trigger( 'resize' );
}).on( 'shown.bs.modal', function() {
var $modal = $( this ), $iframe = $( 'iframe', $modal );
if( $iframe[ 0 ].src != 'javascript:;' ) {
return false;
}
$iframe.on( 'load', function() {
var iWin = this.contentWindow || this, $iframe = $( this );
iWin.parentSuccessCallback = function() {
callback.apply( window, arguments );
$modal.modal( 'hide' );
};
iWin.parentErrorCallback = function() {
$modal.modal( 'hide' );
};
$( iWin.document ).on( 'load', 'img', function() {
$iframe.height( window.innerHeight * .75 );
});
$iframe.height( window.innerHeight * .75 );
$( 'h3', $modal ).text( iWin.document.title );
})[ 0 ].src = url;
}).modal( 'show' );
}, loader : {
counter : 0,
show : function( options ) {
if( $( '#bsLoaderModal' ).length > 0 ) {
this.counter++;
return false;
}
options = $.extend( {
message : 'Loading ...',
showIcon : true,
icon : 'gear',
spinIcon : true,
timeout : 0,
callback : $.noop,
type : 'info'
}, options );
$( '<div id="bsLoaderModal" class="modal fade" data-backdrop="static"><div class="modal-dialog"><div class="modal-content"><div class="card card-inverse pt-1 pl-1 pb-1 pr-1 card-' + options.type + '" style="margin-bottom: 0;"><div class="card-title"><h3>' + ( options.showIcon ? '<i class="fa fa-' + options.icon + ( options.spinIcon ? ' fa-spin' : '' ) + '"></i> ' : '' ) + options.message + '</h3></div></div></div></div></div>' ).appendTo( $bs.$body ).modal().modal( 'show' ).on( 'hidden.bs.modal', function() {
$( this ).remove();
$( window ).trigger( 'resize' );
options.callback();
}).on( 'shown.bs.modal', function() {
options.timeout && setTimeout( function() {
$bs.loader.hide();
}, options.timeout );
});
}, hide : function() {
if( this.counter > 0 ) {
this.counter--;
return false;
}
$( '#bsLoaderModal' ).modal( 'hide' );
}
}, progress : {
started : false,
percent : 10,
start : function( type, update ) {
if( $( '#app-progress' ).length == 0 ) {
$( '<style type="text/css">#app-progress{position: fixed;display: none;position: fixed;top: 0;left: 0;width: 10%;z-index: 100;height: 3px;width: 10%;background: #ef5350;}#app-progress.in{display: block;}#app-progress:after{position: absolute;content: \'\';top: 0;opacity: 1;width: 10%;right: 0px;height: 3px;box-shadow: #b91f1f 1px 0 6px 2px;border-radius: 50%;}</style>' ).appendTo( document.head );
$( '<div id="app-progress"></div>' ).prependTo( document.body );
}
type = type || 'danger';
update = typeof update == 'undefined' ? true : update;
$( '.bs-progress', $( '#app-progress' ).addClass( 'in' ) );
this.started = true;
this.percent = 10;
update && setTimeout( this.update.bind( this ), parseInt( Math.random() * 10000000 ) % 1500 );
}, update : function() {
if( !this.started ) {
return false;
}
var me = this;
this.notify( this.percent + ( parseInt( Math.random() * 10000000 ) % 30 ), function() {
setTimeout( me.update.bind( me ), parseInt( Math.random() * 10000000 ) % 1500 );
});
}, notify : function( percent, callback ) {
if( !this.started ) {
return false;
}
if( percent > 95 ) {
percent = 95;
}
if( percent <= this.percent ) {
return false;
}
this.percent = percent;
callback = callback || $.noop;
$( '#app-progress' ).animate({
width : percent + '%'
}, 'fast', callback );
}, end : function() {
if( !this.started ) {
return false;
}
var me = this;
$( '#app-progress' ).animate({
width : '100%'
}, 'fast', function() {
$( '#app-progress' ).removeClass( 'in' ).removeAttr( 'style' );
me.started = false;
me.percent = 10;
});
}
}
};
})( jQuery );