Update: we've made some changes to the functions in this blog post. We wanted to make it easier for one plugin to include a JavaScript library and another to use it. The post has been updated.
Development on Elgg 1.8 is moving along at a good clip. One of the new features that I have appreciated as I update the plugins are the new functions for including JavaScript and CSS files. In Elgg 1.0-1.7 including an external CSS file is done through extending themetatags view. Not exactly intuitive! It also means that if I have two plugins including the same file, the file is included twice in the HTML <head>. This all changes with Elgg 1.8.
Including CSS
The new functions including CSS are elgg_register_css()
and elgg_load_css()
. The register function takes three parameters: the identifier for the CSS file, the URL of the CSS file, and an optional priority. This function lets Elgg know about the existence of the CSS file. It should normally be called in a plugin's initialization function. Last chance to use it is just before elgg_view_page()
is called at the end of a page handler.
The load function tells Elgg to include the CSS file in the html <head>. It's only parameter is the identifier used in the register function.
If I wanted to include a CSS file on every page, I can register the file in my plugin's initialization function and also call load:
$css_url = 'mod/myplugin/vendor/special.css';
elgg_register_css('special', $css_url);
elgg_load_css('special');
You may have noticed that the URL for the CSS file is a relative URL. We can do that because the core functions automatically add the base site url to links in Elgg 1.8.
Including JavaScript
A problem without a good solution in Elgg 1.7 is what to do with a JavaScript file that you want to include only when it is needed. One technique was to use a global variable in the view that uses that JavaScript (think TinyMCE plugin) and then include the script reference directly in the view the first time it is called based on the value of the global. In Elgg 1.8, you will be able to register the script with elgg_register_js()
in your plugin's init function and then do this in the view:
elgg_load_js('jquery.rating');
It doesn't matter if the view is called one hundred times. Elgg will only insert the script a single time. Further, you get to choose between having the script in the HTML <head> section or in the footer in when registering the script.
If you want to include a different version of jQuery on your site, you don't have to override the head view anymore (fewer headaches with upgrades!). Instead, just override the core's registration in your plugin's init function:
elgg_register_js($google_cdn_jquery_url, 'jquery');
You can do the same thing with other plugins if you needed a newer version or want to switch to using a CDN rather than locally serving the JavaScript file.
Conclusion
Paraphrasing jQuery's slogan, including CSS and JavaScript in Elgg 1.8 requires less code with more functionality. You'll be hearing more in the coming days about other new features for developers coming in Elgg 1.8.
分享到:
相关推荐
这个“welcomer”插件专为Elgg 1.8版本设计,目的是为了改变新用户的默认体验,将他们重定向到一个自定义的欢迎页面,从而增强用户体验和品牌形象。 首先,让我们深入理解一下Elgg 1.8。Elgg 1.8是该平台的一个稳定...
适用于Elgg的Google工具为各种Google产品提供Elgg支持: 加一键加徽章分析工具网站管理员工具验证Google Maps JS API Google JS API客户端(gapi.client) Google JS加载器(goog.load)加一键要发出带有默认设置的...
5. **主题和布局**:Elgg 支持自定义主题和布局,用户可以通过修改 CSS 和模板文件来改变网站的外观和布局,满足个性化需求。 6. **插件生态**:Elgg 拥有活跃的开发社区,提供了大量插件,覆盖了博客、论坛、文件...
founded to govern, protect, and promote the Elgg open source social network engine. The Foundation aims to provide a stable, commercially and individually independent organization that operates in the...
8. **主题定制**:除了插件,ElGG 还支持自定义主题,允许设计者通过CSS和HTML修改网站的整体样式,打造独特的用户体验。 9. **数据库管理**:ElGG 支持多种数据库系统,包括MySQL和SQLite,这为不同规模的站点提供...
2. **自定义主题**:Elgg 允许通过修改CSS和HTML模板来创建独特的网站外观,开发者可以创建自己的主题或使用社区提供的免费和付费主题。 3. **插件开发**:借助Elgg的插件机制,开发者可以扩展平台功能,如集成第三...
Elgg是一款免费开源的社会性网络脚本程序(php/mysql),以BLOG为中心实现社会网络化elgg:社会性网络构建平台elgg作为一个社会性网络构建平台,一经问世,即好评如潮,更有人将其与大名鼎鼎的moodle相提并论。...
**Elgg:开源社交网络平台** Elgg是一个强大的开源社交网络平台,专为构建自定义社区网站而设计。它的核心特性使得用户能够轻松创建个人资料、建立社交网络、分享内容并进行互动。作为一款开放源码的解决方案,Elgg...
《Elgg社交网络》一书由Mayank Sharma撰写,由Packt Publishing出版,于2008年首次发行。本书聚焦于如何使用Elgg这一免费开源工具创建并管理自己的社交网络站点,为读者提供了深入理解社交网络搭建与管理的专业知识...
Elgg的工具提示 Elgg的工具提示组件 特征 集成Tooltipster( ) 开发人员友好的API 用法 要将工具提示添加到字符串或html元素,请使用components/tooltip视图: $ tooltip = elgg_view ( 'components/tooltip' , ...
elgg的新插件 这是用于两步验证的插件。您可以使用OTP身份验证器应用程序创建密码和sacn QR码的密码和QR码。 转到设置->配置您的工具,然后设置两步验证设置。 如果您为自己设置了秘密,则除了登录名和密码外,还要...
Elgg 是一个开源的社交网络平台,用于构建各种类型的在线社区和社交网站。这个"最新elgg源码"指的是Elgg的1.8.16版本。Elgg 的设计目标是提供一个灵活、可定制的框架,使得开发者可以快速创建具有用户互动功能的Web...
【Ubuntu系统下安装elgg】 在Ubuntu系统中安装开源社交网络平台elgg,需要先搭建LAMP(Linux、Apache、MySQL、PHP)服务器环境。LAMP是Linux操作系统中常用的一种Web开发平台组合,适合用于搭建各种基于PHP的网站...
Elgg是一个开源社交网络平台,它允许开发者构建高度定制化的社交应用。在“Elgg的游戏机制功能_PHP_JavaScript_下载.zip”这个压缩包中,我们很显然关注的是Elgg平台如何结合游戏化机制来增强用户体验。游戏机制通常...
**Elgg 2.0.0 版本详解** Elgg 是一个开源的社交网络平台,专为构建个性化社交环境而设计。Elgg 2.0.0 是该平台的一个重要版本,它提供了丰富的功能和改进,使得开发者和用户能够创建自定义的社交网络应用程序。在...
**Elgg-bitly 插件详解** Elgg-bitly 是一款专门为 Elgg 社区平台设计的插件,它利用 bit.ly 的服务来实现URL的缩短功能。在现代社交媒体环境中,短链接对于分享和传播信息至关重要,因为它们不仅节省空间,而且更...
**开源SNS架构——Elgg深度解析** 在互联网社交领域,SNS(Social Networking Service)网站已经成为人们在线交流、分享信息的重要平台。Elgg是一款强大的开源SNS框架,以其灵活性和可扩展性受到开发者的青睐。本文...
客户端API由RequireJS和内置Ajax服务通过异步JavaScript模块提供支持,以便与服务器轻松通信 灵活的实体系统,允许应用程序原型化新类型的内容和用户交互 带有统一API层的自以为是的数据模型,使开发人员可以轻松地...
docker-elgg-dev docker上的Elgg开发环境。 快速开始 下载或克隆要使用的Elgg版本。 运行Docker镜像挂载Elgg作为卷/ app。 如果您使用的是Windows或OS X,并且使用boot2docker,请记住它会将C:\ Users或/ Users...
Elgg是一款免费开源的社会性网络引擎程序,以BLOG为中心实现社会网络化,从社会性来讲:Elgg以兴趣为核心的社交平台。支持多国语言,暂不支持中文。 Elgg 2.3.10 更新日志:2018-12-21Bug修复js:输入datepicker可以...