Skip to content

Commit

Permalink
fix global object and clean - fix destroy after use
Browse files Browse the repository at this point in the history
  • Loading branch information
janfix committed Feb 7, 2023
1 parent 61bd3ff commit 572491f
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,33 +21,34 @@ define([
var GGBPCIStateQuestion = stateFactory.extend(Question, function () {



console.log("STATEFACTORY 2 : First code to be read")


}, function () {


console.log("STATEFACTORY 1 : it is coming at the end of the loading")


});

GGBPCIStateQuestion.prototype.initForm = function() {

//Rappel : interaction.prop() is a setter for config in renderer
// interaction.properties = config in render



var _widget = this.widget,
Sform = _widget.$form,
interaction = _widget.element,
response = interaction.getResponseDeclaration(),
response = interaction.getResponseDeclaration(),
//GGB - APP Parameters get from pciCreator
param_appName = interaction.prop('param').appName,
param_width = interaction.prop('param').width,
param_height = interaction.prop('param').height,
param_enableShiftDragZoom = interaction.prop('param').enableShiftDragZoom,
param_showZoomButtons = interaction.prop('param').showZoomButtons,
param_showFullscreenButton = interaction.prop('param').showFullscreenButton,
param_language = interaction.prop('param').language,
// param_country = interaction.prop('param').country,
param_showMenuBar = interaction.prop('param').showMenuBar,
param_showToolBar = interaction.prop('param').showToolBar,
param_allowStyleBar = interaction.prop('param').allowStyleBar,
Expand All @@ -56,7 +57,11 @@ define([
param_saveB64 = interaction.prop('resp').data,
param_AnswerSet = interaction.prop('resp').answerSet;




//response.correctResponse = 1

var correct = _.values(interaction.getResponseDeclaration().getCorrect());

//This is the responseDeclaration in XML
Expand All @@ -79,10 +84,13 @@ define([
//init form javascript
formElement.initWidget(Sform);



$(".saveAppData").on("click", function() {

interaction.properties.state = "modified";
interaction.properties.param.filename="saved";
interaction.properties.param.filename="saved";

interaction.triggerPci('dataChange', [interaction.properties]); // Send it to AMD for action

})
Expand Down Expand Up @@ -134,7 +142,6 @@ define([

Sform.find("#RightClick").on("click", function() {
let toggle = $(this).prop("checked");
console.log(toggle);
interaction.triggerPci('RightClickChange', [toggle]); // Send it to AMD for action
interaction.properties.param.enableRightClick = toggle;

Expand Down Expand Up @@ -168,23 +175,13 @@ define([
interaction.properties.param.showZoomButtons = GGBConfig.appShowZoomBT;
interaction.properties.param.showFullscreenButton = GGBConfig.appShowFScreenBT;
interaction.properties.param.language = GGBConfig.language;
//interaction.properties.param.country = GGBConfig.country;
interaction.properties.param.showMenuBar = GGBConfig.MenuBar;
interaction.properties.param.showToolBar = GGBConfig.ToolBar;
interaction.properties.param.algebraInputPosition = true;
interaction.properties.param.allowStyleBar = GGBConfig.StyleBar;
interaction.properties.param.enableRightClick = GGBConfig.RightClick;
interaction.properties.param.enableUndoRedo = GGBConfig.UndoRedo;

/* try {
console.log("NO DATA");
//ggbApplet.getBase64(function(b) { GGBConfig.file = b });
} catch (error) {
//console.error(error);
GGBConfig.file = "";
console.log(error);
} */

interaction.triggerPci('appChange', [GGBConfig]); // Send it to AMD for action

});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ define(['qtiCustomInteractionContext',
* @param {Object} [state] - the json serialized state object, returned by previous call to getStatus(), use to initialize an
*/
getInstance: function getInstance(dom, config, state) {

var response = config.boundTo;

config.properties.param = JSON.parse(config.properties.param)
config.properties.resp = JSON.parse(config.properties.resp)

Expand Down Expand Up @@ -159,9 +159,11 @@ define(['qtiCustomInteractionContext',
* @param {Object} interaction
*/
destroy: function () {
if (typeof this.api !== "undefined") {
this.api.remove();
if (typeof this.previewApplet !== "undefined") {
this.previewApplet.remove();
}

//window.ggbApplet.remove()

var $container = $(this.dom);
$container.off().empty();
Expand Down Expand Up @@ -202,6 +204,7 @@ define(['qtiCustomInteractionContext',
//renderer.render(_this, _this.dom, _this.config, assetManager);
renderer.render(_this, _this.dom, config, assetManager);


//Listening to Change Data called from Question after changing values for config
this.on('dataChange', function (conf) {

Expand Down Expand Up @@ -265,7 +268,8 @@ define(['qtiCustomInteractionContext',

} else {
// Fail code

console.log(data.thumbUrl);
console.log('No valid Thumbnail found ! Sorry')
$('#miniat').html("");
}
});
Expand Down Expand Up @@ -326,9 +330,13 @@ define(['qtiCustomInteractionContext',

setTimeout(() => {
$(_this.dom).find(".groupPanel").removeAttr("style");

// $(_this.dom).find(".groupPanel").css("backgroundColor", "red");
$(_this.dom).find(".groupPanel").css("width", "");

$(_this.dom).find(".mowColorPlusButton").css("width", "");
$(_this.dom).find(".mowColorPlusButton").css("top", "");
//$(_this.dom).find(".groupPanel").css("width", "360px!important");
}, 500);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ define(['GGBPCI/interaction/runtime/js/lib/deployggb'], function(GGBApplet) {
'use strict';

function instancer(pciObj, $container, config) {

var ggbdom = "ggb_" + Date.now();
$container.find(".GGBPCI").append('<div class=' + ggbdom + '></div>');

if ($container.parent().hasClass('widget-box')) {

initGGB(config);
} else {

previeGGBPCI(config)
}

Expand Down Expand Up @@ -51,6 +53,7 @@ define(['GGBPCI/interaction/runtime/js/lib/deployggb'], function(GGBApplet) {
function initGGB(config) {
if (config.param.filename.length > 0) {
var ggbApp = new GGBApplet({
id: "ggbAssess",
filename: config.param.filename,
detachKeyboard: false,
appName: config.param.appName,
Expand Down Expand Up @@ -87,10 +90,9 @@ define(['GGBPCI/interaction/runtime/js/lib/deployggb'], function(GGBApplet) {
ggbApp.inject(ggbdom);
cssCorrecter();



} else {
var ggbApp = new GGBApplet({
id: "ggbAssess",
detachKeyboard : false,
appName : config.param.appName,
showToolBar : config.param.showToolBar,
Expand Down Expand Up @@ -129,8 +131,9 @@ define(['GGBPCI/interaction/runtime/js/lib/deployggb'], function(GGBApplet) {
}

function previeGGBPCI(config) {

var ggbApp = new GGBApplet({
id: "ggbAssess",
detachKeyboard: false,
appName: config.param.appName,
showToolBar: config.param.showToolBar,
Expand Down Expand Up @@ -161,12 +164,11 @@ define(['GGBPCI/interaction/runtime/js/lib/deployggb'], function(GGBApplet) {
pciObj.previewApplet = api;
} else {
pciObj.previewApplet = api;
}
}
}
}, true);

ggbApp.inject(ggbdom);

cssCorrecter()

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -383,9 +383,11 @@
web3d.succeeded = web3d.succeeded || web3d() //JANFIX : Here is the launcher
}
scriptLoaded()
console.log("JPTRACKER1")
console.log("JPTRACKER100")

} else if (html5Codebase.requirejs) { require(["geogebra/runtime/js/web3d/web3d.nocache"], scriptLoaded); } else { // original
} else if (html5Codebase.requirejs) {
//require(["geogebra/runtime/js/web3d/web3d.nocache"], scriptLoaded);
} else { // original
script.onload = scriptLoaded;
appletElem.appendChild(script)
console.log("JPTRACKER2")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ define(['taoQtiItem/portableLib/jquery_2_1_1',
'use strict';

function renderChoices(pciObj, $container, config) {

instancer.ggb(pciObj, $container, config);

}
Expand Down

0 comments on commit 572491f

Please sign in to comment.