538 var args = Array.prototype.slice.call(arguments, 2); |
538 var args = Array.prototype.slice.call(arguments, 2); |
539 return func.apply(context, args); |
539 return func.apply(context, args); |
540 } |
540 } |
541 }; |
541 }; |
542 |
542 |
|
543 /** |
|
544 * Check to know if given element is still present in DOM |
|
545 */ |
|
546 MyAMS.isInDOM = function(element) { |
|
547 element = $(element); |
|
548 if (!element.exists()) { |
|
549 return false; |
|
550 } |
|
551 return globals.document.contains(element[0]); |
|
552 }; |
543 |
553 |
544 /** |
554 /** |
545 * Get script or CSS file using browser cache |
555 * Get script or CSS file using browser cache |
546 * Script or CSS URLs can include variable names, given between braces, as in |
556 * Script or CSS URLs can include variable names, given between braces, as in |
547 * {MyAMS.baseURL} |
557 * {MyAMS.baseURL} |
2498 }); |
2508 }); |
2499 |
2509 |
2500 // Inner plug-in loader function |
2510 // Inner plug-in loader function |
2501 var plugin; |
2511 var plugin; |
2502 |
2512 |
2503 function _loadPlugin() { |
2513 function _loadPlugin(reload) { |
2504 var index; |
2514 var index; |
2505 var callbacks = plugin.callbacks, |
2515 var callbacks = plugin.callbacks, |
2506 callback; |
2516 callback; |
2507 if (callbacks && callbacks.length) { |
2517 if (callbacks && callbacks.length) { |
2508 for (index=0; index < callbacks.length; index++) { |
2518 for (index=0; index < callbacks.length; index++) { |
2520 } else { |
2530 } else { |
2521 if (plugin.register !== false) { |
2531 if (plugin.register !== false) { |
2522 ams.plugins.enabled[name] = null; |
2532 ams.plugins.enabled[name] = null; |
2523 } |
2533 } |
2524 } |
2534 } |
2525 // If running in async mode, registered plug-ins are run |
2535 // If running in async mode, newly registered plug-ins are run |
2526 // before callback is called so we call plug-in manually |
2536 // before callback is called so we call plug-in manually |
2527 if (callbacks && callbacks.length && (plugin.async !== false)) { |
2537 if ((reload !== true) && callbacks && callbacks.length && (plugin.async !== false)) { |
2528 for (index=0; index < callbacks.length; index++) { |
2538 for (index=0; index < callbacks.length; index++) { |
2529 callback = callbacks[index]; |
2539 callback = callbacks[index]; |
2530 ams.executeFunctionByName(callback.callback, element, callback.context); |
2540 ams.executeFunctionByName(callback.callback, element, callback.context); |
2531 } |
2541 } |
2532 } |
2542 } |
2533 } |
2543 } |
2534 |
2544 |
|
2545 function _checkPluginContext() { |
|
2546 // Update context for an already loaded plug-in |
|
2547 var enabled = ams.plugins.enabled[name]; |
|
2548 // Clean all plug-in contexts |
|
2549 for (index=0; index < enabled.length; index++) { |
|
2550 var callback = enabled[index]; |
|
2551 if (callback && callback.context && !ams.isInDOM(callback.context)) { |
|
2552 enabled[index] = null; |
|
2553 } |
|
2554 } |
|
2555 } |
|
2556 |
2535 for (name in plugins) { |
2557 for (name in plugins) { |
|
2558 plugin = plugins[name]; |
2536 if (ams.plugins.enabled[name] === undefined) { |
2559 if (ams.plugins.enabled[name] === undefined) { |
2537 plugin = plugins[name]; |
|
2538 ams.getScript(plugin.src, _loadPlugin, { |
2560 ams.getScript(plugin.src, _loadPlugin, { |
2539 async: plugin.async === undefined ? true : plugin.async |
2561 async: plugin.async === undefined ? true : plugin.async |
2540 }); |
2562 }); |
|
2563 } else { |
|
2564 _checkPluginContext(); |
|
2565 _loadPlugin(true); |
2541 } |
2566 } |
2542 } |
2567 } |
2543 |
2568 |
2544 // Run all enabled plug-ins |
2569 // Run all enabled plug-ins |
2545 for (var index in ams.plugins.enabled) { |
2570 for (var index in ams.plugins.enabled) { |
4922 }); |
4949 }); |
4923 |
4950 |
4924 // Initialize custom change handlers |
4951 // Initialize custom change handlers |
4925 $(document).on('change', '[data-ams-change-handler]', function(e) { |
4952 $(document).on('change', '[data-ams-change-handler]', function(e) { |
4926 var source = $(this); |
4953 var source = $(this); |
|
4954 // Disable change handlers for readonly inputs |
|
4955 // These change handlers are activated by IE!!! |
|
4956 if (source.prop('readonly')) { |
|
4957 return; |
|
4958 } |
4927 var handlers = source.data('ams-disabled-handlers'); |
4959 var handlers = source.data('ams-disabled-handlers'); |
4928 if ((handlers === true) || (handlers === 'change') || (handlers === 'all')) { |
4960 if ((handlers === true) || (handlers === 'change') || (handlers === 'all')) { |
4929 return; |
4961 return; |
4930 } |
4962 } |
4931 var data = source.data(); |
4963 var data = source.data(); |