-
Notifications
You must be signed in to change notification settings - Fork 1
/
jquery.fullscreen.js
143 lines (125 loc) · 4.06 KB
/
jquery.fullscreen.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
/**
* jQuery Fullscreen 0.1
*
* CopyRight 2014 Prabin Giri
*
* Download Source:
* https://github.com/prabeengiri/jquery_fullscreen/archive/master.zip
* Depends:
* jQuery.js
*
* This Fullscreen Plugin will expand the selected element to fullscreen
* with close button at the top. It does not clone and append the
* fullscreen element like Lighbox, ModalBox. It can be perfectly used with
* Iframes. It does not reload the iframes.
*/
(function($) {
// Construct the Fullscreen Object.
var FullScreen = function (el, options) {
if (el.size() == 0) {
throw new Error("FullScreen element not found in current context.");
return;
}
this.settings = $.extend({}, this.defaults, options);
this.fullScreenElement = el;
this.init();
this.fullScreenMode = false;
};
// Extend Fullscreen Object.
FullScreen.prototype = {
defaults : {
fullScreenElement: null,
cancel : null,
title : function(fullScreenElement) {
return null;
},
//Activates fullscreen when CTRL + F key is pressed.
controlF : false,
hidden: function (el) {},
shown: function (el) {},
exitTitle: "Exit Fullscreen",
titleLength: 85
},
// Show fullscreen when fullscreen icon/link is clicked.
init : function () {
this.showAll();
},
// Display fullscreen and exit bar.
showAll : function() {
this.showFullScreen();
this.showCloseUI();
this.fullScreenMode = true;
// Expose event.
this.settings.shown(this.fullScreenElement);
this.fullScreenElement.trigger('onFullScreenShown', [this.fullScreenElement]);
},
hideAll: function () {
this.hideCloseUI();
this.hideFullScreen();
this.fullScreenMode = false;
// Expose event.
this.settings.hidden(this.fullScreenElement);
this.fullScreenElement.trigger('onFullScreenHidden', [this.fullScreenElement]);
},
showCloseUI : function () {
var self = this;
var title = this.trimTitle ( self.settings.title(self.fullScreenElement) );
$("<div>", {
'id' : 'fullscreen-close',
'align' : "center"
})
.appendTo('body')
.append('<span class="fullscreen-title">' + title + "</span>")
.append("<span class='fullscreen-close-text'>" + self.settings.exitTitle + "</span>")
.slideDown('slow', function() {
$(this).click(function () {
self.hideAll();
});
});
// Hide ScrollBar.
$('html,body').css({'overflow' : 'hidden'});
},
// Trim title if its too long with dots.
trimTitle : function (title) {
if (title.length > this.settings.titleLength) {
return title.substring(0, this.settings.titleLength) + " ...";
}
return title;
},
// Remove the Close UI from DOM.
hideCloseUI : function () {
$('#fullscreen-close').slideUp('fast', function () {
$(this).remove();
});
// Get the scrollbar back.
$('html,body').css({'overflow' : 'auto'});
},
showFullScreen : function() {
// @todo What if fullscreenElement has inline height/width and its set
// as important.
this.fullScreenElement.addClass('fullscreen-active');
},
hideFullScreen: function() {
this.fullScreenElement.toggleClass('fullscreen-active');
},
keyDown : function (e) {
// Close when ESC key is pressed and fullscreen mode is on.
if (e.keyCode == 27 && this.fullScreenMode) {
this.hideAll();
}
// Open the fullscreen on ctrl + f.
else if(e.keyCode == 70 && e.ctrlKey && e.shiftKey && !this.fullScreenMode && this.settings.controlF) {
this.showAll();
}
// If tab is pressed, it puts focus on other elements in DOM which are not being
// displayed and its messes the fullscreen.
else if (e.keyCode == 9 && this.fullScreenMode) {
e.preventDefault();
}
}
};
$.fn.FullScreen = function(options) {
new FullScreen(this, options);
return this;
};
})(jQuery);