PageRenderTime 24ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/web/assets/front/js/screen.js

https://github.com/snowcap/snowcap-website
JavaScript | 319 lines | 237 code | 11 blank | 71 comment | 6 complexity | 6e28162274bf3a18c897b59f824c32e2 MD5 | raw file
  1. (function ($) {
  2. /**
  3. * Flipper class constructor
  4. *
  5. * @param DOMElement element
  6. */
  7. var Flipper = function (element) {
  8. var _element = $(element);
  9. var _this = this;
  10. var _left = _element.width();
  11. /**
  12. * Flipper init
  13. *
  14. */
  15. _this.init = function () {
  16. _element.hover(
  17. function (event) {
  18. _element.find('img').animate({'left':'+=' + _left}, 200);
  19. },
  20. function (event) {
  21. _element.find('img').animate({'left':'-=' + _left}, 200);
  22. }
  23. );
  24. };
  25. /* INIT */
  26. _this.init();
  27. };
  28. /**
  29. * Namespace Flipper in jQuery
  30. */
  31. $.fn.flipper = function () {
  32. return this.each(function () {
  33. new Flipper(this);
  34. });
  35. };
  36. /**
  37. * Navigation class constructor
  38. *
  39. * @param DOMElement element
  40. */
  41. var Navigation = function (element) {
  42. var _element = $(element);
  43. var _this = this;
  44. var _handle;
  45. var _move;
  46. /**
  47. * Move the handle to the specified element
  48. *
  49. * @param DOMElement element
  50. * @param int speed
  51. */
  52. _this.moveTo = function (element, speed) {
  53. var activeOffset = $(element).position().left;
  54. var handleOffset = activeOffset + (element.outerWidth() / 2) - 5;
  55. _handle.animate({'left':handleOffset}, speed);
  56. };
  57. /**
  58. * Move the handle to the active element
  59. *
  60. * @param int speed
  61. */
  62. _this.moveToActive = function (speed) {
  63. var activeElement = _element.find('.active');
  64. if (activeElement.length > 0) {
  65. _this.moveTo(activeElement, speed);
  66. return true;
  67. }
  68. return false;
  69. };
  70. /**
  71. * Follow (on mouseenter)
  72. *
  73. * @param DOMEvent event
  74. */
  75. _this.follow = function (event) {
  76. window.clearTimeout(_move);
  77. var element = $(this);
  78. _move = window.setTimeout(function () {
  79. _this.moveTo(element, 200);
  80. }, 300);
  81. };
  82. /**
  83. * Go back to active (on mouseleave)
  84. *
  85. * @param DOMEvent event
  86. */
  87. _this.gohome = function (event) {
  88. window.clearTimeout(_move);
  89. _move = window.setTimeout(function () {
  90. _this.moveToActive(200);
  91. }, 300);
  92. };
  93. /**
  94. * Navigation init
  95. *
  96. */
  97. _this.init = function () {
  98. _handle = $('<span>').addClass('handle').hide();
  99. _element.append(_handle);
  100. if (_this.moveToActive(0)) {
  101. _handle.show();
  102. _element.find('a').hover(_this.follow, _this.gohome);
  103. _element.find('a').click(function (event) {
  104. $(this).unbind('hover');
  105. });
  106. }
  107. };
  108. /* INIT */
  109. _this.init();
  110. };
  111. $.fn.navigation = function (element) {
  112. return this.each(function () {
  113. new Navigation(this);
  114. });
  115. };
  116. var TwitterFeed = function (element) {
  117. var _this = this;
  118. var _element = $(element);
  119. var loader = $('a.ajax-loader', _element);
  120. var url = loader.attr('href');
  121. var max_elements = 4;
  122. _this.scroll = function () {
  123. var first_child = $('li:first-child', _element);
  124. var siblings = first_child.siblings();
  125. first_child.slideUp(1000);
  126. $(siblings[max_elements - 1]).fadeIn(1000, function () {
  127. _element.append(first_child);
  128. first_child.hide();
  129. });
  130. };
  131. _this.init = function () {
  132. $.get(url, function (data) {
  133. _element.html(data);
  134. if ($('li', _element).length > max_elements) {
  135. $('li', _element).each(function (offset, element) {
  136. if (offset >= max_elements) {
  137. $(element).hide();
  138. }
  139. });
  140. setInterval(_this.scroll, 5000);
  141. }
  142. })
  143. .error(function () {
  144. // Do nothing
  145. }
  146. );
  147. };
  148. this.init();
  149. };
  150. $.fn.twitterFeed = function () {
  151. return this.each(function () {
  152. new TwitterFeed(this);
  153. });
  154. };
  155. var TechnoTip = function (element) {
  156. var _this = this;
  157. var _element = $(element);
  158. /**
  159. * Technotip init
  160. */
  161. _this.init = function () {
  162. var trigger = _element.prev();
  163. _element.addClass('qtip');
  164. var quit;
  165. trigger.mouseenter(function (event) {
  166. clearTimeout(quit);
  167. _element.fadeIn(500);
  168. $('.qtip').not(_element).hide();
  169. _element.mouseenter(function (event) {
  170. clearTimeout(quit);
  171. });
  172. _element.mouseleave(function (event) {
  173. quit = setTimeout(function () {
  174. _element.fadeOut(500);
  175. }, 500);
  176. });
  177. });
  178. trigger.mouseleave(function (event) {
  179. quit = setTimeout(function () {
  180. _element.fadeOut(500);
  181. }, 500);
  182. });
  183. trigger.click(function (event) {
  184. event.preventDefault();
  185. event.stopPropagation();
  186. $('.qtip').not(_element).hide();
  187. _element.fadeToggle(500);
  188. });
  189. $('body').click(function (event) {
  190. _element.fadeOut(500);
  191. });
  192. };
  193. /* INIT */
  194. _this.init();
  195. };
  196. $.fn.technoTip = function () {
  197. return this.each(function () {
  198. new TechnoTip(this);
  199. });
  200. };
  201. /**
  202. * Map class constructor
  203. *
  204. * @param DOMElement element
  205. */
  206. var SnowMap = function (element) {
  207. var $element = $(element);
  208. var _this = this;
  209. var _map;
  210. /**
  211. * Map init
  212. *
  213. */
  214. this.init = function () {
  215. var latlng = new google.maps.LatLng($element.data('latitude'), $element.data('longitude'));
  216. var options = {
  217. 'zoom':13,
  218. 'center':latlng,
  219. 'mapTypeId':google.maps.MapTypeId.TERRAIN,
  220. 'disableDefaultUI':true,
  221. 'zoomControlOptions':{
  222. 'style':google.maps.ZoomControlStyle.SMALL
  223. }
  224. };
  225. _map = new google.maps.Map(element, options);
  226. var image = new google.maps.MarkerImage(
  227. 'assets/front/images/marker_front.png',
  228. new google.maps.Size(50, 49),
  229. new google.maps.Point(0, 0),
  230. new google.maps.Point(25, 49)
  231. );
  232. var shadow = new google.maps.MarkerImage(
  233. 'assets/front/images/marker_shadow.png',
  234. new google.maps.Size(78, 49),
  235. new google.maps.Point(0, 0),
  236. new google.maps.Point(25, 49)
  237. );
  238. var shape = {
  239. 'coord':[49, 0, 49, 1, 49, 2, 49, 3, 49, 4, 49, 5, 49, 6, 49, 7, 49, 8, 49, 9, 49, 10, 49, 11, 49, 12, 49, 13, 49, 14, 49, 15, 49, 16, 49, 17, 49, 18, 49, 19, 49, 20, 49, 21, 49, 22, 49, 23, 49, 24, 49, 25, 49, 26, 49, 27, 49, 28, 49, 29, 49, 30, 49, 31, 49, 32, 49, 33, 49, 34, 49, 35, 49, 36, 49, 37, 49, 38, 49, 39, 49, 40, 49, 41, 28, 42, 28, 43, 27, 44, 26, 45, 26, 46, 25, 47, 25, 48, 24, 48, 23, 47, 23, 46, 22, 45, 21, 44, 21, 43, 20, 42, 0, 41, 0, 40, 0, 39, 0, 38, 0, 37, 0, 36, 0, 35, 0, 34, 0, 33, 0, 32, 0, 31, 0, 30, 0, 29, 0, 28, 0, 27, 0, 26, 0, 25, 0, 24, 0, 23, 0, 22, 0, 21, 0, 20, 0, 19, 0, 18, 0, 17, 0, 16, 0, 15, 0, 14, 0, 13, 0, 12, 0, 11, 0, 10, 0, 9, 0, 8, 0, 7, 0, 6, 0, 5, 0, 4, 0, 3, 0, 2, 0, 1, 0, 0, 49, 0],
  240. 'type':'poly'
  241. };
  242. var marker = new google.maps.Marker({
  243. 'icon':image,
  244. 'shadow':shadow,
  245. 'shape':shape,
  246. 'map':_map,
  247. 'position':latlng
  248. });
  249. };
  250. /**
  251. * Google maps async load
  252. */
  253. if (window.snowcap_map_init === undefined) {
  254. var script = document.createElement("script");
  255. script.type = "text/javascript";
  256. window.snowcap_map_init = function () {
  257. _this.init();
  258. };
  259. script.src = "http://maps.googleapis.com/maps/api/js?v=3.7&sensor=false&callback=snowcap_map_init";
  260. document.body.appendChild(script);
  261. }
  262. else {
  263. _this.init();
  264. }
  265. };
  266. /**
  267. * Namespace Map in jQuery
  268. *
  269. */
  270. $.fn.snowMap = function () {
  271. return this.each(function () {
  272. new SnowMap(this);
  273. });
  274. };
  275. /* DOMREADY */
  276. $(document).ready(function (event) {
  277. // Flip images on latest project for homepage
  278. $('.flipper').flipper();
  279. // Remove title on latest project for homepage links
  280. $(".home .projects li a").attr('title', '');
  281. // Apply active menu styles
  282. $('header nav').navigation();
  283. // Load and autoscroll twitter feed
  284. $('section.tweets').twitterFeed();
  285. $('.technology').technoTip();
  286. // Observer external links
  287. $('a[rel*=external]').live('click', function (event) {
  288. event.preventDefault();
  289. window.open(this.href);
  290. });
  291. $('.snowcap-map').snowMap();
  292. $('a.obem').each(function () {
  293. a = "sh";
  294. b = "@";
  295. e = "snowcap";
  296. c = "oot";
  297. d = ".";
  298. f = "be";
  299. x = "ma";
  300. y = "il";
  301. z = "to";
  302. m = a + c + b + e + d + f;
  303. mm = x + y + z + ":" + m;
  304. $(this).html(m);
  305. $(this).attr("href", mm);
  306. });
  307. });
  308. })(jQuery);