forked from mattkersley/Responsive-Design-Testing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
responsive.js
110 lines (90 loc) · 2.67 KB
/
responsive.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
var defaultURL = 'nauweb.com'; //<---- CHANGE TO YOUR WEBSITE URL
//show loading graphic
function showLoader(id) {
$('#' + id + ' img').fadeIn('slow');
}
//hdie loading graphic
function hideLoader(id) {
$('#' + id + ' img').fadeOut('slow');
}
//function to check load state of each frame
function allLoaded(){
var results = [];
$('iframe').each(function(){
if(!$(this).data('loaded')){results.push(false)}
});
var result = (results.length > 0) ? false : true;
return result;
};
function loadPage($frame, url) {
if ( url.substr(0,7) !== 'http://' && url.substr(0,8) !== 'https://' && url.substr(0, 7) !== 'file://' ) {
url = 'http://'+url;
}
$('iframe').not($frame).each(function(){showLoader($(this).parent().attr('id'));})
$('iframe').not($frame).data('loaded', false);
$('iframe').not($frame).attr('src', url);
}
$('.frame').each(function(){showLoader($(this).attr('id'))});
//when document loads
$(document).ready(function(){
loadPage('', defaultURL);
//query string
var qsArray = window.location.href.split('?');
var qs = qsArray[qsArray.length-1];
if(qs != '' && qsArray.length > 1){
$('#url input[type=text]').val(qs);
loadPage('', qs);
}
//set slidable div width
$('#frames #inner').css('width', function(){
var width = 0;
$('.frame').each(function(){width += $(this).outerWidth() + 20});
return width;
});
//add event handlers for options radio buttons
$('input[type=radio]').change(function(){
$frames = $('#frames');
$inputs = $('input[type=radio]:checked').val();
if($inputs == '1'){
$frames.addClass('widthOnly');
} else {
$frames.removeClass('widthOnly');
}
});
//when the url textbox is used
$('form').submit(function(){
loadPage('' , $('#url input[type=text]').val());
return false;
});
//when frame loads
$('iframe').load(function(){
var $this = $(this);
var url = '';
var error = false;
try{
url = $this.contents().get(0).location.href;
} catch(e) {
error = true;
if($('#url input[type=text]').val() != ''){
url = $('#url input[type=text]').val();
} else {
url = defaultURL;
}
}
//load other pages with the same URL
if(allLoaded()){
if(error){
alert('Browsers prevent navigation from inside iframes across domains.\nPlease use the textbox at the top for external sites.');
loadPage('', defaultURL);
}else{
loadPage($this, url);
}
}
//when frame loads, hide loader graphic
else{
error = false;
hideLoader($(this).parent().attr('id'));
$(this).data('loaded',true);
}
});
});