mooSocial Javascript upgrade guide

Overview

The Javascript Layer of Moosocial is changed in the way that it is divided into modules . It is using RequireJS as module loader to load nested moosocial javascript  module dependencies . It means that you need to change the way you are using the jQuery in your customization code .

Requires only jQuery library

If your code requires only jQuery library that looked like the sample code below  :

$( document ).ready(function() {

    // Your code

});

 You can upgrade it  like this :

require(["jquery"], function($){

    $( document ).ready(function() {

         // Your code

      });

});

Requires jQuery library and plugin which doesn’t support AMD

We assume that you are want to add magnificPopup plugin which is saved in mooStie/app/webroot/js/sample/jquery.mp.min.js , you need go to moosite/app/Lib/MooViewListener.php , then:

  1. Adding the code
    • 'magnificPopupSample’=>$v->Helpers->MooRequirejs->assetUrlJS('js/sample/jquery.mp.min.js'),
    • below the line 532 ( mooSocial 2.4.0)
    • 'textcomplete'=>$v->Helpers->MooRequirejs->assetUrlJS('js/global/jquery-textcomplete/jquery.textcomplete.js'),
  2. Adding  the code
    • 'magnificPopupSample'=>array("deps" =>array('jquery')),
    • below the line 599 ( mooSocial 2.4.0)
    • 'simplemodal'=>array("deps" =>array('jquery','mooPhrase')),

You can using the magnificPopupSample plugin is very simple by using this code  :

require(["jquery”,'magnificPopupSample'], function($){

$('.attached-image').magnificPopup({
    type:'image',
    gallery: { enabled: true },
    zoom: {
        enabled: true,
        opener: function(openerElement) {
            return openerElement;
        }
    }
});

Requires jQuery library and plugin which  support AMD

If the plugin supports AMD , you just do the step 1 in “requires jQuery library and plugin which doesn’t support AMD” . Then using the example code bellow ( we assumed that we are using  the mooAlert plugin in mooSite ) 

require(["mooAlert"],function(mooAlert){  mooAlert.alert('please_select_area_for_cropping');});

How to check your plugin is using that supports AMD 

You can check the the plugin is using the Universal Module Definition pattern , for more infomatinon , see https://github.com/jquery-boilerplate/jquery-patterns/blob/master/patterns/amd%2Bcommonjs/pluginCore.js

Posted in How To on 05/21/16 at 00:25
Comments (10)
Eddie Layla Hope that will help you get familiar with mooSocial Javascript in 2.4.0 version .
Eddie  
Thanks... I do hope you guys will add more ways to edit the core files and update the wiki for mooSocial... as I'm sure a lot of people would like to see this too.
shohbek  
How to control css library in mooSocial like cakephp , or there is deference , Please help me
Long Tran   
Hi , You can follow this code to add CSS to your mooosocial site .
<?php echo $this->Html->css(array( ' YOURFILENAME ' ) , array('inline' => false)); ?>
shohbek  
Yes , I tried like that many times , This cakephp functionality , I am afraid of that moosocial team changed cakephp functionality ,Traditional way in cakephp your answer correct , but I guess some adding extra css and scripts are not supported by moosocial in traditional way
shohbek  
For example , How to add javascript libs without requirejs functionality , I want to add new javascript which isn't AMD script type , So I cannot use requirejs here , I want to add javascript libs and css lib in terms of traditional way of cakephp , but it does't support , Long Tran can you help me , Moosocial team please help me !!!
We assume that you are using default theme .
First , you need to add the code bellow to your default file /app/View/Layouts/default.ctp in header tag :
<?php echo $this->fetch('yourCustomJS' ) ; ?>

Second , you can add your libs by using the code like bellow :
<?php echo $this->Html->script('your-libs', array('block' => 'yourCustomJS' ) ) ; ?>

For more information , you can see : https://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#HtmlHelper::script
shohbek  
I confused , yourcustomjs is my js file , what does it mean 'your-libs'
No login
Login or register to post your comment
Cookies on mooCommunity - Social Networking Script.
This site uses cookies to store your information on your computer.