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B,YAAM,CAAC,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;AACjC,YAAM,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;AAC3B,UAAI,KAAK,EAAE;AACT,cAAM,CAAC,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;AAClC,cAAM,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;OAC3B;AACD,YAAM,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;KACpC;GACF,CAAC;CAEH,CAAA,CAAC,MAAM,EAAE,MAAM,CAAC,CAAE","file":"jquery.data-remote.js","sourcesContent":["/**\n * jQuery Data Remote Plugin\n * http://github.com/codonnell822/jquery-dataremote\n * Copyright 2014-2015, Chris O'Donnell\n *\n * jQuery plugin that simplifies the common task of making api/remote requests\n * and injecting the response to the page. Optionally leverages templating\n * engines (handlebars). Inpired by ruby on rails' unobtrusive scripting adapter\n * for jQuery (https://github.com/rails/jquery-ujs).\n */\n;(function($, window, undefined) {\n \"use strict\";\n\n $.fn.dataRemote = function(opts = {}) {\n // Default Settings\n var defaults = {\n url: null, // request url\n data: {}, // request data\n debug: false,\n eventType: 'load', // js event type to fire data request on (load, click, submit, mouseover, custom, etc.)\n dataType: 'json', // data type that's expected in response from your request\n type: 'GET', // type of request (currently only supports GET)\n target: '', // selector of the element where you want your response injected\n handlebars: false, // use handlebars to render the response?\n template: '', // handlebar template selector. by default it will look inside target\n placement: 'html', // where to inject response relative to target (jquery DOM insertion methods )\n loaderImg: null, // target selector for data response\n oneAndDone: true, // whether to remove the event binding after the first time running\n success: successCallback, // gets passed 3 parameters ($target, options, response)\n error: errorCallback, // gets passed 4 parameters ($target, options, response, error)\n complete: function($target) {}, // callback fires after the request is made (on success OR error)\n before: function($target) {} // callback fires directly before the request is made\n };\n\n // Extend our default options with those provided when instantiating\n var options = $.extend({}, defaults, opts);\n\n /**\n * Default success callback for ajax requests.\n *\n * Handles hiding of loader image, debugging (if option is set),\n * and handling the ajax requests' response (levering handlebars if option\n * is set or handlebars template is found inside the target element).\n *\n * @param {jQuery} $target jquery object containing the target element for the ajax response\n * @param {object} options plugin options set during instantiation\n * @param {object} response data response from the ajax request\n */\n function successCallback($target, options, response) {\n var source;\n var template;\n var html;\n var $template;\n\n $target.find('.loader-image').hide();\n\n if (options.debug) {\n $.fn.dataRemote.debug($target, response);\n }\n\n // Use handlebars if the option is set to true *or* if a handlebars template is found\n if (options.handlebars !== false || $target.find('[type=\"text/x-handlebars-template\"]').length) {\n $template = options.template ? $(options.template) : $target.find('[type=\"text/x-handlebars-template\"]');\n source = $template.html();\n template = Handlebars.compile(source);\n html = template(response);\n } else {\n html = response;\n }\n\n // use proper jQuery method based on append option\n // if append == true, append results to target element,\n // or else replace inner html with results\n var validPlacements = ['html', 'append', 'prepend', 'after', 'before'];\n var placementIsValid = validPlacements.indexOf(options.placement) !== -1;\n if (!placementIsValid) {\n return;\n }\n $target[options.placement](html);\n }\n\n /**\n * Default error callback for ajax requests\n *\n * Hides the loader image, triggers debugging if it's turned on.\n *\n * @param {jQuery} $target jquery object containing the target element for the ajax response\n * @param {object} options plugin options set during instantiation\n * @param {object} response data response from the ajax request\n * @param {string} error textual portion of the HTTP status, i.e. \"Not Found\" or \"Internal Server Error.\"\n */\n function errorCallback($target, options, response, error) {\n $target.find('.loader-image').hide();\n\n if (options.debug) {\n $.fn.dataRemote.debug($target, response, error);\n }\n }\n\n /**\n * Private helper method for making the ajax request\n *\n * @param {object} url request url\n * @param {object} settings additional settings for the request\n * {\n * @param {jQuery} element jQuery object containing the current data remote element\n * @param {object} options data remote plugin options for current data remote element\n * @param {jQuery} $target jQuery object containing the target element to inject response\n * }\n * @return {void}\n */\n function fetch(url, settings) {\n var $element = settings.element;\n var $target = settings.target;\n var options = settings.options;\n\n // display loader image while retrieving content\n if (options.loaderImg) {\n $target.prepend(String() +\n '
' +\n '\"Loading...\"' +\n '
'\n );\n }\n\n // make the ajax request. Trigger the callbacks using $element as the\n // context, making the value of `this` for the callbacks the $element\n $.ajax({\n url: url,\n data: options.data,\n type: options.type,\n dataType: options.dataType,\n cache: true,\n success: function(response) {\n options.success.call($element, $target, options, response);\n options.complete.call($element, $target);\n },\n error: function(response, status, error) {\n options.error.call($element, $target, options, response, error);\n options.complete.call($element, $target);\n }\n });\n }\n\n return this.each(function(idx, element) {\n var $element = $(element);\n\n // Create a local copy of the options for each element. This will allow each\n // individual element to override options from its' data attributes.\n var _options = $.extend({}, options);\n _options.dataType = $element.data('response-type') || options.dataType;\n _options.eventType = $element.data('event-type') || options.eventType;\n _options.type = $element.data('type') || options.type;\n _options.url = $element.data('url') || options.url;\n _options.data = $element.data('data') ? $element.data('data') : options.data;\n _options.template = $element.data('template') || options.template;\n _options.placement = $element.data('response-placement') || options.placement;\n _options.target = $element.data('target') || options.target;\n _options.debug = element.hasAttribute('data-debug') ? $element.data('debug') : options.debug;\n _options.oneAndDone = element.hasAttribute('data-one-and-done') ? $element.data('one-and-done') : options.oneAndDone;\n _options.handlebars = element.hasAttribute('data-handlebars') ? $element.data('handlebars') : options.handlebars;\n\n // if no target selector is given, default to actual element\n var $target = _options.target ? $(_options.target) : $element;\n\n // if event type is 'load', execute the request immediately otherwise,\n // execute ajax request on specified type (click, submit, mouseover, etc.)\n if (_options.eventType === 'load') {\n _options.before.call($element, $target);\n\n // execute ajax request immediately\n fetch(_options.url, {\n element: $element,\n target: $target,\n options: _options,\n });\n } else {\n // use proper jQuery method based on oneAndDone option\n var method = _options.oneAndDone ? 'one' : 'on';\n\n // bind to specific event type\n $element[method](_options.eventType, function(evt) {\n evt.preventDefault();\n\n // if you're watching on keyup or change events, let's assume you want to\n // send the value of the element as a query parameter.\n // Think autosuggest search boxes.\n // \n if (['keyup', 'change'].indexOf(evt.type) !== -1) {\n _options.data[this.name] = this.value;\n }\n\n // execute before request callback\n _options.before.call($element, $target);\n\n fetch(_options.url, {\n element: $element,\n target: $target,\n options: _options,\n });\n });\n } // end if else (_options.eventType)\n }); // end this.each\n }; // end $.fn.dataRemote\n\n /**\n * Helper function for debugging\n */\n $.fn.dataRemote.debug = function(element, output, error) {\n if (window.console && window.console.log) {\n window.console.log('Element: ');\n window.console.log(element);\n window.console.log('Response: ');\n window.console.log(output);\n if (error) {\n window.console.log(' -> Error: ');\n window.console.log(error);\n }\n window.console.log('------------');\n }\n };\n\n}(jQuery, window));\n"],"sourceRoot":"/source/"}