application.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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.2.1.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/bootstrap/bootstrap-datepicker.js
  32. //= require ./app/lib/rangy/rangy-core.js
  33. //= require ./app/lib/rangy/rangy-classapplier.js
  34. //= require ./app/lib/rangy/rangy-textrange.js
  35. //= require ./app/lib/rangy/rangy-highlighter.js
  36. //= require_tree ./app/lib/base
  37. //= require ./app/index.coffee
  38. // IE8 workaround for missing console.log
  39. if (!window.console) {
  40. window.console = {}
  41. }
  42. if (!console.log) {
  43. console.log = function(){}
  44. }
  45. function escapeRegExp(str) {
  46. return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
  47. }
  48. Date.prototype.getWeek = function() {
  49. var onejan = new Date(this.getFullYear(),0,1);
  50. return Math.ceil((((this - onejan) / 86400000) + onejan.getDay()+1)/7);
  51. }
  52. function difference(object1, object2) {
  53. var changes = {};
  54. for (var name in object1) {
  55. if (name in object2) {
  56. if (_.isObject(object2[name]) && !_.isArray(object2[name])) {
  57. var diff = difference(object1[name], object2[name]);
  58. if (!_.isEmpty(diff)) {
  59. changes[name] = diff;
  60. }
  61. } else if (!_.isEqual(object1[name], object2[name])) {
  62. changes[name] = object2[name];
  63. }
  64. }
  65. }
  66. return changes;
  67. }
  68. // clone, just data, no instances of objects
  69. function clone(item, full) {
  70. // just return/clone false conditions
  71. if (!item) { return item }
  72. var itemType = item.constructor.name
  73. // IE behavior // doesn't know item.constructor.name, detect it by underscore
  74. if (itemType === undefined) {
  75. if (_.isArray(item)) {
  76. itemType = 'Array'
  77. }
  78. else if (_.isNumber(item)) {
  79. itemType = 'Number'
  80. }
  81. else if (_.isString(item)) {
  82. itemType = 'String'
  83. }
  84. else if (_.isBoolean(item)) {
  85. itemType = 'Boolean'
  86. }
  87. else if (_.isFunction(item)) {
  88. itemType = 'Function'
  89. }
  90. else if (_.isObject(item)) {
  91. itemType = 'Object'
  92. }
  93. }
  94. // ignore certain objects
  95. var acceptedInstances = [ 'Object', 'Number', 'String', 'Boolean', 'Array' ]
  96. if (full) {
  97. acceptedInstances.push('Function')
  98. }
  99. // check if item is accepted to get cloned
  100. if (itemType && !_.contains(acceptedInstances, itemType)) {
  101. console.log('no acceptedInstances', itemType, item)
  102. return
  103. }
  104. // copy array
  105. var result;
  106. if (itemType == 'Array') {
  107. result = []
  108. item.forEach(function(child, index, array) {
  109. result[index] = clone( child, full )
  110. });
  111. }
  112. // copy function
  113. else if (itemType == 'Function') {
  114. result = item.bind({})
  115. }
  116. // copy object
  117. else if (itemType == 'Object') {
  118. result = {}
  119. for(var key in item) {
  120. if (item.hasOwnProperty(key)) {
  121. result[key] = clone(item[key], full)
  122. }
  123. }
  124. }
  125. // copy others
  126. else {
  127. result = item
  128. }
  129. return result
  130. }
  131. // taken from https://github.com/epeli/underscore.string/blob/master/underscored.js
  132. function underscored (str) {
  133. return str.trim().replace(/([a-z\d])([A-Z]+)/g, '$1_$2').replace(/[-\s]+/g, '_').toLowerCase();
  134. }
  135. function toCamelCase (str) {
  136. return str
  137. .replace(/\s(.)/g, function($1) { return $1.toUpperCase(); })
  138. .replace(/\s/g, '')
  139. .replace(/^(.)/, function($1) { return $1.toUpperCase(); });
  140. };
  141. jQuery.event.special.remove = {
  142. remove: function(e) {
  143. if (e.handler) e.handler();
  144. }
  145. };
  146. // checkbox-replacement helper
  147. // native checkbox focus behaviour is the following:
  148. // tab to checkbox: :focus state and focus outline
  149. // click on checkbox: :focus state but no focus outline
  150. $('body').on('click', '.checkbox-replacement, .radio-replacement', function(event){
  151. $(event.currentTarget).find('input').addClass('is-active')
  152. });
  153. $('body').on('blur', '.checkbox-replacement input, .radio-replacement input', function(){
  154. $(this).removeClass('is-active')
  155. });
  156. // start application
  157. jQuery(function(){
  158. new App.Run();
  159. });