dojo创建浮动工具栏_创建由Dojo驱动的WordPress网站视图

news/2024/5/20 22:48:29/文章来源:https://blog.csdn.net/culuo8053/article/details/107909445

dojo创建浮动工具栏

Yesterday I showed you WordPress' awesome JSON plugin named JSON API.  Now that I can get my blog posts in JSON format, it's time to create an awesome AJAX'ed web app with that data.  I've chosen to use the power of Dojo and Dijit to create a stylish, AJAX-powered web app which provides intelligent views of all of my blog posts.  You wont want to miss this post!

昨天我向您展示了WordPress很棒的JSON插件JSON API 。 现在,我可以使用JSON格式获取博客文章,是时候使用该数据创建一个很棒的AJAX版本的Web应用程序了。 我选择使用Dojo和Dijit的功能来创建一个时尚的,由AJAX驱动的网络应用程序,该应用程序可提供所有博客文章的智能视图。 您不会想错过这篇文章!

Dojo WordPress JSON

View Demo观看演示

HTML (The HTML)

There's very little HTML (initially) to get the app going;  simply create a container DIV with explicit size dimensions which will act as a application "holder":

最初只有很少HTML可以使应用程序运行; 只需创建具有明确大小尺寸的容器DIV,即可用作应用程序的“持有人”:


<body class="claro">
<!-- will set the eventual dimensions for the tab container -->
<div style="width:900px;height:1000px" id="appbase"></div>
</body>

These size dimensions will allow use to use height and width settings of 100% for our inner widgets.  Note that I'm showing you the BODY tag -- I'll be using the claro theme for my page.

这些尺寸尺寸将允许我们为内部小部件使用100%的高度和宽度设置。 请注意,我正在向您显示BODY标签-我将在页面中使用claro主题。

CSS (The CSS)

There's no app-specific CSS required.  You do, however, need to pull in the CSS file for the desired theme.

不需要特定于应用程序CSS。 但是,您确实需要提取所需主题CSS文件。


/* bring in the claro theme */
@import "http://ajax.googleapis.com/ajax/libs/dojo/1.5/dijit/themes/claro/claro.css";

As I mentioned above, I'm using the new claro theme.

如上所述,我正在使用新的claro主题。

Dojo JavaScript (The Dojo JavaScript)

There's a good amount of JavaScript required to make this awesome layout work so I've broken it down by task.

要使这种出色的布局有效,需要大量JavaScript,因此我已按任务对其进行了细分。

要求Dijit类 (Requiring Dijit Classes)

As always, requiring Dojo and the classes we will use on the page will always be the first step.

与往常一样,要求Dojo和我们将在页面上使用的类始终是第一步。


/* require necessary classes */
dojo.require('dijit.layout.AccordionContainer');
dojo.require('dijit.layout.AccordionPane');
dojo.require('dijit.layout.TabContainer');
dojo.require('dijit.layout.ContentPane');
dojo.require('dijit.layout.BorderContainer');
dojo.require('dijit.form.Button');
dojo.require('dojo.behavior');
/* when all classes have loaded... */
dojo.ready(function() {
// subsequent code goes here
});

Try keeping your dependencies down -- less classes to load means faster application performance.

尝试降低依赖关系-减少要加载的类意味着更快的应用程序性能。

建立版面 (Building the Layout)

The first step is to build the layout.  I'm going to create a two column layout, encompassed by a BorderContainer, in which the left side will provide categories and articles via an AccordionContainer layout.  The right side will feature a TabContainer layout with a separate tab opening for every article requested.

第一步是构建布局。 我将创建一个由BorderContainer包围的两列布局,其中左侧将通过AccordionContainer布局提供类别和文章。 右侧将具有TabContainer布局,并为每个请求的文章提供单独的选项卡开口。


/* generate the layout */
// settings
var appbase = dojo.byId('appbase');
// create the layout container
var container = new dijit.layout.BorderContainer({
design: 'sidebar',
gutters: true
},dojo.create('div',{ style:'height:100%;width:100%;' },appbase));
// create the left sidebar
var accordionContainer = new dijit.layout.AccordionContainer({
splitter: true,
region: 'leading'
},dojo.create('div',{ style:'height:100%;width:30%;' },container.domNode));
container.addChild(accordionContainer);
// create the right content pane
var tabContainer = new dijit.layout.TabContainer({
tabPosition: 'top',
region: 'center'
},dojo.create('div',{ style:'height:100%;width:70%;' },container.domNode));
container.addChild(tabContainer);
// add an initial tab to the tabContainer
tabContainer.addChild(new dijit.layout.ContentPane({
title: 'Welcome!',
content: 'Click on any of the posts you see on the left side of the page.  All post previews will display here!'
},dojo.create('div',{},tabContainer.domNode)));
// start the layout up!
container.startup();

A persistent "welcome" tab is added just so there is always a tab open.

添加持久性“ welcome”选项卡只是为了始终打开一个选项卡。

Dojo WordPress JSON

JSON内容加载-类别和帖子 (JSON Content Loading - Categories & Posts)

Loading the category list is the first order of business.  When the JSON list of categories is returned, a new AccordionPane is added to the Accordion for every category returned:

加载类别列表是第一要务。 当返回类别的JSON列表时,对于返回的每个类别,将新的AccordionPane添加到手风琴:


// create a var to store currently displayed posts
var displayedPosts = [];
// load json topics 
dojo.xhrGet({
url: '/',
handleAs: 'json',
content: {
json: 'get_category_index'
}
}).then(function(response) {
// for every topic...
dojo.forEach(response.categories,function(category,i) {
// create a new accordion item
var pane = new dijit.layout.AccordionPane({
title: category.title + '(' + category.post_count + ')'
},dojo.create('div',{ innerHTML: 'Loading ' + category.title + ' posts...' },accordionContainer.domNode));
accordionContainer.addChild(pane);

After the AccordionPane is within the Accordion, the next step is adding an onShow event to the AccordionPane which will load posts within the given category when the category receives focus:

在AccordionPane放入Accordion之后,下一步是向on AccordionPane添加一个onShow事件,当该类别获得焦点时,该事件将加载给定类别内的帖子:


// when this pane becomes selected...
var beenSelected = false;
dojo.connect(pane,'onShow',function() {
// if not selected yet...
if(!beenSelected) {
beenSelected = true;
// get posts for this category;  limit 100
dojo.xhrGet({
url: '/',
handleAs: 'json',
content: {
json: 'get_category_posts',
slug: category.slug,
count: 100
}
}).then(function(postsResponse) {
// empty content for the pane (removes loading message)
pane.set('content','');
// make content!

When the posts are loaded, a list of links is added to the AccordionPane:

加载帖子后,链接列表将添加到AccordionPane:


// make content!
var ul = dojo.create('ul',{},pane.domNode);
dojo.forEach(postsResponse.posts,function(post) {
//create list items and links
var li = dojo.create('li',{},ul),
a = dojo.create('a',{
href: '/' + post.slug,
innerHTML: post.title
},li);

With every link we create, it's necessary to add a click event which stops the user from leaving the page and generates a tab within the right TabContainer widget:

对于我们创建的每个链接,有必要添加一个click事件,该事件将阻止用户离开页面并在右侧的TabContainer小部件内生成一个标签:


// when the link is clicked, create a new tab pane and "select" it
dojo.connect(a,'onclick',function(e) {
// stop propagation
dojo.stopEvent(e);
// if this post isn't already open, create it...
if(!displayedPosts[post.slug]) {
//add a new tab content pane
displayedPosts[post.slug] = new dijit.layout.ContentPane({
title: post.title,
content: '<h1>' + post.title + '</h1>' + post.content,
closable: true
});
// add and select this tab
tabContainer.addChild(displayedPosts[post.slug]);

The next step is turning the "Continue Reading" and "Discussion" links into Dijit Button instances:

下一步是将“继续阅读”和“讨论”链接转换为Dijit Button实例:


// make links into buttons
dojo.behavior.add({
'.conred,.concom,.demo': function(node) {
var button = new dijit.form.Button({},node);
dojo.connect(button,'onClick',function() {
window.location = node.href;
});
}
});
dojo.behavior.apply();
//when this tab is closed, remove it from the opened list
dojo.connect(displayedPosts[post.slug],'onClose',function() {
displayedPosts[post.slug] = false;
return true;
});

To finish things off, we direct the first AccordionPane to show (and thus load posts) and then direct the Accordion to start up:

为了完成任务,我们指示第一个AccordionPane显示(并因此加载帖子),然后指示Accordion启动:


}
// select the tab!
tabContainer.selectChild(displayedPosts[post.slug]);
});
});
});
}
});
//if this is the *first* pane, load the content
if(i == 0) pane.onShow();
});
});
// start up the accordion!
accordionContainer.startup();
});

The code itself should be fairly self explanatory;  my comments should be of help.

该代码本身应该是相当自我解释的; 我的意见应该有所帮助。

完整JavaScript (The Complete JavaScript)

Here's the complete JavaScript source:

这是完整JavaScript来源:


/* require necessary classes */
dojo.require('dijit.layout.AccordionContainer');
dojo.require('dijit.layout.AccordionPane');
dojo.require('dijit.layout.TabContainer');
dojo.require('dijit.layout.ContentPane');
dojo.require('dijit.layout.BorderContainer');
dojo.require('dijit.form.Button');
dojo.require('dojo.behavior');
/* when all classes have loaded... */
dojo.ready(function() {
/* generate the layout */
// settings
var appbase = dojo.byId('appbase');
// create the layout container
var container = new dijit.layout.BorderContainer({
design: 'sidebar',
gutters: true
},dojo.create('div',{ style:'height:100%;width:100%;' },appbase));
// create the left sidebar
var accordionContainer = new dijit.layout.AccordionContainer({
splitter: true,
region: 'leading'
},dojo.create('div',{ style:'height:100%;width:30%;' },container.domNode));
container.addChild(accordionContainer);
// create the right content pane
var tabContainer = new dijit.layout.TabContainer({
tabPosition: 'top',
region: 'center'
},dojo.create('div',{ style:'height:100%;width:70%;' },container.domNode));
container.addChild(tabContainer);
// add an initial tab to the tabContainer
tabContainer.addChild(new dijit.layout.ContentPane({
title: 'Welcome!',
content: 'Click on any of the posts you see on the left side of the page.  All post previews will display here!'
},dojo.create('div',{},tabContainer.domNode)));
// start the layout up!
container.startup();
// create a var to store currently displayed posts
var displayedPosts = [];
// load json topics 
dojo.xhrGet({
url: '/',
handleAs: 'json',
content: {
json: 'get_category_index'
}
}).then(function(response) {
// for every topic...
dojo.forEach(response.categories,function(category,i) {
// create a new accordion item
var pane = new dijit.layout.AccordionPane({
title: category.title + '(' + category.post_count + ')'
},dojo.create('div',{ innerHTML: 'Loading ' + category.title + ' posts...' },accordionContainer.domNode));
accordionContainer.addChild(pane);
// when this pane becomes selected...
var beenSelected = false;
dojo.connect(pane,'onShow',function() {
// if not selected yet...
if(!beenSelected) {
beenSelected = true;
// get posts for this category;  limit 100
dojo.xhrGet({
url: '/',
handleAs: 'json',
content: {
json: 'get_category_posts',
slug: category.slug,
count: 100
}
}).then(function(postsResponse) {
// empty content for the pane (removes loading message)
pane.set('content','');
// make content!
var ul = dojo.create('ul',{},pane.domNode);
dojo.forEach(postsResponse.posts,function(post) {
//create list items and links
var li = dojo.create('li',{},ul),
a = dojo.create('a',{
href: '/' + post.slug,
innerHTML: post.title
},li);
// when the link is clicked, create a new tab pane and "select" it
dojo.connect(a,'onclick',function(e) {
// stop propagation
dojo.stopEvent(e);
// if this post isn't already open, create it...
if(!displayedPosts[post.slug]) {
//add a new tab content pane
displayedPosts[post.slug] = new dijit.layout.ContentPane({
title: post.title,
content: '<h1>' + post.title + '</h1>' + post.content,
closable: true
});
// add and select this tab
tabContainer.addChild(displayedPosts[post.slug]);
// make links into buttons
dojo.behavior.add({
'.conred,.concom,.demo': function(node) {
var button = new dijit.form.Button({},node);
dojo.connect(button,'onClick',function() {
window.location = node.href;
});
}
});
dojo.behavior.apply();
//when this tab is closed, remove it from the opened list
dojo.connect(displayedPosts[post.slug],'onClose',function() {
displayedPosts[post.slug] = false;
return true;
});
}
// select the tab!
tabContainer.selectChild(displayedPosts[post.slug]);
});
});
});
}
});
//if this is the *first* pane, load the content
if(i == 0) pane.onShow();
});
});
// start up the accordion!
accordionContainer.startup();
});

It may look like there's a lot of JavaScript but don't get intimidated by it; when you break down each code block, it should all make sense.

看起来好像有很多JavaScript,但不要被它吓倒了。 当您分解每个代码块时,它们都应该有意义。

有待改进 (Room For Improvement)

I've chosen to simply load posts and their previews.  You could easily load the complete posts with comments and all!  JSON API provides you more than enough methods to create a complete blog layout with JSON and whichever JavaScript toolkit you'd like.

我选择仅加载帖子及其预览。 您可以轻松地在完整的帖子中添加评论和所有内容! JSON API为您提供了足够多的方法,可以使用JSON和所需的任何JavaScript工具包创建完整的博客布局。

If I were looking to port this code to other sites or simply want to keep adding to the class, I would make this code into a custom Dijit widget.  I may do that in the future to show you how it's done.

如果我想将此代码移植到其他站点,或者只是想继续添加到类中,则可以将此代码制作到自定义Dijit小部件中。 将来我可能会告诉您它是如何完成的。

View Demo观看演示

There you have it!  The amount of existing code provided to you by Dojo, paired with its intelligent design and awesome Dijit architecture, makes creating advanced layouts quick, easy, and accessible.  I especially like how easy dealing with JSON and callbacks is with Dojo promises.  Have any suggestions for this layout?  Share them!

你有它! Dojo提供给您的大量现有代码,再加上其智能的设计和令人敬畏的Dijit架构,使得创建快速布局,快速,轻松和可访问性成为可能。 我特别喜欢使用Dojo promises来轻松处理JSON和回调。 对这种布局有什么建议吗? 分享他们!

翻译自: https://davidwalsh.name/dojo-wordpress

dojo创建浮动工具栏

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.luyixian.cn/news_show_727231.aspx

如若内容造成侵权/违法违规/事实不符,请联系dt猫网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

dz论坛mysql 占用cpu_解决宝塔面板CPU占满100%,负载100%网站缓慢等问题

宝塔服务器面板cpu、负载都是100%&#xff0c;一般来说这种问题的可能性很多&#xff0c;有可能是程序性能、服务器负载能力、PHP或Mysql并发访问、PHP-FPM进程占用、磁盘空间不足、木马病毒、被植入了挖矿程序等等&#xff0c;我们初步以几个方面来为大家做一下分析。其实这类…

在centOs 上搭建nginx来部署静态页面网站

2019独角兽企业重金招聘Python工程师标准>>> 一、部署服务器环境 nginx&#xff1a;轻量级、高性能的HTTP及反向代理服务器&#xff0c;占用内存少&#xff0c;并发能力强&#xff0c;相比老牌的apache作为web服务器&#xff0c;性能更加卓越。 在centOs上&#xff…

除了X站,程序员还喜欢上这些网站...

点击上方[全栈开发者社区]→右上角[...]→[设为星标⭐]说到p站&#xff0c;估计不知道的人已经很少了&#xff0c;除了p站还有哪些站&#xff1f;场主盲猜&#xff0c;应该很多人思考过这个问题了 二次元可是有ABCDEFGKNMTP站等诸多圣地的&#xff01;外面的世界很精彩&#xf…

大型网站技术架构:核心原理与案例分析 mobi_阿里架构师15年开发经验分享:Redis+JVM+Spring cloud+MySQL文档...

最近一个哥们去面试某当红大厂了&#xff0c;其中几个他印象深刻的面试题你们品品&#xff1a;1、介绍下如何对MySQL SQL语句进行分析和优化&#xff1f;2、Redis 怎样实现的分布式锁&#xff1f;3、如何实现本地缓存和分布式缓存&#xff1f;4、说一下 JVM 的内存布局和运行原…

mfc菜单建立响应步骤_设置以建立响应性网站

mfc菜单建立响应步骤Eric Wendelin is one versatile dude. When I met him he was writing Java at a small startup called Sun / Oracle, and now hes writing front-end code for a startup -- thats a big leap. With this responsive design post, Eric flexes a little …

Flutter 中文文档网站 flutter.cn 正式发布!

在通常的对 Flutter 介绍中&#xff0c;最耳熟能详的是下面四个特点&#xff1a;精美 (Beautiful)&#xff1a;充分的赋予和发挥设计师的创造力和想象力&#xff0c;让你真正掌控屏幕上的每一个像素。极速 (Fast)&#xff1a;基于 Skia 的硬件加速图形引擎&#xff0c;帮助你媲…

合并脚本和样式表_将脚本和样式供稿添加到您的网站

合并脚本和样式表Script & Style is a website created by myself and Chris Coyier where bloggers and developers alike submit articles about CSS, XHTML, jQuery, MooTools, and other website design and development topics. The sites popularity continues to gr…

vue网站案例_个人博客网站搭建

个人博客网站搭建VuePress介绍本人的个人博客网站&#xff0c;网站地址&#xff0c;是基于VuePress进行搭建。什么是VuePress根据官网&#xff1a;VuePress 由两部分组成&#xff1a;第一部分是一个极简静态网站生成器&#xff0c; 它包含由 Vue 驱动的主题系统和插件 API&…

如何将应用转换成系统应用_将网站转换为应用

如何将应用转换成系统应用Converting a website to a native app, whether on mobile or desktop, can be quite useful. The problem with bookmarks, especially for software engineers, is that we often need to work in different browsers, so having everything in on…

女朋友想让我的网站下点雪,我立马打开电脑…(附源码)

点击上方[全栈开发者社区]→右上角[...]→[设为星标⭐]前言女朋友常逛的设计网站这两天页面上多了下雪的效果&#xff0c;于是问我我的网站能下雪吗&#xff0c;作为一个程序员我一般会说实现不了&#xff0c;但是作为男朋友&#xff0c;不能说不行。雪雪我们可以使用span标签和…

amazon s3_在Amazon S3上托管网站

amazon s3Everyone knows that Amazon S3 is great for storing files. Its fast, inexpensive, and easy to setup. What you may not realize is that you can also host static websites on this robust platform. 众所周知&#xff0c; Amazon S3非常适合存储文件。 它快速…

linux文件服务器用途,文件服务器CPU篇 - 构建文件服务器:OS与CPU应用选择篇_服务器应用_Linux公社-Linux系统门户网站...

文件服务器CPU篇文件服务器的主要用途是存储&#xff0c;而不是处理能力&#xff0c;特别是家庭文件服务器而言&#xff0c;包括处理器在内部件都应该让位于硬盘、机箱和电源。文件服务器不需要最新的处理器&#xff0c;对于可能从来没必要将数据同时分发到多个客户机的文件服务…

必看,程序员应该访问的最佳网站

【公众号回复 “1024”&#xff0c;免费领取程序员赚钱实操经验】大家好&#xff0c;我是章鱼猫。今天给大家推荐的这个项目是「Best-websites-a-programmer-should-visit-zh」—— 程序员应该访问的最佳网站中文版&#xff0c;一些对程序员有用的网站。在学习 CS 的时候有一些…

查找微信公众号服务器,墨涩网 - 免插件实现微信公众号搜索连接wordpress网站文章——墨涩网...

微信公众号当前是每个用户都在使用的功能&#xff0c;而使用wordpress程序的站长会希望把自己的网站连接到微信公众号。连接后通过公众号访问网站的内容。目前网上有很多可以实现微信公众号和wordpress网站链接的插件很多&#xff0c;个人觉得醉的最好的应该是功能强大的水煮鱼…

php 网站语言切换,php 多语言切换

目录结构&#xff1a; // 文件内容&#xff1a; /include/language.php Java代码 ?php $languagesarray(); $languages[ zh-cn ][ name ] china ; $languages[ zh-cn ][ image ] flag1.jpg ; $languages[ en ][ name ] english目录结构&#xff1a;//文件内容&#xff1a;/inc…

突发:全球最大的同性交友网站挂了,修复长达四个小时的背后是一个悲伤的故事...

loonggg读完需要3分钟速读仅需 1 分钟今天下午&#xff0c;作为全球最大的同性交友网站&#xff1a;GitHub&#xff0c;突然挂了&#xff0c;一直在这两张图中间来回切换。再刷新一下&#xff0c;从 500 变成了小马&#xff0c;你还别说&#xff0c;我仔细看这个小马&#xff0…

2017年最受欢迎的10个编程挑战网站

来源&#xff1a;CSDN大数据 作者&#xff1a;Daniel Borowski 本文长度为1704字&#xff0c;建议阅读4分钟 如果你想不断地提高自己的编程技能&#xff0c;那么不断尝试去解决那些编程中的难题&#xff0c;这是一个非常不错的途径。本文为你列举了10个编程挑战网站&#xff0c…

透过日播放量超过6亿的《延禧攻略》,看2018视频网站格局

作者介绍徐麟目前就职于上海唯品会产品技术中心&#xff0c;哥大统计数据狗&#xff0c;从事数据挖掘&分析工作&#xff0c;喜欢用R&Python玩一些不一样的数据文章来源数据森麟如需转载&#xff0c;请联系原作者授权前言随着《延禧攻略》的播出&#xff0c;魏璎珞、富察…

看看黑客是如何攻破一个网站的?网友:原来...

点击上方[全栈开发者社区]→右上角[...]→[设为星标⭐]点击领取全栈资料&#xff1a;全栈资料通过本文你将了解黑客常用的入手思路和技术手法&#xff0c;适合热爱网络信息安全的新手朋友了解学习。本文将从最开始的信息收集开始讲述黑客是如何一步步的攻破你的网站和服务器的。…

有哪些网站,一旦知道,你就离不开了?

loonggg读完需要5分钟速读仅需 2 分钟大家好&#xff0c;我是你们的校长。感觉好久没有给大家分享工具类的好东西了&#xff0c;今天给大家分享几个好东西。作为程序员&#xff0c;一个技术人员&#xff0c;我从工作的角度和职场的角度给大家推荐几个非常不错的网站吧&#xff…