EonerCMS-CMS for a desktop-like system (III)

Source: Internet
Author: User

In a twinkling of an eye, it seems that more than half a month has passed and has recently been busy with other things, so the progress of this CMS is also slow, but yesterday and today I added a little shift, make the biggest one, that is, what I want to say below --

Window

Let's take a look at the approximate structure of the window:

The window is very simple. The title area at the top, the display area in the middle, and the functional area at the bottom. First, the window must be generated after the icon is clicked, that is, the window is not loaded and hidden in advance, but is clicked on an icon and then written to the page through jquery, we need to bind an event to the icon to create a window. Let's look at the Code:

// Create a form Core. create = function (obj) {var SC = obj. attr ('shortcut '); var window_warp = 'window _' + shortcut [SC] [0] + '_ warp '; var window_inner = 'window _ '+ shortcut [SC] [0] +' _ inner '; var resizeTemp =' <div resize = "{resize_type}" style = "position: absolute; overflow: hidden; background: url (img/transparent.gif) repeat; display: block; {css} "></ div> '; _ cache. resize = {"t": "left: 0; top:-3px; width: 100%; height: 5px; z-index: 1; cursor: n-resize ", "r": "right:-3px; top: 0; width: 5px; height: 100%; z-index: 1; cursor: e-resize", "B ": "left: 0; bottom:-3px; width: 100%; height: 5px; z-index: 1; cursor: s-resize", "l": "left: -3px; top: 0; width: 5px; height: 100%; z-index: 1; cursor: w-resize "," rt ":" right:-3px; top: -3px; width: 10px; height: 10px; z-index: 2; cursor: ne-resize "," rb ":" right:-3px; bottom:-3px; width: 10px; height: 10px; z-index: 2; cursor: se-resize "," lt ":" left:-3px; top:-3px; width: 10px; height: 10px; z-index: 2; cursor: nw-resize "," lb ":" left:-3px; bottom:-3px; width: 10px; height: 10px; z-index: 2; cursor: sw-resize "}; $ ('# desk '). append ('<div id = "' + window_warp + '" window = "' + shortcut cut [SC] [0] + '" class = "window-container window-current" style = "width: '+ shortcut [SC] [4] + 'px; height:' + shortcut [SC] [5] + 'px; top: '+ shortcut [SC] [6] + 'px; left:' + shortcut [SC] [7] + 'px; z-index: '+ Core. config. createIndexid + '"> <div id ="' + window_inner + '"style =" height: 100% "> </div> '); $ ("#" + window_warp ). data ("info", {width: shortcut [SC] [4], height: shortcut [SC] [5], top: shortcut [SC] [6], left: shortcut [SC] [7]}); Core. config. createIndexid + = 1; $ ('#' + window_inner ). append ('<div class = "title-bar">' + shortcut [SC] [1] + '<div class = "title-handle"> <a class = "ha -hide "btn =" hide "href =" # ha-hide "> minimized </a> <a class =" ha-max "btn =" max "href = "# ha-max "> maximize </a> <a class =" ha-revert "btn =" revert "href =" # ha-revert "style =" display: none "> restore </a> <a class =" ha-close "btn =" close "href =" # ha-close "> close </a> </div> </div> '); $ ('#' + window_inner ). append ('<div class = "window-frame"> <div style = "z-index: 9000000; background: none; height: 100%; position: absolute; width: 100%; filter: alpha (opacity = 0);-moz-opacity: 0; opacity: 0; display: none "> </div> <iframe frameborder =" 0 "id =" frame "+ Cut [SC] [0] + '" src = "' + cut [SC] [3] + '"> </iframe> </div> '); $ ('#' + window_inner ). append ('<div class = "set-bar"> <div class = "fr"> <a id = "refresh" class = "btn"> <I class = "icon ico-refresh "> </I> <span class =" btn-con "> refresh </span> </a> </div> '); for (var k in _ cache. resize) {var ele = FormatModel (resizeTemp, {resize_type: k, css: _ cache. resize [k]}); $ ('#' + window_inner ). append (ele);} // bind the window to move event Core. bindWindowMove ($ ('#' + window_warp); // bind the window zoom event Core. bindWindowResize ($ ('#' + window_warp); // bind the window function button event Core. handle ($ ('#' + window_warp ));};

We can see from here, because the previous definition:

$ ('# Desk '). append ('<div id = "' + window_warp + '" window = "' + shortcut cut [SC] [0] + '" class = "window-container window-current" style = "width: '+ shortcut [SC] [4] + 'px; height:' + shortcut [SC] [5] + 'px; top: '+ shortcut [SC] [6] + 'px; left:' + shortcut [SC] [7] + 'px; z-index: '+ Core. config. createIndexid + '"> <div id ="' + window_inner + '"style =" height: 100% "> </div>'); (1) $ ("#" + window_warp ). data ("info", {width: shortcut [SC] [4], height: shortcut [SC] [5], top: shortcut [SC] [6], left: shortcut [SC] [7]}); (2) Core. config. createIndexid + = 1; (3) $ ('#' + window_inner ). append ('<div class = "title-bar">' + shortcut [SC] [1] + '<div class = "title-handle"> <a class = "ha -hide "btn =" hide "href =" # ha-hide "> minimized </a> <a class =" ha-max "btn =" max "href = "# ha-max "> maximize </a> <a class =" ha-revert "btn =" revert "href =" # ha-revert "style =" display: none "> restore </a> <a class =" ha-close "btn =" close "href =" # ha-close "> close </a> </div> </div> '); (4) $ ('#' + window_inner ). append ('<div class = "window-frame"> <div style = "z-index: 9000000; background: none; height: 100%; position: absolute; width: 100%; filter: alpha (opacity = 0);-moz-opacity: 0; opacity: 0; display: none "> </div> <iframe frameborder =" 0 "id =" frame "+ Cut [SC] [0] + '" src = "' + cut [SC] [3] + '"> </iframe> </div> '); (5) $ ('#' + window_inner ). append ('<div class = "set-bar"> <div class = "fr"> <a id = "refresh" class = "btn"> <I class = "icon ico-refresh "> </I> <span class =" btn-con "> refresh </span> </a> </div> '); (6)

(1) Here I add a div to # desk, which is the div of the entire form, and the form is in the use status, because the newly created window must be in the use status and will not be overwritten under other windows, I wrote z-index in the style, and the value is not fixed. (3) I add 1 to the global variable z-index immediately after the addition, so that the newly created form can appear at the top.

(2) After adding the form, I immediately bound its data to the form, namely width, height, top, and left. After that, I will explain how to use it and skip it first.

(4) Then I add the four necessary buttons for the form to minimize, maximize, restore, and close. Of course, the restore button is hidden.

(5) Then I loaded the iframe to display the page to be loaded.

(6) I added the function bar at the bottom.

Then let's take a look at this Code:

for(var k in _cache.resize){var ele = FormatModel(resizeTemp,{resize_type:k, css:_cache.resize[k]});$('#'+window_inner).append(ele);}

I defined an array (_ cache. resize), here we are looping it. In the circular body, I used a FormatModel (). I mentioned this method in the previous article, so I will not describe the usage: plug-in for a self-written share button (extensible, with a development and production process included)

The length of this array is 8, that is, this loop adds a total of 8 Divs, So what are these 8 divs? Let's see the figure below:

By the way, there are eight directions. I believe that some shoes should know what to use. That is, the Form Scaling needs to be used. I will bind events to these eight divs separately, let them scale the form size.

At this point, the function of adding a form is roughly complete, but it still needs to be improved. For example, if the form of the same icon has been created, you do not need to create it again. Instead, you only need to change the style of the form, for example, you can change the value of z-index to the usage status. I will not post the specific code. I will leave it for analysis.

Taskbar

When creating a form, you also need to create a taskbar. The code is very simple. Let's take a look at it:

$('.task-window li b').removeClass('focus');$('.task-window').append('<li window="'+shortcut[sc][0]+'"><b class="focus"><span>'+shortcut[sc][1]+'</span></b></li>');

The principle is to clear the selected style of an existing task in the taskbar before adding the task, and then add a new task.

Switch window

When I open more than two windows at the same time, I directly switch the window events in the window or in the taskbar. The function is relatively simple. Let's take a look at the code first, then I will explain my thoughts a little more.

// Taskbar Core. taskwindow = function (obj) {var window_warp = 'window _ '+ obj. attr ('window') + '_ warp'; var window_inner = 'window _' + obj. attr ('window') + '_ inner'; // change the taskbar style $ ('. task-window li B '). removeClass ('focal '); obj. children ('B '). addClass ('core'); // values ({'z-Index': Core. config. createIndexid }). show (); // change the style of the window mask layer $ ('. window-frame '). children ('div '). show (); $ ('#' + window_inner + '. window-frame '). children ('div '). hide (); Core. config. createIndexid + = 1 ;}; // window Core. container = function (obj) {// change the taskbar style $ ('. task-window li B '). removeClass ('focal '); $ ('. task-window li [window = "'+ obj. attr ('window') + '"] B '). addClass ('core'); // values ({'z-Index': Core. config. createIndexid}); // change the style of the window mask layer $ ('. window-frame '). children ('div '). show (); obj. find ('. window-frame '). children ('div '). hide (); Core. config. createIndexid + = 1 ;};

The general idea is that when I click a task in the taskbar, find the corresponding window for the task, display and update the z-index, and change myself to the selected status, similarly, when you click a window, an event similar to this will be triggered. You can see that the code execution process is almost the same through the annotations in the two functions.

Here is a tip. Do you still remember the three parts of the window? Top, center, and bottom, and iframe in the middle. TIPS: When I create a form, I add a div mask layer to the iframe. The width and height are exactly the same as that of iframe. When the form is not in use, for example, it is overwritten by another window, the mask layer is displayed, and the iframe is just covered. Because the mask layer is transparent, there is no difference. Why do we need to do this? In this way, when switching the window, click events can not only be written in the title area on the top, but also click iframe (mask layer when actually clicking) you can also implement the form switching function. Of course, the mask layer should be hidden immediately after the switch.

Let's talk about it today. Next time I will show you how to move and scale the window. The reason why I need to pull it out is that I have been doing this for the past two days, although it is done now, it still seems a bit problematic and there are still many things to be optimized, so next time I will leave out my questions and hope to be answered by the experts.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.