diff --git a/src/js/base/ripe.js b/src/js/base/ripe.js index 6ea7a66ad..9092656cd 100644 --- a/src/js/base/ripe.js +++ b/src/js/base/ripe.js @@ -191,19 +191,12 @@ ripe.Ripe.prototype.setParts = function(update, noUpdate, options) { update = this._partsList(update); } - if (!noUpdate) { - this.trigger("pre_parts", this.parts, options); - } - - for (var index = 0; index < update.length; index++) { - var part = update[index]; - this._setPart(part[0], part[1], part[2]); - } - if (noUpdate) { - return; + return this._setParts(update); } + this.trigger("pre_parts", this.parts, options); + this._setParts(update); this.update(); this.trigger("parts", this.parts, options); this.trigger("post_parts", this.parts, options); @@ -367,6 +360,13 @@ ripe.Ripe.prototype._setPart = function(part, material, color) { this.trigger("post_part", part, value); }; +ripe.Ripe.prototype._setParts = function(update) { + for (var index = 0; index < update.length; index++) { + var part = update[index]; + this._setPart(part[0], part[1], part[2]); + } +}; + ripe.Ripe.prototype._partsList = function(parts) { parts = parts || this.parts; var partsList = []; diff --git a/src/js/ripe-min.js b/src/js/ripe-min.js index 3bf8d79e6..24114cae7 100644 --- a/src/js/ripe-min.js +++ b/src/js/ripe-min.js @@ -23,16 +23,14 @@ for(index=this.plugins.length-1;index>=0;index--){var plugin=this.plugins[index] ripe.Observable.prototype.deinit.call(this);};ripe.Ripe.prototype.load=function(){this.update();};ripe.Ripe.prototype.unload=function(){};ripe.Ripe.prototype.config=function(brand,model,options){this.brand=brand;this.model=model;options=ripe.assign({update:true},this.options,options);this.setOptions(options);var hasParts=this.parts&&Object.keys(this.parts).length!==0;var loadDefaults=!hasParts&&this.useDefaults;var loadParts=loadDefaults?this.getDefaults:function(callback){setTimeout(callback);};loadParts.call(this,function(result){result=result||this.parts;this.history=[];this.historyPointer=-1;if(this.ready===false){this.ready=true;this.trigger("ready");} this.setParts(result);this.remote();this.update();}.bind(this));var update=this.options.update||false;this.ready=update?this.ready:hasParts;this.trigger("config");};ripe.Ripe.prototype.remote=function(){var loadCombinations=this.useCombinations;loadCombinations&&this.getCombinations(function(result){this.combinations=result;this.trigger("combinations",this.combinations);}.bind(this));};ripe.Ripe.prototype.setOptions=function(options){this.options=options||{};this.variant=this.options.variant||null;this.url=this.options.url||"https://sandbox.platforme.com/api/";this.parts=this.options.parts||{};this.country=this.options.country||null;this.currency=this.options.currency||null;this.format=this.options.format||"jpeg";this.backgroundColor=this.options.backgroundColor||"";this.noDefaults=this.options.noDefaults===undefined?false:this.options.noDefaults;this.useDefaults=this.options.useDefaults===undefined?!this.noDefaults:this.options.useDefaults;this.noCombinations=this.options.noCombinations===undefined?false:this.options.noCombinations;this.useCombinations=this.options.useCombinations===undefined?!this.noCombinations:this.options.useCombinations;this.noPrice=this.options.noPrice===undefined?false:this.options.noPrice;this.usePrice=this.options.usePrice===undefined?!this.noPrice:this.options.usePrice;this.backgroundColor=this.backgroundColor.replace("#","");};ripe.Ripe.prototype.setPart=function(part,material,color,noUpdate,options){if(noUpdate){return this._setPart(part,material,color);} this.trigger("pre_parts",this.parts,options);this._setPart(part,material,color);this.update();this.trigger("parts",this.parts,options);this.trigger("post_parts",this.parts,options);};ripe.Ripe.prototype.setParts=function(update,noUpdate,options){if(typeof update==="object"&&!Array.isArray(update)){update=this._partsList(update);} -if(!noUpdate){this.trigger("pre_parts",this.parts,options);} -for(var index=0;index0;};ripe.Ripe.prototype.canRedo=function(){return this.history.length-1>this.historyPointer;};ripe.Ripe.prototype.addPlugin=function(plugin){plugin.register(this);this.plugins.push(plugin);};ripe.Ripe.prototype.removePlugin=function(plugin){plugin.unregister(this);this.plugins.splice(this.plugins.indexOf(plugin),1);};ripe.Ripe.prototype._getState=function(){return{parts:this.parts,initials:this.initials,engraving:this.engraving};};ripe.Ripe.prototype._setPart=function(part,material,color){var value=this.parts[part]||{};value.material=material;value.color=color;this.parts[part]=value;this.trigger("pre_part",part,value);this.trigger("part",part,value);this.trigger("post_part",part,value);};ripe.Ripe.prototype._partsList=function(parts){parts=parts||this.parts;var partsList=[];for(var part in parts){var value=parts[part];partsList.push([part,value.material,value.color]);} +this.historyPointer+=1;var parts=this.history[this.historyPointer];parts&&this.setParts(parts,false,{action:"redo"});};ripe.Ripe.prototype.canUndo=function(){return this.historyPointer>0;};ripe.Ripe.prototype.canRedo=function(){return this.history.length-1>this.historyPointer;};ripe.Ripe.prototype.addPlugin=function(plugin){plugin.register(this);this.plugins.push(plugin);};ripe.Ripe.prototype.removePlugin=function(plugin){plugin.unregister(this);this.plugins.splice(this.plugins.indexOf(plugin),1);};ripe.Ripe.prototype._getState=function(){return{parts:this.parts,initials:this.initials,engraving:this.engraving};};ripe.Ripe.prototype._setPart=function(part,material,color){var value=this.parts[part]||{};value.material=material;value.color=color;this.parts[part]=value;this.trigger("pre_part",part,value);this.trigger("part",part,value);this.trigger("post_part",part,value);};ripe.Ripe.prototype._setParts=function(update){for(var index=0;indexinitial?Math.min(value,final):Math.max(value,final);element.style[property]=value;last=current;var incrementAnimation=final>initial&&valuefinal;if(incrementAnimation||decrementAnimation){var id=requestAnimationFrame(frame);element.dataset.animation_id=id;}else{callback&&callback();}};frame();};ripe.getFrameKey=function(view,position,token){token=token||"-";return view+token+position;};ripe.parseFrameKey=function(frame,token){token=token||"-";return frame.split(token);};ripe.frameNameHack=function(frame){if(!frame){return"";} var _frame=ripe.parseFrameKey(frame);var view=_frame[0];var position=_frame[1];position=view==="side"?position:view;return position;};ripe.fixEvent=function(event){if(event.hasOwnProperty("offsetX")&&event.offsetX!==undefined){return event;} diff --git a/src/js/ripe.js b/src/js/ripe.js index 066e98294..a09313229 100644 --- a/src/js/ripe.js +++ b/src/js/ripe.js @@ -436,19 +436,12 @@ ripe.Ripe.prototype.setParts = function(update, noUpdate, options) { update = this._partsList(update); } - if (!noUpdate) { - this.trigger("pre_parts", this.parts, options); - } - - for (var index = 0; index < update.length; index++) { - var part = update[index]; - this._setPart(part[0], part[1], part[2]); - } - if (noUpdate) { - return; + return this._setParts(update); } + this.trigger("pre_parts", this.parts, options); + this._setParts(update); this.update(); this.trigger("parts", this.parts, options); this.trigger("post_parts", this.parts, options); @@ -612,6 +605,13 @@ ripe.Ripe.prototype._setPart = function(part, material, color) { this.trigger("post_part", part, value); }; +ripe.Ripe.prototype._setParts = function(update) { + for (var index = 0; index < update.length; index++) { + var part = update[index]; + this._setPart(part[0], part[1], part[2]); + } +}; + ripe.Ripe.prototype._partsList = function(parts) { parts = parts || this.parts; var partsList = []; diff --git a/src/python/ripe_demo/static/js/ripe.js b/src/python/ripe_demo/static/js/ripe.js index 066e98294..a09313229 100644 --- a/src/python/ripe_demo/static/js/ripe.js +++ b/src/python/ripe_demo/static/js/ripe.js @@ -436,19 +436,12 @@ ripe.Ripe.prototype.setParts = function(update, noUpdate, options) { update = this._partsList(update); } - if (!noUpdate) { - this.trigger("pre_parts", this.parts, options); - } - - for (var index = 0; index < update.length; index++) { - var part = update[index]; - this._setPart(part[0], part[1], part[2]); - } - if (noUpdate) { - return; + return this._setParts(update); } + this.trigger("pre_parts", this.parts, options); + this._setParts(update); this.update(); this.trigger("parts", this.parts, options); this.trigger("post_parts", this.parts, options); @@ -612,6 +605,13 @@ ripe.Ripe.prototype._setPart = function(part, material, color) { this.trigger("post_part", part, value); }; +ripe.Ripe.prototype._setParts = function(update) { + for (var index = 0; index < update.length; index++) { + var part = update[index]; + this._setPart(part[0], part[1], part[2]); + } +}; + ripe.Ripe.prototype._partsList = function(parts) { parts = parts || this.parts; var partsList = [];