altair_admin_common.js 78 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868
  1. /*
  2. * Altair Admin
  3. * author: tzd
  4. *
  5. * 1. Init functions
  6. * 2. Helpers / Variables
  7. * 3. Common functions & variables
  8. *
  9. * */
  10. // 1. Init common functions on document ready
  11. $(function() {
  12. "use strict";
  13. // page onload functions
  14. altair_page_onload.init();
  15. // main header
  16. altair_main_header.init();
  17. // main sidebar
  18. altair_main_sidebar.init();
  19. // secondary sidebar
  20. altair_secondary_sidebar.init();
  21. // top bar
  22. altair_top_bar.init();
  23. // page heading
  24. altair_page_heading.init();
  25. // material design
  26. altair_md.init();
  27. // forms
  28. altair_forms.init();
  29. // truncate text helper
  30. altair_helpers.truncate_text($('.truncate-text'));
  31. // full screen
  32. altair_helpers.full_screen();
  33. // table check
  34. altair_helpers.table_check();
  35. // print page
  36. altair_helpers.print_page();
  37. });
  38. // 2. Helpers
  39. /* Detect hi-res devices */
  40. function isHighDensity() {
  41. return ((window.matchMedia && (window.matchMedia('only screen and (min-resolution: 124dpi), only screen and (min-resolution: 1.3dppx), only screen and (min-resolution: 48.8dpcm)').matches || window.matchMedia('only screen and (-webkit-min-device-pixel-ratio: 1.3), only screen and (-o-min-device-pixel-ratio: 2.6/2), only screen and (min--moz-device-pixel-ratio: 1.3), only screen and (min-device-pixel-ratio: 1.3)').matches)) || (window.devicePixelRatio && window.devicePixelRatio > 1.3));
  42. }
  43. /* Calculate Scrollbar Width (http://chris-spittles.co.uk/jquery-calculate-scrollbar-width/) */
  44. function scrollbarWidth(){var a=jQuery('<div style="width: 100%; height:200px;">test</div>'),b=jQuery('<div style="width:200px;height:150px; position: absolute; top: 0; left: 0; visibility: hidden; overflow:hidden;"></div>').append(a),c=a[0],a=b[0];jQuery("body").append(a);c=c.offsetWidth;b.css("overflow","scroll");a=a.clientWidth;b.remove();return c-a};
  45. /* random id generator */
  46. function randID_generator() {
  47. var randLetter = String.fromCharCode(65 + Math.floor(Math.random() * 26));
  48. return randLetter + Date.now();
  49. }
  50. /* detect IE */
  51. function detectIE(){var a=window.navigator.userAgent,b=a.indexOf("MSIE ");if(0<b)return parseInt(a.substring(b+5,a.indexOf(".",b)),10);if(0<a.indexOf("Trident/"))return b=a.indexOf("rv:"),parseInt(a.substring(b+3,a.indexOf(".",b)),10);b=a.indexOf("Edge/");return 0<b?parseInt(a.substring(b+5,a.indexOf(".",b)),10):!1};
  52. /* reverse array */
  53. jQuery.fn.reverse = [].reverse;
  54. /* serialize form */
  55. $.fn.serializeObject = function() {
  56. var o = {};
  57. var a = this.serializeArray();
  58. $.each(a, function() {
  59. if (o[this.name] !== undefined) {
  60. if (!o[this.name].push) {
  61. o[this.name] = [o[this.name]];
  62. }
  63. o[this.name].push(this.value || '');
  64. } else {
  65. o[this.name] = this.value || '';
  66. }
  67. });
  68. return o;
  69. };
  70. /* hex 2 rgba conversion */
  71. function hex2rgba(hex,opacity){
  72. hex = hex.replace('#','');
  73. r = parseInt(hex.substring(0,2), 16);
  74. g = parseInt(hex.substring(2,4), 16);
  75. b = parseInt(hex.substring(4,6), 16);
  76. result = 'rgba('+r+','+g+','+b+','+opacity/100+')';
  77. return result;
  78. }
  79. /* Modernizr test for localStorage */
  80. function lsTest(){
  81. var test = 'test';
  82. try {
  83. localStorage.setItem(test, test);
  84. localStorage.removeItem(test);
  85. return true;
  86. } catch(e) {
  87. return false;
  88. }
  89. }
  90. // selectize plugin
  91. if(typeof $.fn.selectize != 'undefined') {
  92. // inline dropdown
  93. Selectize.define('dropdown_after', function(options) {
  94. this.positionDropdown = (function () {
  95. var $control = this.$control,
  96. position = $control.position(),
  97. position_left = position.left,
  98. position_top = position.top + $control.outerHeight(true) + 32;
  99. this.$dropdown.css({
  100. width : $control.outerWidth(),
  101. top : position_top,
  102. left : position_left
  103. });
  104. });
  105. });
  106. // tooltip
  107. Selectize.define('tooltip', function(options) {
  108. var self = this;
  109. this.setup = (function() {
  110. var original = self.setup;
  111. return function() {
  112. original.apply(this, arguments);
  113. var $wrapper = this.$wrapper,
  114. $input = this.$input;
  115. if($input.attr('title')) {
  116. $wrapper
  117. .attr('title', $input.attr('title'))
  118. .attr('data-uk-tooltip', $input.attr('data-uk-tooltip'));
  119. }
  120. };
  121. })();
  122. });
  123. }
  124. // 3. Common functions & variables
  125. // 3.1 material design easing
  126. // 3.2 page onload init functions
  127. // 3.3 page content
  128. // 3.4 forms
  129. // 3.5 main sidebar / main menu (left)
  130. // 3.6 secondary sidebar (right)
  131. // 3.7 top bar
  132. // 3.8 main header
  133. // 3.9 material design
  134. // 3.10 common helpers
  135. // 3.11 uikit custom
  136. // 3.1 material design easing
  137. easing_swiftOut = [ 0.35,0,0.25,1 ];
  138. bez_easing_swiftOut = $.bez(easing_swiftOut);
  139. var $body = $('body'),
  140. $html = $('html'),
  141. $document = $(document),
  142. $window = $(window),
  143. $page_content = $('#page_content'),
  144. $page_content_inner = $('#page_content_inner'),
  145. $sidebar_main = $('#sidebar_main'),
  146. $sidebar_main_toggle = $('#sidebar_main_toggle'),
  147. $sidebar_secondary = $('#sidebar_secondary'),
  148. $sidebar_secondary_toggle = $('#sidebar_secondary_toggle'),
  149. $topBar = $('#top_bar'),
  150. $pageHeading = $('#page_heading'),
  151. $header_main = $('#header_main'),
  152. header__main_height = 48;
  153. // 3.2 page init functions
  154. altair_page_onload = {
  155. init: function() {
  156. $window.on('load',function(){
  157. // fire functions on window load
  158. altair_helpers.hierarchical_show();
  159. altair_helpers.hierarchical_slide();
  160. });
  161. }
  162. };
  163. // 3.3 page content
  164. altair_page_content = {
  165. hide_content_sidebar: function() {
  166. if(!$body.hasClass('header_double_height')) {
  167. //$page_content.css('max-height',$html.height() - 40);
  168. $html.css({
  169. 'paddingRight': scrollbarWidth(),
  170. 'overflow': 'hidden'
  171. });
  172. }
  173. },
  174. show_content_sidebar: function() {
  175. if(!$body.hasClass('header_double_height')) {
  176. //$page_content.css('max-height','');
  177. $html.css({
  178. 'paddingRight': '',
  179. 'overflow': ''
  180. });
  181. }
  182. }
  183. };
  184. // 3.4 forms
  185. altair_forms = {
  186. init: function() {
  187. altair_forms.textarea_autosize();
  188. altair_forms.select_elements();
  189. altair_forms.switches();
  190. altair_forms.dynamic_fields();
  191. },
  192. textarea_autosize: function() {
  193. $textarea = $('textarea.md-input').not('.no_autosize');
  194. if($textarea.hasClass('selecize_init')) {
  195. autosize.destroy($textarea);
  196. }
  197. autosize($textarea);
  198. $textarea.addClass('selecize_init');
  199. },
  200. select_elements: function(parent) {
  201. var $selectize = parent ? $(parent).find('select') : $("[data-md-selectize],.data-md-selectize");
  202. $selectize.each(function(){
  203. var $this = $(this);
  204. if(!$this.hasClass('selectized')) {
  205. var thisPosBottom = $this.attr('data-md-selectize-bottom'),
  206. sel_plugins = ['tooltip'];
  207. $this
  208. .after('<div class="selectize_fix"></div>')
  209. .selectize({
  210. plugins: sel_plugins,
  211. hideSelected: true,
  212. dropdownParent: 'body',
  213. onDropdownOpen: function($dropdown) {
  214. $dropdown
  215. .hide()
  216. .velocity('slideDown', {
  217. begin: function() {
  218. if (typeof thisPosBottom !== 'undefined') {
  219. $dropdown.css({'margin-top':'0'})
  220. }
  221. },
  222. duration: 200,
  223. easing: easing_swiftOut
  224. })
  225. },
  226. onDropdownClose: function($dropdown) {
  227. $dropdown
  228. .show()
  229. .velocity('slideUp', {
  230. complete: function() {
  231. if (typeof thisPosBottom !== 'undefined') {
  232. $dropdown.css({'margin-top': ''})
  233. }
  234. },
  235. duration: 200,
  236. easing: easing_swiftOut
  237. });
  238. },
  239. onChange: function(value) {
  240. if( !!$this.attr('data-parsley-id')) {
  241. $this.parsley().validate();
  242. }
  243. }
  244. });
  245. }
  246. });
  247. // dropdowns
  248. var $selectize_inline = $("[data-md-selectize-inline]");
  249. $selectize_inline.each(function(){
  250. var $this = $(this);
  251. if(!$this.hasClass('selectized')) {
  252. var thisPosBottom = $this.attr('data-md-selectize-bottom');
  253. $this
  254. .after('<div class="selectize_fix"></div>')
  255. .closest('div').addClass('uk-position-relative')
  256. .end()
  257. .selectize({
  258. plugins: [
  259. 'dropdown_after'
  260. ],
  261. dropdownParent: $this.closest('div'),
  262. hideSelected: true,
  263. onDropdownOpen: function($dropdown) {
  264. $dropdown
  265. .hide()
  266. .velocity('slideDown', {
  267. begin: function() {
  268. if (typeof thisPosBottom !== 'undefined') {
  269. $dropdown.css({'margin-top':'0'})
  270. }
  271. },
  272. duration: 200,
  273. easing: easing_swiftOut
  274. })
  275. },
  276. onDropdownClose: function($dropdown) {
  277. $dropdown
  278. .show()
  279. .velocity('slideUp', {
  280. complete: function() {
  281. if (typeof thisPosBottom !== 'undefined') {
  282. $dropdown.css({'margin-top': ''})
  283. }
  284. },
  285. duration: 200,
  286. easing: easing_swiftOut
  287. });
  288. },
  289. onChange: function(value) {
  290. if( !!$this.attr('data-parsley-id')) {
  291. $this.parsley().validate();
  292. }
  293. }
  294. });
  295. }
  296. })
  297. },
  298. // switchery plugin
  299. switches: function(parent) {
  300. var $elem = parent ? $(parent).find('[data-switchery]') : $('[data-switchery]');
  301. if($elem.length) {
  302. $elem.each(function() {
  303. if(!$(this).siblings('.switchery').length) {
  304. var $this = this,
  305. this_size = $($this).attr('data-switchery-size'),
  306. this_color = $($this).attr('data-switchery-color'),
  307. this_secondary_color = $($this).attr('data-switchery-secondary-color');
  308. new Switchery($this, {
  309. color: (typeof this_color !== 'undefined') ? hex2rgba(this_color,50) : hex2rgba('#009688',50),
  310. jackColor: (typeof this_color !== 'undefined') ? hex2rgba(this_color,100) : hex2rgba('#009688',100),
  311. secondaryColor: (typeof this_secondary_color !== 'undefined') ? hex2rgba(this_secondary_color,50) : 'rgba(0, 0, 0,0.26)',
  312. jackSecondaryColor: (typeof this_secondary_color !== 'undefined') ? hex2rgba(this_secondary_color,50) : '#fafafa',
  313. className: 'switchery' + ( (typeof this_size !== 'undefined') ? ' switchery-'+ this_size : '' )
  314. });
  315. }
  316. })
  317. }
  318. },
  319. parsley_validation_config: function() {
  320. window.ParsleyConfig = {
  321. excluded: 'input[type=button], input[type=submit], input[type=reset], input[type=hidden], input.exclude_validation',
  322. trigger: 'change',
  323. errorsWrapper: '<div class="parsley-errors-list"></div>',
  324. errorTemplate: '<span></span>',
  325. errorClass: 'md-input-danger',
  326. successClass: 'md-input-success',
  327. errorsContainer: function (ParsleyField) {
  328. var element = ParsleyField.$element;
  329. return element.closest('.parsley-row');
  330. },
  331. classHandler: function (ParsleyField) {
  332. var element = ParsleyField.$element;
  333. if( element.is(':checkbox') || element.is(':radio') || element.parent().is('label') || $(element).is('[data-md-selectize]') ) {
  334. return element.closest('.parsley-row');
  335. }
  336. }
  337. };
  338. },
  339. parsley_extra_validators: function() {
  340. window.ParsleyConfig = window.ParsleyConfig || {};
  341. window.ParsleyConfig.validators = window.ParsleyConfig.validators || {};
  342. window.ParsleyConfig.validators.date = {
  343. fn: function (value) {
  344. var matches = /^(\d{2})[.\/](\d{2})[.\/](\d{4})$/.exec(value);
  345. if (matches == null) return false;
  346. var parts = value.split(/[.\/-]+/),
  347. day = parseInt(parts[1], 10),
  348. month = parseInt(parts[0], 10),
  349. year = parseInt(parts[2], 10);
  350. if (year == 0 || month == 0 || month > 12) {
  351. return false;
  352. }
  353. var monthLength = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
  354. if (year % 400 == 0 || (year % 100 != 0 && year % 4 == 0)) {
  355. monthLength[1] = 29;
  356. }
  357. return day > 0 && day <= monthLength[month - 1];
  358. },
  359. priority: 256
  360. };
  361. },
  362. dynamic_fields: function() {
  363. // clone section
  364. $('.btnSectionClone').on('click', function(e) {
  365. e.preventDefault();
  366. var $this = $(this),
  367. section_to_clone = $this.attr('data-section-clone'),
  368. section_number = $(section_to_clone).parent().children('[data-section-added]:last').attr('data-section-added') ? parseInt($(section_to_clone).parent().children('[data-section-added]:last').attr('data-section-added')) + 1 : 1,
  369. cloned_section = $(section_to_clone).clone();
  370. cloned_section
  371. .attr('data-section-added',section_number)
  372. .removeAttr('id')
  373. // inputs
  374. .find('.md-input').each(function(index) {
  375. var $thisInput = $(this),
  376. name = $thisInput.attr('name');
  377. $thisInput
  378. .val('')
  379. .attr('name',name ? name + '[s_'+section_number +':i_'+ index +']' : '[s_'+section_number +':i_'+ index +']')
  380. altair_md.update_input($thisInput);
  381. })
  382. .end()
  383. // replace clone button with remove button
  384. .find('.btnSectionClone').replaceWith('<a href="javascript:void(0);" class="btnSectionRemove"><i class="material-icons md-24">&#xE872;</i></a>')
  385. .end()
  386. // clear checkboxes
  387. .find('[data-md-icheck]:checkbox').each(function(index) {
  388. var $thisInput = $(this),
  389. name = $thisInput.attr('name'),
  390. id = $thisInput.attr('id'),
  391. $inputLabel = cloned_section.find('label[for="'+ id +'"]'),
  392. newName = name ? name + '-s'+section_number +':cb'+ index +'' : 's'+section_number +':cb'+ index;
  393. newId = id ? id + '-s'+section_number +':cb'+ index +'' : 's'+section_number +':cb'+ index;
  394. $thisInput
  395. .attr('name', newName)
  396. .attr('id', newId)
  397. .removeAttr('style').removeAttr('checked').unwrap().next('.iCheck-helper').remove();
  398. $inputLabel.attr('for', newId);
  399. })
  400. .end()
  401. // clear radio
  402. .find('.dynamic_radio').each(function(index) {
  403. var $this = $(this),
  404. thisIndex = index;
  405. $this.find('[data-md-icheck]').each(function(index) {
  406. var $thisInput = $(this),
  407. name = $thisInput.attr('name'),
  408. id = $thisInput.attr('id'),
  409. $inputLabel = cloned_section.find('label[for="'+ id +'"]'),
  410. newName = name ? name + '-s'+section_number +':cb'+ thisIndex +'' : '[s'+section_number +':cb'+ thisIndex;
  411. newId = id ? id + '-s'+section_number +':cb'+ index +'' : 's'+section_number +':cb'+ index;
  412. $thisInput
  413. .attr('name', newName)
  414. .attr('id', newId)
  415. .attr('data-parsley-multiple', newName)
  416. .removeAttr('data-parsley-id')
  417. .removeAttr('style').removeAttr('checked').unwrap().next('.iCheck-helper').remove();
  418. $inputLabel.attr('for', newId);
  419. })
  420. })
  421. .end()
  422. // switchery
  423. .find('[data-switchery]').each(function(index) {
  424. var $thisInput = $(this),
  425. name = $thisInput.attr('name'),
  426. id = $thisInput.attr('id'),
  427. $inputLabel = cloned_section.find('label[for="'+ id +'"]'),
  428. newName = name ? name + '-s'+section_number +':sw'+ index +'' : 's'+section_number +':sw'+ index,
  429. newId = id ? id + '-s'+section_number +':sw'+ index +'' : 's'+section_number +':sw'+ index;
  430. $thisInput
  431. .attr('name', newName)
  432. .attr('id', newId)
  433. .removeAttr('style').removeAttr('checked').next('.switchery').remove();
  434. $inputLabel.attr('for', newId);
  435. })
  436. .end()
  437. // selectize
  438. .find('[data-md-selectize]').each(function(index) {
  439. var $thisSelect = $(this),
  440. name = $thisSelect.attr('name'),
  441. id = $thisSelect.attr('id'),
  442. orgSelect = $('#'+id),
  443. newName = name ? name + '-s'+section_number +':sel'+ index +'' : 's'+section_number +':sel'+ index,
  444. newId = id ? id + '-s'+section_number +':sel'+ index +'' : 's'+section_number +':sel'+ index;
  445. // destroy selectize
  446. var selectize = orgSelect[0].selectize;
  447. if(selectize) {
  448. selectize.destroy();
  449. orgSelect.val('').next('.selectize_fix').remove();
  450. var clonedOptions = orgSelect.html();
  451. altair_forms.select_elements(orgSelect.parent());
  452. $thisSelect
  453. .html(clonedOptions)
  454. .attr('name', newName)
  455. .attr('id', newId)
  456. .removeClass('selectized')
  457. .next('.selectize-control').remove()
  458. .end()
  459. .next('.selectize_fix').remove();
  460. }
  461. });
  462. $(section_to_clone).before(cloned_section);
  463. var $newSection = $(section_to_clone).prev();
  464. if($newSection.hasClass('form_section_separator')) {
  465. $newSection.after('<hr class="form_hr">')
  466. }
  467. // reinitialize checkboxes
  468. altair_md.checkbox_radio($newSection.find('[data-md-icheck]'));
  469. // reinitialize switches
  470. altair_forms.switches($newSection);
  471. // reinitialize selectize
  472. altair_forms.select_elements($newSection);
  473. });
  474. // remove section
  475. $('#page_content').on('click', '.btnSectionRemove', function(e) {
  476. e.preventDefault();
  477. var $this = $(this);
  478. $this.closest('.form_section').remove();
  479. })
  480. }
  481. };
  482. // 3.5 main sidebar (left)
  483. altair_main_sidebar = {
  484. init: function() {
  485. if($sidebar_main.length) {
  486. // check if browser support localstorage
  487. if(lsTest()) {
  488. // check if mini sidebar is enabled
  489. if(localStorage.getItem("altair_sidebar_mini") !== null) {
  490. $body.addClass('sidebar_mini');
  491. }
  492. if(localStorage.getItem("altair_sidebar_slim") !== null) {
  493. $body.addClass('sidebar_slim');
  494. }
  495. }
  496. if ($body.hasClass('sidebar_mini')) {
  497. // small sidebar
  498. altair_main_sidebar.mini_sidebar();
  499. setTimeout(function() {
  500. $window.resize();
  501. }, 280);
  502. } else if($body.hasClass('sidebar_slim')) {
  503. // slim sidebar
  504. altair_main_sidebar.slim_sidebar();
  505. // custom scroller
  506. altair_helpers.custom_scrollbar($sidebar_main);
  507. // menu
  508. altair_main_sidebar.sidebar_menu();
  509. setTimeout(function() {
  510. $window.resize();
  511. }, 280);
  512. } else {
  513. $sidebar_main_toggle.on('click', function(e) {
  514. e.preventDefault();
  515. ( $body.hasClass('sidebar_main_active') || ($body.hasClass('sidebar_main_open') && $window.width() >= 1220) ) ? altair_main_sidebar.hide_sidebar() : altair_main_sidebar.show_sidebar();
  516. });
  517. // hide sidebar (outside click/esc key pressed)
  518. $document.on('click keyup', function(e) {
  519. if( $body.hasClass('sidebar_main_active') && $window.width() < 1220 ) {
  520. if (
  521. ( !$(e.target).closest($sidebar_main).length && !$(e.target).closest($sidebar_main_toggle).length )
  522. || ( e.keyCode == 27 )
  523. ) {
  524. altair_main_sidebar.hide_sidebar();
  525. }
  526. }
  527. });
  528. // custom scroller
  529. altair_helpers.custom_scrollbar($sidebar_main);
  530. if( $body.hasClass('sidebar_main_active') && $window.width() < 1220 ) {
  531. altair_page_content.hide_content_sidebar();
  532. } else {
  533. altair_page_content.show_content_sidebar();
  534. }
  535. if( $body.hasClass('sidebar_main_open') && $window.width() < 1220 ) {
  536. $body.removeClass('sidebar_main_open')
  537. }
  538. // menu
  539. altair_main_sidebar.sidebar_menu();
  540. // swipe to open (touch devices)
  541. altair_main_sidebar.swipe_open();
  542. }
  543. // language switcher
  544. altair_main_sidebar.lang_switcher();
  545. }
  546. },
  547. hide_sidebar: function() {
  548. $body.addClass('sidebar_main_hiding').removeClass('sidebar_main_active sidebar_main_open');
  549. if( $window.width() < 1220 ) {
  550. altair_page_content.show_content_sidebar();
  551. }
  552. setTimeout(function() {
  553. $body.removeClass('sidebar_main_hiding');
  554. $window.resize();
  555. },290);
  556. },
  557. show_sidebar: function() {
  558. $body.addClass('sidebar_main_active');
  559. if( $window.width() < 1220 ) {
  560. altair_page_content.hide_content_sidebar();
  561. }
  562. setTimeout(function() {
  563. $window.resize();
  564. },290);
  565. },
  566. sidebar_menu: function() {
  567. // check for submenu
  568. $sidebar_main.find('.menu_section > ul').find('li').each(function() {
  569. var hasChildren = $(this).children('ul').length;
  570. if(hasChildren) {
  571. $(this).addClass('submenu_trigger')
  572. }
  573. });
  574. // toggle sections
  575. $('.submenu_trigger > a').on('click',function(e) {
  576. e.preventDefault();
  577. var $this = $(this);
  578. var slideToogle = $this.next('ul').is(':visible') ? 'slideUp' : 'slideDown';
  579. // accordion mode
  580. var accordion_mode = $sidebar_main.hasClass('accordion_mode');
  581. $this.next('ul')
  582. .velocity(slideToogle, {
  583. duration: 400,
  584. easing: easing_swiftOut,
  585. begin: function() {
  586. if(slideToogle == 'slideUp') {
  587. $(this).closest('.submenu_trigger').removeClass('act_section')
  588. } else {
  589. if(accordion_mode) {
  590. $this.closest('li').siblings('.submenu_trigger').each(function() {
  591. $(this).children('ul').velocity('slideUp', {
  592. duration: 400,
  593. easing: easing_swiftOut,
  594. begin: function() {
  595. $(this).closest('.submenu_trigger').removeClass('act_section')
  596. }
  597. })
  598. })
  599. }
  600. $(this).closest('.submenu_trigger').addClass('act_section')
  601. }
  602. },
  603. complete: function() {
  604. if(slideToogle !== 'slideUp') {
  605. var scrollContainer = $sidebar_main.find(".scroll-content").length ? $sidebar_main.find(".scroll-content") : $sidebar_main.find(".scrollbar-inner");
  606. $this.closest('.act_section').velocity("scroll", {
  607. duration: 500,
  608. easing: easing_swiftOut,
  609. container: scrollContainer
  610. });
  611. }
  612. }
  613. });
  614. });
  615. // open section/add classes if children has class .act_item
  616. $sidebar_main
  617. .find('.act_item')
  618. .closest('.submenu_trigger')
  619. .addClass('act_section current_section')
  620. .children('a')
  621. .trigger('click');
  622. },
  623. lang_switcher: function() {
  624. var $lang_switcher = $('#lang_switcher');
  625. if($lang_switcher.length) {
  626. $lang_switcher.selectize({
  627. options: [
  628. {id: 1, title: 'English', value: 'gb'},
  629. {id: 2, title: 'French', value: 'fr'},
  630. {id: 3, title: 'Chinese', value: 'cn'},
  631. {id: 4, title: 'Dutch', value: 'nl'},
  632. {id: 5, title: 'Italian', value: 'it'},
  633. {id: 6, title: 'Spanish', value: 'es'},
  634. {id: 7, title: 'German', value: 'de'},
  635. {id: 8, title: 'Polish', value: 'pl'}
  636. ],
  637. render: {
  638. option: function(data, escape) {
  639. return '<div class="option">' +
  640. '<i class="item-icon flag-' + escape(data.value).toUpperCase() + '"></i>' +
  641. '<span>' + escape(data.title) + '</span>' +
  642. '</div>';
  643. },
  644. item: function(data, escape) {
  645. return '<div class="item"><i class="item-icon flag-' + escape(data.value).toUpperCase() + '"></i></div>';
  646. }
  647. },
  648. valueField: 'value',
  649. labelField: 'title',
  650. searchField: 'title',
  651. create: false,
  652. hideSelected: true,
  653. onDropdownOpen: function($dropdown) {
  654. $dropdown
  655. .hide()
  656. .velocity('slideDown', {
  657. begin: function() {
  658. $dropdown.css({'margin-top':'-33px'})
  659. },
  660. duration: 200,
  661. easing: easing_swiftOut
  662. })
  663. },
  664. onDropdownClose: function($dropdown) {
  665. $dropdown
  666. .show()
  667. .velocity('slideUp', {
  668. complete: function() {
  669. $dropdown.css({'margin-top':''})
  670. },
  671. duration: 200,
  672. easing: easing_swiftOut
  673. })
  674. }
  675. });
  676. $lang_switcher.next().children('.selectize-input').find('input').attr('readonly',true);
  677. }
  678. },
  679. swipe_open: function() {
  680. if( $body.hasClass('sidebar_main_swipe') && Modernizr.touch) {
  681. $body.append('<div id="sidebar_swipe_area" style="position: fixed;left: 0;top:0;z-index:1000;width:16px;height:100%"></div>');
  682. var sidebar_swipe_area = document.getElementById("sidebar_swipe_area");
  683. mc = new Hammer.Manager(sidebar_swipe_area);
  684. mc.add(new Hammer.Swipe({
  685. threshold: 0,
  686. pointers: 2,
  687. velocity: 0
  688. }));
  689. mc.on("swiperight", function() {
  690. if (!$body.hasClass('sidebar_main_active')) {
  691. altair_main_sidebar.show_sidebar();
  692. }
  693. });
  694. }
  695. },
  696. mini_sidebar: function() {
  697. $sidebar_main_toggle.hide();
  698. $sidebar_main.find('.menu_section > ul').children('li').each(function() {
  699. var hasChildren = $(this).children('ul').length;
  700. if(hasChildren) {
  701. $(this).addClass('sidebar_submenu');
  702. if($(this).find('.act_item').length) {
  703. $(this).addClass('current_section');
  704. }
  705. } else {
  706. $(this).attr({
  707. 'data-uk-tooltip': "{pos:'right'}"
  708. });
  709. }
  710. });
  711. $body
  712. .addClass('sidebar_mini')
  713. .removeClass('sidebar_main_active sidebar_main_open sidebar_main_swipe');
  714. },
  715. slim_sidebar: function() {
  716. $sidebar_main_toggle.hide();
  717. $body
  718. .addClass('sidebar_slim sidebar_slim_inactive')
  719. .removeClass('sidebar_main_active sidebar_main_open sidebar_main_swipe');
  720. $sidebar_main
  721. .mouseenter(function() {
  722. $body.removeClass('sidebar_slim_inactive');
  723. $body.addClass('sidebar_slim_active');
  724. })
  725. .mouseleave(function() {
  726. $body.addClass('sidebar_slim_inactive');
  727. $body.removeClass('sidebar_slim_active');
  728. })
  729. }
  730. };
  731. // secondary sidebar (right)
  732. altair_secondary_sidebar = {
  733. init: function() {
  734. if($sidebar_secondary.length) {
  735. $sidebar_secondary_toggle.removeClass('sidebar_secondary_check');
  736. $sidebar_secondary_toggle.on('click', function (e) {
  737. e.preventDefault();
  738. $body.hasClass('sidebar_secondary_active') ? altair_secondary_sidebar.hide_sidebar() : altair_secondary_sidebar.show_sidebar();
  739. });
  740. // hide sidebar (outside/esc click)
  741. $document.on('click keydown', function(e) {
  742. if($body.hasClass('sidebar_secondary_persisten')) {
  743. return;
  744. }
  745. if( $body.hasClass('sidebar_secondary_active') && ( ( !$(e.target).closest($sidebar_secondary).length && !$(e.target).closest($sidebar_secondary_toggle).length ) || (e.which == 27) )) {
  746. altair_secondary_sidebar.hide_sidebar();
  747. }
  748. });
  749. // hide page sidebar on page load
  750. if ( $body.hasClass('sidebar_secondary_active') ) {
  751. altair_secondary_sidebar.hide_sidebar();
  752. }
  753. // custom scroller
  754. altair_helpers.custom_scrollbar($sidebar_secondary);
  755. // chat section
  756. altair_secondary_sidebar.chat_sidebar();
  757. }
  758. },
  759. hide_sidebar: function() {
  760. $body.removeClass('sidebar_secondary_active');
  761. },
  762. show_sidebar: function() {
  763. $body.addClass('sidebar_secondary_active');
  764. },
  765. chat_sidebar: function() {
  766. if($sidebar_secondary.find('.md-list.chat_users').length) {
  767. $('.md-list.chat_users').children('li').on('click',function() {
  768. $('.md-list.chat_users').velocity("transition.slideRightBigOut", {
  769. duration: 280,
  770. easing: easing_swiftOut,
  771. complete: function() {
  772. $sidebar_secondary
  773. .find('.chat_box_wrapper')
  774. .addClass('chat_box_active')
  775. .velocity("transition.slideRightBigIn", {
  776. duration: 280,
  777. easing: easing_swiftOut,
  778. begin: function() {
  779. $sidebar_secondary.addClass('chat_sidebar')
  780. }
  781. })
  782. }
  783. });
  784. });
  785. $sidebar_secondary
  786. .find('.chat_sidebar_close')
  787. .on('click',function() {
  788. $sidebar_secondary
  789. .find('.chat_box_wrapper')
  790. .removeClass('chat_box_active')
  791. .velocity("transition.slideRightBigOut", {
  792. duration: 280,
  793. easing: easing_swiftOut,
  794. complete: function () {
  795. $sidebar_secondary.removeClass('chat_sidebar')
  796. $('.md-list.chat_users').velocity("transition.slideRightBigIn", {
  797. duration: 280,
  798. easing: easing_swiftOut
  799. })
  800. }
  801. })
  802. });
  803. if($sidebar_secondary.find('.uk-tab').length) {
  804. $sidebar_secondary.find('.uk-tab').on('change.uk.tab',function(event, active_item, previous_item) {
  805. if($(active_item).hasClass('chat_sidebar_tab') && $sidebar_secondary.find('.chat_box_wrapper').hasClass('chat_box_active')) {
  806. $sidebar_secondary.addClass('chat_sidebar')
  807. } else {
  808. $sidebar_secondary.removeClass('chat_sidebar')
  809. }
  810. })
  811. }
  812. }
  813. }
  814. };
  815. // top bar
  816. altair_top_bar = {
  817. init: function () {
  818. if($topBar.length) {
  819. $body.addClass('top_bar_active');
  820. }
  821. }
  822. };
  823. // page heading
  824. altair_page_heading = {
  825. init: function () {
  826. if($pageHeading.length) {
  827. $body.addClass('page_heading_active');
  828. }
  829. }
  830. };
  831. // main header
  832. altair_main_header = {
  833. init: function() {
  834. altair_main_header.search_activate();
  835. altair_main_header.search_autocomplete();
  836. },
  837. search_activate: function() {
  838. $('#main_search_btn').on('click',function(e) {
  839. e.preventDefault();
  840. altair_main_header.search_show();
  841. });
  842. // hide main search
  843. $(document).on('click keydown', function(e) {
  844. if( !$body.hasClass('main_search_persistent') && $body.hasClass('main_search_active') ) {
  845. if (
  846. ( !$(e.target).closest('.header_main_search_form').length && !$(e.target).closest('#main_search_btn').length )
  847. || ( e.which == 27 )
  848. ) {
  849. altair_main_header.search_hide();
  850. }
  851. }
  852. });
  853. $('.header_main_search_close').on('click', function() {
  854. altair_main_header.search_hide();
  855. });
  856. if($body.hasClass('main_search_persistent')) {
  857. altair_main_header.search_show();
  858. }
  859. },
  860. search_show: function() {
  861. $header_main
  862. .children('.header_main_content')
  863. .velocity("transition.slideUpBigOut", {
  864. duration: 280,
  865. easing: easing_swiftOut,
  866. begin: function() {
  867. $body.addClass('main_search_active');
  868. },
  869. complete: function() {
  870. $header_main
  871. .children('.header_main_search_form')
  872. .velocity("transition.slideDownBigIn", {
  873. duration: 280,
  874. easing: easing_swiftOut,
  875. complete: function() {
  876. $('.header_main_search_input').focus();
  877. }
  878. })
  879. }
  880. });
  881. },
  882. search_hide: function() {
  883. $header_main
  884. .children('.header_main_search_form')
  885. .velocity("transition.slideUpBigOut", {
  886. duration: 280,
  887. easing: easing_swiftOut,
  888. begin: function() {
  889. $header_main.velocity("reverse");
  890. $body.removeClass('main_search_active');
  891. },
  892. complete: function() {
  893. $header_main
  894. .children('.header_main_content')
  895. .velocity("transition.slideDownBigIn", {
  896. duration: 280,
  897. easing: easing_swiftOut,
  898. complete: function() {
  899. $('.header_main_search_input').blur().val('');
  900. }
  901. })
  902. }
  903. });
  904. },
  905. search_autocomplete: function() {
  906. /*function cb(release) {
  907. var data = [];
  908. // build your data ...
  909. $.ajax({
  910. type: "POST",
  911. url: "process.php",
  912. data: dataString,
  913. dataType: "json",
  914. success: function (data) {
  915. if (data.response == 'captcha') {
  916. alert('captcha');
  917. } else if (data.response == 'success') {
  918. alert('success');
  919. } else {
  920. alert('sorry there was an error');
  921. }
  922. }
  923. });
  924. release(data); // release the data back to the autocompleter
  925. }
  926. var autocomplete = $.UIkit.autocomplete($('#header_autocomplete'), {
  927. 'source': cb
  928. });*/
  929. }
  930. };
  931. // material design
  932. altair_md = {
  933. init: function() {
  934. altair_md.inputs();
  935. altair_md.checkbox_radio();
  936. altair_md.card_fullscreen();
  937. altair_md.card_expand();
  938. altair_md.card_overlay();
  939. altair_md.card_single();
  940. altair_md.card_panel();
  941. altair_md.card_progress();
  942. altair_md.list_outside();
  943. // FAB transitions
  944. altair_md.fab_speed_dial();
  945. altair_md.fab_toolbar();
  946. altair_md.fab_sheet();
  947. altair_md.wave_effect();
  948. },
  949. // card toggle fullscreen
  950. card_fullscreen: function() {
  951. $('.md-card-fullscreen-activate').on('click',function() {
  952. var $thisCard = $(this).closest('.md-card');
  953. if(!$thisCard.hasClass('md-card-fullscreen')) {
  954. // get card atributes
  955. var mdCard_h = $thisCard.height(),
  956. mdCardToolbarFixed = $(this).hasClass('toolbar_fixed'),
  957. mdCard_w = $thisCard.width(),
  958. body_scroll_top = $body.scrollTop(),
  959. mdCard_offset = $thisCard.offset();
  960. // create placeholder for card
  961. $thisCard.after('<div class="md-card-placeholder" style="width:'+ mdCard_w+'px;height:'+ mdCard_h+'px;"/>');
  962. // add overflow hidden to #page_content (fix for ios)
  963. //$body.addClass('md-card-fullscreen-active');
  964. // add width/height to card (preserve original size)
  965. $thisCard
  966. .addClass('md-card-fullscreen')
  967. .css({
  968. 'width': mdCard_w,
  969. 'height': mdCard_h,
  970. 'left': mdCard_offset.left,
  971. 'top': mdCard_offset.top - body_scroll_top
  972. })
  973. // animate card to top/left position
  974. .velocity(
  975. {
  976. left: 0,
  977. top: 0
  978. },
  979. {
  980. duration: 400,
  981. easing: easing_swiftOut,
  982. begin: function(elements) {
  983. // add back button
  984. var $toolbar = $thisCard.find('.md-card-toolbar');
  985. if($toolbar.length) {
  986. $toolbar.prepend('<span class="md-icon md-card-fullscreen-deactivate material-icons uk-float-left">&#xE5C4;</span>');
  987. } else {
  988. $thisCard.append('<span class="md-icon md-card-fullscreen-deactivate material-icons uk-position-top-right" style="margin:10px 10px 0 0">&#xE5CD;</span>')
  989. }
  990. altair_page_content.hide_content_sidebar();
  991. }
  992. }
  993. // resize card to full width/height
  994. ).velocity(
  995. {
  996. height: '100%',
  997. width: '100%'
  998. },
  999. {
  1000. duration: 400,
  1001. easing: easing_swiftOut,
  1002. complete: function(elements) {
  1003. // show fullscreen content
  1004. $thisCard.find('.md-card-fullscreen-content').velocity("transition.slideUpBigIn", {
  1005. duration: 400,
  1006. easing: easing_swiftOut,
  1007. complete: function(elements) {
  1008. // activate onResize callback for some js plugins
  1009. $(window).resize();
  1010. }
  1011. });
  1012. if(mdCardToolbarFixed) {
  1013. $thisCard.addClass('mdToolbar_fixed')
  1014. }
  1015. }
  1016. }
  1017. );
  1018. }
  1019. });
  1020. $page_content.on('click', '.md-card-fullscreen-deactivate', function() {
  1021. // get card placeholder width/height and offset
  1022. var $thisPlaceholderCard = $('.md-card-placeholder'),
  1023. mdPlaceholderCard_h = $thisPlaceholderCard.height(),
  1024. mdPlaceholderCard_w = $thisPlaceholderCard.width(),
  1025. body_scroll_top = $body.scrollTop(),
  1026. mdPlaceholderCard_offset_top = $thisPlaceholderCard.offset().top - body_scroll_top,
  1027. mdPlaceholderCard_offset_left = $thisPlaceholderCard.offset().left,
  1028. $thisCard = $('.md-card-fullscreen'),
  1029. mdCardToolbarFixed = $thisCard.hasClass('mdToolbar_fixed');
  1030. $thisCard
  1031. // resize card to original size
  1032. .velocity(
  1033. {
  1034. height: mdPlaceholderCard_h,
  1035. width: mdPlaceholderCard_w
  1036. },
  1037. {
  1038. duration: 400,
  1039. easing: easing_swiftOut,
  1040. begin: function(elements) {
  1041. // hide fullscreen content
  1042. $thisCard.find('.md-card-fullscreen-content').velocity("transition.slideDownOut",{ duration: 275, easing: easing_swiftOut });
  1043. if(mdCardToolbarFixed) {
  1044. $thisCard.removeClass('mdToolbar_fixed')
  1045. }
  1046. },
  1047. complete: function(elements) {
  1048. // activate onResize callback for js plugins
  1049. $window.resize();
  1050. // remove back button
  1051. $thisCard.find('.md-card-fullscreen-deactivate').remove();
  1052. altair_page_content.show_content_sidebar();
  1053. }
  1054. }
  1055. )
  1056. // move card to original position
  1057. .velocity(
  1058. {
  1059. left: mdPlaceholderCard_offset_left,
  1060. top: mdPlaceholderCard_offset_top
  1061. },
  1062. {
  1063. duration: 400,
  1064. easing: easing_swiftOut,
  1065. complete: function(elements) {
  1066. // remove some styles added by velocity.js
  1067. $thisCard.removeClass('md-card-fullscreen').css({
  1068. width: '',
  1069. height: '',
  1070. left: '',
  1071. top: ''
  1072. });
  1073. // remove card placeholder
  1074. $thisPlaceholderCard.remove();
  1075. // remove overflow:hidden from #page_content (ios fix)
  1076. $body.removeClass('md-card-fullscreen-active');
  1077. }
  1078. }
  1079. );
  1080. });
  1081. },
  1082. card_expand: function() {
  1083. // expand elements
  1084. $(".md-expand").velocity("transition.expandIn", { stagger: 175, drag: true });
  1085. $(".md-expand-group").children().velocity("transition.expandIn", { stagger: 175, drag: true });
  1086. },
  1087. card_overlay: function() {
  1088. var $md_card = $('.md-card');
  1089. // replace toggler icon (x) when overlay is active
  1090. $md_card.each(function() {
  1091. var $this = $(this);
  1092. if($this.hasClass('md-card-overlay-active')) {
  1093. $this.find('.md-card-overlay-toggler').html('&#xE5CD;')
  1094. }
  1095. });
  1096. // toggle card overlay
  1097. $md_card.on('click','.md-card-overlay-toggler', function(e) {
  1098. e.preventDefault();
  1099. if(!$(this).closest('.md-card').hasClass('md-card-overlay-active')) {
  1100. $(this)
  1101. .html('&#xE5CD;')
  1102. .closest('.md-card').addClass('md-card-overlay-active');
  1103. } else {
  1104. $(this)
  1105. .html('&#xE5D4;')
  1106. .closest('.md-card').removeClass('md-card-overlay-active');
  1107. }
  1108. })
  1109. },
  1110. card_single: function() {
  1111. var $md_card_single = $('.md-card-single');
  1112. if($md_card_single && $body.hasClass('header_double_height')) {
  1113. function md_card_content_height() {
  1114. var content_height = $window.height() - ((header__main_height * 2) + 12);
  1115. $md_card_single.find('.md-card-content').innerHeight(content_height);
  1116. }
  1117. md_card_content_height();
  1118. $window.on('debouncedresize',function() {
  1119. md_card_content_height();
  1120. });
  1121. }
  1122. },
  1123. card_panel: function() {
  1124. $('.md-card-close').on('click',function(e) {
  1125. e.preventDefault();
  1126. var $this = $(this),
  1127. thisCard = $this.closest('.md-card'),
  1128. removeCard = function() {
  1129. $(thisCard).remove();
  1130. };
  1131. altair_md.card_show_hide(thisCard,undefined,removeCard)
  1132. });
  1133. $('.md-card-toggle').on('click',function(e) {
  1134. e.preventDefault();
  1135. var $this = $(this),
  1136. thisCard = $this.closest('.md-card');
  1137. $(thisCard).toggleClass('md-card-collapsed').children('.md-card-content').slideToggle('280', bez_easing_swiftOut);
  1138. $this.velocity({
  1139. scale: 0,
  1140. opacity: 0.2
  1141. }, {
  1142. duration: 280,
  1143. easing: easing_swiftOut,
  1144. complete: function() {
  1145. $(thisCard).hasClass('md-card-collapsed') ? $this.html('&#xE313;') : $this.html('&#xE316;');
  1146. $this.velocity('reverse');
  1147. $window.resize();
  1148. }
  1149. });
  1150. });
  1151. $('.md-card-collapsed').each(function() {
  1152. var $card = $(this),
  1153. $this_toggle = $card.find('.md-card-toggle');
  1154. $this_toggle.html('&#xE313;');
  1155. $card.children('.md-card-content').hide();
  1156. })
  1157. },
  1158. card_show_hide: function(card,begin_callback,complete_callback,callback_element) {
  1159. $(card)
  1160. .velocity({
  1161. scale: 0,
  1162. opacity: 0.2
  1163. }, {
  1164. duration: 400,
  1165. easing: easing_swiftOut,
  1166. // on begin callback
  1167. begin: function () {
  1168. if (typeof begin_callback !== 'undefined') {
  1169. begin_callback(callback_element);
  1170. }
  1171. },
  1172. // on complete callback
  1173. complete: function () {
  1174. if (typeof complete_callback !== 'undefined') {
  1175. complete_callback(callback_element);
  1176. }
  1177. }
  1178. })
  1179. .velocity('reverse');
  1180. },
  1181. card_progress: function(card,percent,steps) {
  1182. var $toolbar_progress = card ? $(card).children('.md-card-toolbar') : $('[data-toolbar-progress]');
  1183. $toolbar_progress.each(function() {
  1184. var $this = $(this),
  1185. bg_percent = percent ? parseInt(percent) : parseInt($this.attr('data-toolbar-progress')),
  1186. progress_steps = $this.attr('data-toolbar-progress-steps');
  1187. if(steps || progress_steps) {
  1188. if(bg_percent > 66) {
  1189. var bg_color = '#dcedc8';
  1190. } else if(bg_percent > 33) {
  1191. var bg_color = '#ffecb3';
  1192. } else {
  1193. var bg_color = '#ffcdd2';
  1194. }
  1195. } else {
  1196. var bg_color_default = $this.attr('data-toolbar-bg-default');
  1197. if(!bg_color_default) {
  1198. var bg_color = $this.css('backgroundColor');
  1199. $this.attr('data-toolbar-bg-default',bg_color)
  1200. } else {
  1201. var bg_color = bg_color_default;
  1202. }
  1203. }
  1204. if(percent) {
  1205. $this.attr('data-toolbar-progress',percent);
  1206. }
  1207. var bg_theme = '#fff';
  1208. $this
  1209. .css({ 'background': '-moz-linear-gradient(left, '+bg_color+' '+bg_percent+'%, '+ bg_theme+' '+(bg_percent)+'%)'})
  1210. .css({ 'background': 'linear-gradient(to right, '+bg_color+' '+bg_percent+'%, '+bg_theme+' '+(bg_percent)+'%)'})
  1211. .css({ 'background': '-webkit-linear-gradient(left, '+bg_color+' '+bg_percent+'%, '+bg_theme+' '+(bg_percent)+'%)'});
  1212. })
  1213. },
  1214. list_outside: function() {
  1215. var $md_list_outside_wrapper = $('.md-list-outside-wrapper');
  1216. if($md_list_outside_wrapper && $body.hasClass('header_double_height')) {
  1217. function md_list_outside_height() {
  1218. // check header height
  1219. var content_height = $window.height() - ((header__main_height * 2) + 10);
  1220. $md_list_outside_wrapper.height(content_height);
  1221. }
  1222. md_list_outside_height();
  1223. $window.on('debouncedresize',function() {
  1224. md_list_outside_height();
  1225. });
  1226. altair_helpers.custom_scrollbar($md_list_outside_wrapper);
  1227. }
  1228. },
  1229. inputs: function(parent) {
  1230. var $mdInput = (typeof parent === 'undefined') ? $('.md-input') : $(parent).find('.md-input');
  1231. $mdInput.each(function() {
  1232. if(!$(this).closest('.md-input-wrapper').length) {
  1233. var $this = $(this),
  1234. extraClass = '';
  1235. if($this.is('[class*="uk-form-width-"]')) {
  1236. var elClasses = $this.attr('class').split (' ');
  1237. for(var i = 0; i < elClasses.length; i++){
  1238. var classPart = elClasses[i].substr(0,14);
  1239. if(classPart == "uk-form-width-"){
  1240. var extraClass = elClasses[i];
  1241. }
  1242. }
  1243. }
  1244. if( $this.prev('label').length ) {
  1245. $this.prev('label').andSelf().wrapAll('<div class="md-input-wrapper"/>');
  1246. } else if($this.siblings('[data-uk-form-password]').length) {
  1247. $this.siblings('[data-uk-form-password]').andSelf().wrapAll('<div class="md-input-wrapper"/>');
  1248. } else {
  1249. $this.wrap('<div class="md-input-wrapper"/>');
  1250. }
  1251. $this.closest('.md-input-wrapper').append('<span class="md-input-bar '+extraClass+'"/>');
  1252. altair_md.update_input($this);
  1253. }
  1254. $body
  1255. .on('focus', '.md-input', function() {
  1256. $(this).closest('.md-input-wrapper').addClass('md-input-focus')
  1257. })
  1258. .on('blur', '.md-input', function() {
  1259. $(this).closest('.md-input-wrapper').removeClass('md-input-focus');
  1260. if(!$(this).hasClass('label-fixed')) {
  1261. if($(this).val() != '') {
  1262. $(this).closest('.md-input-wrapper').addClass('md-input-filled')
  1263. } else {
  1264. $(this).closest('.md-input-wrapper').removeClass('md-input-filled')
  1265. }
  1266. }
  1267. })
  1268. .on('change', '.md-input', function() {
  1269. altair_md.update_input($(this));
  1270. });
  1271. })
  1272. },
  1273. checkbox_radio: function(checkbox) {
  1274. var mdCheckbox = (typeof checkbox === 'undefined') ? $("[data-md-icheck],.data-md-icheck") : $(checkbox);
  1275. mdCheckbox.each(function() {
  1276. if( !$(this).next('.iCheck-helper').length ) {
  1277. $(this)
  1278. .iCheck({
  1279. checkboxClass: 'icheckbox_md',
  1280. radioClass: 'iradio_md',
  1281. increaseArea: '20%'
  1282. })
  1283. // validate inputs on change (parsley)
  1284. .on('ifChanged', function(event){
  1285. if ( !!$(this).data('parsley-multiple') ) {
  1286. $(this).parsley().validate();
  1287. }
  1288. });
  1289. }
  1290. });
  1291. },
  1292. update_input: function(object) {
  1293. // clear wrapper classes
  1294. object.closest('.uk-input-group').removeClass('uk-input-group-danger uk-input-group-success');
  1295. object.closest('.md-input-wrapper').removeClass('md-input-wrapper-danger md-input-wrapper-success md-input-wrapper-disabled');
  1296. if(object.hasClass('md-input-danger')) {
  1297. if(object.closest('.uk-input-group').length) {
  1298. object.closest('.uk-input-group').addClass('uk-input-group-danger')
  1299. }
  1300. object.closest('.md-input-wrapper').addClass('md-input-wrapper-danger')
  1301. }
  1302. if(object.hasClass('md-input-success')) {
  1303. if(object.closest('.uk-input-group').length) {
  1304. object.closest('.uk-input-group').addClass('uk-input-group-success')
  1305. }
  1306. object.closest('.md-input-wrapper').addClass('md-input-wrapper-success')
  1307. }
  1308. if(object.prop('disabled')) {
  1309. object.closest('.md-input-wrapper').addClass('md-input-wrapper-disabled')
  1310. }
  1311. if(object.val() != '') {
  1312. object.closest('.md-input-wrapper').addClass('md-input-filled')
  1313. } else {
  1314. object.closest('.md-input-wrapper').removeClass('md-input-filled')
  1315. }
  1316. if(object.hasClass('label-fixed')) {
  1317. object.closest('.md-input-wrapper').addClass('md-input-filled')
  1318. }
  1319. },
  1320. fab_speed_dial: function() {
  1321. function toggleFAB(obj) {
  1322. var $this = $(obj),
  1323. $this_wrapper = $this.closest('.md-fab-wrapper');
  1324. $this_wrapper.toggleClass('md-fab-active');
  1325. $this.velocity({
  1326. scale: 0
  1327. }, {
  1328. duration: 140,
  1329. easing: easing_swiftOut,
  1330. complete: function() {
  1331. $this
  1332. .velocity({
  1333. scale: 1
  1334. },{
  1335. duration: 140,
  1336. easing: easing_swiftOut
  1337. })
  1338. .children().toggle()
  1339. }
  1340. })
  1341. }
  1342. $('.md-fab-speed-dial,.md-fab-speed-dial-horizontal')
  1343. .children('.md-fab')
  1344. .append('<i class="material-icons md-fab-action-close" style="display:none">&#xE5CD;</i>')
  1345. .on('click',function() {
  1346. toggleFAB(this)
  1347. })
  1348. .closest('.md-fab-wrapper').find('.md-fab-small')
  1349. .on('click',function() {
  1350. toggleFAB($(this).closest('.md-fab-wrapper').children('.md-fab'));
  1351. });
  1352. },
  1353. fab_toolbar: function() {
  1354. var $fab_toolbar = $('.md-fab-toolbar');
  1355. if($fab_toolbar) {
  1356. $fab_toolbar
  1357. .children('i')
  1358. .on('click', function(e) {
  1359. e.preventDefault();
  1360. var toolbarItems = $fab_toolbar.children('.md-fab-toolbar-actions').children().length;
  1361. $fab_toolbar.addClass('md-fab-animated');
  1362. var FAB_padding = !$fab_toolbar.hasClass('md-fab-small') ? 16 : 24,
  1363. FAB_size = !$fab_toolbar.hasClass('md-fab-small') ? 64 : 44;
  1364. setTimeout(function() {
  1365. $fab_toolbar
  1366. .width((toolbarItems*FAB_size + FAB_padding))
  1367. },140);
  1368. setTimeout(function() {
  1369. $fab_toolbar.addClass('md-fab-active');
  1370. },420);
  1371. });
  1372. $document.on('click scroll', function(e) {
  1373. if( $fab_toolbar.hasClass('md-fab-active') ) {
  1374. if (!$(e.target).closest($fab_toolbar).length) {
  1375. $fab_toolbar
  1376. .css('width','')
  1377. .removeClass('md-fab-active');
  1378. setTimeout(function() {
  1379. $fab_toolbar.removeClass('md-fab-animated');
  1380. },140);
  1381. }
  1382. }
  1383. });
  1384. }
  1385. },
  1386. fab_sheet: function() {
  1387. var $fab_sheet = $('.md-fab-sheet');
  1388. if($fab_sheet) {
  1389. $fab_sheet
  1390. .children('i')
  1391. .on('click', function(e) {
  1392. e.preventDefault();
  1393. var sheetItems = $fab_sheet.children('.md-fab-sheet-actions').children('a').length;
  1394. $fab_sheet.addClass('md-fab-animated');
  1395. setTimeout(function() {
  1396. $fab_sheet
  1397. .width('240px')
  1398. .height(sheetItems*40 + 8);
  1399. },140);
  1400. setTimeout(function() {
  1401. $fab_sheet.addClass('md-fab-active');
  1402. },280);
  1403. });
  1404. $document.on('click scroll', function(e) {
  1405. if( $fab_sheet.hasClass('md-fab-active') ) {
  1406. if (!$(e.target).closest($fab_sheet).length) {
  1407. $fab_sheet
  1408. .css({
  1409. 'height':'',
  1410. 'width':''
  1411. })
  1412. .removeClass('md-fab-active');
  1413. setTimeout(function() {
  1414. $fab_sheet.removeClass('md-fab-animated');
  1415. },140);
  1416. }
  1417. }
  1418. });
  1419. }
  1420. },
  1421. wave_effect: function() {
  1422. if(!$html.hasClass('lte-ie9')) {
  1423. Waves.attach('.md-btn-wave,.md-fab-wave', ['waves-button']);
  1424. Waves.attach('.md-btn-wave-light,.md-fab-wave-light', ['waves-button', 'waves-light']);
  1425. Waves.attach('.wave-box', ['waves-float']);
  1426. Waves.init({
  1427. delay: 300
  1428. });
  1429. }
  1430. }
  1431. };
  1432. // common helpers
  1433. altair_helpers = {
  1434. truncate_text: function($object) {
  1435. $object.each(function() {
  1436. $(this).dotdotdot({
  1437. watch: "window"
  1438. });
  1439. })
  1440. },
  1441. custom_scrollbar: function($object) {
  1442. if(!$object.children('.scrollbar-inner').length) {
  1443. $object.wrapInner("<div class='scrollbar-inner'></div>");
  1444. }
  1445. if(Modernizr.touch) {
  1446. $object.children('.scrollbar-inner').addClass('touchscroll');
  1447. } else {
  1448. $object.children('.scrollbar-inner').scrollbar({
  1449. disableBodyScroll: true,
  1450. scrollx: false,
  1451. duration: 100
  1452. });
  1453. }
  1454. },
  1455. hierarchical_show: function() {
  1456. var $hierarchical_show = $('.hierarchical_show');
  1457. if($hierarchical_show.length) {
  1458. $hierarchical_show.each(function() {
  1459. var $this = $(this),
  1460. thisChildrenLength = $this.children().length,
  1461. baseDelay = 100;
  1462. $this
  1463. .children()
  1464. .each(function(index) {
  1465. $(this).css({
  1466. '-webkit-animation-delay': (index * baseDelay) + "ms",
  1467. 'animation-delay': (index * baseDelay) + "ms"
  1468. })
  1469. })
  1470. .end()
  1471. .waypoint({
  1472. handler: function() {
  1473. $this.addClass('hierarchical_show_inView');
  1474. setTimeout(function() {
  1475. $this
  1476. .removeClass('hierarchical_show hierarchical_show_inView fast_animation')
  1477. .children()
  1478. .css({
  1479. '-webkit-animation-delay': '',
  1480. 'animation-delay': ''
  1481. });
  1482. }, (thisChildrenLength*baseDelay)+1200 );
  1483. this.destroy();
  1484. },
  1485. context: 'window',
  1486. offset: '90%'
  1487. });
  1488. })
  1489. }
  1490. },
  1491. hierarchical_slide: function() {
  1492. var $hierarchical_slide = $('.hierarchical_slide');
  1493. if($hierarchical_slide.length) {
  1494. $hierarchical_slide.each(function() {
  1495. var $this = $(this),
  1496. $thisChildren = $this.attr('data-slide-children') ? $this.children($this.attr('data-slide-children')) : $this.children(),
  1497. thisChildrenLength = $thisChildren.length,
  1498. thisContext = $this.attr('data-slide-context') ? $this.closest($this.attr('data-slide-context'))[0] : 'window',
  1499. baseDelay = 100;
  1500. if(thisChildrenLength >= 1) {
  1501. $thisChildren.each(function(index) {
  1502. $(this).css({
  1503. '-webkit-animation-delay': (index * baseDelay) + "ms",
  1504. 'animation-delay': (index * baseDelay) + "ms"
  1505. })
  1506. });
  1507. $this.waypoint({
  1508. handler: function() {
  1509. $this.addClass('hierarchical_slide_inView');
  1510. setTimeout(function() {
  1511. $this.removeClass('hierarchical_slide hierarchical_slide_inView');
  1512. $thisChildren.css({
  1513. '-webkit-animation-delay': '',
  1514. 'animation-delay': ''
  1515. });
  1516. }, (thisChildrenLength*baseDelay)+1200 );
  1517. this.destroy();
  1518. },
  1519. context: thisContext,
  1520. offset: '90%'
  1521. });
  1522. }
  1523. })
  1524. }
  1525. },
  1526. content_preloader_show: function(style,variant,container,width,height) {
  1527. if(!$body.find('.content-preloader').length) {
  1528. var image_density = isHighDensity() ? '@2x' : '',
  1529. width = width ? width : 48,
  1530. height = height ? height : 48;
  1531. var preloader_content = (style == 'regular')
  1532. ? '<img src="assets/img/spinners/spinner' + image_density + '.gif" alt="" width="32" height="32">'
  1533. : '<div class="md-preloader"><svg xmlns="http://www.w3.org/2000/svg" version="1.1" height="'+height+'" width="'+width+'" viewbox="0 0 75 75"><circle cx="37.5" cy="37.5" r="33.5" stroke-width="8"/></svg></div>';
  1534. var thisContainer = (typeof container !== 'undefined') ? $(container) : $body;
  1535. thisContainer.append('<div class="content-preloader content-preloader-'+variant+'" style="height:'+height+'px;width:'+width+'px;margin-left:-'+width/2+'px">' + preloader_content + '</div>');
  1536. setTimeout(function() {
  1537. $('.content-preloader').addClass('preloader-active');
  1538. }, 0);
  1539. }
  1540. },
  1541. content_preloader_hide: function() {
  1542. if($body.find('.content-preloader').length) {
  1543. // hide preloader
  1544. $('.content-preloader').removeClass('preloader-active');
  1545. // remove preloader
  1546. preloader_timeout = window.setTimeout(function() {
  1547. $('.content-preloader').remove();
  1548. }, 500);
  1549. }
  1550. },
  1551. color_picker: function(object,pallete,callback) {
  1552. if(object) {
  1553. var cp_id = randID_generator(),
  1554. cp_pallete = pallete ? pallete : ['#e53935','#d81b60','#8e24aa','#5e35b1','#3949ab','#1e88e5','#039be5','#0097a7','#00897b','#43a047','#689f38','#ef6c00','#f4511e','#6d4c41','#757575','#546e7a'],
  1555. cp_pallete_length = cp_pallete.length,
  1556. cp_wrapper = $('<div class="cp_altair" id="'+cp_id+'"/>');
  1557. for(var $i=0;$i<cp_pallete_length;$i++) {
  1558. var span = (cp_pallete[$i].substring(0, 6) == "md-bg-" ) ?
  1559. '<span data-color=' + cp_pallete[$i] + ' class="' + cp_pallete[$i] + '"></span>'
  1560. :
  1561. '<span data-color=' + cp_pallete[$i] + ' style="background:' + cp_pallete[$i] + '"></span>';
  1562. cp_wrapper.append(span);
  1563. }
  1564. cp_wrapper.append('<input type="hidden">');
  1565. $body.on('click', '#'+cp_id+' span',function() {
  1566. $(this)
  1567. .addClass('active_color')
  1568. .siblings().removeClass('active_color')
  1569. .end()
  1570. .closest('.cp_altair').find('input').val($(this).attr('data-color'));
  1571. if(typeof callback == 'function') {
  1572. callback.call(this);
  1573. }
  1574. });
  1575. return object.append(cp_wrapper);
  1576. }
  1577. },
  1578. retina_images: function() {
  1579. if (typeof $.fn.dense !== "undefined") {
  1580. $('img').dense({
  1581. glue: "@"
  1582. });
  1583. }
  1584. },
  1585. full_screen: function() {
  1586. $('#full_screen_toggle').on('click',function(e) {
  1587. e.preventDefault();
  1588. screenfull.toggle();
  1589. $window.resize();
  1590. })
  1591. },
  1592. table_check: function() {
  1593. $table_check = $('.table_check');
  1594. $table_check.each(function() {
  1595. var $this = $(this),
  1596. $checkAll = $this.find('.check_all'),
  1597. $checkRow = $this.find('.check_row');
  1598. $checkAll
  1599. .on('ifChecked',function() {
  1600. $checkRow.iCheck('check');
  1601. })
  1602. .on('ifUnchecked',function() {
  1603. $checkRow.iCheck('uncheck');
  1604. });
  1605. $checkRow
  1606. .on('ifChecked',function(event) {
  1607. $(event.currentTarget).closest('tr').addClass('row_checked');
  1608. })
  1609. .on('ifUnchecked',function(event) {
  1610. $(event.currentTarget).closest('tr').removeClass('row_checked');
  1611. })
  1612. });
  1613. },
  1614. ie_fix: function() {
  1615. if(detectIE()) {
  1616. $('svg,canvas,video').each(function() {
  1617. $(this).css('height', 0);
  1618. });
  1619. setTimeout(function() {
  1620. $('svg,canvas,video').each(function() {
  1621. var $this = $(this),
  1622. height = $(this).attr('height'),
  1623. width = $(this).attr('width');
  1624. if(height) {
  1625. $this.css('height', height);
  1626. }
  1627. if(width) {
  1628. $this.css('width', width);
  1629. }
  1630. var peity = $this.prev('.peity_data');
  1631. if(peity.length) {
  1632. peity.peity().change()
  1633. }
  1634. });
  1635. }, 1000)
  1636. }
  1637. },
  1638. print_page: function() {
  1639. $body.on('click','#page_print',function(e) {
  1640. e.preventDefault();
  1641. UIkit.modal.confirm('Do you want to print this page?', function () {
  1642. // hide sidebar
  1643. altair_main_sidebar.hide_sidebar();
  1644. // wait for dialog to fully hide
  1645. setTimeout(function () {
  1646. window.print();
  1647. }, 300)
  1648. }, {
  1649. labels: {
  1650. 'Ok': 'print'
  1651. }
  1652. });
  1653. })
  1654. }
  1655. };
  1656. // uikit custom
  1657. altair_uikit = {
  1658. reinitialize_grid_margin: function() {
  1659. $("[data-uk-grid-margin]").each(function() {
  1660. var element = $(this);
  1661. if (!element.data("gridMargin")) {
  1662. $.UIkit.gridMargin(element, $.UIkit.Utils.options(element.attr("data-uk-grid-margin")));
  1663. }
  1664. });
  1665. $window.resize();
  1666. }
  1667. };