This commit is contained in:
2024-01-07 00:30:53 -05:00
parent 7fad640cca
commit 1c7e2e794e
5 changed files with 548 additions and 413 deletions

View File

@ -7,7 +7,7 @@
var make = function( element ){
//construct array
function makeArray( input ){
function makeArray( input , index ){
var result = [];
@ -25,6 +25,20 @@
configurable: true
} );
Object.defineProperty( result, "__jq_index", {
value: index,
writable: true,
enumerable: false,
configurable: true
} );
function removeEmpty(){
if(result.__jq_empty){
result.__jq_empty.remove();
delete result.__jq_empty;
}
}
result.splice = function(inputValue, ...args){
//splice does all the heavy lifting by interacting with the DOM elements.
@ -88,6 +102,7 @@
//if there are fields to add to the array, add them
if( toAdd.length > 0 ){
removeEmpty()
//$.each( toAdd, function( key, value ){
for(var I = 0; I < toAdd.length; I++){
@ -176,7 +191,7 @@
result.indexOf = function( key, value ){
if( !value ){
value = arguments[0];
key = this.__index;
key = this.__jq_index;
}
for ( var index = 0; index < this.length; ++index ) {
if( this[index][key] === value ){
@ -200,7 +215,7 @@
if( !update ){
update = arguments[1];
value = arguments[0];
key = this.__index;
key = this.__jq_index;
}
var index = this.indexOf( key, value );
@ -226,7 +241,7 @@
if( type === 'object' ){
result.push( value );
}else if( type === 'string' ){
Object.defineProperty( result, "__index", {
Object.defineProperty( result, "__jq_index", {
value: value,
writable: true,
enumerable: false,
@ -248,19 +263,23 @@
var $this = $( element );
var repeatId = $this.attr( 'jq-repeat' );
var index = $this.attr( 'jq-repeat-index' );
var tempId = repeatId + 'Template';
var templateId = $( '#' + tempId ).html();
var empty = $(`[jq-repeat-defualt="${repeatId}"]`);
$this.removeAttr( 'jq-repeat' );
var template = element.outerHTML
$this.removeAttr( 'jq-repeat-index' );
var template = element.outerHTML
$this.replaceWith( '<script type="x-tmpl-mustache" id="' + tempId + '" class="jq-repeat-' + repeatId + ' " jq-repeat-index="holder"><\/script>' );
Mustache.parse(templateId); // optional, speeds up future uses
$.scope[repeatId] = makeArray($.scope[repeatId]);
$.scope[repeatId].__rq_template = template
$.scope[repeatId] = makeArray($.scope[repeatId], index);
$.scope[repeatId].__rq_template = template;
$.scope[repeatId].__jq_empty = empty;
};
$( document ).ready( function(){