Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $.fn.getAllAttributes = function () {
- var
- elem = this,
- attr = {};
- if (elem && elem.length) $.each(elem.get(0).attributes, function (v, n) {
- n = n.nodeName || n.name;
- v = elem.attr(n); // relay on $.fn.attr, it makes some filtering and checks
- if (v != undefined && v !== false) attr[n] = v
- })
- return attr;
- }
- function syncAttributes($sourceElement, $targetElement) {
- if (!$sourceElement.length || !$targetElement.length) {
- return;
- }
- var sourceAttrs = $sourceElement.getAllAttributes();
- $targetElement.attr(sourceAttrs);
- }
- function PJAXUpdateNodes(data) {
- return new Promise(function (resolve, reject) {
- var
- $nextContainer = $($.parseHTML(data.next.html)),
- nodesToUpdate = [
- '#js-burger',
- ]; // selectors of elements that needed to update
- $.each(nodesToUpdate, function () {
- var
- $item = $(this),
- $nextItem = $nextContainer.find(this);
- // sync attributes if element exist in the new container
- if ($nextItem.length) {
- syncAttributes($nextItem, $item);
- }
- });
- resolve(true);
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement