application.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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.4.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. // No-op to mark translatable strings.
  46. function __(str) {
  47. return str
  48. }
  49. function escapeRegExp(str) {
  50. return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
  51. }
  52. Date.prototype.getWeek = function() {
  53. var onejan = new Date(this.getFullYear(),0,1);
  54. return Math.ceil((((this - onejan) / 86400000) + onejan.getDay()+1)/7);
  55. }
  56. function difference(object1, object2) {
  57. var changes = {};
  58. for (var name in object1) {
  59. if (name in object2) {
  60. if (_.isObject(object2[name]) && !_.isArray(object2[name])) {
  61. var diff = difference(object1[name], object2[name]);
  62. if (!_.isEmpty(diff)) {
  63. changes[name] = diff;
  64. }
  65. } else if (!_.isEqual(object1[name], object2[name])) {
  66. changes[name] = object2[name];
  67. }
  68. }
  69. }
  70. return changes;
  71. }
  72. // returns the byte length of an utf8 string
  73. // taken from http://stackoverflow.com/questions/5515869/string-length-in-bytes-in-javascript
  74. function byteLength(str) {
  75. var s = str.length
  76. for (var i=str.length-1; i>=0; i--) {
  77. var code = str.charCodeAt(i)
  78. if (code > 0x7f && code <= 0x7ff) s++
  79. else if (code > 0x7ff && code <= 0xffff) s+=2
  80. if (code >= 0xDC00 && code <= 0xDFFF) i-- //trail surrogate
  81. }
  82. return s
  83. }
  84. // clone, just data, no instances of objects
  85. function clone(item, full) {
  86. // just return/clone false conditions
  87. if (!item) { return item }
  88. var itemType = item.constructor.name
  89. // IE behavior // doesn't know item.constructor.name, detect it by underscore
  90. if (itemType === undefined) {
  91. if (_.isArray(item)) {
  92. itemType = 'Array'
  93. }
  94. else if (_.isNumber(item)) {
  95. itemType = 'Number'
  96. }
  97. else if (_.isString(item)) {
  98. itemType = 'String'
  99. }
  100. else if (_.isBoolean(item)) {
  101. itemType = 'Boolean'
  102. }
  103. else if (_.isFunction(item)) {
  104. itemType = 'Function'
  105. }
  106. else if (_.isObject(item)) {
  107. itemType = 'Object'
  108. }
  109. }
  110. // ignore certain objects
  111. var acceptedInstances = [ 'Object', 'Number', 'String', 'Boolean', 'Array' ]
  112. if (full) {
  113. acceptedInstances.push('Function')
  114. }
  115. // check if item is accepted to get cloned
  116. if (itemType && !_.contains(acceptedInstances, itemType)) {
  117. console.log('no acceptedInstances', itemType, item)
  118. console.trace()
  119. return
  120. }
  121. // copy array
  122. var result;
  123. if (itemType == 'Array') {
  124. result = []
  125. item.forEach(function(child, index, array) {
  126. result[index] = clone( child, full )
  127. });
  128. }
  129. // copy function
  130. else if (itemType == 'Function') {
  131. result = item.bind({})
  132. }
  133. // copy object
  134. else if (itemType == 'Object') {
  135. result = {}
  136. for(var key in item) {
  137. if (item.hasOwnProperty(key)) {
  138. result[key] = clone(item[key], full)
  139. }
  140. }
  141. }
  142. // copy others
  143. else {
  144. result = item
  145. }
  146. return result
  147. }
  148. // taken from https://github.com/epeli/underscore.string/blob/master/underscored.js
  149. function underscored(str) {
  150. return str.trim().replace(/([a-z\d])([A-Z]+)/g, '$1_$2').replace(/[-\s]+/g, '_').toLowerCase();
  151. }
  152. function toCamelCase(str) {
  153. return str
  154. .replace(/\s(.)/g, function($1) { return $1.toUpperCase(); })
  155. .replace(/\s/g, '')
  156. .replace(/^(.)/, function($1) { return $1.toUpperCase(); });
  157. };
  158. function isRetina(){
  159. if (window.matchMedia) {
  160. var mq = window.matchMedia("only screen and (min--moz-device-pixel-ratio: 1.3), only screen and (-o-min-device-pixel-ratio: 2.6/2), only screen and (-webkit-min-device-pixel-ratio: 1.3), only screen and (min-device-pixel-ratio: 1.3), only screen and (min-resolution: 1.3dppx)");
  161. return (mq && mq.matches || (window.devicePixelRatio > 1));
  162. }
  163. }
  164. jQuery.event.special.remove = {
  165. remove: function(e) {
  166. if (e.handler) e.handler();
  167. }
  168. };
  169. // checkbox-replacement helper
  170. // native checkbox focus behaviour is the following:
  171. // tab to checkbox: :focus state and focus outline
  172. // click on checkbox: :focus state but no focus outline
  173. $('body').on('click', '.checkbox-replacement, .radio-replacement', function(event){
  174. $(event.currentTarget).find('input').addClass('is-active')
  175. });
  176. $('body').on('blur', '.checkbox-replacement input, .radio-replacement input', function(){
  177. $(this).removeClass('is-active')
  178. });
  179. // remove attributes by regex
  180. // http://stackoverflow.com/questions/8968767/remove-multiple-html5-data-attributes-with-jquery
  181. jQuery.fn.removeAttrs = function(regex) {
  182. return this.each(function() {
  183. var $this = $(this),
  184. names = [];
  185. $.each(this.attributes, function(i, attr) {
  186. if (attr && attr.specified && regex.test(attr.name)) {
  187. $this.removeAttr(attr.name);
  188. }
  189. });
  190. });
  191. };
  192. // based on jquery serializeArray
  193. // changes
  194. // - set type based on data('field-type')
  195. // - also catch [disabled] params
  196. jQuery.fn.extend( {
  197. serializeArrayWithType: function() {
  198. var r20 = /%20/g,
  199. rbracket = /\[\]$/,
  200. rCRLF = /\r?\n/g,
  201. rsubmitterTypes = /^(?:submit|button|image|reset|file)$/i,
  202. rsubmittable = /^(?:input|select|textarea|keygen)/i;
  203. var rcheckableType = ( /^(?:checkbox|radio)$/i );
  204. return this.map( function() {
  205. // We dont use jQuery.prop( this, "elements" ); here anymore
  206. // because it did not work out for IE 11
  207. var elements = $(this).find('*').filter(':input');
  208. return elements ? jQuery.makeArray( elements ) : this;
  209. } )
  210. .filter( function() {
  211. var type = this.type;
  212. return this.name &&
  213. rsubmittable.test( this.nodeName ) && !rsubmitterTypes.test( type ) &&
  214. ( this.checked || !rcheckableType.test( type ) );
  215. } )
  216. .map( function( i, elem ) {
  217. var $elem = jQuery( this );
  218. var val = $elem.val();
  219. var type = $elem.data('field-type');
  220. var result;
  221. if ( val == null ) {
  222. // be sure that also null values are transferred
  223. // https://github.com/zammad/zammad/issues/944
  224. if ($elem.prop('multiple')) {
  225. result = { name: elem.name, value: null, type: type }
  226. } else {
  227. result = null
  228. }
  229. }
  230. else if ( jQuery.isArray( val ) ) {
  231. result = jQuery.map( val, function( val ) {
  232. return { name: elem.name, value: val.replace( rCRLF, "\r\n" ), type: type };
  233. } );
  234. }
  235. else {
  236. result = { name: elem.name, value: val.replace( rCRLF, "\r\n" ), type: type };
  237. }
  238. return result;
  239. } ).get();
  240. }
  241. } );
  242. // start application
  243. jQuery(function(){
  244. new App.Run();
  245. });