jqueryPlugins.js 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  3. * You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. define(["jquery"], function ($) {
  5. // This isn't really a "module" since it just patches jQuery itself
  6. // FIX ME Animations TO DO
  7. // walkthrough animations go here
  8. // animate participant cursor and box popping in when they enter the session
  9. // animate participant cursor and box popping out when they leave the session
  10. // animate the participant cursor -> rotate down when they're down the page
  11. $.fn.rotateCursorDown = function () {
  12. $('svg').animate({borderSpacing: -150, opacity: 1}, {
  13. step: function(now, fx) {
  14. if (fx.prop == "borderSpacing") {
  15. $(this).css('-webkit-transform', 'rotate('+now+'deg)')
  16. .css('-moz-transform', 'rotate('+now+'deg)')
  17. .css('-ms-transform', 'rotate('+now+'deg)')
  18. .css('-o-transform', 'rotate('+now+'deg)')
  19. .css('transform', 'rotate('+now+'deg)');
  20. } else {
  21. $(this).css(fx.prop, now);
  22. }
  23. },
  24. duration: 500
  25. }, 'linear').promise().then(function () {
  26. this.css('-webkit-transform', '');
  27. this.css('-moz-transform', '');
  28. this.css('-ms-transform', '');
  29. this.css('-o-transform', '');
  30. this.css('transform', '');
  31. this.css("opacity", "");
  32. });
  33. };
  34. // animate the participant cursor -> rotate up when they're on the same frame as the user
  35. $.fn.rotateCursorDown = function () {
  36. $('.togetherjs-cursor svg').animate({borderSpacing: 0, opacity: 1}, {
  37. step: function(now, fx) {
  38. if (fx.prop == "borderSpacing") {
  39. $(this).css('-webkit-transform', 'rotate('+now+'deg)')
  40. .css('-moz-transform', 'rotate('+now+'deg)')
  41. .css('-ms-transform', 'rotate('+now+'deg)')
  42. .css('-o-transform', 'rotate('+now+'deg)')
  43. .css('transform', 'rotate('+now+'deg)');
  44. } else {
  45. $(this).css(fx.prop, now);
  46. }
  47. },
  48. duration: 500
  49. }, 'linear').promise().then(function () {
  50. this.css('-webkit-transform', '');
  51. this.css('-moz-transform', '');
  52. this.css('-ms-transform', '');
  53. this.css('-o-transform', '');
  54. this.css('transform', '');
  55. this.css("opacity", "");
  56. });
  57. };
  58. // Move notification when another notification slides in //
  59. /* Pop in window from dock button: */
  60. $.fn.popinWindow = function () {
  61. //mobile popout window with no animation
  62. if($.browser.mobile) {
  63. //starting position
  64. this.css({
  65. left: "0px",
  66. opacity: 1,
  67. "zIndex": 8888
  68. });
  69. //starting position for arrow
  70. $('#togetherjs-window-pointer-right').css({
  71. left: "+=74px",
  72. opacity: 1,
  73. "zIndex": 8888
  74. });
  75. //animate arrow out
  76. $('#togetherjs-window-pointer-right').animate({
  77. opacity: 1,
  78. left: "-=78px"
  79. }, {
  80. duration:60, easing:"linear"
  81. });
  82. $('#togetherjs-window-pointer-right').queue();
  83. //bounce arrow back
  84. $('#togetherjs-window-pointer-right').animate({
  85. left:'+=4px'
  86. }, {
  87. duration:60, easing:"linear"
  88. });
  89. //animate window out
  90. this.animate({
  91. opacity: 1,
  92. left: "0px"
  93. }, {
  94. duration:60, easing:"linear"
  95. });
  96. this.queue();
  97. //bounce window back
  98. this.animate({
  99. left:'0px'
  100. }, {
  101. duration:60, easing:"linear"
  102. });
  103. }
  104. else {
  105. //starting position
  106. this.css({
  107. left: "+=74px",
  108. opacity: 1,
  109. "zIndex": 8888
  110. });
  111. //starting position for arrow
  112. $('#togetherjs-window-pointer-right').css({
  113. left: "+=74px",
  114. opacity: 1,
  115. "zIndex": 8888
  116. });
  117. //animate arrow out
  118. $('#togetherjs-window-pointer-right').animate({
  119. opacity: 1,
  120. left: "-=78px"
  121. }, {
  122. duration:60, easing:"linear"
  123. });
  124. $('#togetherjs-window-pointer-right').queue();
  125. //bounce arrow back
  126. $('#togetherjs-window-pointer-right').animate({
  127. left:'+=4px'
  128. }, {
  129. duration:60, easing:"linear"
  130. });
  131. //animate window out
  132. this.animate({
  133. opacity: 1,
  134. left: "-=78px"
  135. }, {
  136. duration:60, easing:"linear"
  137. });
  138. this.queue();
  139. //bounce window back
  140. this.animate({
  141. left:'+=4px'
  142. }, {
  143. duration:60, easing:"linear"
  144. });
  145. }
  146. };
  147. /* Slide in notification window: */
  148. $.fn.slideIn = function () {
  149. this.css({
  150. //top: "240px",
  151. left: "+=74px",
  152. opacity: 0,
  153. "zIndex": 8888
  154. });
  155. return this.animate({
  156. "left": "-=74px",
  157. opacity: 1,
  158. "zIndex": 9999
  159. }, "fast");
  160. };
  161. /* Used to fade away notification windows + flip the bottom of them out: */
  162. $.fn.fadeOut = function () {
  163. this.animate({borderSpacing: -90, opacity: 0.5}, {
  164. step: function(now, fx) {
  165. if (fx.prop == "borderSpacing") {
  166. $(this).css('-webkit-transform', 'perspective( 600px ) rotateX('+now+'deg)')
  167. .css('-moz-transform', 'perspective( 600px ) rotateX('+now+'deg)')
  168. .css('-ms-transform', 'perspective( 600px ) rotateX('+now+'deg)')
  169. .css('-o-transform', 'perspective( 600px ) rotateX('+now+'deg)')
  170. .css('transform', 'perspective( 600px ) rotateX('+now+'deg)');
  171. } else {
  172. $(this).css(fx.prop, now);
  173. }
  174. },
  175. duration: 500
  176. }, 'linear').promise().then(function () {
  177. this.css('-webkit-transform', '');
  178. this.css('-moz-transform', '');
  179. this.css('-ms-transform', '');
  180. this.css('-o-transform', '');
  181. this.css('transform', '');
  182. this.css("opacity", "");
  183. });
  184. return this;
  185. };
  186. /* used when user goes down to participant cursor location on screen */
  187. $.fn.easeTo = function (y) {
  188. return this.animate({
  189. scrollTop: y
  190. }, {
  191. duration: 400,
  192. easing: "swing"
  193. });
  194. };
  195. // avatar animate in
  196. $.fn.animateDockEntry = function () {
  197. var height = this.height();
  198. var width = this.width();
  199. var backgroundSize = height + 4;
  200. var margin = parseInt(this.css("marginLeft"), 10);
  201. // set starting position CSS for avatar
  202. this.css({
  203. marginLeft: margin + width/2,
  204. height: 0,
  205. width: 0,
  206. backgroundSize: "0 0"
  207. });
  208. var self = this;
  209. //then animate avatar to the actual dimensions, and reset the values
  210. this.animate({
  211. marginLeft: margin,
  212. height: height,
  213. width: width,
  214. backgroundSize: backgroundSize
  215. }, {
  216. duration: 600
  217. }).promise().then(function () {
  218. self.css({
  219. marginLeft: "",
  220. height: "",
  221. width: "",
  222. backgroundSize: ""
  223. });
  224. });
  225. return this;
  226. };
  227. // avatar animate out, reverse of above
  228. $.fn.animateDockExit = function () {
  229. // get the current avatar dimenensions
  230. var height = this.height();
  231. var width = this.width();
  232. var backgroundSize = height + 4;
  233. var margin = parseInt(this.css("marginLeft"), 10);
  234. //then animate avatar to shrink to nothing, and reset the values again
  235. // FIXME this needs to animate from the CENTER
  236. this.animate({
  237. marginLeft: margin + width/2,
  238. height: 0,
  239. width: 0,
  240. backgroundSize: "0 0",
  241. opacity: 0
  242. }, 600 );
  243. return this;
  244. };
  245. $.fn.animateCursorEntry = function () {
  246. // Make the cursor bubble pop in
  247. };
  248. // keyboard typing animation
  249. $.fn.animateKeyboard = function () {
  250. var one = this.find(".togetherjs-typing-ellipse-one");
  251. var two = this.find(".togetherjs-typing-ellipse-two");
  252. var three = this.find(".togetherjs-typing-ellipse-three");
  253. var count = -1;
  254. var run = (function () {
  255. count = (count+1) % 4;
  256. if (count === 0) {
  257. one.css("opacity", 0.5);
  258. two.css("opacity", 0.5);
  259. three.css("opacity", 0.5);
  260. } else if (count == 1) {
  261. one.css("opacity", 1);
  262. } else if (count == 2) {
  263. two.css("opacity", 1);
  264. } else { // count==3
  265. three.css("opacity", 1);
  266. }
  267. }).bind(this);
  268. run();
  269. var interval = setInterval(run, 300);
  270. this.data("animateKeyboard", interval);
  271. };
  272. $.fn.stopKeyboardAnimation = function () {
  273. clearTimeout(this.data("animateKeyboard"));
  274. this.data("animateKeyboard", null);
  275. };
  276. // FIXME: not sure if this is legit, but at least the modern mobile devices we
  277. // care about should have this defined:
  278. if (! $.browser) {
  279. $.browser = {};
  280. }
  281. $.browser.mobile = window.orientation !== undefined;
  282. if (navigator.userAgent.search(/mobile/i) != -1) {
  283. // FIXME: At least on the Firefox OS simulator I need this
  284. $.browser.mobile = true;
  285. }
  286. if ($.browser.mobile && window.matchMedia && ! window.matchMedia("screen and (max-screen-width: 480px)").matches) {
  287. // FIXME: for Firefox OS simulator really:
  288. document.body.className += " togetherjs-mobile-browser";
  289. }
  290. });