/static/modaal/js/modaal.js

https://github.com/leoiceo/OpenSA · JavaScript · 1390 lines · 848 code · 227 blank · 315 comment · 230 complexity · 518947ca01725ec15a39b3f5282fb858 MD5 · raw file

  1. /*!
  2. Modaal - accessible modals - v0.4.3
  3. by Humaan, for all humans.
  4. http://humaan.com
  5. */
  6. /**
  7. Modaal jQuery Plugin : Accessible Modals
  8. ==== General Options ===
  9. type (string) : ajax, inline, image, iframe, confirm. Defaults to 'inline'
  10. content_source (stribg) : Accepts a string value for your target element, such as '#my-content'. This allows for when trigger element is
  11. an `<a href="#">` link. Not to be confused with the already existing `source` event.
  12. animation (string) : Fade, expand, down, up. Defaults to 'fade'
  13. after_callback_delay (integer) : Specify a delay value for the after open callbacks. This is necessary because with the bundled animations
  14. have a set duration in the bundled CSS. Specify a delay of the same amount as the animation duration in so
  15. more accurately fire the after open/close callbacks. Defaults 350, does not apply if animation is 'none',
  16. after open callbacks are dispatched immediately
  17. is_locked (boolean) : Set this to true to disable closing the modal via keypress or clicking the background. Beware that if
  18. type != 'confirm' there will be no interface to dismiss the modal if is_locked = true, you'd have to
  19. programmatically arrange to dismiss the modal. Confirm modals are always locked regardless of this option
  20. Defaults to false
  21. hide_close (boolean) : Set this to true to hide the close modal button. Key press and overlay click will still close the modal.
  22. This method is best used when you want to put a custom close button inside the modal container space.
  23. background (string) : Background overlay style. Defaults to '#000'
  24. overlay_opacity (float) : Background overlay transparency. Defaults to 0.8
  25. overlay_close (boolean) : Set this to false if you want to disable click to close on overlay background.
  26. accessible_title (string) : Accessible title. Default 'Dialog Window'
  27. start_open (boolean) : Set this to true to launch the Modaal window immediately on page open
  28. fullscreen (boolean) : Set this to true to make the modaal fill the entire screen, false will default to own width/height attributes.
  29. custom_class (string) : Fill in this string with a custom class that will be applied to the outer most modal wrapper.
  30. width (integer) : Desired width of the modal. Required for iframe type. Defaults to undefined //TODO
  31. height (integer) : Desired height of the modal. Required for iframe type. Defaults to undefined //TODO
  32. background_scroll (boolean) : Set this to true to enable the page to scroll behind the open modal.
  33. should_open (boolean|function) : Boolean or closure that returns a boolean to determine whether to open the modal or not.
  34. close_text : String for close button text. Available for localisation and alternative languages to be used.
  35. close_aria_label : String for close button aria-label attribute (value that screen readers will read out). Available for localisation and alternative languages to be used.
  36. === Events ===
  37. before_open (function) : Callback function executed before modal is opened
  38. after_open (function) : Callback function executed after modal is opened
  39. before_close (function) : Callback function executed before modal is closed
  40. after_close (function) : Callback function executed after modal is closed
  41. source (function(element, src)) : Callback function executed on the default source, it is intended to transform the
  42. source (href in an AJAX modal or iframe). The function passes in the triggering element
  43. as well as the default source depending of the modal type. The default output of the
  44. function is an untransformed default source.
  45. === Confirm Options & Events ===
  46. confirm_button_text (string) : Text on the confirm button. Defaults to 'Confirm'
  47. confirm_cancel_button_text (string) : Text on the confirm modal cancel button. Defaults to 'Cancel'
  48. confirm_title (string) : Title for confirm modal. Default 'Confirm Title'
  49. confirm_content (string) : HTML content for confirm message
  50. confirm_callback (function) : Callback function for when the confirm button is pressed as opposed to cancel
  51. confirm_cancel_callback (function) : Callback function for when the cancel button is pressed
  52. === Gallery Options & Events ===
  53. gallery_active_class (string) : Active class applied to the currently active image or image slide in a gallery 'gallery_active_item'
  54. outer_controls (boolean) : Set to true to put the next/prev controls outside the Modaal wrapper, at the edges of the browser window.
  55. before_image_change (function) : Callback function executed before the image slide changes in a gallery modal. Default function( current_item, incoming_item )
  56. after_image_change (function) : Callback function executed after the image slide changes in a gallery modal. Default function ( current_item )
  57. === AJAX Options & Events ===
  58. loading_content (string) : HTML content for loading message. Default 'Loading &hellip;'
  59. loading_class (string) : Class name to be applied while content is loaded via AJAX. Default 'is_loading'
  60. ajax_error_class (string) : Class name to be applied when content has failed to load. Default is 'modaal-error'
  61. ajax_success (function) : Callback for when AJAX content is loaded in
  62. === SOCIAL CONTENT ===
  63. instagram_id (string) : Unique photo ID for an Instagram photo.
  64. */
  65. ( function( $ ) {
  66. var modaal_loading_spinner = '<div class="modaal-loading-spinner"><div><div></div></div><div><div></div></div><div><div></div></div><div><div></div></div><div><div></div></div><div><div></div></div><div><div></div></div><div><div></div></div></div>'
  67. var Modaal = {
  68. init : function(options, elem) {
  69. var self = this;
  70. self.dom = $('body');
  71. self.$elem = $(elem);
  72. self.options = $.extend({}, $.fn.modaal.options, self.$elem.data(), options);
  73. self.xhr = null;
  74. // set up the scope
  75. self.scope = {
  76. is_open: false,
  77. id: 'modaal_' + ( new Date().getTime() ) + ( Math.random().toString(16).substring(2) ),
  78. source: self.options.content_source ? self.options.content_source : self.$elem.attr('href')
  79. };
  80. // add scope attribute to trigger element
  81. self.$elem.attr('data-modaal-scope', self.scope.id);
  82. // private options
  83. self.private_options = {
  84. active_class: 'is_active'
  85. };
  86. self.lastFocus = null;
  87. // if is_locked
  88. if ( self.options.is_locked || self.options.type == 'confirm' || self.options.hide_close ) {
  89. self.scope.close_btn = '';
  90. } else {
  91. self.scope.close_btn = '<button type="button" class="modaal-close" id="modaal-close" aria-label="' + self.options.close_aria_label + '"><span>' + self.options.close_text + '</span></button>';
  92. }
  93. // reset animation_speed
  94. if (self.options.animation === 'none' ){
  95. self.options.animation_speed = 0;
  96. self.options.after_callback_delay = 0;
  97. }
  98. // On click to open modal
  99. $(elem).on('click.Modaal', function(e) {
  100. e.preventDefault();
  101. self.create_modaal(self, e);
  102. });
  103. // Define next/prev buttons
  104. if (self.options.outer_controls === true) {
  105. var mod_class = 'outer';
  106. } else {
  107. var mod_class = 'inner';
  108. }
  109. self.scope.prev_btn = '<button type="button" class="modaal-gallery-control modaal-gallery-prev modaal-gallery-prev-' + mod_class + '" id="modaal-gallery-prev" aria-label="Previous image (use left arrow to change)"><span>Previous Image</span></button>';
  110. self.scope.next_btn = '<button type="button" class="modaal-gallery-control modaal-gallery-next modaal-gallery-next-' + mod_class + '" id="modaal-gallery-next" aria-label="Next image (use right arrow to change)"><span>Next Image</span></button>';
  111. // Check for start_open
  112. if (self.options.start_open === true ){
  113. self.create_modaal( self );
  114. }
  115. },
  116. // Initial create to determine which content type it requires
  117. // ----------------------------------------------------------------
  118. create_modaal : function(self, e) {
  119. var self = this;
  120. var source;
  121. // Save last active state before modal
  122. self.lastFocus = self.$elem;
  123. if ( self.options.should_open === false || ( typeof self.options.should_open === 'function' && self.options.should_open() === false ) ) {
  124. return;
  125. }
  126. // CB: before_open
  127. self.options.before_open.call(self, e);
  128. switch (self.options.type) {
  129. case 'inline':
  130. self.create_basic();
  131. break;
  132. case 'ajax':
  133. source = self.options.source( self.$elem, self.scope.source );
  134. self.fetch_ajax( source );
  135. break;
  136. case 'confirm':
  137. self.options.is_locked = true;
  138. self.create_confirm();
  139. break;
  140. case 'image':
  141. self.create_image();
  142. break;
  143. case 'iframe':
  144. source = self.options.source( self.$elem, self.scope.source );
  145. self.create_iframe( source );
  146. break;
  147. case 'video':
  148. self.create_video(self.scope.source);
  149. break;
  150. case 'instagram':
  151. self.create_instagram();
  152. break;
  153. }
  154. // call events to be watched (click, tab, keyup, keydown etc.)
  155. self.watch_events();
  156. },
  157. // Watching Modal
  158. // ----------------------------------------------------------------
  159. watch_events : function() {
  160. var self = this;
  161. self.dom.off('click.Modaal keyup.Modaal keydown.Modaal');
  162. // Body keydown
  163. self.dom.on('keydown.Modaal', function(e) {
  164. var key = e.keyCode;
  165. var target = e.target;
  166. // look for tab change and reset focus to modal window
  167. // done in keydown so the check fires repeatedly when you hold the tab key down
  168. if (key == 9 && self.scope.is_open) {
  169. if (!$.contains(document.getElementById(self.scope.id), target) ) {
  170. $('#' + self.scope.id).find('*[tabindex="0"]').focus();
  171. }
  172. }
  173. });
  174. // Body keyup
  175. self.dom.on('keyup.Modaal', function(e) {
  176. var key = e.keyCode;
  177. var target = e.target;
  178. if ( (e.shiftKey && e.keyCode == 9) && self.scope.is_open) {
  179. // Watch for shift + tab key press. if open shift focus to close button.
  180. if (!$.contains(document.getElementById(self.scope.id), target) ) {
  181. $('#' + self.scope.id).find('.modaal-close').focus();
  182. }
  183. }
  184. if ( !self.options.is_locked ){
  185. // On escape key press close modal
  186. if (key == 27 && self.scope.is_open ) {
  187. if ( $(document.activeElement).is('input:not(:checkbox):not(:radio)') ) {
  188. return false;
  189. }
  190. self.modaal_close();
  191. return;
  192. }
  193. }
  194. // is gallery open and images length is > 1
  195. if ( self.options.type == 'image' ) {
  196. // arrow left for back
  197. if (key == 37 && self.scope.is_open && (!$('#' + self.scope.id + ' .modaal-gallery-prev').hasClass('is_hidden')) ) {
  198. self.gallery_update('prev');
  199. }
  200. // arrow right for next
  201. if (key == 39 && self.scope.is_open && (!$('#' + self.scope.id + ' .modaal-gallery-next').hasClass('is_hidden')) ) {
  202. self.gallery_update('next');
  203. }
  204. return;
  205. }
  206. });
  207. // Body click/touch
  208. self.dom.on('click.Modaal', function(e) {
  209. var trigger = $(e.target);
  210. // General Controls: If it's not locked allow greedy close
  211. if ( !self.options.is_locked ){
  212. if ( (self.options.overlay_close && trigger.is('.modaal-inner-wrapper')) || trigger.is('.modaal-close') || trigger.closest('.modaal-close').length ) {
  213. self.modaal_close();
  214. return;
  215. }
  216. }
  217. //Confirm Controls
  218. if ( trigger.is('.modaal-confirm-btn' ) ){
  219. // if 'OK' button is clicked, run confirm_callback()
  220. if ( trigger.is('.modaal-ok') ) {
  221. self.options.confirm_callback.call(self, self.lastFocus);
  222. }
  223. if ( trigger.is('.modaal-cancel') ) {
  224. self.options.confirm_cancel_callback.call(self, self.lastFocus);
  225. }
  226. self.modaal_close();
  227. return;
  228. }
  229. // Gallery Controls
  230. if ( trigger.is( '.modaal-gallery-control' ) ){
  231. // it not active, don't do nuthin!
  232. if ( trigger.hasClass('is_hidden') ) {
  233. return;
  234. }
  235. // trigger previous
  236. if ( trigger.is('.modaal-gallery-prev') ) {
  237. self.gallery_update('prev');
  238. }
  239. // trigger next
  240. if ( trigger.is('.modaal-gallery-next') ) {
  241. self.gallery_update('next');
  242. }
  243. return;
  244. }
  245. });
  246. },
  247. // Append markup into DOM
  248. build_modal : function(content) {
  249. var self = this;
  250. // if is instagram
  251. var igClass = '';
  252. if ( self.options.type == 'instagram' ) {
  253. igClass = ' modaal-instagram';
  254. }
  255. var wrap_class = (self.options.type == 'video') ? 'modaal-video-wrap' : 'modaal-content';
  256. /*
  257. modaal-start_none : fully hidden via display:none;
  258. modaal-start_fade : hidden via opacity:0
  259. modaal-start_slidedown : ...
  260. */
  261. var animation_class;
  262. switch ( self.options.animation ) {
  263. case 'fade' :
  264. animation_class = ' modaal-start_fade';
  265. break;
  266. case 'slide-down' :
  267. animation_class = ' modaal-start_slidedown';
  268. break;
  269. default :
  270. animation_class = ' modaal-start_none'
  271. }
  272. // fullscreen check
  273. var fullscreen_class = '';
  274. if ( self.options.fullscreen ) {
  275. fullscreen_class = ' modaal-fullscreen';
  276. }
  277. // custom class check
  278. if ( self.options.custom_class !== '' || typeof(self.options.custom_class) !== 'undefined' ) {
  279. self.options.custom_class = ' ' + self.options.custom_class;
  280. }
  281. // if width and heights exists and is typeof number
  282. var dimensionsStyle = '';
  283. if ( self.options.width && self.options.height && typeof self.options.width == 'number' && typeof self.options.height == 'number' ) {
  284. // if width and height exist, and they are both numbers
  285. dimensionsStyle = ' style="max-width:' + self.options.width + 'px;height:' + self.options.height + 'px;overflow:auto;"';
  286. } else if ( self.options.width && typeof self.options.width == 'number' ) {
  287. // if only width
  288. dimensionsStyle = ' style="max-width:' + self.options.width + 'px;"';
  289. } else if ( self.options.height && typeof self.options.height == 'number' ) {
  290. // if only height
  291. dimensionsStyle = ' style="height:' + self.options.height + 'px;overflow:auto;"';
  292. }
  293. // Reset dimensions style (width and height) for certain types
  294. if ( self.options.type == 'image' || self.options.type == 'video' || self.options.type == 'instagram' || self.options.fullscreen ) {
  295. dimensionsStyle = '';
  296. }
  297. // if is touch
  298. // this is a bug fix for iOS to allow regular click events on div elements.
  299. var touchTrigger = '';
  300. if ( self.is_touch() ) {
  301. touchTrigger = ' style="cursor:pointer;"'
  302. }
  303. var build_markup = '<div class="modaal-wrapper modaal-' + self.options.type + animation_class + igClass + fullscreen_class + self.options.custom_class + '" id="' + self.scope.id + '"><div class="modaal-outer-wrapper"><div class="modaal-inner-wrapper"' + touchTrigger + '>';
  304. // hide if video
  305. if (self.options.type != 'video') {
  306. build_markup += '<div class="modaal-container"' + dimensionsStyle + '>';
  307. }
  308. // add the guts of the content
  309. build_markup += '<div class="' + wrap_class + ' modaal-focus" aria-hidden="false" aria-label="' + self.options.accessible_title + ' - ' + self.options.close_aria_label + '" role="dialog">';
  310. // If it's inline type, we want to clone content instead of dropping it straight in
  311. if (self.options.type == 'inline') {
  312. build_markup += '<div class="modaal-content-container" role="document"></div>';
  313. } else {
  314. // Drop in the content if it's not inline
  315. build_markup += content;
  316. }
  317. // close wrap_class
  318. build_markup += '</div>' + self.scope.close_btn;
  319. // hide if video
  320. if (self.options.type != 'video') {
  321. build_markup += '</div>';
  322. }
  323. // close off modaal-inner-wrapper
  324. build_markup += '</div>';
  325. // If type is image AND outer_controls is true: add gallery next and previous controls.
  326. if (self.options.type == 'image' && self.options.outer_controls === true) {
  327. build_markup += self.scope.prev_btn + self.scope.next_btn;
  328. }
  329. // close off modaal-wrapper
  330. build_markup += '</div></div>';
  331. // append ajax modal markup to dom
  332. if ($('#' + self.scope.id + '_overlay').length < 1) {
  333. self.dom.append(build_markup);
  334. }
  335. // if inline, clone content into space
  336. if (self.options.type == 'inline') {
  337. content.appendTo('#' + self.scope.id + ' .modaal-content-container');
  338. }
  339. // Trigger overlay show (which triggers modal show)
  340. self.modaal_overlay('show');
  341. },
  342. // Create Basic Inline Modal
  343. // ----------------------------------------------------------------
  344. create_basic : function() {
  345. var self = this;
  346. var target = $(self.scope.source);
  347. var content = '';
  348. if (target.length) {
  349. content = target.contents().detach();
  350. target.empty();
  351. } else {
  352. content = 'Content could not be loaded. Please check the source and try again.';
  353. }
  354. // now push content into markup
  355. self.build_modal(content);
  356. },
  357. // Create Instagram Modal
  358. // ----------------------------------------------------------------
  359. create_instagram : function() {
  360. var self = this;
  361. var id = self.options.instagram_id;
  362. var content = '';
  363. var error_msg = 'Instagram photo couldn\'t be loaded, please check the embed code and try again.';
  364. self.build_modal('<div class="modaal-content-container' + ( self.options.loading_class != '' ? ' ' + self.options.loading_class : '' ) + '">' + self.options.loading_content + '</div>' );
  365. // ID exists, is not empty null or undefined.
  366. if ( id != '' && id !== null && id !== undefined ) {
  367. // set up oembed url
  368. var ig_url = 'https://api.instagram.com/oembed?url=http://instagr.am/p/' + id + '/';
  369. $.ajax({
  370. url: ig_url,
  371. dataType: "jsonp",
  372. cache: false,
  373. success: function (data) {
  374. // Create temp dom element from which we'll clone into the modaal instance. This is required to bypass the unusual small thumb issue instagram oembed was serving up
  375. self.dom.append('<div id="temp-ig" style="width:0;height:0;overflow:hidden;">' + data.html + '</div>');
  376. // Check if it has loaded once before.
  377. // This is to stop the Embeds.process from throwing and error the first time it's being loaded.
  378. // private_options are individual to a modaal_scope so will not work across multiple scopes when checking if true, only that one item.
  379. if ( self.dom.attr('data-igloaded') ) {
  380. window.instgrm.Embeds.process();
  381. } else {
  382. // first time it's loaded, let's set a new private option to use next time it's opened.
  383. self.dom.attr('data-igloaded', 'true');
  384. }
  385. // now set location for new content
  386. // timeout is required as well to bypass the unusual small thumb issue instagram oembed was serving up
  387. var target = '#' + self.scope.id + ' .modaal-content-container';
  388. if ( $(target).length > 0) {
  389. setTimeout(function() {
  390. $('#temp-ig').contents().clone().appendTo( target );
  391. $('#temp-ig').remove();
  392. }, 1000);
  393. }
  394. },
  395. error: function() {
  396. content = error_msg;
  397. // now set location for new content
  398. var target = $('#' + self.scope.id + ' .modaal-content-container');
  399. if ( target.length > 0) {
  400. target.removeClass( self.options.loading_class ).addClass( self.options.ajax_error_class );
  401. target.html(content);
  402. }
  403. }
  404. });
  405. } else {
  406. content = error_msg;
  407. }
  408. return false;
  409. },
  410. // Fetch Ajax Data
  411. // ----------------------------------------------------------------
  412. fetch_ajax : function(url) {
  413. var self = this;
  414. var content = '';
  415. // If no accessible title, set it to 'Dialog Window'
  416. if ( self.options.accessible_title == null ) {
  417. self.options.accessible_title = 'Dialog Window'
  418. }
  419. if ( self.xhr !== null ){
  420. self.xhr.abort();
  421. self.xhr = null;
  422. }
  423. self.build_modal('<div class="modaal-content-container' + ( self.options.loading_class != '' ? ' ' + self.options.loading_class : '' ) + '">' + self.options.loading_content + '</div>' );
  424. self.xhr = $.ajax(url, {
  425. success: function(data) {
  426. // content fetch is successful so push it into markup
  427. var target = $('#' + self.scope.id).find('.modaal-content-container');
  428. if ( target.length > 0){
  429. target.removeClass( self.options.loading_class );
  430. target.html( data );
  431. self.options.ajax_success.call(self, target);
  432. }
  433. },
  434. error: function( xhr ) {
  435. // There were some errors so return an error message
  436. if ( xhr.statusText == 'abort' ){
  437. return;
  438. }
  439. var target = $('#' + self.scope.id + ' .modaal-content-container');
  440. if ( target.length > 0){
  441. target.removeClass( self.options.loading_class ).addClass( self.options.ajax_error_class );
  442. target.html( 'Content could not be loaded. Please check the source and try again.' );
  443. }
  444. }
  445. });
  446. },
  447. // Create Confirm Modal
  448. // ----------------------------------------------------------------
  449. create_confirm : function() {
  450. var self = this;
  451. var content;
  452. content = '<div class="modaal-content-container">' +
  453. '<h1 id="modaal-title">' + self.options.confirm_title + '</h1>' +
  454. '<div class="modaal-confirm-content">' + self.options.confirm_content + '</div>' +
  455. '<div class="modaal-confirm-wrap">' +
  456. '<button type="button" class="modaal-confirm-btn modaal-ok" aria-label="Confirm">' + self.options.confirm_button_text + '</button>' +
  457. '<button type="button" class="modaal-confirm-btn modaal-cancel" aria-label="Cancel">' + self.options.confirm_cancel_button_text + '</button>' +
  458. '</div>' +
  459. '</div>' +
  460. '</div>';
  461. // now push content into markup
  462. self.build_modal(content);
  463. },
  464. // Create Image/Gallery Modal
  465. // ----------------------------------------------------------------
  466. create_image : function() {
  467. var self = this;
  468. var content;
  469. var modaal_image_markup = '';
  470. var gallery_total;
  471. // If has group attribute
  472. if ( self.$elem.is('[data-group]') || self.$elem.is('[rel]') ) {
  473. // find gallery groups
  474. var use_group = self.$elem.is('[data-group]');
  475. var gallery_group = use_group ? self.$elem.attr('data-group') : self.$elem.attr('rel');
  476. var gallery_group_items = use_group ? $('[data-group="' + gallery_group + '"]') : $('[rel="' + gallery_group + '"]');
  477. // remove any previous active attribute to any in the group
  478. gallery_group_items.removeAttr('data-gallery-active', 'is_active');
  479. // add active attribute to the item clicked
  480. self.$elem.attr('data-gallery-active', 'is_active');
  481. // how many in the grouping are there (-1 to connect with each function starting with 0)
  482. gallery_total = gallery_group_items.length - 1;
  483. // prepare array for gallery data
  484. var gallery = [];
  485. // start preparing markup
  486. modaal_image_markup = '<div class="modaal-gallery-item-wrap">';
  487. // loop each grouping item and push it into our gallery array
  488. gallery_group_items.each(function(i, item) {
  489. // setup default content
  490. var img_src = '';
  491. var img_alt = '';
  492. var img_description = '';
  493. var img_active = false;
  494. var img_src_error = false;
  495. var data_modaal_desc = item.getAttribute('data-modaal-desc');
  496. var data_item_active = item.getAttribute('data-gallery-active');
  497. // if item has inline custom source, use that instead of href. Fall back to href if available.
  498. if ( $(item).attr('data-modaal-content-source') ) {
  499. img_src = $(item).attr('data-modaal-content-source');
  500. } else if ( $(item).attr('href') ) {
  501. img_src = $(item).attr('href');
  502. } else if ( $(item).attr('src') ) {
  503. img_src = $(item).attr('src');
  504. } else {
  505. img_src = 'trigger requires href or data-modaal-content-source attribute';
  506. img_src_error = true;
  507. }
  508. // Does it have a modaal description
  509. if ( data_modaal_desc != '' && data_modaal_desc !== null && data_modaal_desc !== undefined ) {
  510. img_alt = data_modaal_desc;
  511. img_description = '<div class="modaal-gallery-label"><span class="modaal-accessible-hide">Image ' + (i+1) + ' - </span>' + data_modaal_desc + '</div>'
  512. } else {
  513. img_description = '<div class="modaal-gallery-label"><span class="modaal-accessible-hide">Image ' + (i+1) + '</span></div>';
  514. }
  515. // is it the active item
  516. if ( data_item_active ) {
  517. img_active = true
  518. }
  519. // set new object for values we want
  520. var gallery_item = {
  521. 'url': img_src,
  522. 'alt': img_alt,
  523. 'rawdesc': data_modaal_desc,
  524. 'desc': img_description,
  525. 'active': img_active,
  526. 'src_error': img_src_error
  527. };
  528. // push object into gallery array
  529. gallery.push( gallery_item );
  530. });
  531. // now loop through all items in the gallery and build up the markup
  532. for (var i = 0; i < gallery.length; i++) {
  533. // Set default active class, then check if array item active is true and update string for class
  534. var is_active = '';
  535. var aria_label = gallery[i].rawdesc ? 'Image: ' + gallery[i].rawdesc : 'Image ' + i + ' no description';
  536. if ( gallery[i].active ) {
  537. is_active = ' ' + self.private_options.active_class;
  538. }
  539. // if gallery item has source error, output message rather than undefined image
  540. var image_output = gallery[i].src_error ? gallery[i].url : '<img src="' + gallery[i].url + '" alt=" " style="width:100%">';
  541. // for each item build up the markup
  542. modaal_image_markup += '<div class="modaal-gallery-item gallery-item-' + i + is_active + '" aria-label="' + aria_label + '">' +
  543. image_output + gallery[i].desc +
  544. '</div>';
  545. }
  546. // Close off the markup for the gallery
  547. modaal_image_markup += '</div>';
  548. // Add next and previous buttons if outside
  549. if (self.options.outer_controls != true) {
  550. modaal_image_markup += self.scope.prev_btn + self.scope.next_btn;
  551. }
  552. } else {
  553. // This is only a single gallery item so let's grab the necessary values
  554. // define the source, check if content_source option exists, and use that or fall back to href.
  555. var this_img_src;
  556. var img_src_error = false;
  557. if ( self.$elem.attr('data-modaal-content-source') ) {
  558. this_img_src = self.$elem.attr('data-modaal-content-source');
  559. } else if ( self.$elem.attr('href') ) {
  560. this_img_src = self.$elem.attr('href');
  561. } else if ( self.$elem.attr('src') ) {
  562. this_img_src = self.$elem.attr('src');
  563. } else {
  564. this_img_src = 'trigger requires href or data-modaal-content-source attribute';
  565. img_src_error = true;
  566. }
  567. var this_img_alt_txt = '';
  568. var this_img_alt = '';
  569. var aria_label = '';
  570. if ( self.$elem.attr('data-modaal-desc') ) {
  571. aria_label = self.$elem.attr('data-modaal-desc');
  572. this_img_alt_txt = self.$elem.attr('data-modaal-desc');
  573. this_img_alt = '<div class="modaal-gallery-label"><span class="modaal-accessible-hide">Image - </span>' + this_img_alt_txt + '</div>';
  574. } else {
  575. aria_label = "Image with no description";
  576. }
  577. // if image item has source error, output message rather than undefined image
  578. var image_output = img_src_error ? this_img_src : '<img src="' + this_img_src + '" alt=" " style="width:100%">';
  579. // build up the html
  580. modaal_image_markup = '<div class="modaal-gallery-item is_active" aria-label="' + aria_label + '">' +
  581. image_output + this_img_alt +
  582. '</div>';
  583. }
  584. // Update content variable
  585. content = modaal_image_markup;
  586. // now push content into markup
  587. self.build_modal(content);
  588. // setup next & prev buttons
  589. if ( $('.modaal-gallery-item.is_active').is('.gallery-item-0') ) {
  590. $('.modaal-gallery-prev').hide();
  591. }
  592. if ( $('.modaal-gallery-item.is_active').is('.gallery-item-' + gallery_total) ) {
  593. $('.modaal-gallery-next').hide();
  594. }
  595. },
  596. // Gallery Change Image
  597. // ----------------------------------------------------------------
  598. gallery_update : function(direction) {
  599. var self = this;
  600. var this_gallery = $('#' + self.scope.id);
  601. var this_gallery_item = this_gallery.find('.modaal-gallery-item');
  602. var this_gallery_total = this_gallery_item.length - 1;
  603. // if single item, don't proceed
  604. if ( this_gallery_total == 0 ) {
  605. return false;
  606. }
  607. var prev_btn = this_gallery.find('.modaal-gallery-prev'),
  608. next_btn = this_gallery.find('.modaal-gallery-next');
  609. var duration = 250;
  610. var new_img_w = 0,
  611. new_img_h = 0;
  612. // CB: Before image change
  613. var current_item = this_gallery.find( '.modaal-gallery-item.' + self.private_options.active_class ),
  614. incoming_item = ( direction == 'next' ? current_item.next( '.modaal-gallery-item' ) : current_item.prev( '.modaal-gallery-item' ) );
  615. self.options.before_image_change.call(self, current_item, incoming_item);
  616. // stop change if at start of end
  617. if ( direction == 'prev' && this_gallery.find('.gallery-item-0').hasClass('is_active') ) {
  618. return false;
  619. } else if ( direction == 'next' && this_gallery.find('.gallery-item-' + this_gallery_total).hasClass('is_active') ) {
  620. return false;
  621. }
  622. // lock dimensions
  623. current_item.stop().animate({
  624. opacity: 0
  625. }, duration, function(){
  626. // Move to appropriate image
  627. incoming_item.addClass('is_next').css({
  628. 'position': 'absolute',
  629. 'display': 'block',
  630. 'opacity': 0
  631. });
  632. // Collect doc width
  633. var doc_width = $(document).width();
  634. var width_threshold = doc_width > 1140 ? 280 : 50;
  635. // start toggle to 'is_next'
  636. new_img_w = this_gallery.find('.modaal-gallery-item.is_next').width();
  637. new_img_h = this_gallery.find('.modaal-gallery-item.is_next').height();
  638. var new_natural_w = this_gallery.find('.modaal-gallery-item.is_next img').prop('naturalWidth');
  639. var new_natural_h = this_gallery.find('.modaal-gallery-item.is_next img').prop('naturalHeight');
  640. // if new image is wider than doc width
  641. if ( new_natural_w > (doc_width - width_threshold) ) {
  642. // set new width just below doc width
  643. new_img_w = doc_width - width_threshold;
  644. // Set temp widths so we can calulate the correct height;
  645. this_gallery.find('.modaal-gallery-item.is_next').css({ 'width': new_img_w });
  646. this_gallery.find('.modaal-gallery-item.is_next img').css({ 'width': new_img_w });
  647. // Set new height variable
  648. new_img_h = this_gallery.find('.modaal-gallery-item.is_next').find('img').height();
  649. } else {
  650. // new img is not wider than screen, so let's set the new dimensions
  651. new_img_w = new_natural_w;
  652. new_img_h = new_natural_h;
  653. }
  654. // resize gallery region
  655. this_gallery.find('.modaal-gallery-item-wrap').stop().animate({
  656. 'width': new_img_w,
  657. 'height': new_img_h
  658. }, duration, function() {
  659. // hide old active image
  660. current_item.removeClass(self.private_options.active_class + ' ' + self.options.gallery_active_class).removeAttr('style');
  661. current_item.find('img').removeAttr('style');
  662. // show new image
  663. incoming_item.addClass(self.private_options.active_class + ' ' + self.options.gallery_active_class).removeClass('is_next').css('position','');
  664. // animate in new image (now has the normal is_active class
  665. incoming_item.stop().animate({
  666. opacity: 1
  667. }, duration, function(){
  668. $(this).removeAttr('style').css({
  669. 'width': '100%'
  670. });
  671. $(this).find('img').css('width', '100%');
  672. // remove dimension lock
  673. this_gallery.find('.modaal-gallery-item-wrap').removeAttr('style');
  674. // CB: After image change
  675. self.options.after_image_change.call( self, incoming_item );
  676. });
  677. // Focus on the new gallery item
  678. this_gallery.find('.modaal-gallery-item').removeAttr('tabindex');
  679. this_gallery.find('.modaal-gallery-item.' + self.private_options.active_class + '').attr('tabindex', '0').focus();
  680. // hide/show next/prev
  681. if ( this_gallery.find('.modaal-gallery-item.' + self.private_options.active_class).is('.gallery-item-0') ) {
  682. prev_btn.stop().animate({
  683. opacity: 0
  684. }, 150, function(){
  685. $(this).hide();
  686. });
  687. } else {
  688. prev_btn.stop().css({
  689. 'display': 'block',
  690. 'opacity': prev_btn.css('opacity')
  691. }).animate({
  692. opacity: 1
  693. }, 150);
  694. }
  695. if ( this_gallery.find('.modaal-gallery-item.' + self.private_options.active_class).is('.gallery-item-' + this_gallery_total) ) {
  696. next_btn.stop().animate({
  697. opacity: 0
  698. }, 150, function(){
  699. $(this).hide();
  700. });
  701. } else {
  702. next_btn.stop().css({
  703. 'display': 'block',
  704. 'opacity': prev_btn.css('opacity')
  705. }).animate({
  706. opacity: 1
  707. }, 150);
  708. }
  709. });
  710. });
  711. },
  712. // Create Video Modal
  713. // ----------------------------------------------------------------
  714. create_video : function(url) {
  715. var self = this;
  716. var content;
  717. // video markup
  718. content = '<iframe src="' + url + '" class="modaal-video-frame" frameborder="0" allowfullscreen></iframe>';
  719. // now push content into markup
  720. self.build_modal('<div class="modaal-video-container">' + content + '</div>');
  721. },
  722. // Create iFrame Modal
  723. // ----------------------------------------------------------------
  724. create_iframe : function(url) {
  725. var self = this;
  726. var content;
  727. if ( self.options.width !== null || self.options.width !== undefined || self.options.height !== null || self.options.height !== undefined ) {
  728. // video markup
  729. content = '<iframe src="' + url + '" class="modaal-iframe-elem" frameborder="0" allowfullscreen></iframe>';
  730. } else {
  731. content = '<div class="modaal-content-container">Please specify a width and height for your iframe</div>';
  732. }
  733. // now push content into markup
  734. self.build_modal(content);
  735. },
  736. // Open Modaal
  737. // ----------------------------------------------------------------
  738. modaal_open : function() {
  739. var self = this;
  740. var modal_wrapper = $( '#' + self.scope.id );
  741. var animation_type = self.options.animation;
  742. if (animation_type === 'none' ){
  743. modal_wrapper.removeClass('modaal-start_none');
  744. self.options.after_open.call(self, modal_wrapper);
  745. }
  746. // Open with fade
  747. if (animation_type === 'fade') {
  748. modal_wrapper.removeClass('modaal-start_fade');
  749. }
  750. // Open with slide down
  751. if (animation_type === 'slide-down') {
  752. modal_wrapper.removeClass('modaal-start_slide_down');
  753. }
  754. var focusTarget = modal_wrapper;
  755. // Switch focusTarget tabindex (switch from other modal if exists)
  756. $('.modaal-wrapper *[tabindex=0]').removeAttr('tabindex');
  757. if ( self.options.type == 'image' ) {
  758. focusTarget = $('#' + self.scope.id).find('.modaal-gallery-item.' + self.private_options.active_class);
  759. } else if ( modal_wrapper.find('.modaal-iframe-elem').length ) {
  760. focusTarget = modal_wrapper.find('.modaal-iframe-elem');
  761. } else if ( modal_wrapper.find('.modaal-video-wrap').length ) {
  762. focusTarget = modal_wrapper.find('.modaal-video-wrap');
  763. } else {
  764. focusTarget = modal_wrapper.find('.modaal-focus');
  765. }
  766. // now set the focus
  767. focusTarget.attr('tabindex', '0').focus();
  768. // Run after_open
  769. if (animation_type !== 'none') {
  770. // CB: after_open
  771. setTimeout(function() {
  772. self.options.after_open.call(self, modal_wrapper)
  773. }, self.options.after_callback_delay);
  774. }
  775. },
  776. // Close Modal
  777. // ----------------------------------------------------------------
  778. modaal_close : function() {
  779. var self = this;
  780. var modal_wrapper = $( '#' + self.scope.id );
  781. // CB: before_close
  782. self.options.before_close.call(self, modal_wrapper);
  783. if (self.xhr !== null){
  784. self.xhr.abort();
  785. self.xhr = null;
  786. }
  787. // Now we close the modal
  788. if (self.options.animation === 'none' ){
  789. modal_wrapper.addClass('modaal-start_none');
  790. }
  791. // Close with fade
  792. if (self.options.animation === 'fade') {
  793. modal_wrapper.addClass('modaal-start_fade');
  794. }
  795. // Close with slide up (using initial slide down)
  796. if (self.options.animation === 'slide-down') {
  797. modal_wrapper.addClass('modaal-start_slide_down');
  798. }
  799. // CB: after_close and remove
  800. setTimeout(function() {
  801. // clone inline content back to origin place
  802. if (self.options.type == 'inline') {
  803. $('#' + self.scope.id + ' .modaal-content-container').contents().detach().appendTo( self.scope.source )
  804. }
  805. // remove markup from dom
  806. modal_wrapper.remove();
  807. // CB: after_close
  808. self.options.after_close.call(self);
  809. // scope is now closed
  810. self.scope.is_open = false;
  811. }, self.options.after_callback_delay);
  812. // Call overlay hide
  813. self.modaal_overlay('hide');
  814. // Roll back to last focus state before modal open. If was closed programmatically, this might not be set
  815. if (self.lastFocus != null) {
  816. self.lastFocus.focus();
  817. }
  818. },
  819. // Overlay control (accepts action for show or hide)
  820. // ----------------------------------------------------------------
  821. modaal_overlay : function(action) {
  822. var self = this;
  823. if (action == 'show') {
  824. // Modal is open so update scope
  825. self.scope.is_open = true;
  826. // set body to overflow hidden if background_scroll is false
  827. if (! self.options.background_scroll) {
  828. self.dom.addClass('modaal-noscroll');
  829. }
  830. // append modaal overlay
  831. if ($('#' + self.scope.id + '_overlay').length < 1) {
  832. self.dom.append('<div class="modaal-overlay" id="' + self.scope.id + '_overlay"></div>');
  833. }
  834. // now show
  835. $('#' + self.scope.id + '_overlay').css('background', self.options.background).stop().animate({
  836. opacity: self.options.overlay_opacity
  837. }, self.options.animation_speed, function(){
  838. // now open the modal
  839. self.modaal_open();
  840. });
  841. } else if (action == 'hide') {
  842. // now hide the overlay
  843. $('#' + self.scope.id + '_overlay').stop().animate({
  844. opacity: 0
  845. }, self.options.animation_speed, function(){
  846. // remove overlay from dom
  847. $(this).remove();
  848. // remove body overflow lock
  849. self.dom.removeClass('modaal-noscroll');
  850. });
  851. }
  852. },
  853. // Check if is touch
  854. // ----------------------------------------------------------------
  855. is_touch : function() {
  856. return 'ontouchstart' in window || navigator.maxTouchPoints;
  857. }
  858. };
  859. // Define default object to store
  860. var modaal_existing_selectors = [];
  861. // Declare the modaal jQuery method
  862. // ------------------------------------------------------------
  863. $.fn.modaal = function(options) {
  864. return this.each(function (i) {
  865. var existing_modaal = $(this).data('modaal');
  866. if ( existing_modaal ){
  867. // Checking for string value, used for methods
  868. if (typeof(options) == 'string'){
  869. switch (options) {
  870. case 'open':
  871. // create the modal
  872. existing_modaal.create_modaal(existing_modaal);
  873. break;
  874. case 'close':
  875. existing_modaal.modaal_close();
  876. break;
  877. }
  878. }
  879. } else {
  880. // Not a string, so let's setup the modal ready to use
  881. var modaal = Object.create(Modaal);
  882. modaal.init(options, this);
  883. $.data(this, "modaal", modaal);
  884. // push this select into existing selectors array which is referenced during modaal_dom_observer
  885. modaal_existing_selectors.push({
  886. 'element': $(this).attr('class'),
  887. 'options': options
  888. });
  889. }
  890. });
  891. };
  892. // Default options
  893. // ------------------------------------------------------------
  894. $.fn.modaal.options = {
  895. //General
  896. type: 'inline',
  897. content_source: null,
  898. animation: 'fade',
  899. animation_speed: 300,
  900. after_callback_delay: 350,
  901. is_locked: false,
  902. hide_close: false,
  903. background: '#000',
  904. overlay_opacity: '0.8',
  905. overlay_close: true,
  906. accessible_title: 'Dialog Window',
  907. start_open: false,
  908. fullscreen: false,
  909. custom_class: '',
  910. background_scroll: false,
  911. should_open: true,
  912. close_text: 'Close',
  913. close_aria_label: 'Close (Press escape to close)',
  914. width: null,
  915. height: null,
  916. //Events
  917. before_open: function(){},
  918. after_open: function(){},
  919. before_close: function(){},
  920. after_close: function(){},
  921. source: function( element, src ){
  922. return src;
  923. },
  924. //Confirm Modal
  925. confirm_button_text: 'Confirm', // text on confirm button
  926. confirm_cancel_button_text: 'Cancel',
  927. confirm_title: 'Confirm Title', // title for confirm modal
  928. confirm_content: '<p>This is the default confirm dialog content. Replace me through the options</p>', // html for confirm message
  929. confirm_callback: function() {},
  930. confirm_cancel_callback: function() {},
  931. //Gallery Modal
  932. gallery_active_class: 'gallery_active_item',
  933. outer_controls: false,
  934. before_image_change: function( current_item, incoming_item ) {},
  935. after_image_change: function( current_item ) {},
  936. //Ajax Modal
  937. loading_content: modaal_loading_spinner,
  938. loading_class: 'is_loading',
  939. ajax_error_class: 'modaal-error',
  940. ajax_success: function(){},
  941. //Instagram
  942. instagram_id: null
  943. };
  944. // Check and Set Inline Options
  945. // ------------------------------------------------------------
  946. function modaal_inline_options(self) {
  947. // new empty options
  948. var options = {};
  949. var inline_options = false;
  950. // option: type
  951. if ( self.attr('data-modaal-type') ) {
  952. inline_options = true;
  953. options.type = self.attr('data-modaal-type');
  954. }
  955. // option: type
  956. if ( self.attr('data-modaal-content-source') ) {
  957. inline_options = true;
  958. options.content_source = self.attr('data-modaal-content-source');
  959. }
  960. // option: animation
  961. if ( self.attr('data-modaal-animation') ) {
  962. inline_options = true;
  963. options.animation = self.attr('data-modaal-animation');
  964. }
  965. // option: animation_speed
  966. if ( self.attr('data-modaal-animation-speed') ) {
  967. inline_options = true;
  968. options.animation_speed = self.attr('data-modaal-animation-speed');
  969. }
  970. // option: after_callback_delay
  971. if ( self.attr('data-modaal-after-callback-delay') ) {
  972. inline_options = true;
  973. options.after_callback_delay = self.attr('data-modaal-after-callback-delay');
  974. }
  975. // option: is_locked
  976. if ( self.attr('data-modaal-is-locked') ) {
  977. inline_options = true;
  978. options.is_locked = (self.attr('data-modaal-is-locked') === 'true' ? true : false);
  979. }
  980. // option: hide_close
  981. if ( self.attr('data-modaal-hide-close') ) {
  982. inline_options = true;
  983. options.hide_close = (self.attr('data-modaal-hide-close') === 'true' ? true : false);
  984. }
  985. // option: background
  986. if ( self.attr('data-modaal-background') ) {
  987. inline_options = true;
  988. options.background = self.attr('data-modaal-background');
  989. }
  990. // option: overlay_opacity
  991. if ( self.attr('data-modaal-overlay-opacity') ) {
  992. inline_options = true;
  993. options.overlay_opacity = self.attr('data-modaal-overlay-opacity');
  994. }
  995. // option: overlay_close
  996. if ( self.attr('data-modaal-overlay-close') ) {
  997. inline_options = true;
  998. options.overlay_close = (self.attr('data-modaal-overlay-close') === 'false' ? false : true);
  999. }
  1000. // option: accessible_title
  1001. if ( self.attr('data-modaal-accessible-title') ) {
  1002. inline_options = true;
  1003. options.accessible_title = self.attr('data-modaal-accessible-title');
  1004. }
  1005. // option: start_open
  1006. if ( self.attr('data-modaal-start-open') ) {
  1007. inline_options = true;
  1008. options.start_open = (self.attr('data-modaal-start-open') === 'true' ? true : false);
  1009. }
  1010. // option: fullscreen
  1011. if ( self.attr('data-modaal-fullscreen') ) {
  1012. inline_options = true;
  1013. options.fullscreen = (self.attr('data-modaal-fullscreen') === 'true' ? true : false);
  1014. }
  1015. // option: custom_class
  1016. if ( self.attr('data-modaal-custom-class') ) {
  1017. inline_options = true;
  1018. options.custom_class = self.attr('data-modaal-custom-class');
  1019. }
  1020. // option: close_text
  1021. if ( self.attr('data-modaal-close-text') ) {
  1022. inline_options = true;
  1023. options.close_text = self.attr('data-modaal-close-text');
  1024. }
  1025. // option: close_aria_label
  1026. if ( self.attr('data-modaal-close-aria-label') ) {
  1027. inline_options = true;
  1028. options.close_aria_label = self.attr('data-modaal-close-aria-label');
  1029. }
  1030. // option: background_scroll
  1031. if ( self.attr('data-modaal-background-scroll') ) {
  1032. inline_options = true;
  1033. options.background_scroll = (self.attr('data-modaal-background-scroll') === 'true' ? true : false);
  1034. }
  1035. // option: width
  1036. if ( self.attr('data-modaal-width') ) {
  1037. inline_options = true;
  1038. options.width = parseInt( self.attr('data-modaal-width') );
  1039. }
  1040. // option: height
  1041. if ( self.attr('data-modaal-height') ) {
  1042. inline_options = true;
  1043. options.height = parseInt( self.attr('data-modaal-height') );
  1044. }
  1045. // option: confirm_button_text
  1046. if ( self.attr('data-modaal-confirm-button-text') ) {
  1047. inline_options = true;
  1048. options.confirm_button_text = self.attr('data-modaal-confirm-button-text');
  1049. }
  1050. // option: confirm_cancel_button_text
  1051. if ( self.attr('data-modaal-confirm-cancel-button-text') ) {
  1052. inline_options = true;
  1053. options.confirm_cancel_button_text = self.attr('data-modaal-confirm-cancel-button-text');
  1054. }
  1055. // option: confirm_title
  1056. if ( self.attr('data-modaal-confirm-title') ) {
  1057. inline_options = true;
  1058. options.confirm_title = self.attr('data-modaal-confirm-title');
  1059. }
  1060. // option: confirm_content
  1061. if ( self.attr('data-modaal-confirm-content') ) {
  1062. inline_options = true;
  1063. options.confirm_content = self.attr('data-modaal-confirm-content');
  1064. }
  1065. // option: gallery_active_class
  1066. if ( self.attr('data-modaal-gallery-active-class') ) {
  1067. inline_options = true;
  1068. options.gallery_active_class = self.attr('data-modaal-gallery-active-class');
  1069. }
  1070. // option: loading_content
  1071. if ( self.attr('data-modaal-loading-content') ) {
  1072. inline_options = true;
  1073. options.loading_content = self.attr('data-modaal-loading-content');
  1074. }
  1075. // option: loading_class
  1076. if ( self.attr('data-modaal-loading-class') ) {
  1077. inline_options = true;
  1078. options.loading_class = self.attr('data-modaal-loading-class');
  1079. }
  1080. // option: ajax_error_class
  1081. if ( self.attr('data-modaal-ajax-error-class') ) {
  1082. inline_options = true;
  1083. options.ajax_error_class = self.attr('data-modaal-ajax-error-class');
  1084. }
  1085. // option: start_open
  1086. if ( self.attr('data-modaal-instagram-id') ) {
  1087. inline_options = true;
  1088. options.instagram_id = self.attr('data-modaal-instagram-id');
  1089. }
  1090. // now set it up for the trigger, but only if inline_options is true
  1091. if ( inline_options ) {
  1092. self.modaal(options);
  1093. }
  1094. };
  1095. // On body load (or now, if already loaded), init any modaals defined inline
  1096. // Ensure this is done after $.fn.modaal and default options are declared
  1097. // ----------------------------------------------------------------
  1098. $(function(){
  1099. var single_modaal = $('.modaal');
  1100. // Check for existing modaal elements
  1101. if ( single_modaal.length ) {
  1102. single_modaal.each(function() {
  1103. var self = $(this);
  1104. modaal_inline_options(self);
  1105. });
  1106. }
  1107. // Obvserve DOM mutations for newly added triggers
  1108. var modaal_dom_observer = new MutationObserver(function(mutations) {
  1109. mutations.forEach(function(mutation) {
  1110. if (mutation.addedNodes && mutation.addedNodes.length > 0) {
  1111. // element added to DOM
  1112. var findElement = [].some.call(mutation.addedNodes, function(el) {
  1113. var elm = $(el);
  1114. if ( elm.is('a') || elm.is('button') ) {
  1115. if ( elm.hasClass('modaal') ) {
  1116. // is inline Modaal, initialise options
  1117. modaal_inline_options(elm);
  1118. } else {
  1119. // is not inline modaal. Check for existing selector
  1120. modaal_existing_selectors.forEach(function(modaalSelector) {
  1121. if ( modaalSelector.element == elm.attr('class') ) {
  1122. $(elm).modaal( modaalSelector.options );
  1123. return false;
  1124. }
  1125. });
  1126. }
  1127. }
  1128. });
  1129. }
  1130. });
  1131. });
  1132. var observer_config = {
  1133. subtree: true,
  1134. attributes: true,
  1135. childList: true,
  1136. characterData: true
  1137. };
  1138. // pass in the target node, as well as the observer options
  1139. setTimeout(function() {
  1140. modaal_dom_observer.observe(document.body, observer_config);
  1141. }, 500);
  1142. });
  1143. } ( jQuery, window, document ) );