theme.admin.extension.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632
  1. window.admin = {};
  2. // Panels
  3. (function( $ ) {
  4. $(function() {
  5. $('.panel')
  6. .on( 'click', '.panel-actions a.fa-caret-up', function( e ) {
  7. e.preventDefault();
  8. var $this,
  9. $panel;
  10. $this = $( this );
  11. $panel = $this.closest( '.panel' );
  12. $this
  13. .removeClass( 'fa-caret-up' )
  14. .addClass( 'fa-caret-down' );
  15. $panel.find('.panel-body, .panel-footer').slideDown( 200 );
  16. })
  17. .on( 'click', '.panel-actions a.fa-caret-down', function( e ) {
  18. e.preventDefault();
  19. var $this,
  20. $panel;
  21. $this = $( this );
  22. $panel = $this.closest( '.panel' );
  23. $this
  24. .removeClass( 'fa-caret-down' )
  25. .addClass( 'fa-caret-up' );
  26. $panel.find('.panel-body, .panel-footer').slideUp( 200 );
  27. })
  28. .on( 'click', '.panel-actions a.fa-times', function( e ) {
  29. e.preventDefault();
  30. var $panel,
  31. $row;
  32. $panel = $(this).closest('.panel');
  33. if ( !!( $panel.parent('div').attr('class') || '' ).match( /col-(xs|sm|md|lg)/g ) && $panel.siblings().length === 0 ) {
  34. $row = $panel.closest('.row');
  35. $panel.parent('div').remove();
  36. if ( $row.children().length === 0 ) {
  37. $row.remove();
  38. }
  39. } else {
  40. $panel.remove();
  41. }
  42. });
  43. });
  44. })( jQuery );
  45. // Chart Circular
  46. (function( $ ) {
  47. 'use strict';
  48. if ( $.isFunction($.fn[ 'easyPieChart' ]) ) {
  49. $(function() {
  50. $('[data-plugin-chart-circular], .circular-bar-chart:not(.manual)').each(function() {
  51. var $this = $( this ),
  52. opts = {};
  53. var pluginOptions = $this.data('plugin-options');
  54. if (pluginOptions)
  55. opts = pluginOptions;
  56. $this.adminPluginChartCircular(opts);
  57. });
  58. });
  59. }
  60. }).apply(this, [ jQuery ]);
  61. // Chart Circular
  62. (function(admin, $) {
  63. admin = admin || {};
  64. var instanceName = '__chartCircular';
  65. var PluginChartCircular = function($el, opts) {
  66. return this.initialize($el, opts);
  67. };
  68. PluginChartCircular.defaults = {
  69. accX: 0,
  70. accY: -150,
  71. delay: 1,
  72. barColor: '#0088CC',
  73. trackColor: '#f2f2f2',
  74. scaleColor: false,
  75. scaleLength: 5,
  76. lineCap: 'round',
  77. lineWidth: 13,
  78. size: 175,
  79. rotate: 0,
  80. animate: ({
  81. duration: 2500,
  82. enabled: true
  83. })
  84. };
  85. PluginChartCircular.prototype = {
  86. initialize: function($el, opts) {
  87. if ( $el.data( instanceName ) ) {
  88. return this;
  89. }
  90. this.$el = $el;
  91. this
  92. .setData()
  93. .setOptions(opts)
  94. .build();
  95. return this;
  96. },
  97. setData: function() {
  98. this.$el.data(instanceName, this);
  99. return this;
  100. },
  101. setOptions: function(opts) {
  102. this.options = $.extend(true, {}, PluginChartCircular.defaults, opts, {
  103. wrapper: this.$el
  104. });
  105. return this;
  106. },
  107. build: function() {
  108. var self = this,
  109. $el = this.options.wrapper,
  110. value = ($el.attr('data-percent') ? $el.attr('data-percent') : 0),
  111. percentEl = $el.find('.percent'),
  112. shouldAnimate,
  113. data;
  114. shouldAnimate = $.isFunction($.fn[ 'appear' ]) && ( typeof $.browser !== 'undefined' && !$.browser.mobile );
  115. data = { accX: self.options.accX, accY: self.options.accY };
  116. $.extend(true, self.options, {
  117. onStep: function(from, to, currentValue) {
  118. percentEl.html(parseInt(currentValue));
  119. }
  120. });
  121. $el.attr('data-percent', (shouldAnimate ? 0 : value) );
  122. $el.easyPieChart( this.options );
  123. if ( shouldAnimate ) {
  124. $el.appear(function() {
  125. setTimeout(function() {
  126. $el.data('easyPieChart').update(value);
  127. $el.attr('data-percent', value);
  128. }, self.options.delay);
  129. }, data);
  130. } else {
  131. $el.data('easyPieChart').update(value);
  132. $el.attr('data-percent', value);
  133. }
  134. return this;
  135. }
  136. };
  137. // expose to scope
  138. $.extend(true, admin, {
  139. Chart: {
  140. PluginChartCircular: PluginChartCircular
  141. }
  142. });
  143. // jquery plugin
  144. $.fn.adminPluginChartCircular = function(opts) {
  145. return this.map(function() {
  146. var $this = $(this);
  147. if ($this.data(instanceName)) {
  148. return $this.data(instanceName);
  149. } else {
  150. return new PluginChartCircular($this, opts);
  151. }
  152. });
  153. }
  154. }).apply(this, [ window.admin, jQuery ]);
  155. // Slider
  156. (function( $ ) {
  157. 'use strict';
  158. if ( $.isFunction($.fn[ 'slider' ]) ) {
  159. $(function() {
  160. $('[data-plugin-slider]').each(function() {
  161. var $this = $( this ),
  162. opts = {};
  163. var pluginOptions = $this.data('plugin-options');
  164. if (pluginOptions) {
  165. opts = pluginOptions;
  166. }
  167. $this.adminPluginSlider(opts);
  168. });
  169. });
  170. }
  171. }).apply(this, [ jQuery ]);
  172. // Slider
  173. (function(admin, $) {
  174. admin = admin || {};
  175. var instanceName = '__slider';
  176. var PluginSlider = function($el, opts) {
  177. return this.initialize($el, opts);
  178. };
  179. PluginSlider.defaults = {
  180. };
  181. PluginSlider.prototype = {
  182. initialize: function($el, opts) {
  183. if ( $el.data( instanceName ) ) {
  184. return this;
  185. }
  186. this.$el = $el;
  187. this
  188. .setVars()
  189. .setData()
  190. .setOptions(opts)
  191. .build();
  192. return this;
  193. },
  194. setVars: function() {
  195. var $output = $( this.$el.data('plugin-slider-output') );
  196. this.$output = $output.get(0) ? $output : null;
  197. return this;
  198. },
  199. setData: function() {
  200. this.$el.data(instanceName, this);
  201. return this;
  202. },
  203. setOptions: function(opts) {
  204. var _self = this;
  205. this.options = $.extend( true, {}, PluginSlider.defaults, opts );
  206. if ( this.$output ) {
  207. $.extend( this.options, {
  208. slide: function( event, ui ) {
  209. _self.onSlide( event, ui );
  210. }
  211. });
  212. }
  213. return this;
  214. },
  215. build: function() {
  216. this.$el.slider( this.options );
  217. return this;
  218. },
  219. onSlide: function( event, ui ) {
  220. if ( !ui.values ) {
  221. this.$output.val( ui.value );
  222. } else {
  223. this.$output.val( ui.values[ 0 ] + '/' + ui.values[ 1 ] );
  224. }
  225. this.$output.trigger('change');
  226. }
  227. };
  228. // expose to scope
  229. $.extend(admin, {
  230. PluginSlider: PluginSlider
  231. });
  232. // jquery plugin
  233. $.fn.adminPluginSlider = function(opts) {
  234. return this.each(function() {
  235. var $this = $(this);
  236. if ($this.data(instanceName)) {
  237. return $this.data(instanceName);
  238. } else {
  239. return new PluginSlider($this, opts);
  240. }
  241. });
  242. }
  243. }).apply(this, [ window.admin, jQuery ]);
  244. // Data Tables - Config
  245. (function($) {
  246. 'use strict';
  247. // we overwrite initialize of all datatables here
  248. // because we want to use select2, give search input a bootstrap look
  249. // keep in mind if you overwrite this fnInitComplete somewhere,
  250. // you should run the code inside this function to keep functionality.
  251. //
  252. // there's no better way to do this at this time :(
  253. if ( $.isFunction( $.fn[ 'dataTable' ] ) ) {
  254. $.extend(true, $.fn.dataTable.defaults, {
  255. sDom: "<'row datatables-header form-inline'<'col-sm-12 col-md-6'l><'col-sm-12 col-md-6'f>r><'table-responsive't><'row datatables-footer'<'col-sm-12 col-md-6'i><'col-sm-12 col-md-6'p>>",
  256. oLanguage: {
  257. sLengthMenu: '_MENU_ records per page',
  258. sProcessing: '<i class="fa fa-spinner fa-spin"></i> Loading'
  259. },
  260. fnInitComplete: function( settings, json ) {
  261. // select 2
  262. if ( $.isFunction( $.fn[ 'select2' ] ) ) {
  263. $('.dataTables_length select', settings.nTableWrapper).select2({
  264. minimumResultsForSearch: -1
  265. });
  266. }
  267. var options = $( 'table', settings.nTableWrapper ).data( 'plugin-options' ) || {};
  268. // search
  269. var $search = $('.dataTables_filter input', settings.nTableWrapper);
  270. $search
  271. .attr({
  272. placeholder: typeof options.searchPlaceholder !== 'undefined' ? options.searchPlaceholder : 'Search'
  273. })
  274. .addClass('form-control');
  275. if ( $.isFunction( $.fn.placeholder ) ) {
  276. $search.placeholder();
  277. }
  278. }
  279. });
  280. }
  281. }).apply( this, [ jQuery ]);
  282. // Codemirror
  283. (function( $ ) {
  284. 'use strict';
  285. if ( typeof CodeMirror !== 'undefined' ) {
  286. $(function() {
  287. $('[data-plugin-codemirror]').each(function() {
  288. var $this = $( this ),
  289. opts = {};
  290. var pluginOptions = $this.data('plugin-options');
  291. if (pluginOptions)
  292. opts = pluginOptions;
  293. $this.adminPluginCodeMirror(opts);
  294. });
  295. });
  296. }
  297. }).apply(this, [ jQuery ]);
  298. // Codemirror
  299. (function(admin, $) {
  300. admin = admin || {};
  301. var instanceName = '__codemirror';
  302. var PluginCodeMirror = function($el, opts) {
  303. return this.initialize($el, opts);
  304. };
  305. PluginCodeMirror.defaults = {
  306. lineNumbers: true,
  307. styleActiveLine: true,
  308. matchBrackets: true,
  309. theme: 'monokai'
  310. };
  311. PluginCodeMirror.prototype = {
  312. initialize: function($el, opts) {
  313. if ( $el.data( instanceName ) ) {
  314. return this;
  315. }
  316. this.$el = $el;
  317. this
  318. .setData()
  319. .setOptions(opts)
  320. .build();
  321. return this;
  322. },
  323. setData: function() {
  324. this.$el.data(instanceName, this);
  325. return this;
  326. },
  327. setOptions: function(opts) {
  328. this.options = $.extend( true, {}, PluginCodeMirror.defaults, opts );
  329. return this;
  330. },
  331. build: function() {
  332. CodeMirror.fromTextArea( this.$el.get(0), this.options );
  333. return this;
  334. }
  335. };
  336. // expose to scope
  337. $.extend(admin, {
  338. PluginCodeMirror: PluginCodeMirror
  339. });
  340. // jquery plugin
  341. $.fn.adminPluginCodeMirror = function(opts) {
  342. return this.each(function() {
  343. var $this = $(this);
  344. if ($this.data(instanceName)) {
  345. return $this.data(instanceName);
  346. } else {
  347. return new PluginCodeMirror($this, opts);
  348. }
  349. });
  350. }
  351. }).apply(this, [ window.admin, jQuery ]);
  352. // Colorpicker
  353. (function( $ ) {
  354. 'use strict';
  355. if ( $.isFunction($.fn[ 'colorpicker' ]) ) {
  356. $(function() {
  357. $('[data-plugin-colorpicker]').each(function() {
  358. var $this = $( this ),
  359. opts = {};
  360. var pluginOptions = $this.data('plugin-options');
  361. if (pluginOptions)
  362. opts = pluginOptions;
  363. $this.adminPluginColorPicker(opts);
  364. });
  365. });
  366. }
  367. }).apply(this, [ jQuery ]);
  368. // Colorpicker
  369. (function(admin, $) {
  370. admin = admin || {};
  371. var instanceName = '__colorpicker';
  372. var PluginColorPicker = function($el, opts) {
  373. return this.initialize($el, opts);
  374. };
  375. PluginColorPicker.defaults = {
  376. };
  377. PluginColorPicker.prototype = {
  378. initialize: function($el, opts) {
  379. if ( $el.data( instanceName ) ) {
  380. return this;
  381. }
  382. this.$el = $el;
  383. this
  384. .setData()
  385. .setOptions(opts)
  386. .build();
  387. return this;
  388. },
  389. setData: function() {
  390. this.$el.data(instanceName, this);
  391. return this;
  392. },
  393. setOptions: function(opts) {
  394. this.options = $.extend( true, {}, PluginColorPicker.defaults, opts );
  395. return this;
  396. },
  397. build: function() {
  398. this.$el.colorpicker( this.options );
  399. return this;
  400. }
  401. };
  402. // expose to scope
  403. $.extend(admin, {
  404. PluginColorPicker: PluginColorPicker
  405. });
  406. // jquery plugin
  407. $.fn.adminPluginColorPicker = function(opts) {
  408. return this.each(function() {
  409. var $this = $(this);
  410. if ($this.data(instanceName)) {
  411. return $this.data(instanceName);
  412. } else {
  413. return new PluginColorPicker($this, opts);
  414. }
  415. });
  416. }
  417. }).apply(this, [ window.admin, jQuery ]);
  418. // Datepicker
  419. (function( $ ) {
  420. 'use strict';
  421. if ( $.isFunction($.fn[ 'datepicker' ]) ) {
  422. $(function() {
  423. $('[data-plugin-datepicker]').each(function() {
  424. var $this = $( this ),
  425. opts = {};
  426. var pluginOptions = $this.data('plugin-options');
  427. if (pluginOptions)
  428. opts = pluginOptions;
  429. $this.adminPluginDatePicker(opts);
  430. });
  431. });
  432. }
  433. }).apply(this, [ jQuery ]);
  434. // Datepicker
  435. (function(admin, $) {
  436. admin = admin || {};
  437. var instanceName = '__datepicker';
  438. var PluginDatePicker = function($el, opts) {
  439. return this.initialize($el, opts);
  440. };
  441. PluginDatePicker.defaults = {
  442. };
  443. PluginDatePicker.prototype = {
  444. initialize: function($el, opts) {
  445. if ( $el.data( instanceName ) ) {
  446. return this;
  447. }
  448. this.$el = $el;
  449. this
  450. .setVars()
  451. .setData()
  452. .setOptions(opts)
  453. .build();
  454. return this;
  455. },
  456. setVars: function() {
  457. this.skin = this.$el.data( 'plugin-skin' );
  458. return this;
  459. },
  460. setData: function() {
  461. this.$el.data(instanceName, this);
  462. return this;
  463. },
  464. setOptions: function(opts) {
  465. this.options = $.extend( true, {}, PluginDatePicker.defaults, opts );
  466. return this;
  467. },
  468. build: function() {
  469. this.$el.datepicker( this.options );
  470. if ( !!this.skin ) {
  471. this.$el.data('datepicker').picker.addClass( 'datepicker-' + this.skin );
  472. }
  473. return this;
  474. }
  475. };
  476. // expose to scope
  477. $.extend(admin, {
  478. PluginDatePicker: PluginDatePicker
  479. });
  480. // jquery plugin
  481. $.fn.adminPluginDatePicker = function(opts) {
  482. return this.each(function() {
  483. var $this = $(this);
  484. if ($this.data(instanceName)) {
  485. return $this.data(instanceName);
  486. } else {
  487. return new PluginDatePicker($this, opts);
  488. }
  489. });
  490. }
  491. }).apply(this, [ window.admin, jQuery ]);
  492. // iosSwitcher
  493. (function( $ ) {
  494. 'use strict';
  495. if ( typeof Switch !== 'undefined' && $.isFunction( Switch ) ) {
  496. $(function() {
  497. $('[data-plugin-ios-switch]').each(function() {
  498. var $this = $( this );
  499. $this.adminPluginIOS7Switch();
  500. });
  501. });
  502. }
  503. }).apply(this, [ jQuery ]);
  504. // iosSwitcher
  505. (function(admin, $) {
  506. admin = admin || {};
  507. var instanceName = '__IOS7Switch';
  508. var PluginIOS7Switch = function($el) {
  509. return this.initialize($el);
  510. };
  511. PluginIOS7Switch.prototype = {
  512. initialize: function($el) {
  513. if ( $el.data( instanceName ) ) {
  514. return this;
  515. }
  516. this.$el = $el;
  517. this
  518. .setData()
  519. .build();
  520. return this;
  521. },
  522. setData: function() {
  523. this.$el.data(instanceName, this);
  524. return this;
  525. },
  526. build: function() {
  527. var switcher = new Switch( this.$el.get(0) );
  528. $( switcher.el ).on( 'click', function( e ) {
  529. e.preventDefault();
  530. switcher.toggle();
  531. });
  532. return this;
  533. }
  534. };
  535. // expose to scope
  536. $.extend(admin, {
  537. PluginIOS7Switch: PluginIOS7Switch
  538. });
  539. // jquery plugin
  540. $.fn.adminPluginIOS7Switch = function(opts) {
  541. return this.each(function() {
  542. var $this = $(this);
  543. if ($this.data(instanceName)) {
  544. return $this.data(instanceName);
  545. } else {
  546. return new PluginIOS7Switch($this);
  547. }
  548. });
  549. }
  550. }).apply(this, [ window.admin, jQuery ]);
  551. // Markdown
  552. (function( $ ) {
  553. 'use strict';
  554. if ( $.isFunction($.fn[ 'markdown' ]) ) {
  555. $(function() {
  556. $('[data-plugin-markdown-editor]').each(function() {
  557. var $this = $( this ),
  558. opts = {};
  559. var pluginOptions = $this.data('plugin-options');
  560. if (pluginOptions)
  561. opts = pluginOptions;
  562. $this.adminPluginMarkdownEditor(opts);
  563. });
  564. });
  565. }
  566. }).apply(this, [ jQuery ]);
  567. // Markdown
  568. (function(admin, $) {
  569. admin = admin || {};
  570. var instanceName = '__markdownEditor';
  571. var PluginMarkdownEditor = function($el, opts) {
  572. return this.initialize($el, opts);
  573. };
  574. PluginMarkdownEditor.defaults = {
  575. iconlibrary: 'fa'
  576. };
  577. PluginMarkdownEditor.prototype = {
  578. initialize: function($el, opts) {
  579. if ( $el.data( instanceName ) ) {
  580. return this;
  581. }
  582. this.$el = $el;
  583. this
  584. .setData()
  585. .setOptions(opts)
  586. .build();
  587. return this;
  588. },
  589. setData: function() {
  590. this.$el.data(instanceName, this);
  591. return this;
  592. },
  593. setOptions: function(opts) {
  594. this.options = $.extend( true, {}, PluginMarkdownEditor.defaults, opts );
  595. return this;
  596. },
  597. build: function() {
  598. this.$el.markdown( this.options );
  599. return this;
  600. }
  601. };
  602. // expose to scope
  603. $.extend(admin, {
  604. PluginMarkdownEditor: PluginMarkdownEditor
  605. });
  606. // jquery plugin
  607. $.fn.adminPluginMarkdownEditor = function(opts) {
  608. return this.each(function() {
  609. var $this = $(this);
  610. if ($this.data(instanceName)) {
  611. return $this.data(instanceName);
  612. } else {
  613. return new PluginMarkdownEditor($this, opts);
  614. }
  615. });
  616. }
  617. }).apply(this, [ window.admin, jQuery ]);
  618. // Masked Input
  619. (function( $ ) {
  620. 'use strict';
  621. if ( $.isFunction($.fn[ 'mask' ]) ) {
  622. $(function() {
  623. $('[data-plugin-masked-input]').each(function() {
  624. var $this = $( this ),
  625. opts = {};
  626. var pluginOptions = $this.data('plugin-options');
  627. if (pluginOptions)
  628. opts = pluginOptions;
  629. $this.adminPluginMaskedInput(opts);
  630. });
  631. });
  632. }
  633. }).apply(this, [ jQuery ]);
  634. // Masked Input
  635. (function(admin, $) {
  636. admin = admin || {};
  637. var instanceName = '__maskedInput';
  638. var PluginMaskedInput = function($el, opts) {
  639. return this.initialize($el, opts);
  640. };
  641. PluginMaskedInput.defaults = {
  642. };
  643. PluginMaskedInput.prototype = {
  644. initialize: function($el, opts) {
  645. if ( $el.data( instanceName ) ) {
  646. return this;
  647. }
  648. this.$el = $el;
  649. this
  650. .setData()
  651. .setOptions(opts)
  652. .build();
  653. return this;
  654. },
  655. setData: function() {
  656. this.$el.data(instanceName, this);
  657. return this;
  658. },
  659. setOptions: function(opts) {
  660. this.options = $.extend( true, {}, PluginMaskedInput.defaults, opts );
  661. return this;
  662. },
  663. build: function() {
  664. this.$el.mask( this.$el.data('input-mask'), this.options );
  665. return this;
  666. }
  667. };
  668. // expose to scope
  669. $.extend(admin, {
  670. PluginMaskedInput: PluginMaskedInput
  671. });
  672. // jquery plugin
  673. $.fn.adminPluginMaskedInput = function(opts) {
  674. return this.each(function() {
  675. var $this = $(this);
  676. if ($this.data(instanceName)) {
  677. return $this.data(instanceName);
  678. } else {
  679. return new PluginMaskedInput($this, opts);
  680. }
  681. });
  682. }
  683. }).apply(this, [ window.admin, jQuery ]);
  684. // MaxLength
  685. (function( $ ) {
  686. 'use strict';
  687. if ( $.isFunction( $.fn[ 'maxlength' ]) ) {
  688. $(function() {
  689. $('[data-plugin-maxlength]').each(function() {
  690. var $this = $( this ),
  691. opts = {};
  692. var pluginOptions = $this.data('plugin-options');
  693. if (pluginOptions)
  694. opts = pluginOptions;
  695. $this.adminPluginMaxLength(opts);
  696. });
  697. });
  698. }
  699. }).apply(this, [ jQuery ]);
  700. // MaxLength
  701. (function(admin, $) {
  702. admin = admin || {};
  703. var instanceName = '__maxlength';
  704. var PluginMaxLength = function($el, opts) {
  705. return this.initialize($el, opts);
  706. };
  707. PluginMaxLength.defaults = {
  708. alwaysShow: true,
  709. placement: 'bottom-left',
  710. warningClass: 'label label-success bottom-left',
  711. limitReachedClass: 'label label-danger bottom-left'
  712. };
  713. PluginMaxLength.prototype = {
  714. initialize: function($el, opts) {
  715. if ( $el.data( instanceName ) ) {
  716. return this;
  717. }
  718. this.$el = $el;
  719. this
  720. .setData()
  721. .setOptions(opts)
  722. .build();
  723. return this;
  724. },
  725. setData: function() {
  726. this.$el.data(instanceName, this);
  727. return this;
  728. },
  729. setOptions: function(opts) {
  730. this.options = $.extend( true, {}, PluginMaxLength.defaults, opts );
  731. return this;
  732. },
  733. build: function() {
  734. this.$el.maxlength( this.options );
  735. return this;
  736. }
  737. };
  738. // expose to scope
  739. $.extend(admin, {
  740. PluginMaxLength: PluginMaxLength
  741. });
  742. // jquery plugin
  743. $.fn.adminPluginMaxLength = function(opts) {
  744. return this.each(function() {
  745. var $this = $(this);
  746. if ($this.data(instanceName)) {
  747. return $this.data(instanceName);
  748. } else {
  749. return new PluginMaxLength($this, opts);
  750. }
  751. });
  752. }
  753. }).apply(this, [ window.admin, jQuery ]);
  754. // MultiSelect
  755. (function( $ ) {
  756. 'use strict';
  757. if ( $.isFunction( $.fn[ 'multiselect' ] ) ) {
  758. $(function() {
  759. $( '[data-plugin-multiselect]' ).each(function() {
  760. var $this = $( this ),
  761. opts = {};
  762. var pluginOptions = $this.data('plugin-options');
  763. if (pluginOptions)
  764. opts = pluginOptions;
  765. $this.adminPluginMultiSelect(opts);
  766. });
  767. });
  768. }
  769. }).apply( this, [ jQuery ]);
  770. // MultiSelect
  771. (function(admin, $) {
  772. admin = admin || {};
  773. var instanceName = '__multiselect';
  774. var PluginMultiSelect = function($el, opts) {
  775. return this.initialize($el, opts);
  776. };
  777. PluginMultiSelect.defaults = {
  778. templates: {
  779. filter: '<div class="input-group"><span class="input-group-addon"><i class="fa fa-search"></i></span><input class="form-control multiselect-search" type="text"></div>'
  780. }
  781. };
  782. PluginMultiSelect.prototype = {
  783. initialize: function($el, opts) {
  784. if ( $el.data( instanceName ) ) {
  785. return this;
  786. }
  787. this.$el = $el;
  788. this
  789. .setData()
  790. .setOptions(opts)
  791. .build();
  792. return this;
  793. },
  794. setData: function() {
  795. this.$el.data(instanceName, this);
  796. return this;
  797. },
  798. setOptions: function(opts) {
  799. this.options = $.extend( true, {}, PluginMultiSelect.defaults, opts );
  800. return this;
  801. },
  802. build: function() {
  803. this.$el.multiselect( this.options );
  804. return this;
  805. }
  806. };
  807. // expose to scope
  808. $.extend(admin, {
  809. PluginMultiSelect: PluginMultiSelect
  810. });
  811. // jquery plugin
  812. $.fn.adminPluginMultiSelect = function(opts) {
  813. return this.each(function() {
  814. var $this = $(this);
  815. if ($this.data(instanceName)) {
  816. return $this.data(instanceName);
  817. } else {
  818. return new PluginMultiSelect($this, opts);
  819. }
  820. });
  821. }
  822. }).apply(this, [ window.admin, jQuery ]);
  823. (function( $ ) {
  824. 'use strict';
  825. if ( $.isFunction( $.fn[ 'placeholder' ]) ) {
  826. $('input[placeholder]').placeholder();
  827. }
  828. }).apply(this, [ jQuery ]);
  829. // Select2
  830. (function( $ ) {
  831. 'use strict';
  832. if ( $.isFunction($.fn[ 'select2' ]) ) {
  833. $(function() {
  834. $('[data-plugin-selectTwo]').each(function() {
  835. var $this = $( this ),
  836. opts = {};
  837. var pluginOptions = $this.data('plugin-options');
  838. if (pluginOptions)
  839. opts = pluginOptions;
  840. $this.adminPluginSelect2(opts);
  841. });
  842. });
  843. }
  844. }).apply(this, [ jQuery ]);
  845. // Select2
  846. (function(admin, $) {
  847. admin = admin || {};
  848. var instanceName = '__select2';
  849. var PluginSelect2 = function($el, opts) {
  850. return this.initialize($el, opts);
  851. };
  852. PluginSelect2.defaults = {
  853. };
  854. PluginSelect2.prototype = {
  855. initialize: function($el, opts) {
  856. if ( $el.data( instanceName ) ) {
  857. return this;
  858. }
  859. this.$el = $el;
  860. this
  861. .setData()
  862. .setOptions(opts)
  863. .build();
  864. return this;
  865. },
  866. setData: function() {
  867. this.$el.data(instanceName, this);
  868. return this;
  869. },
  870. setOptions: function(opts) {
  871. this.options = $.extend( true, {}, PluginSelect2.defaults, opts );
  872. return this;
  873. },
  874. build: function() {
  875. this.$el.select2( this.options );
  876. return this;
  877. }
  878. };
  879. // expose to scope
  880. $.extend(admin, {
  881. PluginSelect2: PluginSelect2
  882. });
  883. // jquery plugin
  884. $.fn.adminPluginSelect2 = function(opts) {
  885. return this.each(function() {
  886. var $this = $(this);
  887. if ($this.data(instanceName)) {
  888. return $this.data(instanceName);
  889. } else {
  890. return new PluginSelect2($this, opts);
  891. }
  892. });
  893. }
  894. }).apply(this, [ window.admin, jQuery ]);
  895. // Spinner
  896. (function( $ ) {
  897. 'use strict';
  898. if ( $.isFunction($.fn[ 'spinner' ]) ) {
  899. $(function() {
  900. $('[data-plugin-spinner]').each(function() {
  901. var $this = $( this ),
  902. opts = {};
  903. var pluginOptions = $this.data('plugin-options');
  904. if (pluginOptions)
  905. opts = pluginOptions;
  906. $this.adminPluginSpinner(opts);
  907. });
  908. });
  909. }
  910. }).apply(this, [ jQuery ]);
  911. // Spinner
  912. (function(admin, $) {
  913. admin = admin || {};
  914. var instanceName = '__spinner';
  915. var PluginSpinner = function($el, opts) {
  916. return this.initialize($el, opts);
  917. };
  918. PluginSpinner.defaults = {
  919. };
  920. PluginSpinner.prototype = {
  921. initialize: function($el, opts) {
  922. if ( $el.data( instanceName ) ) {
  923. return this;
  924. }
  925. this.$el = $el;
  926. this
  927. .setData()
  928. .setOptions(opts)
  929. .build();
  930. return this;
  931. },
  932. setData: function() {
  933. this.$el.data(instanceName, this);
  934. return this;
  935. },
  936. setOptions: function(opts) {
  937. this.options = $.extend( true, {}, PluginSpinner.defaults, opts );
  938. return this;
  939. },
  940. build: function() {
  941. this.$el.spinner( this.options );
  942. return this;
  943. }
  944. };
  945. // expose to scope
  946. $.extend(admin, {
  947. PluginSpinner: PluginSpinner
  948. });
  949. // jquery plugin
  950. $.fn.adminPluginSpinner = function(opts) {
  951. return this.each(function() {
  952. var $this = $(this);
  953. if ($this.data(instanceName)) {
  954. return $this.data(instanceName);
  955. } else {
  956. return new PluginSpinner($this, opts);
  957. }
  958. });
  959. }
  960. }).apply(this, [ window.admin, jQuery ]);
  961. // SummerNote
  962. (function( $ ) {
  963. 'use strict';
  964. if ( $.isFunction($.fn[ 'summernote' ]) ) {
  965. $(function() {
  966. $('[data-plugin-summernote]').each(function() {
  967. var $this = $( this ),
  968. opts = {};
  969. var pluginOptions = $this.data('plugin-options');
  970. if (pluginOptions)
  971. opts = pluginOptions;
  972. $this.adminPluginSummerNote(opts);
  973. });
  974. });
  975. }
  976. }).apply(this, [ jQuery ]);
  977. // SummerNote
  978. (function(admin, $) {
  979. admin = admin || {};
  980. var instanceName = '__summernote';
  981. var PluginSummerNote = function($el, opts) {
  982. return this.initialize($el, opts);
  983. };
  984. PluginSummerNote.defaults = {
  985. onfocus: function() {
  986. $( this ).closest( '.note-editor' ).addClass( 'active' );
  987. },
  988. onblur: function() {
  989. $( this ).closest( '.note-editor' ).removeClass( 'active' );
  990. }
  991. };
  992. PluginSummerNote.prototype = {
  993. initialize: function($el, opts) {
  994. if ( $el.data( instanceName ) ) {
  995. return this;
  996. }
  997. this.$el = $el;
  998. this
  999. .setData()
  1000. .setOptions(opts)
  1001. .build();
  1002. return this;
  1003. },
  1004. setData: function() {
  1005. this.$el.data(instanceName, this);
  1006. return this;
  1007. },
  1008. setOptions: function(opts) {
  1009. this.options = $.extend( true, {}, PluginSummerNote.defaults, opts );
  1010. return this;
  1011. },
  1012. build: function() {
  1013. this.$el.summernote( this.options );
  1014. return this;
  1015. }
  1016. };
  1017. // expose to scope
  1018. $.extend(admin, {
  1019. PluginSummerNote: PluginSummerNote
  1020. });
  1021. // jquery plugin
  1022. $.fn.adminPluginSummerNote = function(opts) {
  1023. return this.each(function() {
  1024. var $this = $(this);
  1025. if ($this.data(instanceName)) {
  1026. return $this.data(instanceName);
  1027. } else {
  1028. return new PluginSummerNote($this, opts);
  1029. }
  1030. });
  1031. }
  1032. }).apply(this, [ window.admin, jQuery ]);
  1033. // TextArea AutoSize
  1034. (function( $ ) {
  1035. 'use strict';
  1036. if ( $.isFunction($.fn[ 'autosize' ]) ) {
  1037. $(function() {
  1038. $('[data-plugin-textarea-autosize]').each(function() {
  1039. var $this = $( this ),
  1040. opts = {};
  1041. var pluginOptions = $this.data('plugin-options');
  1042. if (pluginOptions)
  1043. opts = pluginOptions;
  1044. $this.adminPluginTextAreaAutoSize(opts);
  1045. });
  1046. });
  1047. }
  1048. }).apply(this, [ jQuery ]);
  1049. // TextArea AutoSize
  1050. (function(admin, $) {
  1051. admin = admin || {};
  1052. var initialized = false;
  1053. var instanceName = '__textareaAutosize';
  1054. var PluginTextAreaAutoSize = function($el, opts) {
  1055. return this.initialize($el, opts);
  1056. };
  1057. PluginTextAreaAutoSize.defaults = {
  1058. };
  1059. PluginTextAreaAutoSize.prototype = {
  1060. initialize: function($el, opts) {
  1061. if (initialized) {
  1062. return this;
  1063. }
  1064. this.$el = $el;
  1065. this
  1066. .setData()
  1067. .setOptions(opts)
  1068. .build();
  1069. return this;
  1070. },
  1071. setData: function() {
  1072. this.$el.data(instanceName, this);
  1073. return this;
  1074. },
  1075. setOptions: function(opts) {
  1076. this.options = $.extend( true, {}, PluginTextAreaAutoSize.defaults, opts );
  1077. return this;
  1078. },
  1079. build: function() {
  1080. this.$el.autosize( this.options );
  1081. return this;
  1082. }
  1083. };
  1084. // expose to scope
  1085. $.extend(admin, {
  1086. PluginTextAreaAutoSize: PluginTextAreaAutoSize
  1087. });
  1088. // jquery plugin
  1089. $.fn.adminPluginTextAreaAutoSize = function(opts) {
  1090. return this.each(function() {
  1091. var $this = $(this);
  1092. if ($this.data(instanceName)) {
  1093. return $this.data(instanceName);
  1094. } else {
  1095. return new PluginTextAreaAutoSize($this, opts);
  1096. }
  1097. });
  1098. }
  1099. }).apply(this, [ window.admin, jQuery ]);
  1100. // TimePicker
  1101. (function( $ ) {
  1102. 'use strict';
  1103. if ( $.isFunction($.fn[ 'timepicker' ]) ) {
  1104. $(function() {
  1105. $('[data-plugin-timepicker]').each(function() {
  1106. var $this = $( this ),
  1107. opts = {};
  1108. var pluginOptions = $this.data('plugin-options');
  1109. if (pluginOptions)
  1110. opts = pluginOptions;
  1111. $this.adminPluginTimePicker(opts);
  1112. });
  1113. });
  1114. }
  1115. }).apply(this, [ jQuery ]);
  1116. // TimePicker
  1117. (function(admin, $) {
  1118. admin = admin || {};
  1119. var instanceName = '__timepicker';
  1120. var PluginTimePicker = function($el, opts) {
  1121. return this.initialize($el, opts);
  1122. };
  1123. PluginTimePicker.defaults = {
  1124. disableMousewheel: true
  1125. };
  1126. PluginTimePicker.prototype = {
  1127. initialize: function($el, opts) {
  1128. if ( $el.data( instanceName ) ) {
  1129. return this;
  1130. }
  1131. this.$el = $el;
  1132. this
  1133. .setData()
  1134. .setOptions(opts)
  1135. .build();
  1136. return this;
  1137. },
  1138. setData: function() {
  1139. this.$el.data(instanceName, this);
  1140. return this;
  1141. },
  1142. setOptions: function(opts) {
  1143. this.options = $.extend( true, {}, PluginTimePicker.defaults, opts );
  1144. return this;
  1145. },
  1146. build: function() {
  1147. this.$el.timepicker( this.options );
  1148. return this;
  1149. }
  1150. };
  1151. // expose to scope
  1152. $.extend(admin, {
  1153. PluginTimePicker: PluginTimePicker
  1154. });
  1155. // jquery plugin
  1156. $.fn.adminPluginTimePicker = function(opts) {
  1157. return this.each(function() {
  1158. var $this = $(this);
  1159. if ($this.data(instanceName)) {
  1160. return $this.data(instanceName);
  1161. } else {
  1162. return new PluginTimePicker($this, opts);
  1163. }
  1164. });
  1165. }
  1166. }).apply(this, [ window.admin, jQuery ]);