forked from olton/Metro-UI-CSS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pagecontrol.js
64 lines (58 loc) · 2.22 KB
/
pagecontrol.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
(function($){
$.fn.PageControl = function( options ){
var defaults = {
};
var $this = $(this)
, $ul = $this.children("ul")
, $selectors = $ul.find("li a")
, $selector = $ul.find(".active a")
, $frames = $this.find(".frames .frame")
, $frame = $frames.children(".frame.active")
;
var initSelectors = function(selectors){
selectors.on('click', function(e){
e.preventDefault();
var $a = $(this);
if (!$a.parent('li').hasClass('active')) {
$frames.hide();
$ul.find("li").removeClass("active");
var target = $($a.attr("href"));
target.show();
$(this).parent("li").addClass("active");
}
if ($(this).parent("li").parent("ul").parent(".page-control").find(".menu-pull-bar").is(":visible")) {
$(this).parent("li").parent("ul").slideUp("fast", function () {
$(this).css("overflow", "").css("display", "");
});
}
});
$(".page-control .menu-pull-bar").text($(".page-control ul li.active a").text());
$(".page-control ul li a").click(function (e) {
e.preventDefault();
$(this).parent("li").parent("ul").parent(".page-control").find(".menu-pull-bar").text($(this).text());
});
}
return this.each(function(){
if ( options ) {
$.extend(defaults, options)
}
initSelectors($selectors);
});
}
$(function () {
$('[data-role="page-control"]').each(function () {
$(this).PageControl();
})
$(window).resize(function(){
if ($(window).width() >= 768) {
$(".page-control ul").css({
display: "block"
,overflow: "visible"
})
}
if ($(window).width() < 768 && $(".page-control ul").css("display") == "block") {
$(".page-control ul").hide();
}
})
})
})(window.jQuery);