<commit_before>define(["/dev/configuration/config.js", "/dev/configuration/env.js"], function(config) {

    // Insert custom configuration here

    // myberkeley custom begin

    // This is our custom CAS log in information.
    config.Authentication.internal = config.isDev;
    config.Authentication.external = [
        {
          label: "Login using your CalNet ID",
          login_btn: "LOGIN_BTN",
          url: "/system/sling/cas/login?resource=/dev/me.html",
          description: "CAS_NOTE"
        }
    ];
    config.Authentication.allowInternalAccountCreation = false;
    config.Authentication.hideLoginOn = [
        "/dev/create_new_account.html"
    ];
    config.allowPasswordChange = false;

    // set our own default widget arrangement
    config.defaultprivstructure.id546341435.dashboard.columns.column1[1] = {
      "uid": "id7813904133752",
      "visible": "block",
      "name": "mytasks"
    };

    config.defaultprivstructure.id546341435.dashboard.columns.column2[1] = {
        "uid": "id12893445620912",
        "visible": "block",
        "name": "myevents"
    };

    config.defaultprivstructure.id546341435.dashboard.columns.column3[1] = {
        "uid": "id63754673110789",
        "visible": "block",
        "name": "mylinks"
    };

    // Overriding Sakai profile
    // Basic Information --------------
    config.Profile.configuration.defaultConfig.basic.elements = {
        "firstName": {
            "label": "__MSG__PROFILE_BASIC_FIRSTNAME_LABEL__",
            "required": true,
            "display": true,
            "editable": false,
            "limitDisplayLength": 50
        },
        "lastName": {
            "label": "__MSG__PROFILE_BASIC_LASTNAME_LABEL__",
            "required": true,
            "display": true,
            "editable": false,
            "limitDisplayLength": 50
        },
        "picture": {
            "label": "__MSG__PROFILE_BASIC_PICTURE_LABEL__",
            "required": false,
            "display": false
        },
        "preferredName": {
            "label": "__MSG__PROFILE_BASIC_PREFERREDNAME_LABEL__",
            "required": false,
            "display": true
        },
        "email": {
            "label": "__MSG__PROFILE_BASIC_EMAIL_LABEL__",
            "required": false,
            "display": true,
            "editable": false,
            "type": "email"
        },
        "status": {
            "label": "__MSG__PROFILE_BASIC_STATUS_LABEL__",
            "required": false,
            "display": false
        },
        "role": {
            "label": "__MSG__PROFILE_BASIC_ROLE_LABEL__",
            "required": false,
            "display": true,
            "editable": false
        },
        "department": {
            "label": "__MSG__PROFILE_BASIC_DEPARTMENT_LABEL__",
            "required": false,
            "display": true
        },
        "college": {
            "label": "__MSG__PROFILE_BASIC_COLLEGE_LABEL__",
            "required": false,
            "display": true,
            "editable": false
        },
        "major": {
            "label": "__MSG__PROFILE_MAJORORPROGRAM_LABEL__",
            "required": false,
            "display": true,
            "editable": false
        }
    };

	 /*
     * Institution contact details are displayed in the footer
     */
	config.Institution = {
        helpLinkText: "Contact Us",
        helpLinkUrl: "https://confluence.media.berkeley.edu/confluence/display/MYB/Portal+Help",
        helpPhone: ""
    };

    /*
     * These links are displayed in the 403 and 404 error pages.
     */
    config.ErrorPage = {
        Links: {
            whatToDo: [
                {
                    "title": "EXPLORE_MYBERKELEY",
                    "url": "/"
                },
                {
                    "title": "BROWSE_MYBERKELEY_CATEGORIES",
                    "url": "/dev/allcategories.html"
                },
                {
                    "title": "GO_TO_BERKELEY_EDU",
                    "url": "http://berkeley.edu/"
                },
                {
                    "title": "VISIT_THE_SUPPORT_FORUM",
                    "url": "http://sakaiproject.org/"
                }
            ],
            getInTouch: [
                {
                    "title": "SEND_US_YOUR_FEEDBACK",
                    "url": "mailto:portal@berkeley.edu"
                },
                {
                    "title": "CONTACT_SUPPORT",
                    "url": "mailto:portal@berkeley.edu"
                }
            ]
        }
    };

    // so that user gets redirected to CAS logout
    config.followLogoutRedirects = true;

    // remove the SIGN UP feature for anonymous users
    delete(config.Navigation[4]);

    config.Navigation[0].label = "ME";

    // Add My Notification and My Dynamic Lists to Navigation
    config.Navigation[0].subnav.splice(2,0,
        {
            "url": "/dev/me.html#l=notifications/drafts",
            "id": "subnavigation_notifications_link",
            "label": "MY_NOTIFICATIONS",
            "requiresAdviserMembership": true
        }
    );
    config.Navigation[0].subnav.splice(3,0,
        {
            "url": "/dev/me.html#l=dynlists",
            "id": "subnavigation_dynlists_link",
            "label": "MY_DYNAMIC_LISTS",
            "requiresAdviserMembership": true
        }
    );

	config.Directory = {
		ced: {
			title: "Environmental Design",
			children: {
				architecture: {
					title: "Architecture"
				},
				cityregionalplanning: {
					title: "City & Regional Planning"
				},
				landscapearchitecture: {
					title: "Landscape Architecture & Environmental Planning"
				},
				urbandesign: {
					title: "Urban Design"
				}
			}
		},
		cnr: {
			title: "Natural Resources",
			children: {
				agriculturaleconomics: {
					title: "Agricultural and Resource Economics"
				},
				environmentalscience: {
					title: "Environmental Science, Policy, & Management"
				},
				nutritionalscience: {
					title: "Nutritional Science & Toxicology"
				},
				plantmicrobialbiology: {
					title: "Plant & Microbial Biology"
				}
			}
		},
		studentservices: {
			title: "Student Groups",
			children: {
				stg_academic: {
					title: "Academic"
				},
				stg_arts: {
					title: "Arts"
				},
				stg_cultural: {
					title: "Cultural"
				},
				stg_political: {
					title: "Political"
				},
				stg_professional: {
					title: "Professional"
				},
				stg_sport: {
					title: "Sport"
				},
				stg_religious: {
					title: "Religious"
				},
				stg_service: {
					title: "Service"
				},
				stg_other: {
					title: "Other"
				}
			}
		},
		studentgroups: {
			title: "Student Services",
			children: {
				ss_academic: {
					title: "Academic"
				},
				sd_career: {
					title: "Career"
				},
				ss_financial: {
					title: "Financial"
				},
				ss_campuslife: {
					title: "Campus Life"
				}
			}
		}
	};

    config.Profile = {
        /*
         * This is a collection of profile configuration functions and settings
         * The structure of the config object is identical to the storage object
         * When system/me returns profile data for the logged in user the profile_config and profile_data objects could be merged
         * "label": the internationalizable message for the entry label in HTML
         * "required": {Boolean} Whether the entry is compulsory or not
         * "display": {Boolean} Show the entry in the profile or not
         * "editable": {Boolean} Whether or not the entry is editable
         * For a date entry field use "date" as the type for MM/dd/yyyy and "dateITA" as the type for dd/MM/yyyy
         *
         */
        configuration: {

            defaultConfig: {

                "basic": {
                    "label": "__MSG__PROFILE_BASIC_LABEL__",
                    "required": true,
                    "display": true,
                    "access": "everybody",
                    "modifyacl": false,
                    "order": 0,
                    "elements": {
                        "firstName": {
                            "label": "__MSG__PROFILE_BASIC_FIRSTNAME_LABEL__",
                            "required": true,
                            "display": true,
                            "limitDisplayLength": 50,
                            "editable": false
                        },
                        "lastName": {
                            "label": "__MSG__PROFILE_BASIC_LASTNAME_LABEL__",
                            "required": true,
                            "display": true,
                            "limitDisplayLength": 50,
                            "editable": false
                        },
                        "picture": {
                            "label": "__MSG__PROFILE_BASIC_PICTURE_LABEL__",
                            "required": false,
                            "display": false
                        },
                        "preferredName": {
                            "label": "__MSG__PROFILE_BASIC_PREFERREDNAME_LABEL__",
                            "required": false,
                            "display": true
                        },
                        "status": {
                            "label": "__MSG__PROFILE_BASIC_STATUS_LABEL__",
                            "required": false,
                            "display": false
                        }
                    }
                },
                "email" :{
                    "label": "Email Address",
                    "required": true,
                    "display": true,
                    "access": "everybody",
                    "modifyacl": false,
                    "order": 1,
                    "elements": {
                        "email": {
                            "label": "Email",
                            "required": true,
                            "display": true,
                            "limitDisplayLength": 50,
                            "editable": false
                        }
                    }
                },
                "institutional" : {
                    "label": "Institutional Information",
                    "required": true,
                    "display": true,
                    "access": "everybody",
                    "modifyacl": false,
                    "order": 2,
                    "elements": {
                        "role": {
                            "label": "Role/position",
                            "required": true,
                            "display": true,
                            "limitDisplayLength": 50,
                            "editable": false
                        },
                        "college": {
                            "label": "College",
                            "required": true,
                            "display": true,
                            "limitDisplayLength": 50,
                            "editable": false
                        },
                        "major": {
                            "label": "Major",
                            "required": true,
                            "display": true,
                            "limitDisplayLength": 50,
                            "editable": false
                        }
                    }
                },
                "aboutme": {
                    "label": "__MSG__PROFILE_ABOUTME_LABEL__",
                    "required": true,
                    "display": true,
                    "access": "everybody",
                    "modifyacl": true,
                    "order": 3,
                    "elements": {
                        "aboutme": {
                            "label": "__MSG__PROFILE_ABOUTME_LABEL__",
                            "required": false,
                            "display": true,
                            "type": "textarea"
                        },
                        "academicinterests": {
                            "label": "__MSG__PROFILE_ABOUTME_ACADEMICINTERESTS_LABEL__",
                            "required": false,
                            "display": true,
                            "type": "textarea"
                        },
                        "personalinterests": {
                            "label": "__MSG__PROFILE_ABOUTME_PERSONALINTERESTS_LABEL__",
                            "required": false,
                            "display": true,
                            "type": "textarea"
                        },
                        "hobbies": {
                            "label": "__MSG__PROFILE_ABOUTME_HOBBIES_LABEL__",
                            "required": false,
                            "display": true
                        },
                        "tags": {
                            "label": "__MSG__TAGS__",
                            "required": false,
                            "display": true,
                            "type": "textarea",
                            "tagField": true
                        }
                    }
                },
                "locations": {
                    "label": "__MSG__PROFILE_LOCATIONS_LABEL__",
                    "required": false,
                    "display": true,
                    "access": "everybody",
                    "modifyacl": true,
                    "multiple": true,
                    "directory": true,
                    "multipleLabel": "__MSG__PROFILE_LOCATION_LABEL__",
                    "order": 4,
                    "elements": {
                        "locationtitle": {
                            "label": "__MSG__PROFILE_LOCATION_LABEL__",
                            "required": true,
                            "display": true,
                            "type": "location"
                        }
                    }
                },
                "publications": {
                    "label": "__MSG__PROFILE_PUBLICATIONS_LABEL__",
                    "required": false,
                    "display": true,
                    "access": "everybody",
                    "modifyacl": true,
                    "multiple": true,
                    "multipleLabel": "__MSG__PROFILE_PUBLICATION_LABEL__",
                    "order": 5,
                    //"template": "profile_section_publications_template",
                    "elements": {
                        "maintitle": {
                            "label": "__MSG__PROFILE_PUBLICATIONS_MAIN_TITLE__",
                            "required": true,
                            "display": true,
                            "example": "__MSG__PROFILE_PUBLICATIONS_MAIN_TITLE_EXAMPLE__"
                        },
                        "mainauthor": {
                            "label": "__MSG__PROFILE_PUBLICATIONS_MAIN_AUTHOR__",
                            "required": true,
                            "display": true
                        },
                        "coauthor": {
                            "label": "__MSG__PROFILE_PUBLICATIONS_CO_AUTHOR__",
                            "required": false,
                            "display": true,
                            "example": "__MSG__PROFILE_PUBLICATIONS_CO_AUTHOR_EXAMPLE__"
                        },
                        "publisher": {
                            "label": "__MSG__PROFILE_PUBLICATIONS_PUBLISHER__",
                            "required": true,
                            "display": true
                        },
                        "placeofpublication": {
                            "label": "__MSG__PROFILE_PUBLICATIONS_PLACE_OF_PUBLICATION__",
                            "required": true,
                            "display": true
                        },
                        "volumetitle": {
                            "label": "__MSG__PROFILE_PUBLICATIONS_VOLUME_TITLE__",
                            "required": false,
                            "display": true
                        },
                        "volumeinformation": {
                            "label": "__MSG__PROFILE_PUBLICATIONS_VOLUME_INFORMATION__",
                            "required": false,
                            "display": true,
                            "example": "__MSG__PROFILE_PUBLICATIONS_VOLUME_INFORMATION_EXAMPLE__"
                        },
                        "year": {
                            "label": "__MSG__PROFILE_PUBLICATIONS_YEAR__",
                            "required": true,
                            "display": true
                        },
                        "number": {
                            "label": "__MSG__PROFILE_PUBLICATIONS_NUMBER__",
                            "required": false,
                            "display": true
                        },
                        "series title": {
                            "label": "__MSG__PROFILE_PUBLICATIONS_SERIES_TITLE__",
                            "required": false,
                            "display": true
                        },
                        "url": {
                            "label": "__MSG__PROFILE_PUBLICATIONS_URL__",
                            "required": false,
                            "display": true,
                            "validation": "appendhttp url"
                        }
                    }
                }
            }
        },
        /*
         * set what name to display where only the first name is used
         */
        userFirstNameDisplay: "firstName",

        /*
         * set how the user's name is displayed across the entire system
         * - values can be compound, like "firstName lastName" or singular like "displayName"
         */
        userNameDisplay: "firstName lastName",

        /*
         * the default, if the user doesn't have the userNameDisplay property set in their
         * profile, use this one.
         * Note: the value for userNameDisplay and this value can be the same.
         *       If neither exists, nothing will show
         */
        userNameDefaultDisplay: "firstName lastName",

        /*
         * Set the user's short description to appear underneath their name
         * in search results
         */
        userShortDescription: "${role} in ${department} at ${college}",
        groupShortDescription: "asdf"
    };

    return config;

});
<commit_msg>MYB-603 Remove support forum link; remove obsolete unused config elements<commit_after>define(["/dev/configuration/config.js", "/dev/configuration/env.js"], function(config) {

    // Insert custom configuration here

    // myberkeley custom begin

    // This is our custom CAS log in information.
    config.Authentication.internal = config.isDev;
    config.Authentication.external = [
        {
          label: "Login using your CalNet ID",
          login_btn: "LOGIN_BTN",
          url: "/system/sling/cas/login?resource=/dev/me.html",
          description: "CAS_NOTE"
        }
    ];
    config.Authentication.allowInternalAccountCreation = false;
    config.Authentication.hideLoginOn = [
        "/dev/create_new_account.html"
    ];
    config.allowPasswordChange = false;

    // set our own default widget arrangement
    config.defaultprivstructure.id546341435.dashboard.columns.column1[1] = {
      "uid": "id7813904133752",
      "visible": "block",
      "name": "mytasks"
    };

    config.defaultprivstructure.id546341435.dashboard.columns.column2[1] = {
        "uid": "id12893445620912",
        "visible": "block",
        "name": "myevents"
    };

    config.defaultprivstructure.id546341435.dashboard.columns.column3[1] = {
        "uid": "id63754673110789",
        "visible": "block",
        "name": "mylinks"
    };

    /*
     * These links are displayed in the 403 and 404 error pages.
     */
    config.ErrorPage = {
        Links: {
            whatToDo: [
                {
                    "title": "EXPLORE_MYBERKELEY",
                    "url": "/"
                },
                {
                    "title": "BROWSE_MYBERKELEY_CATEGORIES",
                    "url": "/dev/allcategories.html"
                },
                {
                    "title": "GO_TO_BERKELEY_EDU",
                    "url": "http://berkeley.edu/"
                }
            ],
            getInTouch: [
                {
                    "title": "SEND_US_YOUR_FEEDBACK",
                    "url": "mailto:portal@berkeley.edu"
                },
                {
                    "title": "CONTACT_SUPPORT",
                    "url": "mailto:portal@berkeley.edu"
                }
            ]
        }
    };

    // so that user gets redirected to CAS logout
    config.followLogoutRedirects = true;

    // remove the SIGN UP feature for anonymous users
    delete(config.Navigation[4]);

    config.Navigation[0].label = "ME";

    // Add My Notification and My Dynamic Lists to Navigation
    config.Navigation[0].subnav.splice(2,0,
        {
            "url": "/dev/me.html#l=notifications/drafts",
            "id": "subnavigation_notifications_link",
            "label": "MY_NOTIFICATIONS",
            "requiresAdviserMembership": true
        }
    );
    config.Navigation[0].subnav.splice(3,0,
        {
            "url": "/dev/me.html#l=dynlists",
            "id": "subnavigation_dynlists_link",
            "label": "MY_DYNAMIC_LISTS",
            "requiresAdviserMembership": true
        }
    );

	config.Directory = {
		ced: {
			title: "Environmental Design",
			children: {
				architecture: {
					title: "Architecture"
				},
				cityregionalplanning: {
					title: "City & Regional Planning"
				},
				landscapearchitecture: {
					title: "Landscape Architecture & Environmental Planning"
				},
				urbandesign: {
					title: "Urban Design"
				}
			}
		},
		cnr: {
			title: "Natural Resources",
			children: {
				agriculturaleconomics: {
					title: "Agricultural and Resource Economics"
				},
				environmentalscience: {
					title: "Environmental Science, Policy, & Management"
				},
				nutritionalscience: {
					title: "Nutritional Science & Toxicology"
				},
				plantmicrobialbiology: {
					title: "Plant & Microbial Biology"
				}
			}
		},
		studentservices: {
			title: "Student Groups",
			children: {
				stg_academic: {
					title: "Academic"
				},
				stg_arts: {
					title: "Arts"
				},
				stg_cultural: {
					title: "Cultural"
				},
				stg_political: {
					title: "Political"
				},
				stg_professional: {
					title: "Professional"
				},
				stg_sport: {
					title: "Sport"
				},
				stg_religious: {
					title: "Religious"
				},
				stg_service: {
					title: "Service"
				},
				stg_other: {
					title: "Other"
				}
			}
		},
		studentgroups: {
			title: "Student Services",
			children: {
				ss_academic: {
					title: "Academic"
				},
				sd_career: {
					title: "Career"
				},
				ss_financial: {
					title: "Financial"
				},
				ss_campuslife: {
					title: "Campus Life"
				}
			}
		}
	};

    config.Profile = {
        /*
         * This is a collection of profile configuration functions and settings
         * The structure of the config object is identical to the storage object
         * When system/me returns profile data for the logged in user the profile_config and profile_data objects could be merged
         * "label": the internationalizable message for the entry label in HTML
         * "required": {Boolean} Whether the entry is compulsory or not
         * "display": {Boolean} Show the entry in the profile or not
         * "editable": {Boolean} Whether or not the entry is editable
         * For a date entry field use "date" as the type for MM/dd/yyyy and "dateITA" as the type for dd/MM/yyyy
         *
         */
        configuration: {

            defaultConfig: {

                "basic": {
                    "label": "__MSG__PROFILE_BASIC_LABEL__",
                    "required": true,
                    "display": true,
                    "access": "everybody",
                    "modifyacl": false,
                    "order": 0,
                    "elements": {
                        "firstName": {
                            "label": "__MSG__PROFILE_BASIC_FIRSTNAME_LABEL__",
                            "required": true,
                            "display": true,
                            "limitDisplayLength": 50,
                            "editable": false
                        },
                        "lastName": {
                            "label": "__MSG__PROFILE_BASIC_LASTNAME_LABEL__",
                            "required": true,
                            "display": true,
                            "limitDisplayLength": 50,
                            "editable": false
                        },
                        "picture": {
                            "label": "__MSG__PROFILE_BASIC_PICTURE_LABEL__",
                            "required": false,
                            "display": false
                        },
                        "preferredName": {
                            "label": "__MSG__PROFILE_BASIC_PREFERREDNAME_LABEL__",
                            "required": false,
                            "display": true
                        },
                        "status": {
                            "label": "__MSG__PROFILE_BASIC_STATUS_LABEL__",
                            "required": false,
                            "display": false
                        }
                    }
                },
                "email" :{
                    "label": "Email Address",
                    "required": true,
                    "display": true,
                    "access": "everybody",
                    "modifyacl": false,
                    "order": 1,
                    "elements": {
                        "email": {
                            "label": "Email",
                            "required": true,
                            "display": true,
                            "limitDisplayLength": 50,
                            "editable": false
                        }
                    }
                },
                "institutional" : {
                    "label": "Institutional Information",
                    "required": true,
                    "display": true,
                    "access": "everybody",
                    "modifyacl": false,
                    "order": 2,
                    "elements": {
                        "role": {
                            "label": "Role/position",
                            "required": true,
                            "display": true,
                            "limitDisplayLength": 50,
                            "editable": false
                        },
                        "college": {
                            "label": "College",
                            "required": true,
                            "display": true,
                            "limitDisplayLength": 50,
                            "editable": false
                        },
                        "major": {
                            "label": "Major",
                            "required": true,
                            "display": true,
                            "limitDisplayLength": 50,
                            "editable": false
                        }
                    }
                },
                "aboutme": {
                    "label": "__MSG__PROFILE_ABOUTME_LABEL__",
                    "required": true,
                    "display": true,
                    "access": "everybody",
                    "modifyacl": true,
                    "order": 3,
                    "elements": {
                        "aboutme": {
                            "label": "__MSG__PROFILE_ABOUTME_LABEL__",
                            "required": false,
                            "display": true,
                            "type": "textarea"
                        },
                        "academicinterests": {
                            "label": "__MSG__PROFILE_ABOUTME_ACADEMICINTERESTS_LABEL__",
                            "required": false,
                            "display": true,
                            "type": "textarea"
                        },
                        "personalinterests": {
                            "label": "__MSG__PROFILE_ABOUTME_PERSONALINTERESTS_LABEL__",
                            "required": false,
                            "display": true,
                            "type": "textarea"
                        },
                        "hobbies": {
                            "label": "__MSG__PROFILE_ABOUTME_HOBBIES_LABEL__",
                            "required": false,
                            "display": true
                        },
                        "tags": {
                            "label": "__MSG__TAGS__",
                            "required": false,
                            "display": true,
                            "type": "textarea",
                            "tagField": true
                        }
                    }
                },
                "locations": {
                    "label": "__MSG__PROFILE_LOCATIONS_LABEL__",
                    "required": false,
                    "display": true,
                    "access": "everybody",
                    "modifyacl": true,
                    "multiple": true,
                    "directory": true,
                    "multipleLabel": "__MSG__PROFILE_LOCATION_LABEL__",
                    "order": 4,
                    "elements": {
                        "locationtitle": {
                            "label": "__MSG__PROFILE_LOCATION_LABEL__",
                            "required": true,
                            "display": true,
                            "type": "location"
                        }
                    }
                },
                "publications": {
                    "label": "__MSG__PROFILE_PUBLICATIONS_LABEL__",
                    "required": false,
                    "display": true,
                    "access": "everybody",
                    "modifyacl": true,
                    "multiple": true,
                    "multipleLabel": "__MSG__PROFILE_PUBLICATION_LABEL__",
                    "order": 5,
                    //"template": "profile_section_publications_template",
                    "elements": {
                        "maintitle": {
                            "label": "__MSG__PROFILE_PUBLICATIONS_MAIN_TITLE__",
                            "required": true,
                            "display": true,
                            "example": "__MSG__PROFILE_PUBLICATIONS_MAIN_TITLE_EXAMPLE__"
                        },
                        "mainauthor": {
                            "label": "__MSG__PROFILE_PUBLICATIONS_MAIN_AUTHOR__",
                            "required": true,
                            "display": true
                        },
                        "coauthor": {
                            "label": "__MSG__PROFILE_PUBLICATIONS_CO_AUTHOR__",
                            "required": false,
                            "display": true,
                            "example": "__MSG__PROFILE_PUBLICATIONS_CO_AUTHOR_EXAMPLE__"
                        },
                        "publisher": {
                            "label": "__MSG__PROFILE_PUBLICATIONS_PUBLISHER__",
                            "required": true,
                            "display": true
                        },
                        "placeofpublication": {
                            "label": "__MSG__PROFILE_PUBLICATIONS_PLACE_OF_PUBLICATION__",
                            "required": true,
                            "display": true
                        },
                        "volumetitle": {
                            "label": "__MSG__PROFILE_PUBLICATIONS_VOLUME_TITLE__",
                            "required": false,
                            "display": true
                        },
                        "volumeinformation": {
                            "label": "__MSG__PROFILE_PUBLICATIONS_VOLUME_INFORMATION__",
                            "required": false,
                            "display": true,
                            "example": "__MSG__PROFILE_PUBLICATIONS_VOLUME_INFORMATION_EXAMPLE__"
                        },
                        "year": {
                            "label": "__MSG__PROFILE_PUBLICATIONS_YEAR__",
                            "required": true,
                            "display": true
                        },
                        "number": {
                            "label": "__MSG__PROFILE_PUBLICATIONS_NUMBER__",
                            "required": false,
                            "display": true
                        },
                        "series title": {
                            "label": "__MSG__PROFILE_PUBLICATIONS_SERIES_TITLE__",
                            "required": false,
                            "display": true
                        },
                        "url": {
                            "label": "__MSG__PROFILE_PUBLICATIONS_URL__",
                            "required": false,
                            "display": true,
                            "validation": "appendhttp url"
                        }
                    }
                }
            }
        },
        /*
         * set what name to display where only the first name is used
         */
        userFirstNameDisplay: "firstName",

        /*
         * set how the user's name is displayed across the entire system
         * - values can be compound, like "firstName lastName" or singular like "displayName"
         */
        userNameDisplay: "firstName lastName",

        /*
         * the default, if the user doesn't have the userNameDisplay property set in their
         * profile, use this one.
         * Note: the value for userNameDisplay and this value can be the same.
         *       If neither exists, nothing will show
         */
        userNameDefaultDisplay: "firstName lastName",

        /*
         * Set the user's short description to appear underneath their name
         * in search results
         */
        userShortDescription: "${role} in ${department} at ${college}",
        groupShortDescription: "asdf"
    };

    return config;

});
<|endoftext|>


<commit_before>var $ = require('jquery-browserify');
var chosen = require('chosen-jquery-browserify');
var _ = require('underscore');
_.merge = require('deepmerge');
var jsyaml = require('js-yaml');
var Backbone = require('backbone');
var templates = require('../../dist/templates');
var util = require('.././util');

module.exports = Backbone.View.extend({
  template: templates.metadata,

  events: {
    'change input': 'updateModel',
    'click .create-select': 'createSelect',
    'click .finish': 'exit'
  },

  initialize: function(options) {
    _.bindAll(this);

    this.model = options.model;
    this.titleAsHeading = options.titleAsHeading;
    this.view = options.view;
  },

  render: function() {
    this.$el.empty().append(_.template(this.template));

    var form = this.$el.find('.form');

    var metadata = this.model.get('metadata');
    var lang = metadata && metadata.lang ? metadata.lang : 'en';

    // This renders any fields defined in the metadata entry
    // of a given prose configuration file.
    _.each(this.model.get('defaults'), (function(data, key) {
      var metadata = this.model.get('metadata');
      var renderTitle = true;

      if (data && data.name === 'title' && this.titleAsHeading) {
        renderTitle = false;
      };

      if (renderTitle) {
        if (data && data.field) {
          switch (data.field.element) {
            case 'button':
              var button = {
                name: data.name,
                label: data.field.label,
                on: data.field.on,
                off: data.field.off
              };

              form.append(_.template(templates.meta.button, button, {
                variable: 'meta'
              }));
              break;
            case 'checkbox':
              var checkbox = {
                name: data.name,
                label: data.field.label,
                value: data.name,
                checked: data.field.value
              };

              form.append(_.template(templates.meta.checkbox, checkbox, {
                variable: 'meta'
              }));
              break;
            case 'text':
              var text = {
                name: data.name,
                label: data.field.label,
                value: data.field.value,
                type: 'text'
              };

              form.append(_.template(templates.meta.text, text, {
                variable: 'meta'
              }));
              break;
            case 'textarea':
              var id = util.stringToUrl(data.name);
              var textarea = {
                name: data.name,
                id: id,
                value: data.field.value,
                label: data.field.label,
                type: 'textarea'
              };

              form.append(_.template(templates.meta.textarea, textarea, {
                variable: 'meta'
              }));

              var textElement = document.getElementById(id);

              this[id] = CodeMirror(function(el) {
                textElement.parentNode.replaceChild(el, textElement);
                el.id = id;
                el.className += ' inner ';
                el.setAttribute('data-name', data.name);
              }, {
                mode: id,
                value: textElement.value,
                lineWrapping: true,
                theme: 'prose-bright'
              });

              break;
            case 'number':
              var number = {
                name: data.name,
                label: data.field.label,
                value: data.field.value,
                type: 'number'
              };

              form.append(_.template(templates.meta.text, number, {
                variable: 'meta'
              }));
              break;
            case 'select':
              var select = {
                name: data.name,
                label: data.field.label,
                placeholder: data.field.placeholder,
                options: data.field.options,
                lang: lang
              };

              form.append(_.template(templates.meta.select, select, {
                variable: 'meta'
              }));
              break;
            case 'multiselect':
              var multiselect = {
                name: data.name,
                label: data.field.label,
                alterable: data.field.alterable,
                placeholder: data.field.placeholder,
                options: data.field.options,
                lang: lang
              };

              form.append(_.template(templates.meta.multiselect, multiselect, {
                variable: 'meta'
              }));

              break;
            case 'hidden':
              var tmpl = {};
              var value = metadata[data.name];

              if (_.isArray(value)) {
                // Any defaults not currently in metadata?
                var diff = _.difference(data.field.value, value);
                tmpl[data.name] = diff.length ?
                  _.union(data.field.value, value) : value;
              } else {
                tmpl[data.name] = data.field.value;
              }

              this.model.set('metadata', _.extend(tmpl, this.model.get('metadata') || {}));
              break;
          }
        } else {
          var txt = {
            name: key,
            label: key,
            value: data,
            type: 'text'
          };

          form.append(_.template(templates.meta.text, txt, {
            variable: 'meta'
          }));
        }
      }
    }).bind(this));

    this.$el.find('.chzn-select').chosen().change(this.updateModel);

    this.renderRaw();

    return this;
  },

  updateModel: function(e) {
    var target = e.currentTarget;
    var key = target.name;
    var value = target.value;

    var delta = {};
    delta[key] = value;

    var metadata = this.model.get('metadata');
    this.model.set('metadata', _.extend(metadata, delta));

    this.view.makeDirty();
  },

  rawKeyMap: function() {
    return {
      'Ctrl-S': this.view.updateFile
    };
  },

  renderRaw: function() {
    var yaml = this.model.get('lang') === 'yaml';
    var $el;

    if (yaml) {
      $el = this.view.$el.find('#code');
      $el.empty();
    } else {
      this.$el.find('.form').append(_.template(templates.meta.raw));
    }

    var el = (yaml ? $el : this.$el.find('#raw'))[0];

    this.raw = CodeMirror(el, {
      mode: 'yaml',
      value: '',
      lineWrapping: true,
      lineNumbers: yaml,
      extraKeys: this.rawKeyMap(),
      theme: 'prose-bright'
    });

    this.listenTo(this.raw, 'blur', (function(cm) {
      var value = cm.getValue();
      var raw;

      try {
        raw = jsyaml.load(value);
      } catch(err) {
        console.log(err);
      }

      if (raw) {
        var metadata = this.model.get('metadata');
        this.model.set('metadata', _.extend(metadata, raw));

        this.view.makeDirty();
      }
    }).bind(this));

    this.setValue(this.model.get('metadata'));
  },

  getValue: function() {
    var view = this;
    var metadata = this.model.get('metadata');

    if (this.view.toolbar &&
       this.view.toolbar.publishState() ||
       (metadata && metadata.published)) {
      metadata.published = true;
    } else {
      metadata.published = false;
    }

    // Get the title value from heading if we need to.
    if (this.titleAsHeading) {
      metadata.title = (this.view.header) ?
        this.view.header.inputGet() :
        this.model.get('metadata').title[0];
    }

    _.each(this.$el.find('[name]'), function(item) {
      var $item = $(item);
      var value = $item.val();

      switch (item.type) {
        case 'select-multiple':
        case 'select-one':
        case 'textarea':
        case 'text':
          if (value) {
            value = $item.data('type') === 'number' ? Number(value) : value;
            if (metadata.hasOwnProperty(item.name) && metadata[item.name] !== value) {
              metadata[item.name] = _.union(metadata[item.name], value);
            } else {
              metadata[item.name] = value;
            }
          }
          break;
        case 'checkbox':
          if (item.checked) {

            if (metadata.hasOwnProperty(item.name) && metadata[item.name] !== value) {
              metadata[item.name] = _.union(metadata[item.name], item.value);
            } else if (item.value === item.name) {
              metadata[item.name] = item.checked;
            } else {
              metadata[item.name] = item.value;
            }

          } else if (!metadata.hasOwnProperty(item.name) && item.value === item.name) {
            metadata[item.name] = item.checked;
          } else {
            metadata[item.name] = item.checked;
          }
          break;
        case 'button':
          if (value === 'true') {
            metadata[item.name] = true;
          } else if (value === 'false') {
            metadata[item.name] = false;
          }
          break;
      }
    });

    // Load any data coming from a yaml-block of content.
    this.$el.find('.yaml-block').each(function() {
      var editor = $(this).find('.CodeMirror').attr('id');
      var name = $('#' + editor).data('name');

      if (view[editor]) {
        metadata[name] = jsyaml.load(view[editor].getValue());
      }
    });

    // Load any data coming from not defined raw yaml front matter.
    if (this.raw) {
      try {
        metadata = _.merge(metadata, jsyaml.load(this.raw.getValue()) || {});
      } catch (err) {
        throw err;
      }
    }

    return metadata;
  },

  setValue: function(data) {
    var form = this.$el.find('.form');

    var missing = {};
    var raw;

    _.each(data, (function(value, key) {
      var matched = false;
      var input = this.$el.find('[name="' + key + '"]');
      var length = input.length;
      var options;

      if (length) {

        // iterate over matching fields
        for (var i = 0; i < length; i++) {

          // if value is an array
          if (_.isArray(value)) {

            // iterate over values in array
            for (var j = 0; j < value.length; j++) {
              switch (input[i].type) {
                case 'select-multiple':
                case 'select-one':
                  options = $(input[i]).find('option[value="' + value[j] + '"]');
                  if (options.length) {
                    for (var k = 0; k < options.length; k++) {
                      options[k].selected = 'selected';
                    }

                    matched = true;
                  }
                  break;
                case 'text':
                case 'textarea':
                  input[i].value = value;
                  matched = true;
                  break;
                case 'checkbox':
                  if (input[i].value === value) {
                    input[i].checked = 'checked';
                    matched = true;
                  }
                  break;
              }
            }

          } else {

            switch (input[i].type) {
              case 'select-multiple':
              case 'select-one':
                options = $(input[i]).find('option[value="' + value + '"]');
                if (options.length) {
                  for (var m = 0; m < options.length; m++) {
                    options[m].selected = 'selected';
                  }

                  matched = true;
                }
                break;
              case 'text':
              case 'textarea':
                input[i].value = value;
                matched = true;
                break;
              case 'checkbox':
                input[i].checked = value ? 'checked' : false;
                matched = true;
                break;
              case 'button':
                input[i].value = value ? true : false;
                input[i].innerHTML = value ? input[i].getAttribute('data-on') : input[i].getAttribute('data-off');
                matched = true;
                break;
            }

          }
        }

        if (!matched && value !== null) {
          if (missing.hasOwnProperty(key) && missing[key] !== value) {
            missing[key] = _.union(missing[key], value);
          } else {
            missing[key] = value;
          }
        }

      } else {
        // Don't render the 'published' field or hidden metadata
        // TODO: render metadata values that share a key with a hidden value
        var defaults = _.find(this.model.get('defaults'), function(data) { return data && (data.name === key); });
        var diff = defaults && _.isArray(value) ? _.difference(value, defaults.field.value) : value;

        if (key !== 'published' && key !== 'title' && !defaults) {
          raw = {};
          raw[key] = value;

          if (this.raw) {
            this.raw.setValue(this.raw.getValue() + jsyaml.dump(raw));
          }
        }
      }
    }).bind(this));

    _.each(missing, (function(value, key) {
      if (value === null) return;

      switch (typeof value) {
        case 'boolean':
          var bool = {
            name: key,
            label: value,
            value: value,
            checked: value ? 'checked' : false
          };

          form.append(_.template(templates.meta.checkbox, bool, {
            variable: 'meta'
          }));
          break;
        case 'string':
          var string = {
            name: key,
            label: value,
            value: value,
            type: 'text'
          };

          form.append(_.template(templates.meta.text, string, {
            variable: 'meta'
          }));
          break;
        case 'object':
          var obj = {
            name: key,
            label: key,
            placeholder: key,
            options: value,
            lang: data.lang || 'en'
          };

          form.append(_.template(templates.meta.multiselect, obj, {
            variable: 'meta'
          }));
          break;
        default:
          console.log('ERROR could not create metadata field for ' + typeof value, key + ': ' + value);
          break;
      }

      this.$el.find('.chzn-select').chosen().change(this.updateModel);
    }).bind(this));

    this.$el.find('.chzn-select').trigger('liszt:updated');

    // Update model with defaults
    // TODO: should this makeDirty if any differences?
    this.model.set('metadata', this.getValue());
  },

  getRaw: function() {
    return jsyaml.dump(this.getValue()).trim();
  },

  setRaw: function(data) {
    try {
      this.raw.setValue(jsyaml.dump(data));
      this.refresh;
    } catch (err) {
      throw err;
    }
  },

  refresh: function() {
    var view = this;
    this.$el.find('.yaml-block').each(function() {
      var editor = $(this).find('.CodeMirror').attr('id');
      if (view[editor]) view[editor].refresh();
    });

    // Refresh CodeMirror
    if (this.raw) this.raw.refresh();
  },

  createSelect: function(e) {
    var $parent = $(e.target).parent();
    var $input = $parent.find('input');
    var selectTarget = $(e.target).data('select');
    var $select = this.$el.find('#' + selectTarget);
    var value = $input.val();

    if (value.length > 0) {
      var option = '<option value="' + value + '" selected="selected">' + value + '</option>';

      // Append this new option to the select list.
      $select.append(option);

      // Clear the now added value.
      $input.attr('value', '');

      // Update the list
      $select.trigger('liszt:updated');
    }

    return false;
  },

  exit: function() {
    this.view.nav.active(this.view.mode);

    if (this.view.mode === 'blob') {
      this.view.blob();
    } else {
      this.view.edit();
    }

    return false;
  }
});
<commit_msg>empty object default if metadata undefined in getValue<commit_after>var $ = require('jquery-browserify');
var chosen = require('chosen-jquery-browserify');
var _ = require('underscore');
_.merge = require('deepmerge');
var jsyaml = require('js-yaml');
var Backbone = require('backbone');
var templates = require('../../dist/templates');
var util = require('.././util');

module.exports = Backbone.View.extend({
  template: templates.metadata,

  events: {
    'change input': 'updateModel',
    'click .create-select': 'createSelect',
    'click .finish': 'exit'
  },

  initialize: function(options) {
    _.bindAll(this);

    this.model = options.model;
    this.titleAsHeading = options.titleAsHeading;
    this.view = options.view;
  },

  render: function() {
    this.$el.empty().append(_.template(this.template));

    var form = this.$el.find('.form');

    var metadata = this.model.get('metadata');
    var lang = metadata && metadata.lang ? metadata.lang : 'en';

    // This renders any fields defined in the metadata entry
    // of a given prose configuration file.
    _.each(this.model.get('defaults'), (function(data, key) {
      var metadata = this.model.get('metadata');
      var renderTitle = true;

      if (data && data.name === 'title' && this.titleAsHeading) {
        renderTitle = false;
      };

      if (renderTitle) {
        if (data && data.field) {
          switch (data.field.element) {
            case 'button':
              var button = {
                name: data.name,
                label: data.field.label,
                on: data.field.on,
                off: data.field.off
              };

              form.append(_.template(templates.meta.button, button, {
                variable: 'meta'
              }));
              break;
            case 'checkbox':
              var checkbox = {
                name: data.name,
                label: data.field.label,
                value: data.name,
                checked: data.field.value
              };

              form.append(_.template(templates.meta.checkbox, checkbox, {
                variable: 'meta'
              }));
              break;
            case 'text':
              var text = {
                name: data.name,
                label: data.field.label,
                value: data.field.value,
                type: 'text'
              };

              form.append(_.template(templates.meta.text, text, {
                variable: 'meta'
              }));
              break;
            case 'textarea':
              var id = util.stringToUrl(data.name);
              var textarea = {
                name: data.name,
                id: id,
                value: data.field.value,
                label: data.field.label,
                type: 'textarea'
              };

              form.append(_.template(templates.meta.textarea, textarea, {
                variable: 'meta'
              }));

              var textElement = document.getElementById(id);

              this[id] = CodeMirror(function(el) {
                textElement.parentNode.replaceChild(el, textElement);
                el.id = id;
                el.className += ' inner ';
                el.setAttribute('data-name', data.name);
              }, {
                mode: id,
                value: textElement.value,
                lineWrapping: true,
                theme: 'prose-bright'
              });

              break;
            case 'number':
              var number = {
                name: data.name,
                label: data.field.label,
                value: data.field.value,
                type: 'number'
              };

              form.append(_.template(templates.meta.text, number, {
                variable: 'meta'
              }));
              break;
            case 'select':
              var select = {
                name: data.name,
                label: data.field.label,
                placeholder: data.field.placeholder,
                options: data.field.options,
                lang: lang
              };

              form.append(_.template(templates.meta.select, select, {
                variable: 'meta'
              }));
              break;
            case 'multiselect':
              var multiselect = {
                name: data.name,
                label: data.field.label,
                alterable: data.field.alterable,
                placeholder: data.field.placeholder,
                options: data.field.options,
                lang: lang
              };

              form.append(_.template(templates.meta.multiselect, multiselect, {
                variable: 'meta'
              }));

              break;
            case 'hidden':
              var tmpl = {};
              var value = metadata[data.name];

              if (_.isArray(value)) {
                // Any defaults not currently in metadata?
                var diff = _.difference(data.field.value, value);
                tmpl[data.name] = diff.length ?
                  _.union(data.field.value, value) : value;
              } else {
                tmpl[data.name] = data.field.value;
              }

              this.model.set('metadata', _.extend(tmpl, this.model.get('metadata') || {}));
              break;
          }
        } else {
          var txt = {
            name: key,
            label: key,
            value: data,
            type: 'text'
          };

          form.append(_.template(templates.meta.text, txt, {
            variable: 'meta'
          }));
        }
      }
    }).bind(this));

    this.$el.find('.chzn-select').chosen().change(this.updateModel);

    this.renderRaw();

    return this;
  },

  updateModel: function(e) {
    var target = e.currentTarget;
    var key = target.name;
    var value = target.value;

    var delta = {};
    delta[key] = value;

    var metadata = this.model.get('metadata');
    this.model.set('metadata', _.extend(metadata, delta));

    this.view.makeDirty();
  },

  rawKeyMap: function() {
    return {
      'Ctrl-S': this.view.updateFile
    };
  },

  renderRaw: function() {
    var yaml = this.model.get('lang') === 'yaml';
    var $el;

    if (yaml) {
      $el = this.view.$el.find('#code');
      $el.empty();
    } else {
      this.$el.find('.form').append(_.template(templates.meta.raw));
    }

    var el = (yaml ? $el : this.$el.find('#raw'))[0];

    this.raw = CodeMirror(el, {
      mode: 'yaml',
      value: '',
      lineWrapping: true,
      lineNumbers: yaml,
      extraKeys: this.rawKeyMap(),
      theme: 'prose-bright'
    });

    this.listenTo(this.raw, 'blur', (function(cm) {
      var value = cm.getValue();
      var raw;

      try {
        raw = jsyaml.load(value);
      } catch(err) {
        console.log(err);
      }

      if (raw) {
        var metadata = this.model.get('metadata');
        this.model.set('metadata', _.extend(metadata, raw));

        this.view.makeDirty();
      }
    }).bind(this));

    this.setValue(this.model.get('metadata'));
  },

  getValue: function() {
    var view = this;
    var metadata = this.model.get('metadata') || {};

    if (this.view.toolbar &&
       this.view.toolbar.publishState() ||
       (metadata && metadata.published)) {
      metadata.published = true;
    } else {
      metadata.published = false;
    }

    // Get the title value from heading if we need to.
    if (this.titleAsHeading) {
      metadata.title = (this.view.header) ?
        this.view.header.inputGet() :
        this.model.get('metadata').title[0];
    }

    _.each(this.$el.find('[name]'), function(item) {
      var $item = $(item);
      var value = $item.val();

      switch (item.type) {
        case 'select-multiple':
        case 'select-one':
        case 'textarea':
        case 'text':
          if (value) {
            value = $item.data('type') === 'number' ? Number(value) : value;
            if (metadata.hasOwnProperty(item.name) && metadata[item.name] !== value) {
              metadata[item.name] = _.union(metadata[item.name], value);
            } else {
              metadata[item.name] = value;
            }
          }
          break;
        case 'checkbox':
          if (item.checked) {

            if (metadata.hasOwnProperty(item.name) && metadata[item.name] !== value) {
              metadata[item.name] = _.union(metadata[item.name], item.value);
            } else if (item.value === item.name) {
              metadata[item.name] = item.checked;
            } else {
              metadata[item.name] = item.value;
            }

          } else if (!metadata.hasOwnProperty(item.name) && item.value === item.name) {
            metadata[item.name] = item.checked;
          } else {
            metadata[item.name] = item.checked;
          }
          break;
        case 'button':
          if (value === 'true') {
            metadata[item.name] = true;
          } else if (value === 'false') {
            metadata[item.name] = false;
          }
          break;
      }
    });

    // Load any data coming from a yaml-block of content.
    this.$el.find('.yaml-block').each(function() {
      var editor = $(this).find('.CodeMirror').attr('id');
      var name = $('#' + editor).data('name');

      if (view[editor]) {
        metadata[name] = jsyaml.load(view[editor].getValue());
      }
    });

    // Load any data coming from not defined raw yaml front matter.
    if (this.raw) {
      try {
        metadata = _.merge(metadata, jsyaml.load(this.raw.getValue()) || {});
      } catch (err) {
        throw err;
      }
    }

    return metadata;
  },

  setValue: function(data) {
    var form = this.$el.find('.form');

    var missing = {};
    var raw;

    _.each(data, (function(value, key) {
      var matched = false;
      var input = this.$el.find('[name="' + key + '"]');
      var length = input.length;
      var options;

      if (length) {

        // iterate over matching fields
        for (var i = 0; i < length; i++) {

          // if value is an array
          if (_.isArray(value)) {

            // iterate over values in array
            for (var j = 0; j < value.length; j++) {
              switch (input[i].type) {
                case 'select-multiple':
                case 'select-one':
                  options = $(input[i]).find('option[value="' + value[j] + '"]');
                  if (options.length) {
                    for (var k = 0; k < options.length; k++) {
                      options[k].selected = 'selected';
                    }

                    matched = true;
                  }
                  break;
                case 'text':
                case 'textarea':
                  input[i].value = value;
                  matched = true;
                  break;
                case 'checkbox':
                  if (input[i].value === value) {
                    input[i].checked = 'checked';
                    matched = true;
                  }
                  break;
              }
            }

          } else {

            switch (input[i].type) {
              case 'select-multiple':
              case 'select-one':
                options = $(input[i]).find('option[value="' + value + '"]');
                if (options.length) {
                  for (var m = 0; m < options.length; m++) {
                    options[m].selected = 'selected';
                  }

                  matched = true;
                }
                break;
              case 'text':
              case 'textarea':
                input[i].value = value;
                matched = true;
                break;
              case 'checkbox':
                input[i].checked = value ? 'checked' : false;
                matched = true;
                break;
              case 'button':
                input[i].value = value ? true : false;
                input[i].innerHTML = value ? input[i].getAttribute('data-on') : input[i].getAttribute('data-off');
                matched = true;
                break;
            }

          }
        }

        if (!matched && value !== null) {
          if (missing.hasOwnProperty(key) && missing[key] !== value) {
            missing[key] = _.union(missing[key], value);
          } else {
            missing[key] = value;
          }
        }

      } else {
        // Don't render the 'published' field or hidden metadata
        // TODO: render metadata values that share a key with a hidden value
        var defaults = _.find(this.model.get('defaults'), function(data) { return data && (data.name === key); });
        var diff = defaults && _.isArray(value) ? _.difference(value, defaults.field.value) : value;

        if (key !== 'published' && key !== 'title' && !defaults) {
          raw = {};
          raw[key] = value;

          if (this.raw) {
            this.raw.setValue(this.raw.getValue() + jsyaml.dump(raw));
          }
        }
      }
    }).bind(this));

    _.each(missing, (function(value, key) {
      if (value === null) return;

      switch (typeof value) {
        case 'boolean':
          var bool = {
            name: key,
            label: value,
            value: value,
            checked: value ? 'checked' : false
          };

          form.append(_.template(templates.meta.checkbox, bool, {
            variable: 'meta'
          }));
          break;
        case 'string':
          var string = {
            name: key,
            label: value,
            value: value,
            type: 'text'
          };

          form.append(_.template(templates.meta.text, string, {
            variable: 'meta'
          }));
          break;
        case 'object':
          var obj = {
            name: key,
            label: key,
            placeholder: key,
            options: value,
            lang: data.lang || 'en'
          };

          form.append(_.template(templates.meta.multiselect, obj, {
            variable: 'meta'
          }));
          break;
        default:
          console.log('ERROR could not create metadata field for ' + typeof value, key + ': ' + value);
          break;
      }

      this.$el.find('.chzn-select').chosen().change(this.updateModel);
    }).bind(this));

    this.$el.find('.chzn-select').trigger('liszt:updated');

    // Update model with defaults
    // TODO: should this makeDirty if any differences?
    this.model.set('metadata', this.getValue());
  },

  getRaw: function() {
    return jsyaml.dump(this.getValue()).trim();
  },

  setRaw: function(data) {
    try {
      this.raw.setValue(jsyaml.dump(data));
      this.refresh;
    } catch (err) {
      throw err;
    }
  },

  refresh: function() {
    var view = this;
    this.$el.find('.yaml-block').each(function() {
      var editor = $(this).find('.CodeMirror').attr('id');
      if (view[editor]) view[editor].refresh();
    });

    // Refresh CodeMirror
    if (this.raw) this.raw.refresh();
  },

  createSelect: function(e) {
    var $parent = $(e.target).parent();
    var $input = $parent.find('input');
    var selectTarget = $(e.target).data('select');
    var $select = this.$el.find('#' + selectTarget);
    var value = $input.val();

    if (value.length > 0) {
      var option = '<option value="' + value + '" selected="selected">' + value + '</option>';

      // Append this new option to the select list.
      $select.append(option);

      // Clear the now added value.
      $input.attr('value', '');

      // Update the list
      $select.trigger('liszt:updated');
    }

    return false;
  },

  exit: function() {
    this.view.nav.active(this.view.mode);

    if (this.view.mode === 'blob') {
      this.view.blob();
    } else {
      this.view.edit();
    }

    return false;
  }
});
<|endoftext|>


<commit_before>// This file is autogenerated via the `commonjs` Grunt task. You can require() this file in a CommonJS environment.
require('../../js/transition.js')
require('../../js/alert.js')
require('../../js/button.js')
require('../../js/carousel.js')
require('../../js/collapse.js')
require('../../js/dropdown.js')
require('../../js/modal.js')
require('../../js/tooltip.js')
require('../../js/popover.js')
require('../../js/scrollspy.js')
require('../../js/tab.js')
require('../../js/affix.js')<commit_msg>Eliminado archivo sin uso.<commit_after><|endoftext|>


<commit_before>/* eslint-disable no-underscore-dangle */

/*
 * Currently Blob is not supported for RN,
 * we should remove it in WebWorker because it will used for `whatwg-fetch`
 */
if (self.Blob && self.Blob.toString() === 'function Blob() { [native code] }') {
  delete self.Blob;
}

// Avoid warning of use `window.require` on dev mode
const avoidWarnForRequire = (moduleName = 'NativeModules') => new Promise(resolve =>
  setTimeout(() => {
    // It's replaced console.warn of react-native
    const originalWarn = console.warn;
    console.warn = (...args) => {
      if (args[0] && args[0].indexOf(`Requiring module '${moduleName}' by name`) > -1) return;
      return originalWarn(...args);
    };
    resolve(() => { console.warn = originalWarn; });
  })
);

const toggleNetworkInspect = enabled => {
  if (!enabled && window.__NETWORK_INSPECT__) {
    window.XMLHttpRequest = window.__NETWORK_INSPECT__.XMLHttpRequest;
    window.FormData = window.__NETWORK_INSPECT__.FormData;
    delete window.__NETWORK_INSPECT__;
    return;
  }
  if (!enabled) return;
  window.__NETWORK_INSPECT__ = {
    XMLHttpRequest: window.XMLHttpRequest,
    FormData: window.FormData,
  };
  window.XMLHttpRequest = window.originalXMLHttpRequest ?
    window.originalXMLHttpRequest :
    window.XMLHttpRequest;
  window.FormData = window.originalFormData ?
    window.originalFormData :
    window.FormData;
};

export const checkAvailableDevMenuMethods = async (enableNetworkInspect = false) => {
  const done = await avoidWarnForRequire();
  const { DevMenu } = window.__DEV__ ? window.require('NativeModules') : {};
  done();

  let result = ['enableNetworkInspect'];
  window.__AVAILABLE_METHODS_CAN_CALL_BY_RNDEBUGGER__ = {
    enableNetworkInspect: toggleNetworkInspect,
  };
  if (DevMenu && DevMenu.reload) {
    window.__AVAILABLE_METHODS_CAN_CALL_BY_RNDEBUGGER__.reload = DevMenu.reload;
    result = ['reload', ...result];
  }

  toggleNetworkInspect(enableNetworkInspect);
  postMessage({ __AVAILABLE_METHODS_CAN_CALL_BY_RNDEBUGGER__: result });
};

export const invokeDevMenuMethod = (name, args = []) => {
  const method = window.__AVAILABLE_METHODS_CAN_CALL_BY_RNDEBUGGER__[name];
  if (method) method(...args);
};
<commit_msg>Support RN 0.43 for checkAvailableDevMenuMethods<commit_after>/* eslint-disable no-underscore-dangle */

/*
 * Currently Blob is not supported for RN,
 * we should remove it in WebWorker because it will used for `whatwg-fetch`
 */
if (self.Blob && self.Blob.toString() === 'function Blob() { [native code] }') {
  delete self.Blob;
}

// Avoid warning of use `window.require` on dev mode
const avoidWarnForRequire = (moduleName = 'NativeModules') => new Promise(resolve =>
  setTimeout(() => {
    // It's replaced console.warn of react-native
    const originalWarn = console.warn;
    console.warn = (...args) => {
      if (args[0] && args[0].indexOf(`Requiring module '${moduleName}' by name`) > -1) return;
      return originalWarn(...args);
    };
    resolve(() => { console.warn = originalWarn; });
  })
);

const toggleNetworkInspect = enabled => {
  if (!enabled && window.__NETWORK_INSPECT__) {
    window.XMLHttpRequest = window.__NETWORK_INSPECT__.XMLHttpRequest;
    window.FormData = window.__NETWORK_INSPECT__.FormData;
    delete window.__NETWORK_INSPECT__;
    return;
  }
  if (!enabled) return;
  window.__NETWORK_INSPECT__ = {
    XMLHttpRequest: window.XMLHttpRequest,
    FormData: window.FormData,
  };
  window.XMLHttpRequest = window.originalXMLHttpRequest ?
    window.originalXMLHttpRequest :
    window.XMLHttpRequest;
  window.FormData = window.originalFormData ?
    window.originalFormData :
    window.FormData;
};

const methodsGlobalName = '__AVAILABLE_METHODS_CAN_CALL_BY_RNDEBUGGER__';

export const checkAvailableDevMenuMethods = async (enableNetworkInspect = false) => {
  const done = await avoidWarnForRequire();
  const NativeModules = window.__DEV__ ? window.require('NativeModules') : {};
  done();

  // RN 0.43 use DevSettings, DevMenu is deprecated
  const DevSettings = NativeModules.DevSettings || NativeModules.DevMenu;

  let result = ['enableNetworkInspect'];
  const methods = {
    enableNetworkInspect: toggleNetworkInspect,
  };
  if (DevSettings && DevSettings.reload) {
    methods.reload = DevSettings.reload;
    result = ['reload', ...result];
  }
  window[methodsGlobalName] = methods;

  toggleNetworkInspect(enableNetworkInspect);
  postMessage({ [methodsGlobalName]: result });
};

export const invokeDevMenuMethod = (name, args = []) => {
  const method = window[methodsGlobalName][name];
  if (method) method(...args);
};
<|endoftext|>


<commit_before>import Icon from '../../../../../src/ol/style/Icon.js';
import IconImage, {
  get as getIconImage,
} from '../../../../../src/ol/style/IconImage.js';
import {getUid} from '../../../../../src/ol/util.js';
import {shared as iconImageCache} from '../../../../../src/ol/style/IconImageCache.js';

describe('ol.style.Icon', function () {
  const size = [36, 48];
  const src =
    'data:image/gif;base64,' +
    'R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=';

  describe('constructor', function () {
    it('caches canvas images with a uid as src', function () {
      const canvas = document.createElement('canvas');
      new Icon({
        img: canvas,
        imgSize: size,
      });
      expect(getIconImage(canvas, getUid(canvas), size, '').getImage()).to.eql(
        canvas
      );
    });

    it('imgSize overrides img.width and img.height', function (done) {
      const style = new Icon({
        src: src,
        imgSize: size,
      });
      const iconImage = style.iconImage_;
      iconImage.addEventListener('change', function () {
        expect([iconImage.image_.width, iconImage.image_.height]).to.eql(size);
        done();
      });
      style.load();
    });
  });

  describe('#clone', function () {
    it('creates a new ol.style.Icon', function () {
      const original = new Icon({
        src: src,
      });
      const clone = original.clone();
      expect(clone).to.be.an(Icon);
      expect(clone).to.not.be(original);
    });

    it('copies all values ', function () {
      const canvas = document.createElement('canvas');
      const original = new Icon({
        anchor: [1, 0],
        anchorOrigin: 'bottom-right',
        anchorXUnits: 'pixels',
        anchorYUnits: 'pixels',
        color: '#319FD3',
        crossOrigin: 'Anonymous',
        img: canvas,
        imgSize: size,
        offset: [1, 2],
        offsetOrigin: 'bottom-left',
        opacity: 0.5,
        scale: 2,
        rotation: 4,
        size: [10, 12],
      });

      const clone = original.clone();
      expect(original.getImage(1)).to.be(clone.getImage(1));
      expect(original.iconImage_).to.be(clone.iconImage_);
      expect(original.getAnchor()).to.eql(clone.getAnchor());
      expect(original.anchorOrigin_).to.eql(clone.anchorOrigin_);
      expect(original.anchorXUnits_).to.eql(clone.anchorXUnits_);
      expect(original.anchorYUnits_).to.eql(clone.anchorYUnits_);
      expect(original.crossOrigin_).to.eql(clone.crossOrigin_);
      expect(original.getColor()).to.eql(clone.getColor());
      expect(original.offset_).to.eql(clone.offset_);
      expect(original.offsetOrigin_).to.eql(clone.offsetOrigin_);
      expect(original.getSize()).to.eql(clone.getSize());
      expect(original.getSrc()).to.eql(clone.getSrc());
      expect(original.getOpacity()).to.eql(clone.getOpacity());
      expect(original.getRotation()).to.eql(clone.getRotation());
      expect(original.getRotateWithView()).to.eql(clone.getRotateWithView());

      const original2 = new Icon({
        src: src,
      });
      const clone2 = original2.clone();
      expect(original2.getImage(1)).to.be(clone2.getImage(1));
      expect(original2.iconImage_).to.be(clone2.iconImage_);
      expect(original2.getSrc()).to.eql(clone2.getSrc());
    });

    it('the clone does not reference the same objects as the original', function () {
      const original = new Icon({
        anchor: [1, 0],
        color: [1, 2, 3, 0.4],
        src: src,
        offset: [1, 2],
        size: [10, 12],
        displacement: [5, 6],
      });
      const clone = original.clone();
      expect(original.getAnchor()).not.to.be(clone.getAnchor());
      expect(original.offset_).not.to.be(clone.offset_);
      expect(original.getColor()).not.to.be(clone.getColor());
      expect(original.getSize()).not.to.be(clone.getSize());
      expect(original.getDisplacement()).not.to.be(clone.getDisplacement());

      clone.anchor_[0] = 0;
      clone.offset_[0] = 0;
      clone.color_[0] = 0;
      clone.size_[0] = 5;
      clone.displacement_[0] = 10;
      expect(original.anchor_).not.to.eql(clone.anchor_);
      expect(original.offset_).not.to.eql(clone.offset_);
      expect(original.color_).not.to.eql(clone.color_);
      expect(original.size_).not.to.eql(clone.size_);
      expect(original.displacement_).not.to.eql(clone.displacement_);
    });
  });

  describe('#getAnchor', function () {
    const fractionAnchor = [0.25, 0.25];

    it('uses fractional units by default', function () {
      const iconStyle = new Icon({
        src: 'test.png',
        size: size,
        anchor: fractionAnchor,
      });
      expect(iconStyle.getAnchor()).to.eql([9, 12]);
    });

    it('uses pixels units', function () {
      const iconStyle = new Icon({
        src: 'test.png',
        size: size,
        anchor: [2, 18],
        anchorXUnits: 'pixels',
        anchorYUnits: 'pixels',
      });
      expect(iconStyle.getAnchor()).to.eql([2, 18]);
    });

    it('uses a bottom left anchor origin', function () {
      const iconStyle = new Icon({
        src: 'test.png',
        size: size,
        anchor: fractionAnchor,
        anchorOrigin: 'bottom-left',
      });
      expect(iconStyle.getAnchor()).to.eql([9, 36]);
    });

    it('uses a bottom right anchor origin', function () {
      const iconStyle = new Icon({
        src: 'test.png',
        size: size,
        anchor: fractionAnchor,
        anchorOrigin: 'bottom-right',
      });
      expect(iconStyle.getAnchor()).to.eql([27, 36]);
    });

    it('uses a top right anchor origin', function () {
      const iconStyle = new Icon({
        src: 'test.png',
        size: size,
        anchor: fractionAnchor,
        anchorOrigin: 'top-right',
      });
      expect(iconStyle.getAnchor()).to.eql([27, 12]);
    });

    it('uses a top right anchor origin + displacement', function () {
      const iconStyle = new Icon({
        src: 'test.png',
        size: size,
        anchor: fractionAnchor,
        anchorOrigin: 'top-right',
        displacement: [20, 10],
      });
      expect(iconStyle.getAnchor()).to.eql([
        size[0] * (1 - fractionAnchor[0]) - 20,
        size[1] * fractionAnchor[1] + 10,
      ]);
    });

    it('uses displacement', function () {
      const iconStyle = new Icon({
        src: 'test.png',
        size: size,
        displacement: [20, 10],
      });
      expect(iconStyle.getAnchor()).to.eql([
        size[0] / 2 - 20,
        size[1] / 2 + 10,
      ]);
    });
  });

  describe('#setAnchor', function () {
    it('resets the cached anchor', function () {
      const iconStyle = new Icon({
        src: 'test.png',
        size: size,
        anchor: [0.25, 0.25],
      });
      expect(iconStyle.getAnchor()).to.eql([9, 12]);

      iconStyle.setAnchor([0.5, 0.5]);
      expect(iconStyle.getAnchor()).to.eql([18, 24]);
    });
  });

  describe('#getOrigin', function () {
    const offset = [16, 20];
    const imageSize = [144, 192];

    it('uses a top left offset origin (default)', function () {
      const iconStyle = new Icon({
        src: 'test.png',
        size: size,
        offset: offset,
      });
      expect(iconStyle.getOrigin()).to.eql([16, 20]);
    });

    it('uses a bottom left offset origin', function () {
      const iconStyle = new Icon({
        src: 'test.png',
        size: size,
        offset: offset,
        offsetOrigin: 'bottom-left',
      });
      iconStyle.iconImage_.size_ = imageSize;
      expect(iconStyle.getOrigin()).to.eql([16, 124]);
    });

    it('uses a bottom right offset origin', function () {
      const iconStyle = new Icon({
        src: 'test.png',
        size: size,
        offset: offset,
        offsetOrigin: 'bottom-right',
      });
      iconStyle.iconImage_.size_ = imageSize;
      expect(iconStyle.getOrigin()).to.eql([92, 124]);
    });

    it('uses a top right offset origin', function () {
      const iconStyle = new Icon({
        src: 'test.png',
        size: size,
        offset: offset,
        offsetOrigin: 'top-right',
      });
      iconStyle.iconImage_.size_ = imageSize;
      expect(iconStyle.getOrigin()).to.eql([92, 20]);
    });
  });

  describe('#getImageSize', function () {
    const imgSize = [144, 192];

    it('takes the real image size', function () {
      // pretend that the image is already in the cache,
      // this image will be used for the icon.
      const src = 'test.png';
      const iconImage = new IconImage(null, 'test.png', imgSize);
      iconImageCache.set(src, null, null, iconImage);

      const iconStyle = new Icon({
        src: 'test.png',
      });
      expect(iconStyle.getImageSize()).to.eql(imgSize);
    });

    it('uses the given image size', function () {
      const iconStyle = new Icon({
        img: {src: 'test.png'},
        imgSize: imgSize,
      });
      expect(iconStyle.getImageSize()).to.eql(imgSize);
    });
  });
});
<commit_msg>Test setDisplacement<commit_after>import Icon from '../../../../../src/ol/style/Icon.js';
import IconImage, {
  get as getIconImage,
} from '../../../../../src/ol/style/IconImage.js';
import {getUid} from '../../../../../src/ol/util.js';
import {shared as iconImageCache} from '../../../../../src/ol/style/IconImageCache.js';

describe('ol.style.Icon', function () {
  const size = [36, 48];
  const src =
    'data:image/gif;base64,' +
    'R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=';

  describe('constructor', function () {
    it('caches canvas images with a uid as src', function () {
      const canvas = document.createElement('canvas');
      new Icon({
        img: canvas,
        imgSize: size,
      });
      expect(getIconImage(canvas, getUid(canvas), size, '').getImage()).to.eql(
        canvas
      );
    });

    it('imgSize overrides img.width and img.height', function (done) {
      const style = new Icon({
        src: src,
        imgSize: size,
      });
      const iconImage = style.iconImage_;
      iconImage.addEventListener('change', function () {
        expect([iconImage.image_.width, iconImage.image_.height]).to.eql(size);
        done();
      });
      style.load();
    });
  });

  describe('#clone', function () {
    it('creates a new ol.style.Icon', function () {
      const original = new Icon({
        src: src,
      });
      const clone = original.clone();
      expect(clone).to.be.an(Icon);
      expect(clone).to.not.be(original);
    });

    it('copies all values ', function () {
      const canvas = document.createElement('canvas');
      const original = new Icon({
        anchor: [1, 0],
        anchorOrigin: 'bottom-right',
        anchorXUnits: 'pixels',
        anchorYUnits: 'pixels',
        color: '#319FD3',
        crossOrigin: 'Anonymous',
        img: canvas,
        imgSize: size,
        offset: [1, 2],
        offsetOrigin: 'bottom-left',
        opacity: 0.5,
        scale: 2,
        rotation: 4,
        size: [10, 12],
      });

      const clone = original.clone();
      expect(original.getImage(1)).to.be(clone.getImage(1));
      expect(original.iconImage_).to.be(clone.iconImage_);
      expect(original.getAnchor()).to.eql(clone.getAnchor());
      expect(original.anchorOrigin_).to.eql(clone.anchorOrigin_);
      expect(original.anchorXUnits_).to.eql(clone.anchorXUnits_);
      expect(original.anchorYUnits_).to.eql(clone.anchorYUnits_);
      expect(original.crossOrigin_).to.eql(clone.crossOrigin_);
      expect(original.getColor()).to.eql(clone.getColor());
      expect(original.offset_).to.eql(clone.offset_);
      expect(original.offsetOrigin_).to.eql(clone.offsetOrigin_);
      expect(original.getSize()).to.eql(clone.getSize());
      expect(original.getSrc()).to.eql(clone.getSrc());
      expect(original.getOpacity()).to.eql(clone.getOpacity());
      expect(original.getRotation()).to.eql(clone.getRotation());
      expect(original.getRotateWithView()).to.eql(clone.getRotateWithView());

      const original2 = new Icon({
        src: src,
      });
      const clone2 = original2.clone();
      expect(original2.getImage(1)).to.be(clone2.getImage(1));
      expect(original2.iconImage_).to.be(clone2.iconImage_);
      expect(original2.getSrc()).to.eql(clone2.getSrc());
    });

    it('the clone does not reference the same objects as the original', function () {
      const original = new Icon({
        anchor: [1, 0],
        color: [1, 2, 3, 0.4],
        src: src,
        offset: [1, 2],
        size: [10, 12],
        displacement: [5, 6],
      });
      const clone = original.clone();
      expect(original.getAnchor()).not.to.be(clone.getAnchor());
      expect(original.offset_).not.to.be(clone.offset_);
      expect(original.getColor()).not.to.be(clone.getColor());
      expect(original.getSize()).not.to.be(clone.getSize());
      expect(original.getDisplacement()).not.to.be(clone.getDisplacement());

      clone.anchor_[0] = 0;
      clone.offset_[0] = 0;
      clone.color_[0] = 0;
      clone.size_[0] = 5;
      clone.displacement_[0] = 10;
      expect(original.anchor_).not.to.eql(clone.anchor_);
      expect(original.offset_).not.to.eql(clone.offset_);
      expect(original.color_).not.to.eql(clone.color_);
      expect(original.size_).not.to.eql(clone.size_);
      expect(original.displacement_).not.to.eql(clone.displacement_);
    });
  });

  describe('#getAnchor', function () {
    const fractionAnchor = [0.25, 0.25];

    it('uses fractional units by default', function () {
      const iconStyle = new Icon({
        src: 'test.png',
        size: size,
        anchor: fractionAnchor,
      });
      expect(iconStyle.getAnchor()).to.eql([9, 12]);
    });

    it('uses pixels units', function () {
      const iconStyle = new Icon({
        src: 'test.png',
        size: size,
        anchor: [2, 18],
        anchorXUnits: 'pixels',
        anchorYUnits: 'pixels',
      });
      expect(iconStyle.getAnchor()).to.eql([2, 18]);
    });

    it('uses a bottom left anchor origin', function () {
      const iconStyle = new Icon({
        src: 'test.png',
        size: size,
        anchor: fractionAnchor,
        anchorOrigin: 'bottom-left',
      });
      expect(iconStyle.getAnchor()).to.eql([9, 36]);
    });

    it('uses a bottom right anchor origin', function () {
      const iconStyle = new Icon({
        src: 'test.png',
        size: size,
        anchor: fractionAnchor,
        anchorOrigin: 'bottom-right',
      });
      expect(iconStyle.getAnchor()).to.eql([27, 36]);
    });

    it('uses a top right anchor origin', function () {
      const iconStyle = new Icon({
        src: 'test.png',
        size: size,
        anchor: fractionAnchor,
        anchorOrigin: 'top-right',
      });
      expect(iconStyle.getAnchor()).to.eql([27, 12]);
    });

    it('uses a top right anchor origin + displacement', function () {
      const iconStyle = new Icon({
        src: 'test.png',
        size: size,
        anchor: fractionAnchor,
        anchorOrigin: 'top-right',
        displacement: [20, 10],
      });
      expect(iconStyle.getAnchor()).to.eql([
        size[0] * (1 - fractionAnchor[0]) - 20,
        size[1] * fractionAnchor[1] + 10,
      ]);
    });

    it('uses displacement', function () {
      const iconStyle = new Icon({
        src: 'test.png',
        size: size,
        displacement: [20, 10],
      });
      expect(iconStyle.getAnchor()).to.eql([
        size[0] / 2 - 20,
        size[1] / 2 + 10,
      ]);
      iconStyle.setDisplacement([10, 20]);
      expect(iconStyle.getAnchor()).to.eql([
        size[0] / 2 - 10,
        size[1] / 2 + 20,
      ]);
    });
  });

  describe('#setAnchor', function () {
    it('resets the cached anchor', function () {
      const iconStyle = new Icon({
        src: 'test.png',
        size: size,
        anchor: [0.25, 0.25],
      });
      expect(iconStyle.getAnchor()).to.eql([9, 12]);

      iconStyle.setAnchor([0.5, 0.5]);
      expect(iconStyle.getAnchor()).to.eql([18, 24]);
    });
  });

  describe('#getOrigin', function () {
    const offset = [16, 20];
    const imageSize = [144, 192];

    it('uses a top left offset origin (default)', function () {
      const iconStyle = new Icon({
        src: 'test.png',
        size: size,
        offset: offset,
      });
      expect(iconStyle.getOrigin()).to.eql([16, 20]);
    });

    it('uses a bottom left offset origin', function () {
      const iconStyle = new Icon({
        src: 'test.png',
        size: size,
        offset: offset,
        offsetOrigin: 'bottom-left',
      });
      iconStyle.iconImage_.size_ = imageSize;
      expect(iconStyle.getOrigin()).to.eql([16, 124]);
    });

    it('uses a bottom right offset origin', function () {
      const iconStyle = new Icon({
        src: 'test.png',
        size: size,
        offset: offset,
        offsetOrigin: 'bottom-right',
      });
      iconStyle.iconImage_.size_ = imageSize;
      expect(iconStyle.getOrigin()).to.eql([92, 124]);
    });

    it('uses a top right offset origin', function () {
      const iconStyle = new Icon({
        src: 'test.png',
        size: size,
        offset: offset,
        offsetOrigin: 'top-right',
      });
      iconStyle.iconImage_.size_ = imageSize;
      expect(iconStyle.getOrigin()).to.eql([92, 20]);
    });
  });

  describe('#getImageSize', function () {
    const imgSize = [144, 192];

    it('takes the real image size', function () {
      // pretend that the image is already in the cache,
      // this image will be used for the icon.
      const src = 'test.png';
      const iconImage = new IconImage(null, 'test.png', imgSize);
      iconImageCache.set(src, null, null, iconImage);

      const iconStyle = new Icon({
        src: 'test.png',
      });
      expect(iconStyle.getImageSize()).to.eql(imgSize);
    });

    it('uses the given image size', function () {
      const iconStyle = new Icon({
        img: {src: 'test.png'},
        imgSize: imgSize,
      });
      expect(iconStyle.getImageSize()).to.eql(imgSize);
    });
  });
});
<|endoftext|>


<commit_before>expect.extend({
	toBeValidModuleId(received, moduleIdString) {
		const pass = typeof received === "number" || received === moduleIdString;
		if (pass) {
			return {
				message: () => `expected ${received} not to be a valid module id`,
				pass: true
			};
		} else {
			return {
				message: () => `expected ${received} to be a valid module id`,
				pass: false
			};
		}
	}
});

it("should replace ! with %21 in the module id string of the context module", function () {
	const moduleId = require.context("./folder", true, /^(?!file1\.js$).*$/i, "lazy").id;
	expect(moduleId).toBeValidModuleId("./context/issue-10969/folder lazy recursive ^(?%21file1\\.js$).*$/");
});
<commit_msg>remove memory leak from test suite<commit_after>it("should replace ! with %21 in the module id string of the context module", function () {
	const moduleId = require.context(
		"./folder",
		true,
		/^(?!file1\.js$).*$/i,
		"lazy"
	).id;
	if (typeof moduleId !== "number")
		expect(moduleId).toBe(
			"./context/issue-10969/folder lazy recursive ^(?%21file1\\.js$).*$/"
		);
});
<|endoftext|>