Skip to main content

Some questions about a H5P-tutorial

this is my first post on stackoverflow.com, I try to follow the posting guide lines. Sorry, that my english is not as good as I would like.

1. Summarize the Problem

I'am trying to get started with H5P and javascript to create simple applications for my pupils in Moodle.

I started with this tutorial. I managed to reproduce the code und create the greetingcard-H5P-application. It worked in my Moodle. I tried to understand the whole code in the file greetingcard.js, but I still have some problems.

My goal is to understand the code, so that I can get a better understanding, how H5P works and create my own small H5P-applications.

2. Describe, what you have tried

I did a few days of internet research to understand some syntax issues, that are unfamiliar for me. I also tried to make some adjustments on the code, to figure out, how it works. For example I tried to add a second text field.

So far, I got a vague understanding how it works. The function in the file 'javascript.js' is created and executed immediately with the parameter 'H5P.jQuery' after it is preloaded by the file 'library.json'. In the first step, there is a constructor function, that extends the parameter 'options' and stores the parameter 'id'. In the second step, a function is attached to function C. In this function, the text field and the picture ist added. At the end, the object C ist returned.

Now I have some question to get a better understanding of the tutorial.

Questions

  1. Why ist the variable H5P defined as H5P? Ist this a special type of a variable? Why is there an or-condition?
var H5P = H5P || {};
  1. Where does the parameters options and id come from? Are they part of the jQuery-Object?
function C(options, id) {
  1. Where does the $Container come from. I assume it is a variable, that is somehow part of the jQuery-Object. Is this right?
 C.prototype.attach = function ($container) {
  1. The constructor function ist defined, but it is never executed. At which part of the code is the object C created?

  2. What happens with the C after it is returned at the end of the code.

Thanks in advance for any answers. I would also appreciate links to tutorials, which explain how to create H5P-applications.

MC

Full Code of Javascript.js

var H5P = H5P || {};
 
H5P.GreetingCard = (function ($) {
  /**
   * Constructor function.
   */
  function C(options, id) {
    // Extend defaults with provided options
    this.options = $.extend(true, {}, {
      greeting: 'Hello world!',
      image: null
    }, options);
    // Keep provided id.
    this.id = id;
  };
 
  /**
   * Attach function called by H5P framework to insert H5P content into
   * page
   *
   * @param {jQuery} $container
   */
  C.prototype.attach = function ($container) {
    // Set class on container to identify it as a greeting card
    // container.  Allows for styling later.
    $container.addClass("h5p-greetingcard");
    // Add image if provided.
    if (this.options.image && this.options.image.path) {
      $container.append('<img class="greeting-image" src="' + H5P.getPath(this.options.image.path, this.id) + '">');
    }
    // Add greeting text.
    $container.append('<div class="greeting-text">' + this.options.greeting + '</div>');
  };
 
  return C;
})(H5P.jQuery);
Via Active questions tagged javascript - Stack Overflow https://ift.tt/2FdjaAW

Comments

Popular posts from this blog

How to show number of registered users in Laravel based on usertype?

i'm trying to display data from the database in the admin dashboard i used this: <?php use Illuminate\Support\Facades\DB; $users = DB::table('users')->count(); echo $users; ?> and i have successfully get the correct data from the database but what if i want to display a specific data for example in this user table there is "usertype" that specify if the user is normal user or admin i want to user the same code above but to display a specific usertype i tried this: <?php use Illuminate\Support\Facades\DB; $users = DB::table('users')->count()->WHERE usertype =admin; echo $users; ?> but it didn't work, what am i doing wrong? source https://stackoverflow.com/questions/68199726/how-to-show-number-of-registered-users-in-laravel-based-on-usertype

Why is my reports service not connecting?

I am trying to pull some data from a Postgres database using Node.js and node-postures but I can't figure out why my service isn't connecting. my routes/index.js file: const express = require('express'); const router = express.Router(); const ordersCountController = require('../controllers/ordersCountController'); const ordersController = require('../controllers/ordersController'); const weeklyReportsController = require('../controllers/weeklyReportsController'); router.get('/orders_count', ordersCountController); router.get('/orders', ordersController); router.get('/weekly_reports', weeklyReportsController); module.exports = router; My controllers/weeklyReportsController.js file: const weeklyReportsService = require('../services/weeklyReportsService'); const weeklyReportsController = async (req, res) => { try { const data = await weeklyReportsService; res.json({data}) console

How to split a rinex file if I need 24 hours data

Trying to divide rinex file using the command gfzrnx but getting this error. While doing that getting this error msg 'gfzrnx' is not recognized as an internal or external command Trying to split rinex file using the command gfzrnx. also install'gfzrnx'. my doubt is I need to run this program in 'gfzrnx' or in 'cmdprompt'. I am expecting a rinex file with 24 hrs or 1 day data.I Have 48 hrs data in RINEX format. Please help me to solve this issue. source https://stackoverflow.com/questions/75385367/how-to-split-a-rinex-file-if-i-need-24-hours-data