/**
* File: jquery.awe-map.ts
* Description: Create jquery plugin init for google map element
* Author: DuyNg
*/
///
var AweMapPlugin = (function () {
function AweMapPlugin(el, options) {
this.markers = [];
if (
window.google === undefined ||
window.google.maps === undefined ||
window.google.maps.Map === undefined
)
throw Error("You must load google map api before use this plugin");
this.el = el;
this.options = jQuery.extend(
true,
{},
AweMapPlugin.defaultOptions,
options
);
this.initialize();
}
AweMapPlugin.prototype.initialize = function () {
// set element height
jQuery(this.el).css("width", "100%").height(this.options.height);
// init map
var options = jQuery.extend(true, {}, this.options);
delete options.height;
delete options.markers;
options.center = AweMapPlugin.parsePosition(options.center);
// wait to el is visible
var _self = this,
wait;
wait = setInterval(function () {
if (jQuery(_self.el).is(":visible")) {
clearInterval(wait);
_self.map = new window.google.maps.Map(_self.el, options);
// init markers
_self.initMarkers();
}
}, 100);
};
/**
* add markers to map
*/
AweMapPlugin.prototype.initMarkers = function () {
var _self = this,
options = this.options;
if (options.markers && options.markers.enable) {
this.markers = [];
if (
jQuery.isArray(options.markers.data) &&
options.markers.data.length > 0
) {
jQuery.each(options.markers.data, function (index, marker) {
marker.index = index + 1;
_self.addMarker(marker);
});
}
}
};
/**
* add new marker to map
* @param data
* @param index
*/
AweMapPlugin.prototype.addMarker = function (data, index) {
if (typeof data === "object" && data.position !== undefined) {
var position = AweMapPlugin.parsePosition(data.position);
if (position) {
var markerOptions = {
position: position,
title: data.title,
zIndex: data.index,
map: this.map,
};
if (data.icon && data.icon.fid !== -1) {
markerOptions.icon = { url: data.icon.url };
}
if (data.animation !== "none") {
markerOptions.animation =
window.google.maps.Animation[data.animation];
}
var marker_1 = new window.google.maps.Marker(markerOptions);
if (data.animation === "BOUNCE") {
marker_1.addListener("click", function () {
marker_1.setAnimation(null);
});
}
if (data.description) {
var _self_1 = this,
isOpen_1 = false,
infoWindow_1 = new window.google.maps.InfoWindow({
content:
'
"));
return (c.inlineElement = f), f;
}
return b.updateStatus("ready"), b._parseMarkup(d, {}, c), d;
},
},
});
var H,
I = "ajax",
J = function () {
H && a(document.body).removeClass(H);
},
K = function () {
J(), b.req && b.req.abort();
};
a.magnificPopup.registerModule(I, {
options: {
settings: null,
cursor: "mfp-ajax-cur",
tError: '
The content could not be loaded.',
},
proto: {
initAjax: function () {
b.types.push(I),
(H = b.st.ajax.cursor),
w(h + "." + I, K),
w("BeforeChange." + I, K);
},
getAjax: function (c) {
H && a(document.body).addClass(H), b.updateStatus("loading");
var d = a.extend(
{
url: c.src,
success: function (d, e, f) {
var g = { data: d, xhr: f };
y("ParseAjax", g),
b.appendContent(a(g.data), I),
(c.finished = !0),
J(),
b._setFocus(),
setTimeout(function () {
b.wrap.addClass(q);
}, 16),
b.updateStatus("ready"),
y("AjaxContentAdded");
},
error: function () {
J(),
(c.finished = c.loadError = !0),
b.updateStatus(
"error",
b.st.ajax.tError.replace("%url%", c.src)
);
},
},
b.st.ajax.settings
);
return (b.req = a.ajax(d)), "";
},
},
});
var L,
M = function (c) {
if (c.data && void 0 !== c.data.title) return c.data.title;
var d = b.st.image.titleSrc;
if (d) {
if (a.isFunction(d)) return d.call(b, c);
if (c.el) return c.el.attr(d) || "";
}
return "";
};
a.magnificPopup.registerModule("image", {
options: {
markup:
'
',
cursor: "mfp-zoom-out-cur",
titleSrc: "title",
verticalFit: !0,
tError: '
The image could not be loaded.',
},
proto: {
initImage: function () {
var c = b.st.image,
d = ".image";
b.types.push("image"),
w(m + d, function () {
"image" === b.currItem.type &&
c.cursor &&
a(document.body).addClass(c.cursor);
}),
w(h + d, function () {
c.cursor && a(document.body).removeClass(c.cursor),
v.off("resize" + p);
}),
w("Resize" + d, b.resizeImage),
b.isLowIE && w("AfterChange", b.resizeImage);
},
resizeImage: function () {
var a = b.currItem;
if (a && a.img && b.st.image.verticalFit) {
var c = 0;
b.isLowIE &&
(c =
parseInt(a.img.css("padding-top"), 10) +
parseInt(a.img.css("padding-bottom"), 10)),
a.img.css("max-height", b.wH - c);
}
},
_onImageHasSize: function (a) {
a.img &&
((a.hasSize = !0),
L && clearInterval(L),
(a.isCheckingImgSize = !1),
y("ImageHasSize", a),
a.imgHidden &&
(b.content && b.content.removeClass("mfp-loading"),
(a.imgHidden = !1)));
},
findImageSize: function (a) {
var c = 0,
d = a.img[0],
e = function (f) {
L && clearInterval(L),
(L = setInterval(function () {
return d.naturalWidth > 0
? void b._onImageHasSize(a)
: (c > 200 && clearInterval(L),
c++,
void (3 === c
? e(10)
: 40 === c
? e(50)
: 100 === c && e(500)));
}, f));
};
e(1);
},
getImage: function (c, d) {
var e = 0,
f = function () {
c &&
(c.img[0].complete
? (c.img.off(".mfploader"),
c === b.currItem &&
(b._onImageHasSize(c), b.updateStatus("ready")),
(c.hasSize = !0),
(c.loaded = !0),
y("ImageLoadComplete"))
: (e++, 200 > e ? setTimeout(f, 100) : g()));
},
g = function () {
c &&
(c.img.off(".mfploader"),
c === b.currItem &&
(b._onImageHasSize(c),
b.updateStatus("error", h.tError.replace("%url%", c.src))),
(c.hasSize = !0),
(c.loaded = !0),
(c.loadError = !0));
},
h = b.st.image,
i = d.find(".mfp-img");
if (i.length) {
var j = document.createElement("img");
(j.className = "mfp-img"),
c.el &&
c.el.find("img").length &&
(j.alt = c.el.find("img").attr("alt")),
(c.img = a(j).on("load.mfploader", f).on("error.mfploader", g)),
(j.src = c.src),
i.is("img") && (c.img = c.img.clone()),
(j = c.img[0]),
j.naturalWidth > 0 ? (c.hasSize = !0) : j.width || (c.hasSize = !1);
}
return (
b._parseMarkup(d, { title: M(c), img_replaceWith: c.img }, c),
b.resizeImage(),
c.hasSize
? (L && clearInterval(L),
c.loadError
? (d.addClass("mfp-loading"),
b.updateStatus("error", h.tError.replace("%url%", c.src)))
: (d.removeClass("mfp-loading"), b.updateStatus("ready")),
d)
: (b.updateStatus("loading"),
(c.loading = !0),
c.hasSize ||
((c.imgHidden = !0),
d.addClass("mfp-loading"),
b.findImageSize(c)),
d)
);
},
},
});
var N,
O = function () {
return (
void 0 === N &&
(N = void 0 !== document.createElement("p").style.MozTransform),
N
);
};
a.magnificPopup.registerModule("zoom", {
options: {
enabled: !1,
easing: "ease-in-out",
duration: 300,
opener: function (a) {
return a.is("img") ? a : a.find("img");
},
},
proto: {
initZoom: function () {
var a,
c = b.st.zoom,
d = ".zoom";
if (c.enabled && b.supportsTransition) {
var e,
f,
g = c.duration,
j = function (a) {
var b = a
.clone()
.removeAttr("style")
.removeAttr("class")
.addClass("mfp-animated-image"),
d = "all " + c.duration / 1e3 + "s " + c.easing,
e = {
position: "fixed",
zIndex: 9999,
left: 0,
top: 0,
"-webkit-backface-visibility": "hidden",
},
f = "transition";
return (
(e["-webkit-" + f] = e["-moz-" + f] = e["-o-" + f] = e[f] = d),
b.css(e),
b
);
},
k = function () {
b.content.css("visibility", "visible");
};
w("BuildControls" + d, function () {
if (b._allowZoom()) {
if (
(clearTimeout(e),
b.content.css("visibility", "hidden"),
(a = b._getItemToZoom()),
!a)
)
return void k();
(f = j(a)),
f.css(b._getOffset()),
b.wrap.append(f),
(e = setTimeout(function () {
f.css(b._getOffset(!0)),
(e = setTimeout(function () {
k(),
setTimeout(function () {
f.remove(), (a = f = null), y("ZoomAnimationEnded");
}, 16);
}, g));
}, 16));
}
}),
w(i + d, function () {
if (b._allowZoom()) {
if ((clearTimeout(e), (b.st.removalDelay = g), !a)) {
if (((a = b._getItemToZoom()), !a)) return;
f = j(a);
}
f.css(b._getOffset(!0)),
b.wrap.append(f),
b.content.css("visibility", "hidden"),
setTimeout(function () {
f.css(b._getOffset());
}, 16);
}
}),
w(h + d, function () {
b._allowZoom() && (k(), f && f.remove(), (a = null));
});
}
},
_allowZoom: function () {
return "image" === b.currItem.type;
},
_getItemToZoom: function () {
return b.currItem.hasSize ? b.currItem.img : !1;
},
_getOffset: function (c) {
var d;
d = c ? b.currItem.img : b.st.zoom.opener(b.currItem.el || b.currItem);
var e = d.offset(),
f = parseInt(d.css("padding-top"), 10),
g = parseInt(d.css("padding-bottom"), 10);
e.top -= a(window).scrollTop() - f;
var h = {
width: d.width(),
height: (u ? d.innerHeight() : d[0].offsetHeight) - g - f,
};
return (
O()
? (h["-moz-transform"] = h.transform =
"translate(" + e.left + "px," + e.top + "px)")
: ((h.left = e.left), (h.top = e.top)),
h
);
},
},
});
var P = "iframe",
Q = "//about:blank",
R = function (a) {
if (b.currTemplate[P]) {
var c = b.currTemplate[P].find("iframe");
c.length &&
(a || (c[0].src = Q),
b.isIE8 && c.css("display", a ? "block" : "none"));
}
};
a.magnificPopup.registerModule(P, {
options: {
markup:
'
',
srcAction: "iframe_src",
patterns: {
youtube: {
index: "youtube.com",
id: "v=",
src: "//www.youtube.com/embed/%id%?autoplay=1",
},
vimeo: {
index: "vimeo.com/",
id: "/",
src: "//player.vimeo.com/video/%id%?autoplay=1",
},
gmaps: { index: "//maps.google.", src: "%id%&output=embed" },
},
},
proto: {
initIframe: function () {
b.types.push(P),
w("BeforeChange", function (a, b, c) {
b !== c && (b === P ? R() : c === P && R(!0));
}),
w(h + "." + P, function () {
R();
});
},
getIframe: function (c, d) {
var e = c.src,
f = b.st.iframe;
a.each(f.patterns, function () {
return e.indexOf(this.index) > -1
? (this.id &&
(e =
"string" == typeof this.id
? e.substr(
e.lastIndexOf(this.id) + this.id.length,
e.length
)
: this.id.call(this, e)),
(e = this.src.replace("%id%", e)),
!1)
: void 0;
});
var g = {};
return (
f.srcAction && (g[f.srcAction] = e),
b._parseMarkup(d, g, c),
b.updateStatus("ready"),
d
);
},
},
});
var S = function (a) {
var c = b.items.length;
return a > c - 1 ? a - c : 0 > a ? c + a : a;
},
T = function (a, b, c) {
return a.replace(/%curr%/gi, b + 1).replace(/%total%/gi, c);
};
a.magnificPopup.registerModule("gallery", {
options: {
enabled: !1,
arrowMarkup:
'
',
preload: [0, 2],
navigateByImgClick: !0,
arrows: !0,
tPrev: "Previous (Left arrow key)",
tNext: "Next (Right arrow key)",
tCounter: "%curr% of %total%",
},
proto: {
initGallery: function () {
var c = b.st.gallery,
e = ".mfp-gallery";
return (
(b.direction = !0),
c && c.enabled
? ((f += " mfp-gallery"),
w(m + e, function () {
c.navigateByImgClick &&
b.wrap.on("click" + e, ".mfp-img", function () {
return b.items.length > 1 ? (b.next(), !1) : void 0;
}),
d.on("keydown" + e, function (a) {
37 === a.keyCode ? b.prev() : 39 === a.keyCode && b.next();
});
}),
w("UpdateStatus" + e, function (a, c) {
c.text &&
(c.text = T(c.text, b.currItem.index, b.items.length));
}),
w(l + e, function (a, d, e, f) {
var g = b.items.length;
e.counter = g > 1 ? T(c.tCounter, f.index, g) : "";
}),
w("BuildControls" + e, function () {
if (b.items.length > 1 && c.arrows && !b.arrowLeft) {
var d = c.arrowMarkup,
e = (b.arrowLeft = a(
d.replace(/%title%/gi, c.tPrev).replace(/%dir%/gi, "left")
).addClass(s)),
f = (b.arrowRight = a(
d
.replace(/%title%/gi, c.tNext)
.replace(/%dir%/gi, "right")
).addClass(s));
e.click(function () {
b.prev();
}),
f.click(function () {
b.next();
}),
b.container.append(e.add(f));
}
}),
w(n + e, function () {
b._preloadTimeout && clearTimeout(b._preloadTimeout),
(b._preloadTimeout = setTimeout(function () {
b.preloadNearbyImages(), (b._preloadTimeout = null);
}, 16));
}),
void w(h + e, function () {
d.off(e),
b.wrap.off("click" + e),
(b.arrowRight = b.arrowLeft = null);
}))
: !1
);
},
next: function () {
(b.direction = !0), (b.index = S(b.index + 1)), b.updateItemHTML();
},
prev: function () {
(b.direction = !1), (b.index = S(b.index - 1)), b.updateItemHTML();
},
goTo: function (a) {
(b.direction = a >= b.index), (b.index = a), b.updateItemHTML();
},
preloadNearbyImages: function () {
var a,
c = b.st.gallery.preload,
d = Math.min(c[0], b.items.length),
e = Math.min(c[1], b.items.length);
for (a = 1; a <= (b.direction ? e : d); a++)
b._preloadItem(b.index + a);
for (a = 1; a <= (b.direction ? d : e); a++)
b._preloadItem(b.index - a);
},
_preloadItem: function (c) {
if (((c = S(c)), !b.items[c].preloaded)) {
var d = b.items[c];
d.parsed || (d = b.parseEl(c)),
y("LazyLoad", d),
"image" === d.type &&
(d.img = a('
![]()
')
.on("load.mfploader", function () {
d.hasSize = !0;
})
.on("error.mfploader", function () {
(d.hasSize = !0), (d.loadError = !0), y("LazyLoadError", d);
})
.attr("src", d.src)),
(d.preloaded = !0);
}
},
},
});
var U = "retina";
a.magnificPopup.registerModule(U, {
options: {
replaceSrc: function (a) {
return a.src.replace(/\.\w+$/, function (a) {
return "@2x" + a;
});
},
ratio: 1,
},
proto: {
initRetina: function () {
if (window.devicePixelRatio > 1) {
var a = b.st.retina,
c = a.ratio;
(c = isNaN(c) ? c() : c),
c > 1 &&
(w("ImageHasSize." + U, function (a, b) {
b.img.css({
"max-width": b.img[0].naturalWidth / c,
width: "100%",
});
}),
w("ElementParse." + U, function (b, d) {
d.src = a.replaceSrc(d, c);
}));
}
},
},
}),
A();
});
/*
* Copyright (C) 2009 Joel Sutherland
* Licenced under the MIT license
* http://www.newmediacampaigns.com/page/jquery-flickr-plugin
*
* Available tags for templates:
* title, link, date_taken, description, published, author, author_id, tags, image*
*/
(function ($) {
$.fn.jflickrfeed = function (settings, callback) {
settings = $.extend(
true,
{
flickrbase: "http://api.flickr.com/services/feeds/",
feedapi: "photos_public.gne",
limit: 20,
qstrings: {
lang: "en-us",
format: "json",
jsoncallback: "?",
},
cleanDescription: true,
useTemplate: true,
itemTemplate: "",
itemCallback: function () {},
},
settings
);
var url = settings.flickrbase + settings.feedapi + "?";
var first = true;
for (var key in settings.qstrings) {
if (!first) url += "&";
url += key + "=" + settings.qstrings[key];
first = false;
}
return $(this).each(function () {
var $container = $(this);
var container = this;
$.getJSON(url, function (data) {
$.each(data.items, function (i, item) {
if (i < settings.limit) {
// Clean out the Flickr Description
if (settings.cleanDescription) {
var regex = /
(.*?)<\/p>/g;
var input = item.description;
if (regex.test(input)) {
item.description = input.match(regex)[2];
if (item.description != undefined)
item.description = item.description
.replace("
", "")
.replace("
", "");
}
}
// Add Image Sizes
// http://www.flickr.com/services/api/misc.urls.html
item["image_s"] = item.media.m.replace("_m", "_s");
item["image_q"] = item.media.m.replace("_m", "_q");
item["image_m"] = item.media.m.replace("_m", "_m");
item["image"] = item.media.m.replace("_m", "");
item["image_b"] = item.media.m.replace("_m", "_b");
item["image_z"] = item.media.m.replace("_m", "_z");
item["image_l"] = item.media.m.replace("_m", "_l");
item["image_o"] = item.media.m.replace("_m", "_o");
delete item.media;
// Use Template
if (settings.useTemplate) {
var template = settings.itemTemplate;
for (var key in item) {
var rgx = new RegExp("{{" + key + "}}", "g");
template = template.replace(rgx, item[key]);
}
$container.append(template);
}
//itemCallback
settings.itemCallback.call(container, item);
}
});
if ($.isFunction(callback)) {
callback.call(container, data);
}
});
});
};
})(jQuery);
(function ($) {
function initFlickrResponsive($selector, options) {
var window_width = $(window).width(),
prefixClass = "type-column-";
$selector
.removeClass(prefixClass + options.col_lg)
.removeClass(prefixClass + options.col_md)
.removeClass(prefixClass + options.col_sm)
.removeClass(prefixClass + options.col_xs);
if (window_width >= 1200) {
$selector.addClass(prefixClass + options.col_lg);
} else if (window_width <= 1199 && window_width > 991) {
$selector.addClass(prefixClass + options.col_md);
} else if (window_width <= 991 && window_width > 767) {
$selector.addClass(prefixClass + options.col_sm);
} else if (window_width <= 767) {
$selector.addClass(prefixClass + options.col_xs);
}
}
$.fn.aweFlickr = function () {
var default_settings = {
flickrbase: "https://api.flickr.com/services/feeds/",
feedapi: "photos_public.gne",
limit: 12,
qstrings: "",
itemTemplate:
'
' +
'' +
'
' +
"" +
"",
enableLightbox: false,
};
this.each(function () {
var $item = $(this);
if ($item.attr("data-flickr") != undefined) {
var settings = JSON.parse($item.attr("data-flickr"));
settings = $.extend(default_settings, settings);
$item.jflickrfeed(settings, function () {
if (settings.enableLightbox) {
$item.find("a").magnificPopup({
type: "image",
removalDelay: 300,
mainClass: "mfp-fade",
gallery: {
enabled: true,
preload: [0, 2],
navigateByImgClick: true,
},
zoom: {
enabled: true,
},
});
}
});
// responsive
if (settings.enableResponsive) {
var $parentFlickr = $item.parent();
initFlickrResponsive($parentFlickr, settings);
$(window).resize(function () {
initFlickrResponsive($parentFlickr, settings);
});
}
}
});
return this;
};
$(document).ready(function () {
$(".js-jflickr").aweFlickr();
});
})(jQuery);
/**
* DO NOT EDIT THIS FILE.
* See the following change record for more information,
* https://www.drupal.org/node/2815083
* @preserve
**/
(function ($, Drupal) {
var states = {
postponed: [],
};
Drupal.states = states;
function invert(a, invertState) {
return invertState && typeof a !== "undefined" ? !a : a;
}
function _compare2(a, b) {
if (a === b) {
return typeof a === "undefined" ? a : true;
}
return typeof a === "undefined" || typeof b === "undefined";
}
function ternary(a, b) {
if (typeof a === "undefined") {
return b;
}
if (typeof b === "undefined") {
return a;
}
return a && b;
}
Drupal.behaviors.states = {
attach: function attach(context, settings) {
var $states = $(context).find("[data-drupal-states]");
var il = $states.length;
var _loop = function _loop(i) {
var config = JSON.parse($states[i].getAttribute("data-drupal-states"));
Object.keys(config || {}).forEach(function (state) {
new states.Dependent({
element: $($states[i]),
state: states.State.sanitize(state),
constraints: config[state],
});
});
};
for (var i = 0; i < il; i++) {
_loop(i);
}
while (states.postponed.length) {
states.postponed.shift()();
}
},
};
states.Dependent = function (args) {
var _this = this;
$.extend(this, { values: {}, oldValue: null }, args);
this.dependees = this.getDependees();
Object.keys(this.dependees || {}).forEach(function (selector) {
_this.initializeDependee(selector, _this.dependees[selector]);
});
};
states.Dependent.comparisons = {
RegExp: function RegExp(reference, value) {
return reference.test(value);
},
Function: function Function(reference, value) {
return reference(value);
},
Number: function Number(reference, value) {
return typeof value === "string"
? _compare2(reference.toString(), value)
: _compare2(reference, value);
},
};
states.Dependent.prototype = {
initializeDependee: function initializeDependee(selector, dependeeStates) {
var _this2 = this;
this.values[selector] = {};
Object.keys(dependeeStates).forEach(function (i) {
var state = dependeeStates[i];
if ($.inArray(state, dependeeStates) === -1) {
return;
}
state = states.State.sanitize(state);
_this2.values[selector][state.name] = null;
$(selector).on(
"state:" + state,
{ selector: selector, state: state },
function (e) {
_this2.update(e.data.selector, e.data.state, e.value);
}
);
new states.Trigger({ selector: selector, state: state });
});
},
compare: function compare(reference, selector, state) {
var value = this.values[selector][state.name];
if (reference.constructor.name in states.Dependent.comparisons) {
return states.Dependent.comparisons[reference.constructor.name](
reference,
value
);
}
return _compare2(reference, value);
},
update: function update(selector, state, value) {
if (value !== this.values[selector][state.name]) {
this.values[selector][state.name] = value;
this.reevaluate();
}
},
reevaluate: function reevaluate() {
var value = this.verifyConstraints(this.constraints);
if (value !== this.oldValue) {
this.oldValue = value;
value = invert(value, this.state.invert);
this.element.trigger({
type: "state:" + this.state,
value: value,
trigger: true,
});
}
},
verifyConstraints: function verifyConstraints(constraints, selector) {
var result = void 0;
if ($.isArray(constraints)) {
var hasXor = $.inArray("xor", constraints) === -1;
var len = constraints.length;
for (var i = 0; i < len; i++) {
if (constraints[i] !== "xor") {
var constraint = this.checkConstraints(constraints[i], selector, i);
if (constraint && (hasXor || result)) {
return hasXor;
}
result = result || constraint;
}
}
} else if ($.isPlainObject(constraints)) {
for (var n in constraints) {
if (constraints.hasOwnProperty(n)) {
result = ternary(
result,
this.checkConstraints(constraints[n], selector, n)
);
if (result === false) {
return false;
}
}
}
}
return result;
},
checkConstraints: function checkConstraints(value, selector, state) {
if (typeof state !== "string" || /[0-9]/.test(state[0])) {
state = null;
} else if (typeof selector === "undefined") {
selector = state;
state = null;
}
if (state !== null) {
state = states.State.sanitize(state);
return invert(this.compare(value, selector, state), state.invert);
}
return this.verifyConstraints(value, selector);
},
getDependees: function getDependees() {
var cache = {};
var _compare = this.compare;
this.compare = function (reference, selector, state) {
(cache[selector] || (cache[selector] = [])).push(state.name);
};
this.verifyConstraints(this.constraints);
this.compare = _compare;
return cache;
},
};
states.Trigger = function (args) {
$.extend(this, args);
if (this.state in states.Trigger.states) {
this.element = $(this.selector);
if (!this.element.data("trigger:" + this.state)) {
this.initialize();
}
}
};
states.Trigger.prototype = {
initialize: function initialize() {
var _this3 = this;
var trigger = states.Trigger.states[this.state];
if (typeof trigger === "function") {
trigger.call(window, this.element);
} else {
Object.keys(trigger || {}).forEach(function (event) {
_this3.defaultTrigger(event, trigger[event]);
});
}
this.element.data("trigger:" + this.state, true);
},
defaultTrigger: function defaultTrigger(event, valueFn) {
var oldValue = valueFn.call(this.element);
this.element.on(
event,
$.proxy(function (e) {
var value = valueFn.call(this.element, e);
if (oldValue !== value) {
this.element.trigger({
type: "state:" + this.state,
value: value,
oldValue: oldValue,
});
oldValue = value;
}
}, this)
);
states.postponed.push(
$.proxy(function () {
this.element.trigger({
type: "state:" + this.state,
value: oldValue,
oldValue: null,
});
}, this)
);
},
};
states.Trigger.states = {
empty: {
keyup: function keyup() {
return this.val() === "";
},
},
checked: {
change: function change() {
var checked = false;
this.each(function () {
checked = $(this).prop("checked");
return !checked;
});
return checked;
},
},
value: {
keyup: function keyup() {
if (this.length > 1) {
return this.filter(":checked").val() || false;
}
return this.val();
},
change: function change() {
if (this.length > 1) {
return this.filter(":checked").val() || false;
}
return this.val();
},
},
collapsed: {
collapsed: function collapsed(e) {
return typeof e !== "undefined" && "value" in e
? e.value
: !this.is("[open]");
},
},
};
states.State = function (state) {
this.pristine = state;
this.name = state;
var process = true;
do {
while (this.name.charAt(0) === "!") {
this.name = this.name.substring(1);
this.invert = !this.invert;
}
if (this.name in states.State.aliases) {
this.name = states.State.aliases[this.name];
} else {
process = false;
}
} while (process);
};
states.State.sanitize = function (state) {
if (state instanceof states.State) {
return state;
}
return new states.State(state);
};
states.State.aliases = {
enabled: "!disabled",
invisible: "!visible",
invalid: "!valid",
untouched: "!touched",
optional: "!required",
filled: "!empty",
unchecked: "!checked",
irrelevant: "!relevant",
expanded: "!collapsed",
open: "!collapsed",
closed: "collapsed",
readwrite: "!readonly",
};
states.State.prototype = {
invert: false,
toString: function toString() {
return this.name;
},
};
var $document = $(document);
$document.on("state:disabled", function (e) {
if (e.trigger) {
$(e.target)
.prop("disabled", e.value)
.closest(".js-form-item, .js-form-submit, .js-form-wrapper")
.toggleClass("form-disabled", e.value)
.find("select, input, textarea")
.prop("disabled", e.value);
}
});
$document.on("state:required", function (e) {
if (e.trigger) {
if (e.value) {
var label = "label" + (e.target.id ? "[for=" + e.target.id + "]" : "");
var $label = $(e.target)
.attr({ required: "required", "aria-required": "true" })
.closest(".js-form-item, .js-form-wrapper")
.find(label);
if (!$label.hasClass("js-form-required").length) {
$label.addClass("js-form-required form-required");
}
} else {
$(e.target)
.removeAttr("required aria-required")
.closest(".js-form-item, .js-form-wrapper")
.find("label.js-form-required")
.removeClass("js-form-required form-required");
}
}
});
$document.on("state:visible", function (e) {
if (e.trigger) {
$(e.target)
.closest(".js-form-item, .js-form-submit, .js-form-wrapper")
.toggle(e.value);
}
});
$document.on("state:checked", function (e) {
if (e.trigger) {
$(e.target).prop("checked", e.value);
}
});
$document.on("state:collapsed", function (e) {
if (e.trigger) {
if ($(e.target).is("[open]") === e.value) {
$(e.target).find("> summary").trigger("click");
}
}
});
})(jQuery, Drupal);
/**
* @file
* JavaScript behaviors for custom webform #states.
*/
(function ($, Drupal) {
"use strict";
Drupal.webform = Drupal.webform || {};
Drupal.webform.states = Drupal.webform.states || {};
Drupal.webform.states.slideDown = Drupal.webform.states.slideDown || {};
Drupal.webform.states.slideDown.duration = "slow";
Drupal.webform.states.slideUp = Drupal.webform.states.slideUp || {};
Drupal.webform.states.slideUp.duration = "fast";
/**
* Check if an element has a specified data attribute.
*
* @param {string} data
* The data attribute name.
*
* @return {boolean}
* TRUE if an element has a specified data attribute.
*/
$.fn.hasData = function (data) {
return typeof this.data(data) !== "undefined";
};
/**
* Check if element is within the webform or not.
*
* @return {boolean}
* TRUE if element is within the webform.
*/
$.fn.isWebform = function () {
return $(this).closest('form[id^="webform"]').length ? true : false;
};
// The change event is triggered by cut-n-paste and select menus.
// Issue #2445271: #states element empty check not triggered on mouse
// based paste.
// @see https://www.drupal.org/node/2445271
Drupal.states.Trigger.states.empty.change = function change() {
return this.val() === "";
};
// Apply solution included in #1962800 patch.
// Issue #1962800: Form #states not working with literal integers as
// values in IE11.
// @see https://www.drupal.org/project/drupal/issues/1962800
// @see https://www.drupal.org/files/issues/core-states-not-working-with-integers-ie11_1962800_46.patch
//
// This issue causes pattern, less than, and greater than support to break.
// @see https://www.drupal.org/project/webform/issues/2981724
var states = Drupal.states;
Drupal.states.Dependent.prototype.compare = function compare(
reference,
selector,
state
) {
var value = this.values[selector][state.name];
var name = reference.constructor.name;
if (!name) {
name = $.type(reference);
name = name.charAt(0).toUpperCase() + name.slice(1);
}
if (name in states.Dependent.comparisons) {
return states.Dependent.comparisons[name](reference, value);
}
if (reference.constructor.name in states.Dependent.comparisons) {
return states.Dependent.comparisons[reference.constructor.name](
reference,
value
);
}
return _compare2(reference, value);
};
function _compare2(a, b) {
if (a === b) {
return typeof a === "undefined" ? a : true;
}
return typeof a === "undefined" || typeof b === "undefined";
}
// Adds pattern, less than, and greater than support to #state API.
// @see http://drupalsun.com/julia-evans/2012/03/09/extending-form-api-states-regular-expressions
Drupal.states.Dependent.comparisons.Object = function (reference, value) {
if ("pattern" in reference) {
return new RegExp(reference["pattern"]).test(value);
} else if ("!pattern" in reference) {
return !new RegExp(reference["!pattern"]).test(value);
} else if ("less" in reference) {
return value !== "" && parseFloat(reference["less"]) > parseFloat(value);
} else if ("greater" in reference) {
return (
value !== "" && parseFloat(reference["greater"]) < parseFloat(value)
);
} else {
return reference.indexOf(value) !== false;
}
};
var $document = $(document);
$document.on("state:required", function (e) {
if (e.trigger && $(e.target).isWebform()) {
var $target = $(e.target);
// Fix #required file upload.
// @see Issue #2860529: Conditional required File upload field don't work.
if (e.value) {
$target
.find('input[type="file"]')
.attr({ required: "required", "aria-required": "true" });
} else {
$target.find('input[type="file"]').removeAttr("required aria-required");
}
// Fix required label for checkboxes and radios.
// @see Issue #2938414: Checkboxes don't support #states required
// @see Issue #2731991: Setting required on radios marks all options required.
// @see Issue #2856315: Conditional Logic - Requiring Radios in a Fieldset.
// Fix #required for fieldsets.
// @see Issue #2977569: Hidden fieldsets that become visible with conditional logic cannot be made required.
if (
$target.is(
".js-webform-type-radios, .js-webform-type-checkboxes, fieldset"
)
) {
if (e.value) {
$target
.find("legend span:not(.visually-hidden)")
.addClass("js-form-required form-required");
} else {
$target
.find("legend span:not(.visually-hidden)")
.removeClass("js-form-required form-required");
}
}
// Fix #required for radios.
// @see Issue #2856795: If radio buttons are required but not filled form is nevertheless submitted.
if (
$target.is(
".js-webform-type-radios, .js-form-type-webform-radios-other"
)
) {
if (e.value) {
$target
.find('input[type="radio"]')
.attr({ required: "required", "aria-required": "true" });
} else {
$target
.find('input[type="radio"]')
.removeAttr("required aria-required");
}
}
// Fix #required for checkboxes.
// @see Issue #2938414: Checkboxes don't support #states required.
// @see checkboxRequiredhandler
if (
$target.is(
".js-webform-type-checkboxes, .js-form-type-webform-checkboxes-other"
)
) {
var $checkboxes = $target.find('input[type="checkbox"]');
if (e.value) {
// Bind the event handler and add custom HTML5 required validation
// to all checkboxes.
$checkboxes.bind("click", checkboxRequiredhandler);
if (!$checkboxes.is(":checked")) {
$checkboxes.attr({ required: "required", "aria-required": "true" });
}
} else {
// Remove custom HTML5 required validation from all checkboxes
// and unbind the event handler.
$checkboxes
.removeAttr("required aria-required")
.unbind("click", checkboxRequiredhandler);
}
}
// Issue #2986017: Fieldsets shouldn't have required attribute.
if ($target.is("fieldset")) {
$target.removeAttr("required aria-required");
}
}
});
$document.on("state:readonly", function (e) {
if (e.trigger && $(e.target).isWebform()) {
$(e.target)
.prop("readonly", e.value)
.closest(".js-form-item, .js-form-wrapper")
.toggleClass("webform-readonly", e.value)
.find("input, textarea")
.prop("readonly", e.value);
}
});
$document.on("state:visible state:visible-slide", function (e) {
if (e.trigger && $(e.target).isWebform()) {
if (e.value) {
$(":input", e.target)
.addBack()
.each(function () {
restoreValueAndRequired(this);
triggerEventHandlers(this);
});
} else {
// @see https://www.sitepoint.com/jquery-function-clear-form-data/
$(":input", e.target)
.addBack()
.each(function () {
backupValueAndRequired(this);
clearValueAndRequired(this);
triggerEventHandlers(this);
});
}
}
});
$document.bind("state:visible-slide", function (e) {
if (e.trigger && $(e.target).isWebform()) {
var effect = e.value ? "slideDown" : "slideUp";
var duration = Drupal.webform.states[effect].duration;
$(e.target)
.closest(".js-form-item, .js-form-submit, .js-form-wrapper")
[effect](duration);
}
});
Drupal.states.State.aliases["invisible-slide"] = "!visible-slide";
$document.on("state:disabled", function (e) {
if (e.trigger && $(e.target).isWebform()) {
// Make sure disabled property is set before triggering webform:disabled.
// Copied from: core/misc/states.js
$(e.target)
.prop("disabled", e.value)
.closest(".js-form-item, .js-form-submit, .js-form-wrapper")
.toggleClass("form-disabled", e.value)
.find("select, input, textarea")
.prop("disabled", e.value);
// Trigger webform:disabled.
$(e.target)
.trigger("webform:disabled")
.find("select, input, textarea")
.trigger("webform:disabled");
}
});
/**
* Trigger custom HTML5 multiple checkboxes validation.
*
* @see https://stackoverflow.com/a/37825072/145846
*/
function checkboxRequiredhandler() {
var $checkboxes = $(this)
.closest(
".js-webform-type-checkboxes, .js-form-type-webform-checkboxes-other"
)
.find('input[type="checkbox"]');
if ($checkboxes.is(":checked")) {
$checkboxes.removeAttr("required aria-required");
} else {
$checkboxes.attr({ required: "required", "aria-required": "true" });
}
}
/**
* Trigger an input's event handlers.
*
* @param {element} input
* An input.
*/
function triggerEventHandlers(input) {
var $input = $(input);
var type = input.type;
var tag = input.tagName.toLowerCase();
// Add 'webform.states' as extra parameter to event handlers.
// @see Drupal.behaviors.webformUnsaved
var extraParameters = ["webform.states"];
if (type === "checkbox" || type === "radio") {
$input
.trigger("change", extraParameters)
.trigger("blur", extraParameters);
} else if (tag === "select") {
$input
.trigger("change", extraParameters)
.trigger("blur", extraParameters);
} else if (type !== "submit" && type !== "button" && type !== "file") {
$input
.trigger("input", extraParameters)
.trigger("change", extraParameters)
.trigger("keydown", extraParameters)
.trigger("keyup", extraParameters)
.trigger("blur", extraParameters);
}
}
/**
* Backup an input's current value and required attribute
*
* @param {element} input
* An input.
*/
function backupValueAndRequired(input) {
var $input = $(input);
var type = input.type;
var tag = input.tagName.toLowerCase(); // Normalize case.
// Backup required.
if ($input.prop("required") && !$input.hasData("webform-required")) {
$input.data("webform-required", true);
}
// Backup value.
if (!$input.hasData("webform-value")) {
if (type === "checkbox" || type === "radio") {
$input.data("webform-value", $input.prop("checked"));
} else if (tag === "select") {
var values = [];
$input.find("option:selected").each(function (i, option) {
values[i] = option.value;
});
$input.data("webform-value", values);
} else if (type !== "submit" && type !== "button") {
$input.data("webform-value", input.value);
}
}
}
/**
* Restore an input's value and required attribute.
*
* @param {element} input
* An input.
*/
function restoreValueAndRequired(input) {
var $input = $(input);
// Restore value.
var value = $input.data("webform-value");
if (typeof value !== "undefined") {
var type = input.type;
var tag = input.tagName.toLowerCase(); // Normalize case.
if (type === "checkbox" || type === "radio") {
$input.prop("checked", value);
} else if (tag === "select") {
$.each(value, function (i, option_value) {
$input
.find("option[value='" + option_value + "']")
.prop("selected", true);
});
} else if (type !== "submit" && type !== "button") {
input.value = value;
}
$input.removeData("webform-value");
}
// Restore required.
var required = $input.data("webform-required");
if (typeof required !== "undefined") {
if (required) {
$input.prop("required", true);
}
$input.removeData("webform-required");
}
}
/**
* Clear an input's value and required attributes.
*
* @param {element} input
* An input.
*/
function clearValueAndRequired(input) {
var $input = $(input);
// Check for #states no clear attribute.
// @see https://css-tricks.com/snippets/jquery/make-an-jquery-hasattr/
if ($input.closest("[data-webform-states-no-clear]").length) {
return;
}
// Clear value.
var type = input.type;
var tag = input.tagName.toLowerCase(); // Normalize case.
if (type === "checkbox" || type === "radio") {
$input.prop("checked", false);
} else if (tag === "select") {
if ($input.find('option[value=""]').length) {
$input.val("");
} else {
input.selectedIndex = -1;
}
} else if (type !== "submit" && type !== "button") {
input.value = type === "color" ? "#000000" : "";
}
// Clear required.
$input.prop("required", false);
}
})(jQuery, Drupal);
/**
* @file
* JavaScript behaviors for webforms.
*/
(function ($, Drupal) {
"use strict";
/**
* Autofocus first input.
*
* @type {Drupal~behavior}
*
* @prop {Drupal~behaviorAttach} attach
* Attaches the behavior for the webform autofocusing.
*/
Drupal.behaviors.webformAutofocus = {
attach: function (context) {
$(context)
.find(
".webform-submission-form.js-webform-autofocus :input:visible:enabled:first"
)
.focus();
},
};
/**
* Prevent webform autosubmit on wizard pages.
*
* @type {Drupal~behavior}
*
* @prop {Drupal~behaviorAttach} attach
* Attaches the behavior for disabling webform autosubmit.
* Wizard pages need to be progressed with the Previous or Next buttons, not by pressing Enter.
*/
Drupal.behaviors.webformDisableAutoSubmit = {
attach: function (context) {
// @see http://stackoverflow.com/questions/11235622/jquery-disable-form-submit-on-enter
$(context)
.find(".webform-submission-form.js-webform-disable-autosubmit input")
.not(":button, :submit, :reset, :image, :file")
.once("webform-disable-autosubmit")
.on("keyup keypress", function (e) {
var keyCode = e.keyCode || e.which;
if (keyCode === 13) {
e.preventDefault();
return false;
}
});
},
};
/**
* Skip client-side validation when submit button is pressed.
*
* @type {Drupal~behavior}
*
* @prop {Drupal~behaviorAttach} attach
* Attaches the behavior for the skipping client-side validation.
*/
Drupal.behaviors.webformSubmitNoValidate = {
attach: function (context) {
$(context)
.find(":submit.js-webform-novalidate")
.once("webform-novalidate")
.on("click", function () {
$(this.form).attr("novalidate", "novalidate");
});
},
};
/**
* Attach behaviors to trigger submit button from input onchange.
*
* @type {Drupal~behavior}
*
* @prop {Drupal~behaviorAttach} attach
* Attaches form trigger submit events.
*/
Drupal.behaviors.webformSubmitTrigger = {
attach: function (context) {
$("[data-webform-trigger-submit]")
.once("webform-trigger-submit")
.on("change", function () {
var submit = $(this).attr("data-webform-trigger-submit");
$(submit).mousedown();
});
},
};
/**
* Custom required error message.
*
* @type {Drupal~behavior}
*
* @prop {Drupal~behaviorAttach} attach
* Attaches the behavior for the webform custom required error message.
*
* @see http://stackoverflow.com/questions/5272433/html5-form-required-attribute-set-custom-validation-message
*/
Drupal.behaviors.webformRequiredError = {
attach: function (context) {
$(context)
.find(":input[data-webform-required-error]")
.once("webform-required-error")
.on("invalid", function () {
this.setCustomValidity("");
if (!this.valid) {
this.setCustomValidity($(this).attr("data-webform-required-error"));
}
})
.on("input, change", function () {
// Find all related elements by name and reset custom validity.
// This specifically applies to required radios and checkboxes.
var name = $(this).attr("name");
$(this.form)
.find(':input[name="' + name + '"]')
.each(function () {
this.setCustomValidity("");
});
});
},
};
// When #state:required is triggered we need to reset the target elements
// custom validity.
$(document).on("state:required", function (e) {
$(e.target)
.filter("[data-webform-required-error]")
.each(function () {
this.setCustomValidity("");
});
});
if (window.imceInput) {
window.imceInput.processUrlInput = function (i, el) {
var button = imceInput.createUrlButton(
el.id,
el.getAttribute("data-imce-type")
);
el.parentNode.insertAfter(button, el);
};
}
})(jQuery, Drupal);
/**
* DO NOT EDIT THIS FILE.
* See the following change record for more information,
* https://www.drupal.org/node/2815083
* @preserve
**/
(function (Drupal, debounce) {
var liveElement = void 0;
var announcements = [];
Drupal.behaviors.drupalAnnounce = {
attach: function attach(context) {
if (!liveElement) {
liveElement = document.createElement("div");
liveElement.id = "drupal-live-announce";
liveElement.className = "visually-hidden";
liveElement.setAttribute("aria-live", "polite");
liveElement.setAttribute("aria-busy", "false");
document.body.appendChild(liveElement);
}
},
};
function announce() {
var text = [];
var priority = "polite";
var announcement = void 0;
var il = announcements.length;
for (var i = 0; i < il; i++) {
announcement = announcements.pop();
text.unshift(announcement.text);
if (announcement.priority === "assertive") {
priority = "assertive";
}
}
if (text.length) {
liveElement.innerHTML = "";
liveElement.setAttribute("aria-busy", "true");
liveElement.setAttribute("aria-live", priority);
liveElement.innerHTML = text.join("\n");
liveElement.setAttribute("aria-busy", "false");
}
}
Drupal.announce = function (text, priority) {
announcements.push({
text: text,
priority: priority,
});
return debounce(announce, 200)();
};
})(Drupal, Drupal.debounce);
/**
* @file
* JavaScript behaviors for details element.
*/
(function ($, Drupal) {
"use strict";
Drupal.webform = Drupal.webform || {};
Drupal.webform.detailsToggle = Drupal.webform.detailsToggle || {};
Drupal.webform.detailsToggle.options =
Drupal.webform.detailsToggle.options || {};
/**
* Attach handler to toggle details open/close state.
*
* @type {Drupal~behavior}
*/
Drupal.behaviors.webformDetailsToggle = {
attach: function (context) {
$(".js-webform-details-toggle", context)
.once("webform-details-toggle")
.each(function () {
var $form = $(this);
var $tabs = $form.find(".webform-tabs");
// Get only the main details elements and ignore all nested details.
var selector = $tabs.length
? ".webform-tab"
: ".js-webform-details-toggle";
var $details = $form.find("details").filter(function () {
// @todo Figure out how to optimize the below code.
var $parents = $(this).parentsUntil(selector);
return $parents.find("details").length === 0;
});
// Toggle is only useful when there are two or more details elements.
if ($details.length < 2) {
return;
}
var options = $.extend(
{
button:
'
',
},
Drupal.webform.detailsToggle.options
);
// Create toggle buttons.
var $toggle = $(options.button)
.attr("title", Drupal.t("Toggle details widget state."))
.on("click", function (e) {
var open;
if (isFormDetailsOpen($form)) {
$form.find("details").removeAttr("open");
open = 0;
} else {
$form.find("details").attr("open", "open");
open = 1;
}
setDetailsToggleLabel($form);
// Set the saved states for all the details elements.
// @see webform.element.details.save.js
if (!Drupal.webformDetailsSaveGetName) {
$form.find("details").each(function () {
var name = Drupal.webformDetailsSaveGetName($(this));
if (name) {
localStorage.setItem(name, open);
}
});
}
})
.wrap('
')
.parent();
if ($tabs.length) {
// Add toggle state before the tabs.
$tabs.find(".item-list:first-child").before($toggle);
} else {
// Add toggle state link to first details element.
$details.eq(0).before($toggle);
}
setDetailsToggleLabel($form);
});
},
};
/**
* Determine if a webform's details are all opened.
*
* @param {jQuery} $form
* A webform.
*
* @return {boolean}
* TRUE if a webform's details are all opened.
*/
function isFormDetailsOpen($form) {
return $form.find("details[open]").length === $form.find("details").length;
}
/**
* Set a webform's details toggle state widget label.
*
* @param {jQuery} $form
* A webform.
*/
function setDetailsToggleLabel($form) {
var isOpen = isFormDetailsOpen($form);
var label = isOpen ? Drupal.t("Collapse all") : Drupal.t("Expand all");
$form.find(".webform-details-toggle-state").html(label);
var text = isOpen
? Drupal.t("All details have been expanded.")
: Drupal.t("All details have been collapsed.");
Drupal.announce(text);
}
})(jQuery, Drupal);
/**
* @file
* JavaScript behaviors for details element.
*/
(function ($, Drupal) {
"use strict";
/**
* Attach handler to save details open/close state.
*
* @type {Drupal~behavior}
*/
Drupal.behaviors.webformDetailsSave = {
attach: function (context) {
if (!window.localStorage) {
return;
}
// Summary click event handler.
$("details > summary", context)
.once("webform-details-summary-save")
.click(function () {
var $details = $(this).parent();
// @see https://css-tricks.com/snippets/jquery/make-an-jquery-hasattr/
if ($details[0].hasAttribute("data-webform-details-nosave")) {
return;
}
var name = Drupal.webformDetailsSaveGetName($details);
if (!name) {
return;
}
var open = $details.attr("open") !== "open" ? "1" : "0";
localStorage.setItem(name, open);
});
// Initialize details open state via local storage.
$("details", context)
.once("webform-details-save")
.each(function () {
var $details = $(this);
var name = Drupal.webformDetailsSaveGetName($details);
if (!name) {
return;
}
var open = localStorage.getItem(name);
if (open === null) {
return;
}
if (open === "1") {
$details.attr("open", "open");
} else {
$details.removeAttr("open");
}
});
},
};
/**
* Get the name used to store the state of details element.
*
* @param {jQuery} $details
* A details element.
*
* @return {string}
* The name used to store the state of details element.
*/
Drupal.webformDetailsSaveGetName = function ($details) {
if (!window.localStorage) {
return "";
}
// Any details element not included a webform must have define its own id.
var webformId = $details.attr("data-webform-element-id");
if (webformId) {
return "Drupal.webform." + webformId.replace("--", ".");
}
var detailsId = $details.attr("id");
if (!detailsId) {
return "";
}
var $form = $details.parents("form");
if (!$form.length || !$form.attr("id")) {
return "";
}
var formId = $form.attr("id");
if (!formId) {
return "";
}
// ISSUE: When Drupal renders a webform in a modal dialog it appends a unique
// identifier to webform ids and details ids. (i.e. my-form--FeSFISegTUI)
// WORKAROUND: Remove the unique id that delimited using double dashes.
formId = formId.replace(/--.+?$/, "").replace(/-/g, "_");
detailsId = detailsId.replace(/--.+?$/, "").replace(/-/g, "_");
return "Drupal.webform." + formId + "." + detailsId;
};
})(jQuery, Drupal);