window.csrfToken = 'VXFmz9VYCh'; function buildWidget(widgetType, args) { var constructor = window.widgets[widgetType.toLowerCase()]; function F() { return constructor.apply(this, args); } F.prototype = constructor.prototype; return new F(); } function widget(elem) { var $widgetElem = $(elem); while (!$widgetElem.is('[data-widget-id],[data-widget-non-interactive-start]')) { $widgetElem = $widgetElem.parent(); if ($widgetElem.length === 0) { return null; // No widget found } } var widgetId = $widgetElem.attr('data-widget-id'); var widgetType = $widgetElem.attr('data-widget-type'); var widgetInstance = buildWidget(widgetType, [widgetId, $widgetElem]); var widgetBaseFunctionality = { id: widgetId, type: widgetType, element: $widgetElem, call: function(method, args, callback, cacheClientSide) { var widget = this; var url = '/widgetResources.axd?widgetCall=' + widgetId; if (!cacheClientSide){ url += '&rnd=' + Math.random(); } $.ajax({ url: window.location.protocol + '//' + window.location.hostname + ':' + window.location.port + url, type: "POST", data: 'token=' + window.csrfToken + '&method=' + method + '&pageData=' + encodeURIComponent(JSON.stringify(getPageData($widgetElem))) + '&data=' + encodeURIComponent(JSON.stringify(args)), success: function(data,status,xhr) { callback(widget,data,status,xhr); }, error: function(xhr,status,err) { callback(widget,err,status,xhr); } }); } }; return $.extend(widgetInstance, widgetBaseFunctionality); }function getPageData($elem){ while($elem.length){ if ($elem.data('pageData')){ return $elem.data('pageData'); } $elem = $elem.parent(); } } //emailform if (!window.widgets) { window.widgets = {}; } window.widgets.emailform = function (args) { return { submitForm: function () { if (typeof (validateChildNodes) != 'undefined') { // This might not be used so check if present if (!validateChildNodes(this.element)) { return; // Invalid } } var data = {}; var $questions = this.element.find(':input[id*=Question]'); // Even though "none" questions dont have any inputs we still need to iterate through them or i will be wrong for (var i = 0; i < $questions.length; i++) { var $question = $($questions[i]); if (typeof ($question.length && $question[0].checkValidity) == 'function') { if (!$question[0].checkValidity()) { $question.css({ outline: 'solid 2px #f00' }).addClass('invalid'); $question.blur(function () { $(this).css({ outline: 'none' }).removeClass('invalid'); }); $question[0].focus(); return; } } if ($question.is(':checkbox,:radio')) { data[$question.attr('data')] = $question.is(':checked'); } else { data[$question.attr('name')] = $question.val(); } } this.call('submitForm', data, this.gotResult); }, gotResult: function (widget, data, status) { if (status != 'success') { alert('An error occurred please try again.\n'); } else { widget.element.empty(); widget.element.append($('

').text(data.result)); } } }; }