application.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. // This is a manifest file that'll be compiled into including all the files listed below.
  2. // Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
  3. // be included in the compiled file accessible from http://example.com/assets/application.js
  4. // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
  5. // the compiled file.
  6. //
  7. //= require ./app/lib/core/jquery-2.1.4.js
  8. //= require ./app/lib/core/jquery-ui-1.11.2.js
  9. //= require ./app/lib/core/underscore-1.8.3.js
  10. //= require ./app/lib/animations/velocity.min.js
  11. //= require ./app/lib/animations/velocity.ui.js
  12. //not_used= require_tree ./app/lib/spine
  13. //= require ./app/lib/spine/spine.coffee
  14. //= require ./app/lib/spine/ajax.coffee
  15. //= require ./app/lib/spine/local.coffee
  16. //= require ./app/lib/spine/route.coffee
  17. //= require ./app/lib/flot/jquery.flot.js
  18. //= require ./app/lib/flot/jquery.flot.selection.js
  19. //not_used= require_tree ./app/lib/bootstrap
  20. //= require ./app/lib/bootstrap/dropdown.js
  21. //= require ./app/lib/bootstrap/tooltip.js
  22. //= require ./app/lib/bootstrap/popover.js
  23. //= require ./app/lib/bootstrap/popover-enhance.js
  24. // modified by Felix Jan-2014
  25. //= require ./app/lib/bootstrap/modal.js
  26. //= require ./app/lib/bootstrap/tab.js
  27. //= require ./app/lib/bootstrap/transition.js
  28. //= require ./app/lib/bootstrap/button.js
  29. //= require ./app/lib/bootstrap/collapse.js
  30. //= require ./app/lib/bootstrap/bootstrap-timepicker.js
  31. //= require ./app/lib/rangy/rangy-core.js
  32. //= require ./app/lib/rangy/rangy-classapplier.js
  33. //= require ./app/lib/rangy/rangy-textrange.js
  34. //= require ./app/lib/rangy/rangy-highlighter.js
  35. //= require_tree ./app/lib/base
  36. //= require ./app/index.js.coffee
  37. // IE8 workaround for missing console.log
  38. if (!window.console) {
  39. window.console = {}
  40. }
  41. if (!console.log) {
  42. console.log = function(){}
  43. }
  44. function escapeRegExp(str) {
  45. return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
  46. }
  47. Date.prototype.getWeek = function() {
  48. var onejan = new Date(this.getFullYear(),0,1);
  49. return Math.ceil((((this - onejan) / 86400000) + onejan.getDay()+1)/7);
  50. }
  51. function difference(object1, object2) {
  52. var changes = {};
  53. for ( var name in object1 ) {
  54. if ( name in object2 ) {
  55. if ( _.isObject( object2[name] ) && !_.isArray( object2[name] ) ) {
  56. var diff = difference( object1[name], object2[name] );
  57. if ( !_.isEmpty( diff ) ) {
  58. changes[name] = diff;
  59. }
  60. } else if ( !_.isEqual( object1[name], object2[name] ) ) {
  61. changes[name] = object2[name];
  62. }
  63. }
  64. }
  65. return changes;
  66. }
  67. // clone, just data, no instances of objects
  68. function clone(item, full) {
  69. // just return/clone false conditions
  70. if (!item) { return item }
  71. var itemType = item.constructor.name
  72. // IE behavior // doesn't know item.constructor.name, detect it by underscore
  73. if (itemType === undefined) {
  74. if (_.isArray(item)) {
  75. itemType = 'Array'
  76. }
  77. else if (_.isNumber(item)) {
  78. itemType = 'Number'
  79. }
  80. else if (_.isString(item)) {
  81. itemType = 'String'
  82. }
  83. else if (_.isBoolean(item)) {
  84. itemType = 'Boolean'
  85. }
  86. else if (_.isFunction(item)) {
  87. itemType = 'Function'
  88. }
  89. else if (_.isObject(item)) {
  90. itemType = 'Object'
  91. }
  92. }
  93. // ignore certain objects
  94. var acceptedInstances = [ 'Object', 'Number', 'String', 'Boolean', 'Array' ]
  95. if (full) {
  96. acceptedInstances.push( 'Function' )
  97. }
  98. // check if item is accepted to get cloned
  99. if (itemType && !_.contains(acceptedInstances, itemType)) {
  100. console.log('no acceptedInstances', itemType, item)
  101. return
  102. }
  103. // copy array
  104. var result;
  105. if (itemType == 'Array') {
  106. result = []
  107. item.forEach(function(child, index, array) {
  108. result[index] = clone( child, full )
  109. });
  110. }
  111. // copy function
  112. else if (itemType == 'Function') {
  113. result = item.bind({})
  114. }
  115. // copy object
  116. else if (itemType == 'Object') {
  117. result = {}
  118. for(var key in item) {
  119. if (item.hasOwnProperty(key)) {
  120. result[key] = clone( item[key], full )
  121. }
  122. }
  123. }
  124. // copy others
  125. else {
  126. result = item
  127. }
  128. return result
  129. }
  130. // taken from http://stackoverflow.com/questions/4459928/how-to-deep-clone-in-javascript
  131. function clone2(item) {
  132. if (!item) { return item; } // null, undefined values check
  133. var types = [ Number, String, Boolean ],
  134. result;
  135. // normalizing primitives if someone did new String('aaa'), or new Number('444');
  136. types.forEach(function(type) {
  137. if (item instanceof type) {
  138. result = type( item );
  139. }
  140. });
  141. if (typeof result == "undefined") {
  142. if (Object.prototype.toString.call( item ) === "[object Array]") {
  143. result = [];
  144. item.forEach(function(child, index, array) {
  145. result[index] = clone( child );
  146. });
  147. } else if (typeof item == "object") {
  148. // testing that this is DOM
  149. if (item.nodeType && typeof item.cloneNode == "function") {
  150. var result = item.cloneNode( true );
  151. } else if (!item.prototype) { // check that this is a literal
  152. if (item instanceof Date) {
  153. result = new Date(item);
  154. } else {
  155. // it is an object literal
  156. result = {};
  157. for (var i in item) {
  158. result[i] = clone( item[i] );
  159. }
  160. }
  161. } else {
  162. // depending what you would like here,
  163. // just keep the reference, or create new object
  164. if (false && item.constructor) {
  165. // would not advice to do that, reason? Read below
  166. result = new item.constructor();
  167. } else {
  168. result = item;
  169. }
  170. }
  171. } else {
  172. result = item;
  173. }
  174. }
  175. return result;
  176. }
  177. // taken from https://github.com/epeli/underscore.string/blob/master/underscored.js
  178. function underscored (str) {
  179. return str.trim().replace(/([a-z\d])([A-Z]+)/g, '$1_$2').replace(/[-\s]+/g, '_').toLowerCase();
  180. }
  181. jQuery.event.special.remove = {
  182. remove: function(e) {
  183. if (e.handler) e.handler();
  184. }
  185. };
  186. // start application
  187. jQuery(function(){
  188. new App.Run();
  189. });