|
32 | 32 | */ |
33 | 33 |
|
34 | 34 | (function() { |
35 | | - var _VERSION = '2.91.0'; |
| 35 | + var _VERSION = '2.92.0'; |
36 | 36 |
|
37 | 37 | /* Establish the win object, 'window' in the browser */ |
38 | 38 | var win = window||globalThis, _doc = document, isSPAReady, docBody = _doc.body; |
|
382 | 382 | return ((''+this).charAt(0).toLowerCase()) + ((''+this).slice(1)); |
383 | 383 | }; |
384 | 384 |
|
| 385 | + _strProto.test = function (rx, rxOpt) { |
| 386 | + if (_isStr(rx)) { |
| 387 | + rx = rxOpt? new RegExp(rx, rxOpt) : new RegExp(rx); |
| 388 | + } |
| 389 | + return rx.test(''+this); |
| 390 | + }; |
| 391 | + |
385 | 392 | function _sanitizeHTML(str) { |
386 | 393 | var sBoxEl = document.createElement('div'); |
387 | 394 | sBoxEl.textContent = str; |
|
4482 | 4489 | return onVirtualDOM? ($contextRoot.html().replace((new RegExp(blockedScriptTagName, 'g')), "script").replace(/spa-vdom-textarea/g,'textarea') ) : $contextRoot; |
4483 | 4490 | }; |
4484 | 4491 |
|
4485 | | - xsr.bindTemplateData = function (xTemplate, data) { |
4486 | | - var xContent = xTemplate; |
| 4492 | + xsr.bindTemplateData = xsr.bindTemplate = xsr.renderTemplate = function (xTemplate, data) { |
| 4493 | + var xContent = xTemplate, tmplType = '', elTarget, renderTarget = arguments[arguments.length-1]; |
4487 | 4494 | if ((/^\s*#[a-z]+/i).test(xTemplate)) { |
4488 | | - xContent = $(xTemplate).html(); |
| 4495 | + elTarget = $(xTemplate)[0]; |
| 4496 | + xContent = elTarget.innerHTML.replace(/^\s*/,''); |
4489 | 4497 | } |
4490 | 4498 |
|
4491 | | - if (_isBlank(data)) { |
| 4499 | + if ((arguments.length==1) || (arguments.length==2 && _isObj(data))) { |
| 4500 | + tmplType = elTarget.getAttribute('type'); |
| 4501 | + renderTarget = elTarget.getAttribute('target'); |
| 4502 | + } |
| 4503 | + |
| 4504 | + if (_isStr(data) && arguments.length==3) { |
| 4505 | + tmplType = data.trim(); |
| 4506 | + data = arguments[2]; |
| 4507 | + } |
| 4508 | + if (!(_isObj(data) || renderTarget)) { |
4492 | 4509 | return xContent; |
4493 | 4510 | } |
4494 | 4511 |
|
4495 | | - if ((/ data-bind\s*=/i).test(xContent)) { |
4496 | | - xContent = xsr.bindData(xTemplate, data); |
| 4512 | + if (elTarget && !tmplType) { |
| 4513 | + tmplType = elTarget.getAttribute('type'); |
4497 | 4514 | } |
4498 | 4515 |
|
4499 | | - if ((/{{(.+)}}/).test(xContent)) { |
4500 | | - if (compileTemplate) { |
4501 | | - try { |
4502 | | - xContent = compileTemplate(xContent)(data); |
4503 | | - } catch (e) { |
4504 | | - console.warn('Error Template compile/bind.', e); |
4505 | | - } |
| 4516 | + (_isUndef(data) && (data={})); |
| 4517 | + |
| 4518 | + if (/knockout|ko/gi.test(tmplType)) { |
| 4519 | + var elTarget = $(xTemplate)[0]; |
| 4520 | + ko.cleanNode(elTarget); |
| 4521 | + ko.applyBindings(data, elTarget); |
| 4522 | + } else { |
| 4523 | + if (tmplType) { |
| 4524 | + xContent = win[tmplType].compile(xContent)(data); |
4506 | 4525 | } else { |
4507 | | - console.warn('Template Library (Handlebars/doT) not found!'); |
| 4526 | + if ((/ data-bind\s*=/i).test(xContent)) { |
| 4527 | + xContent = xsr.bindData(xTemplate, data); |
| 4528 | + } |
| 4529 | + if ((/{{(.+)}}/).test(xContent)) { |
| 4530 | + if (compileTemplate) { |
| 4531 | + try { |
| 4532 | + xContent = compileTemplate(xContent)(data); |
| 4533 | + } catch (e) { |
| 4534 | + console.warn('Error Template compile/bind.', e); |
| 4535 | + } |
| 4536 | + } else { |
| 4537 | + console.warn('Template Library (Handlebars/doT) not found!'); |
| 4538 | + } |
| 4539 | + } |
4508 | 4540 | } |
4509 | 4541 | } |
4510 | 4542 |
|
| 4543 | + if (_isStr(renderTarget) && (/^\s*#[a-z]+/i).test(renderTarget)) { |
| 4544 | + $(renderTarget).html(xContent); |
| 4545 | + } |
| 4546 | + |
4511 | 4547 | return xContent; |
4512 | 4548 | }; |
4513 | 4549 |
|
|
6494 | 6530 | function _isDynSpa$(cName) { |
6495 | 6531 | return (/^(\$)*(dyn)*SPA\$/i.test(cName)); |
6496 | 6532 | } |
| 6533 | + |
6497 | 6534 | function _renderForComponent() { |
6498 | | - event.preventDefault(); |
| 6535 | + (event && event.preventDefault()); |
6499 | 6536 |
|
6500 | 6537 | var onEvent = event; |
6501 | 6538 | var xEl = this; |
|
6692 | 6729 | return (_isFn(defaultPayload)? defaultPayload() : (_isObj(defaultPayload)? _mergeDeep({}, defaultPayload) : defaultPayload) ); |
6693 | 6730 | } |
6694 | 6731 |
|
| 6732 | + function _evalObjProps ( srcObj, asNew ) { |
| 6733 | + var retObj = asNew? {} : srcObj; |
| 6734 | + if (!_isBlank(srcObj)) { |
| 6735 | + Object.keys(srcObj).forEach(function (key) { |
| 6736 | + if (_isFn(srcObj[key])) { |
| 6737 | + retObj[key] = srcObj[key].call(srcObj); |
| 6738 | + } else { |
| 6739 | + retObj[key] = srcObj[key]; |
| 6740 | + } |
| 6741 | + }) |
| 6742 | + }; |
| 6743 | + return retObj; |
| 6744 | + } |
| 6745 | + |
6695 | 6746 | /* |
6696 | 6747 | * xsr.render("#containerID") |
6697 | 6748 | * |
|
7295 | 7346 |
|
7296 | 7347 | dataUrlPayLoad = spaRVOptions.dataParams; |
7297 | 7348 | if ((!spaRVOptions.hasOwnProperty('defaultPayload')) && (!_isBlank(defPayLoad))) { |
7298 | | - dataUrlPayLoad = _mergeDeep({}, defPayLoad, ((!_isBlank(dataUrlPayLoad) && _isObj(dataUrlPayLoad))? dataUrlPayLoad : {})); |
| 7349 | + dataUrlPayLoad = _evalObjProps(_mergeDeep({}, defPayLoad, ((!_isBlank(dataUrlPayLoad) && _isObj(dataUrlPayLoad))? dataUrlPayLoad : {}))); |
7299 | 7350 | } |
7300 | 7351 | if (!_isBlank(dataUrlPayLoad) && _stringifyPayload) { |
7301 | 7352 | dataUrlPayLoad = JSON.stringify(dataUrlPayLoad); |
|
7304 | 7355 | var axOptions = { |
7305 | 7356 | url: dataModelUrl, |
7306 | 7357 | method: (''+(_renderOption('dataUrlMethod', 'urlMethod') || 'GET')).toUpperCase(), |
7307 | | - headers: ((_isFn(ajaxReqHeaders))? ajaxReqHeaders() : ajaxReqHeaders), |
| 7358 | + headers: _evalObjProps(((_isFn(ajaxReqHeaders))? ajaxReqHeaders() : ajaxReqHeaders), true), |
7308 | 7359 | data: dataUrlPayLoad, |
7309 | 7360 | cache: spaRVOptions['dataUrlCache'] || spaRVOptions['dataCache'], |
7310 | 7361 | dataType: spaRVOptions.dataType || _find(window, 'app.api.ajaxOptions.dataType', 'text'), |
|
7943 | 7994 | $(viewContainerId).attr('data-rendered-component', rCompName).data('renderedComponent', rCompName); |
7944 | 7995 | _$renderCountUpdate(rCompName); |
7945 | 7996 | unlock$render(spaRVOptions['inProgress']); |
| 7997 | + $(viewContainerId)[0].removeAttribute('render-for-route'); |
7946 | 7998 | _log.info("Render: SUCCESS"); |
7947 | 7999 | var rhKeys = _keys(xsr.renderHistory); |
7948 | 8000 | var rhLen = rhKeys.length; |
|
8370 | 8422 | }, |
8371 | 8423 | renameAttr: function(oldName, newName){ |
8372 | 8424 | this.each(function(){ |
8373 | | - _attr(this, newName, _attr(this,oldName)); |
8374 | | - this.removeAttribute(oldName); |
| 8425 | + if (this.hasAttribute(oldName)) { |
| 8426 | + _attr(this, newName, _attr(this,oldName)); |
| 8427 | + this.removeAttribute(oldName); |
| 8428 | + } |
8375 | 8429 | }); |
8376 | 8430 | return this; |
8377 | 8431 | }, |
|
8577 | 8631 | var lookupUrl = ((apiKey || '').trim()[0] === xsr.api.urlKeyIndicator); |
8578 | 8632 |
|
8579 | 8633 | apiKey = lookupUrl? (apiKey||'').trimLeftStr(xsr.api.urlKeyIndicator) : (apiKey || ''); |
8580 | | - urlReplaceKeyValues = urlReplaceKeyValues || {}; |
| 8634 | + urlReplaceKeyValues = _evalObjProps(urlReplaceKeyValues || {}, true); |
8581 | 8635 |
|
8582 | 8636 | var apiUrl = _getUrl(apiKey) || apiKey // (xsr.api.urls[apiKey] || apiKey) |
8583 | 8637 | , isStaticUrl = apiUrl.beginsWithStr('!') || xsr.api.mock || app.api.mock |
8584 | 8638 | , forceParamValuesInMockUrls = apiUrl.beginsWithStr('!!') || apiUrl.beginsWithStr('~') || xsr.api.forceParamValuesInMockUrls |
8585 | | - , paramsInUrl = apiUrl.extractStrBetweenIn('{', '}', true) |
| 8639 | + , paramsInUrl = apiUrl.extractStrBetweenIn('{', '}', true).concat(((apiUrl).match(/:[a-zA-Z_](\w*)/gi)||[]).__unique()) |
8586 | 8640 | , pKey, pValue, skip, vFilters=[], ivFilters=[], filterContext = {url: apiUrl, urlParams: urlReplaceKeyValues}, defaultValue |
8587 | 8641 | , isMockReq = (xsr.api.mock || app.api.mock || apiUrl.beginsWithStr('!')); |
8588 | 8642 |
|
8589 | 8643 | if (!isMockReq) { |
8590 | 8644 | apiUrl = _removeMockParams(apiUrl); |
8591 | 8645 | } |
| 8646 | + |
8592 | 8647 | if (!_isBlank(paramsInUrl)) { |
8593 | 8648 | _each(paramsInUrl, function(param){ |
8594 | 8649 | ivFilters = []; |
8595 | 8650 | vFilters = []; |
8596 | | - pKey = param.replace(/[{}<>]/g, '').trim(); |
| 8651 | + pKey = param.replace(/[{}<>:]/g, '').trim(); |
8597 | 8652 | if (pKey) { |
8598 | 8653 | if (pKey.indexOf('|')>0) { |
8599 | 8654 | vFilters = pKey.split('|').map(function(x){ return x.replace(/\(.*\)/g, '').trim(); }); |
|
9635 | 9690 | } |
9636 | 9691 | xsr.parseRoutes = _getNewMatchingRoutes; |
9637 | 9692 |
|
| 9693 | + function _routeByEl ( el ) { |
| 9694 | + if (el.matches('[for][data-render-target]')) { |
| 9695 | + var rTargetEl = $(_attr(el, 'data-render-target'))[0]; |
| 9696 | + if (!rTargetEl.hasAttribute('render-for-route')) { |
| 9697 | + rTargetEl.setAttribute('render-for-route', 'InProgress'); |
| 9698 | + _renderForComponent.call(el); |
| 9699 | + } |
| 9700 | + } |
| 9701 | + } |
9638 | 9702 | function _onRouteElClick(e){ |
9639 | 9703 | var spaRoutePath = xsr.urlHash([], _urlHashBase); |
9640 | 9704 | //console.clear(); |
|
9694 | 9758 | //console.log('Dynamic Route URL', routeName); |
9695 | 9759 | } |
9696 | 9760 |
|
| 9761 | + setTimeout(_routeByEl, 0, targetEl); |
9697 | 9762 | _triggerClickEventOnAttr(targetEl, 'onrouteclick'); |
9698 | 9763 |
|
9699 | 9764 | if ($routeEl.hasClass('AUTO-ROUTING')) { //exit if it's still routing ... |
|
0 commit comments