/* Helper functions */ function fixHTMLtext(stringObj) { return stringObj.replace(/\"/g,'"') }; /* ---------------- */ /* CREATE MAP DATATYPE */ function KeyValue( key, value ) { this.key = key; this.value = value; } function Map() { this.array = new Array(); } Map.prototype.put = function( key, value ) { if( ( typeof key != "undefined" ) && ( typeof value != "undefined" ) ) { this.array[this.array.length] = new KeyValue( key, value ); } } Map.prototype.get = function( key ) { for( var k = 0 ; k < this.array.length ; k++ ) { if( this.array[k].key == key ) { return this.array[k].value; } } return ""; } Map.prototype.length = function() { return this.array.length; } /* --------------------------------- */ /* Stage Object */ function Stage() { this.dirty = false; this.redirect = false; this.redirectOutfitId = -1; this.currentOutfitId = -1; this.itemCount = 0; this.defaultName = "Un-Saved Outfit"; } Stage.prototype.makeDirty = function() { this.dirty = true; } Stage.prototype.makeClean = function() { this.dirty = false; } Stage.prototype.isDirty = function() { return this.dirty; } Stage.prototype.needRedirect = function() { return this.redirect; } Stage.prototype.redirectOn = function() { this.redirect = true;} Stage.prototype.redirectOff = function() { this.redirect = false;} Stage.prototype.getRedirectId = function() { return this.redirectOutfitId; } Stage.prototype.setRedirectId = function(id) { this.redirectOutfitId = id; } Stage.prototype.setOutfitId = function(id) { this.currentOutfitId = id; } Stage.prototype.getOutfitId = function() { return this.currentOutfitId; } Stage.prototype.getItemCount = function() { return this.itemCount; } Stage.prototype.addItem = function() { this.itemCount++; } Stage.prototype.removeItem = function() { this.itemCount--; } Stage.prototype.clearItems = function() { this.itemCount = 0; } Stage.prototype.reset = function() { $("#o-stage-outfit-name").html( this.defaultName ); $("#o-stage-outfit-name-visible").html( this.defaultName ); this.currentOutfitId = -1; this.itemCount = 0; this.dirty = false; } /* ---------------------------------- */ /* Tab Interface */ function TabInterface() { this.currentTab = "null"; this.tabNames = new Map(); this.tabArray = new Array(); this.actionArray = new Array(); this.tabOn = new Array(); this.tabOff = new Array(); this.putTabContentHere = "#o-closet-other-area"; this.tabActiveSufix = "-active"; this.tabFileType = ".gif"; this.activeTabId = "active-tab"; this.itemListId = new Array(); } TabInterface.prototype.getCurrentTab = function() { return this.currentTab; } TabInterface.prototype.addTab = function(id,jqueryId,action,filename,itemAreaId) { this.tabNames.put(id, this.tabArray.length); this.tabArray[this.tabArray.length] = jqueryId; this.actionArray[this.actionArray.length] = action; this.tabOff[this.tabOff.length] = "" + "/assets/ws/images/outfitter/tabs/" + filename + this.tabFileType; this.tabOn[this.tabOn.length] = "" + "/assets/ws/images/outfitter/tabs/" + filename + this.tabActiveSufix + this.tabFileType; this.itemListId[this.itemListId.length] = itemAreaId; } TabInterface.prototype.getActiveTabId = function() { return this.activeTabId; } TabInterface.prototype.getTabImageOn = function(name) { return this.tabOn[ this.tabNames.get(name) ]; } TabInterface.prototype.getTabImageOff = function(name) { return this.tabOff[ this.tabNames.get(name) ]; } TabInterface.prototype.showTab = function(name) { if(name != this.currentTab) { removeManagelayer(); } // hide the current active tab if (this.currentTab != "null" ) { $(this.tabArray[this.tabNames.get(this.currentTab)]).hide(); } // update the currentTab this.currentTab = name; // check to see if we need to load tab or just show tab if( $(this.tabArray[this.tabNames.get(this.currentTab)]).size() == 0 ) { updateHTML(this.actionArray[this.tabNames.get(this.currentTab)],'','GET',this.putTabContentHere); } else { $(this.tabArray[this.tabNames.get(this.currentTab)]).show(); } } TabInterface.prototype.tabRemove = function(tabName) { $(this.tabArray[this.tabNames.get(tabName)]).parent().remove(); } /* -------------------------------- */ /* Manage Layer Interface */ function manageLayerInterface() { this.dirty = false; this.sortBy = ""; this.sortToggle = 1; this.activeLayerId = 0; this.idArray = new Map(); this.actionArray = new Array(); this.hideThis = new Array(); this.actionTableArray = new Array(); this.parameterName = new Array(); this.manageArea = "#o-manage-layer"; this.tableArea = "#o-manage-outfit-table-container"; } manageLayerInterface.prototype.addManageLayer = function(name,hideArea,action,tableAction,parm) { this.idArray.put(name, this.actionArray.length ); this.actionArray[this.actionArray.length] = action; this.hideThis[this.hideThis.length] = hideArea; this.actionTableArray[this.actionTableArray.length] = tableAction; this.parameterName[this.parameterName.length] = parm; } manageLayerInterface.prototype.openManage = function(name) { this.dirty = false; this.activeLayerId = this.idArray.get(name); // load the area, show the area $("#o-stage-item-popup .btn-close-stage-popup").click(); $(this.hideThis[this.activeLayerId]).hide(); $(this.manageArea).show(); updateHTML(this.actionArray[this.activeLayerId],'','GET',this.manageArea); } manageLayerInterface.prototype.removeManage = function() { $(this.manageArea).hide(); $(this.manageArea + "*").remove(); $("#o-manage-loading2").hide(); this.dirty = false; } manageLayerInterface.prototype.makeDirty = function() { this.dirty = true; } manageLayerInterface.prototype.isDirty = function() { return this.dirty; } manageLayerInterface.prototype.removeObject = function(name,id) { this.dirty = true; params = "type=" + name + "&"; params = params + this.parameterName[this.activeLayerId] + "=" + id; updateHTML( this.actionTableArray[this.activeLayerId], params, 'GET', this.tableArea ); } manageLayerInterface.prototype.getSortToggle = function() { this.sortToggle = this.sortToggle * -1; return this.sortToggle; } /* -------------------------- */ /* zIndexObject */ /* ---------------------------- */ function zIndexObject() { this.z_front = 1010 ; this.z_back = 1000; } zIndexObject.prototype.reset = function() { this.z_front = 1010; this.z_back = 1000; } zIndexObject.prototype.addObjectZ = function(z) { this.z_front = (z > this.z_front) ? z : this.z_front; this.z_back = (z < this.z_back) ? z : this.z_back; } zIndexObject.prototype.getFront = function() { this.z_front = this.z_front + 30; return this.z_front; } zIndexObject.prototype.getBack = function() { this.z_back = this.z_back - 30; return this.z_back; } zIndexObject.prototype.forward = function(obj) { cZ = parseInt($(obj).css("z-index")) nZ = this.getFront(); nnZ = nZ; $(".o-stage-image").each(function() { thisZ = parseInt($(this).css("z-index")); if( thisZ > cZ && thisZ < nZ ) { nnZ = nZ; nZ = thisZ; } }); z = parseInt((nZ + nnZ) / 2); this.addObjectZ(z); $(obj).css("z-index", z); } zIndexObject.prototype.backward = function(obj) { cZ = parseInt($(obj).css("z-index")) pZ = this.getBack(); ppZ = pZ; $(".o-stage-image").each(function() { thisZ = parseInt($(this).css("z-index")); if ( thisZ < cZ && thisZ > pZ ) { pZ = thisZ; } if( thisZ < cZ && thisZ < pZ && thisZ > ppZ) { ppZ = thisZ; } }); z = parseInt((pZ + ppZ) / 2); this.addObjectZ(z); $(obj).css("z-index", z); } /* ----------------------------- */ /* Sortable Object */ function Sortable() { this.sortFieldName = new Map(); this.sortFieldState = new Array(); activeField = ""; } Sortable.prototype.addField = function(name) { this.sortFieldName.put(name,this.sortFieldState.length); this.sortFieldState[this.sortFieldState.length] = 1; } Sortable.prototype.changeFieldState = function(name) { if( this.activeField == name ) { this.sortFieldState[this.sortFieldName.get(name)] = this.sortFieldState[this.sortFieldName.get(name)] * -1; } else { this.activeField = name; } } Sortable.prototype.getFieldState = function(name) { return this.sortFieldState[this.sortFieldName.get(name)]; } Sortable.prototype.getActiveField = function() { return this.activeField; } Sortable.prototype.resetState = function() { for(x = 0; x < this.sortFieldState.length; x++) { this.sortFieldState[x] = 1; } this.activeField = ""; } /* ----------------------- */ /* Global Variables */ /* Sortable Objects */ var messagesSort = new Sortable(); messagesSort.addField("from"); messagesSort.addField("subject"); messagesSort.addField("date"); messagesSort.addField("screenName"); /* Stage Object */ var theStage = new Stage(); /* TabInterface Object */ var outfitterTabs = new TabInterface(); outfitterTabs.addTab("tabWardrobe", "#o-my-closet", "showCloset","tab-my-wardrobe","#o-my-closet-items"); outfitterTabs.addTab("tabOutfits", "#o-my-outfits", "showOutfits","tab-my-outfits","#o-my-closet-outfits"); outfitterTabs.addTab("tabMessages", "#o-messages", "showMessages","tab-messages",""); /* ManagelayerInterface Object */ var outfitterManageLayer = new manageLayerInterface(); outfitterManageLayer.addManageLayer("wardrobe","#o-my-closet","manageItems","removeItemManage","productVariantId"); outfitterManageLayer.addManageLayer("outfits","#o-my-outfits","manageOutfits","removeOutfitManage","outfitId"); /* Z-index Object */ var stageZ = new zIndexObject(); /* Misc Variables */ var editOutfitId = -1; var saveTagsTop = 0; var saveTagsShowingLastId = 0; var closetMessage = 0; var outfitInfoHeight = 111; var outfitInfoElCurrentS = 0; var outfitInfoElCurrentE = 0; var outfitInfoPrevH = 0; var outfitTagHeight = 72; var outfitTagElCurrentS = 0; var outfitTagElCurrentE = 0; var outfitTagPrevH = 0; var saveTagHeight = 111; var saveTagElCurrentS = 0; var saveTagElCurrentE = 0; var saveTagPrevH = 0; var imageSizer = new Image(); /* ------------------------------------- */