general.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. jQuery(document).ready(function() {
  2. var $ = jQuery;
  3. var screenRes = $(window).width();
  4. $("[href=#]").click(function(event){
  5. event.preventDefault();
  6. });
  7. // Dropdown Menu
  8. $(".dropdown li").hover(function(){
  9. $(this).addClass('hover');
  10. },function(){
  11. $(this).removeClass('hover');
  12. });
  13. // Remove outline in IE
  14. $("a, input, textarea").attr("hideFocus", "true").css("outline", "none");
  15. // Add gradient to IE
  16. setTimeout(function () {
  17. $(".btn span, .btn input").addClass("gradient");
  18. }, 0);
  19. // buttons
  20. $(".btn-left, .btn-right").hover(function(){
  21. $(this).stop().animate({"opacity": 0.8});
  22. },function(){
  23. $(this).stop().animate({"opacity": 1});
  24. });
  25. $('a.btn, span.btn').on('mousedown', function(){
  26. $(this).addClass('active')
  27. });
  28. $('a.btn, span.btn').on('mouseup mouseout', function(){
  29. $(this).removeClass('active')
  30. });
  31. // style Select, Radio, Checkbox
  32. if ($("select").hasClass("select_styled")) {
  33. cuSel({changedEl: ".select_styled", visRows: 10});
  34. }
  35. if ($("div,p").hasClass("input_styled")) {
  36. $(".input_styled input").customInput();
  37. }
  38. // First Child, Last Child
  39. $("li:first-child, .cusel span:first-child").addClass("first");
  40. $("li:last-child, .cusel span:last-child").addClass("last");
  41. // NavBar Parents Arrow
  42. $(".dropdown ul").parent("li").addClass("parent");
  43. // List Selector
  44. $('#listSelector li a').click(function(){
  45. $('#listSelector li').removeClass('selected');
  46. $('#listSelector .list-double a').removeClass('border-left border-right');
  47. $(this).parent().addClass('selected');
  48. if($('#listSelector .list-multi').hasClass('selected')) {$('#listSelector .list-double a').addClass('border-right')}
  49. if($('#listSelector .list-single').hasClass('selected')) {$('#listSelector .list-double a').addClass('border-left')}
  50. });
  51. // Scroll Bars
  52. var scrolls = $('.scrollbar').length;
  53. var scrollHeight = 0;
  54. for(var i = 1; i <= scrolls; i++){
  55. $('.scrollbar').eq(i-1).addClass('id'+i);
  56. };
  57. setTimeout(function () {
  58. $(".jspTrack").append("<div class='jspProgress'></div>");
  59. $(document).on('jsp-scroll-y','.scrollbar',function(){
  60. for(var i = 1; i <= scrolls; i++){
  61. scrollHeight = $('.scrollbar.id'+i+' .jspDrag').css('top');
  62. $('.scrollbar.id'+i+' .jspDrag').siblings(".jspProgress").css({"height":parseInt(scrollHeight, 10)+10+"px"});
  63. }
  64. });
  65. }, 0);
  66. // Tabs
  67. var $tabs_on_page = $('.tabs').length;
  68. var $bookmarks = 0;
  69. for(var i = 1; i <= $tabs_on_page; i++){
  70. $('.tabs').eq(i-1).addClass('tab_id'+i);
  71. $bookmarks = $('.tab_id'+i+' li').length;
  72. $('.tab_id'+i).addClass('bookmarks'+$bookmarks);
  73. };
  74. $('.tabs li, .payment-form .btn').click(function() {
  75. setTimeout(function () {
  76. for(var i = 1; i <= $tabs_on_page; i++){
  77. $bookmarks = $('.tab_id'+i+' li').length;
  78. for(var j = 1; j <= $bookmarks; j++){
  79. $('.tab_id'+i).removeClass('active_bookmark'+j);
  80. if($('.tab_id'+i+' li').eq(j-1).hasClass('active')){
  81. $('.tab_id'+i).addClass('active_bookmark'+j);
  82. }
  83. }
  84. }
  85. }, 0)
  86. });
  87. // Payment Form
  88. $('.payment-form #billing .btn-next, .payment-form #payment .btn-prev').click(function() {
  89. $('a[href="#shipping"]').tab('show');
  90. });
  91. $('.payment-form #shipping .btn-prev').click(function() {
  92. $('a[href="#billing"]').tab('show');
  93. });
  94. $('.payment-form #shipping .btn-next').click(function() {
  95. $('a[href="#payment"]').tab('show');
  96. });
  97. // prettyPhoto lightbox, check if <a> has atrr data-rel and hide for Mobiles
  98. if($('a').is('[data-rel]') && screenRes > 600) {
  99. $('a[data-rel]').each(function() {
  100. $(this).attr('rel', $(this).data('rel'));
  101. });
  102. $("a[rel^='prettyPhoto']").prettyPhoto({social_tools:false});
  103. };
  104. // Smooth Scroling of ID anchors
  105. function filterPath(string) {
  106. return string
  107. .replace(/^\//,'')
  108. .replace(/(index|default).[a-zA-Z]{3,4}$/,'')
  109. .replace(/\/$/,'');
  110. }
  111. var locationPath = filterPath(location.pathname);
  112. var scrollElem = scrollableElement('html', 'body');
  113. $('a[href*=#].anchor').each(function() {
  114. $(this).click(function(event) {
  115. var thisPath = filterPath(this.pathname) || locationPath;
  116. if ( locationPath == thisPath
  117. && (location.hostname == this.hostname || !this.hostname)
  118. && this.hash.replace(/#/,'') ) {
  119. var $target = $(this.hash), target = this.hash;
  120. if (target && $target.length != 0) {
  121. var targetOffset = $target.offset().top;
  122. event.preventDefault();
  123. $(scrollElem).animate({scrollTop: targetOffset}, 400, function() {
  124. location.hash = target;
  125. });
  126. }
  127. }
  128. });
  129. });
  130. // use the first element that is "scrollable"
  131. function scrollableElement(els) {
  132. for (var i = 0, argLength = arguments.length; i <argLength; i++) {
  133. var el = arguments[i],
  134. $scrollElement = $(el);
  135. if ($scrollElement.scrollTop()> 0) {
  136. return el;
  137. } else {
  138. $scrollElement.scrollTop(1);
  139. var isScrollable = $scrollElement.scrollTop()> 0;
  140. $scrollElement.scrollTop(0);
  141. if (isScrollable) {
  142. return el;
  143. }
  144. }
  145. }
  146. return [];
  147. };
  148. // Audio Player
  149. var $players_on_page = $('.jp-audio').length;
  150. var $song_title = '';
  151. if($players_on_page > 0){
  152. for(var i = 1; i <= $players_on_page; i++){
  153. $('.jp-audio').eq(i-1).addClass('jp-audio'+i);
  154. };
  155. setTimeout(function () {
  156. for(var i = 1; i <= $players_on_page; i++){
  157. $song_title = $('.jp-audio'+i+' .jp-playlist ul li.jp-playlist-current .jp-playlist-item').html();
  158. $('.jp-audio'+i+' .song_title').html($song_title);
  159. };
  160. }, 1000);
  161. function switchSong() {
  162. setTimeout(function () {
  163. for(var i = 1; i <= $players_on_page; i++){
  164. $('.jp-audio'+i+' .jp-previous, .jp-audio'+i+' .jp-next').removeClass('disabled');
  165. if ($('.jp-audio'+i+' .jp-playlist ul li:last-child').hasClass('jp-playlist-current')) {
  166. $('.jp-audio'+i+' .jp-next').addClass('disabled');
  167. }
  168. if ($('.jp-audio'+i+' .jp-playlist ul li:first-child').hasClass('jp-playlist-current')) {
  169. $('.jp-audio'+i+' .jp-previous').addClass('disabled');
  170. }
  171. $song_title = $('.jp-audio'+i+' .jp-playlist ul li.jp-playlist-current .jp-playlist-item').html();
  172. $('.jp-audio'+i+' .song_title').html($song_title);
  173. }
  174. }, 0)
  175. };
  176. $('.jp-previous, .jp-next, .jp-playlist ul').click(function() {
  177. switchSong()
  178. });
  179. $(".jp-jplayer").on($.jPlayer.event.ended, function(event) {
  180. switchSong()
  181. });
  182. };
  183. $(".jp-playlist-toggle").click(function () {
  184. var $this = $(this);
  185. for(var i = 1; i <= $players_on_page; i++){
  186. if ($this.parents('.jp-audio').hasClass('jp-audio'+i)) {
  187. $('.jp-audio'+i+' .jp-playlist').slideToggle("slow");
  188. }
  189. }
  190. });
  191. // Placeholders
  192. if($("[placeholder]").size() > 0) {
  193. $.Placeholder.init({ color : "#c9c2bc" });
  194. }
  195. // Rating Stars
  196. $(".rating span.star").hover(
  197. function() {
  198. $('.rating span.star').removeClass('on').addClass('off');
  199. $(this).prevAll().addClass('over');
  200. }
  201. , function() {
  202. $(this).removeClass('over');
  203. }
  204. );
  205. $(".rating").mouseleave(function(){
  206. $(this).parent().find('.over').removeClass('over');
  207. });
  208. $( ".rating span.star" ).click( function() {
  209. $(this).prevAll().removeClass('off').addClass('on');
  210. $(this).removeClass('off').addClass('on');
  211. });
  212. // Portfolio Filter
  213. var filtersOnPage = $('.widget-portfolio-filter').length,
  214. filterWidth = 0,
  215. filterItems = 0,
  216. filterItemWidth = 0,
  217. filterItemsWidth = 0;
  218. function filterResponsive() {
  219. for(var i = 1; i <= filtersOnPage; i++){
  220. $('.widget-portfolio-filter').eq(i-1).addClass('id'+i);
  221. };
  222. for(var i = 1; i <= filtersOnPage; i++){
  223. filterWidth = $('.widget-portfolio-filter.id'+i+' ul').width();
  224. $('.widget-portfolio-filter.id'+i+' li').each(function () {
  225. var $this = $(this);
  226. filterItemWidth = $this.width();
  227. filterItemsWidth = filterItemsWidth + filterItemWidth;
  228. if(filterItemsWidth > filterWidth){
  229. $this.addClass('left');
  230. filterItemsWidth = filterItemWidth;
  231. }
  232. })
  233. filterItemsWidth = 0;
  234. }
  235. };
  236. filterResponsive();
  237. $(window).resize(function() {
  238. $('.widget-portfolio-filter li').removeClass('left');
  239. filterResponsive();
  240. });
  241. // Crop Images in Image Slider
  242. // adds .naturalWidth() and .naturalHeight() methods to jQuery for retrieving a normalized naturalWidth and naturalHeight.
  243. (function($){
  244. var
  245. props = ['Width', 'Height'],
  246. prop;
  247. while (prop = props.pop()) {
  248. (function (natural, prop) {
  249. $.fn[natural] = (natural in new Image()) ?
  250. function () {
  251. return this[0][natural];
  252. } :
  253. function () {
  254. var
  255. node = this[0],
  256. img,
  257. value;
  258. if (node.tagName.toLowerCase() === 'img') {
  259. img = new Image();
  260. img.src = node.src,
  261. value = img[prop];
  262. }
  263. return value;
  264. };
  265. }('natural' + prop, prop.toLowerCase()));
  266. }
  267. }(jQuery));
  268. var
  269. carousels_on_page = $('.carousel-inner').length,
  270. carouselWidth,
  271. carouselHeight,
  272. ratio,
  273. imgWidth,
  274. imgHeight,
  275. imgRatio,
  276. imgMargin,
  277. this_image,
  278. images_in_carousel;
  279. for(var i = 1; i <= carousels_on_page; i++){
  280. $('.carousel-inner').eq(i-1).addClass('id'+i);
  281. };
  282. function imageSize() {
  283. setTimeout(function () {
  284. for(var i = 1; i <= carousels_on_page; i++){
  285. carouselWidth = $('.carousel-inner.id'+i+' .item').width();
  286. carouselHeight = $('.carousel-inner.id'+i+' .item').height();
  287. ratio = carouselWidth/carouselHeight;
  288. images_in_carousel = $('.carousel-inner.id'+i+' .item img').length;
  289. for(var j = 1; j <= images_in_carousel; j++){
  290. this_image = $('.carousel-inner.id'+i+' .item img').eq(j-1);
  291. imgWidth = this_image.naturalWidth();
  292. imgHeight = this_image.naturalHeight();
  293. imgRatio = imgWidth/imgHeight;
  294. if(ratio <= imgRatio){
  295. imgMargin = parseInt((carouselHeight/imgHeight*imgWidth-carouselWidth)/2, 10);
  296. this_image.css("cssText", "height: "+carouselHeight+"px; margin-left:-"+imgMargin+"px;");
  297. }
  298. else{
  299. imgMargin = parseInt((carouselWidth/imgWidth*imgHeight-carouselHeight)/2, 10);
  300. this_image.css("cssText", "width: "+carouselWidth+"px; margin-top:-"+imgMargin+"px;");
  301. }
  302. }
  303. };
  304. },1000);
  305. };
  306. imageSize();
  307. $(window).resize(function() {
  308. $('.carousel-indicators .first').click();
  309. imageSize();
  310. });
  311. });