ASP.NET WHIDBEY China New Code Compile Features

zhaozj2021-02-11  158

ASP.NET WHIDBEY China New Code Compile Features

G. Andrew Duthiegraymad Enterprises, Inc. October 2003 Abstract: Learn how to use ASP.NET Whidbey to easily use code. The Code directory automatically compiles the code for your site, and the pre-compiled will make the deployment work easier. Download the source code of this article. (Note that in the sample file, the programmer's comment is in English. In this paper, it is translated into Chinese to facilitate the reader understanding.) Directory Introduction New modular code model / code directory interest calculator precompiled support Pred-compiled deployment pre-compilation IntelliSense is everywhere! Summary Introduction The new version of the new version of Microsoft® ASP.NET introduces a large number of new features and improvements, and its code is ASP.NET Whidbey, which is named according to the code of the new Microsoft® Visual Studio® .NET. Some of these features use the foundation Microsoft® .NET Framework version (ASP.NET Whidbey is new features based on this release). In these functions, one of the most useful features is related to code compilation. This article describes the main changes to the ASP.NET Whidbey compilation model, which is the impact of writing ASP.NET applications, and how to use these changes. Improved features and new compilation functions can be divided into the following four basic aspects:

Improvement of modular code model. New Code directory. Added support for pre-compiling ASP.NET applications. Microsoft® IntelliSense® Enhancements. The new modular code model By default, the site developed using Visual Studio .NET 2002 or 2003 uses a function called "modular code" to program a visual element (HTML tag, control, etc.) from the UI Logic is separated. When the developer creates a new web form (such as foo.aspx), Visual Studio automatically creates a related codeBeHind class file, the front part of the file name is the same as the web form, the back is .vb or .cs (depend The language used in the project). Class files will be associated with the web form via the CodeBehind and Inherits properties of the @ Page instruction. Class files contain event processing code (including code for binding event handlers to the corresponding event), and the separation declaration of each control (added to the .aspx file through the Visual Studio Web Form). After compiling (generated) Web application project, all CodeBehind classes will be compiled into a .NET program set, which will place it into the / bin directory of the web application. The web form page itself is compiled during runtime and each web form is inherited from the CodeBehind class related to it. For more information on the modular code model in Visual Studio .NET 2003 and ASP.NET 1.1, see MSDN Library Articles Web Forms Code Model. Although the initial modular code model is in theory (who does not want to separate the UI element to the programming logic phase?), There are still some shortcomings:

Need to be regenerated. In Visual Studio .NET, the CodeBehind class is not automatically compiled, so any changes to the CodeBehind class need to regenerate the entire project to apply these changes. (Note that you can specify dynamic compilation of the modular code file via the SRC property of the @ page instruction, but by default Visual Studio .NET does not do this.) Share development issues. Because all CodeBehind classes in the project have compiled into a program set, it is difficult to let multiple developers develop a project at the same time without encountering bottlenecks. The code is easily destroyed. Controls are exist simultaneously by declaring (in the .aspx page) and programming (in the CodeBehind class), if the two sets of controls are not properly synchronized, the code is easily destroyed. The complexity is increased, and the single file support is missing. In Visual Studio .NET, many functions for increasing productivity (including IntelliSense statements are completed) require modular code. Unfortunately, these features typically add a large number of relatively complex code in the CodeBehind class, which produces a problem that code is easily destroyed because the code that changes Visual Studio .NET is easy to destroy the page. After understanding these disadvantages, it is responsible for developing ASP.NET and Visual Studio .Net Whidbey group decided to reconsider the modular code model. The new modular code model uses the new features known as the local class (known as local types in C #) Microsoft® Visual Basic® .NET and C #. The local class allows you to define different parts of a class in multiple files. When compiling, these parts are combined together by the compiler. ASP.NET Whidbey uses the new CompileWith and ClassName properties in the @ Page instruction to identify the CodeBehind partial class that is integrated with the .aspx page. By using local classes, some other changes can be made, the ASP.NET team can implement the following: No need to write control declarations and event binding code in the CodeBehind class (bind events through the declaration in the control declaration). Allow runtime to dynamically compile the web form page and the CodeBehind class, no need to regenerate the entire project for a subtle changes. Reduce the phenomenon of file contention in sharing development. The same IDE experience can be obtained for developers using modular code files and like single file development (all code and tags are included in .aspx files). Different views of the modular code model before and after the modular code model are given. The following code is just the default code created by Visual Studio when using a modular code to add a new web form (in Visual Studio .NET WHIDBey as a code-separated web form), the default code created by Visual Studio: Visual Studio .NET 2002/2003 Webform1.aspx: <% @ page language = "vb" autoeventwireup = "false"

Codebehind = "Webform1.aspx.vb" inherits = "TestWebApp_121602.webform1"%>

Webform1 </ Title> <meta name = "generator" content = "Microsoft Visual Studio .NET 7.1"></p> <p><meta name = "code_language" content = "Visual Basic .NET 7.1"></p> <p><meta name = vs_defaultclientscript content = "javascript"></p> <p><meta name = vs_targetschema</p> <p>Content = "http://schemas.microsoft.com/intellisense/ie5"></p> <p></ hEAD></p> <p><body ms_positioning = "gridLayout"> <form id = "form1" method = "post" runat = "server"></p> <p></ form></p> <p></ body></p> <p></ html></p> <p>Webform1.aspx.vb: Public Class Webform1</p> <p>Inherits System.Web.ui.page</p> <p>#Region "The code" of the web form designer "</p> <p>'This call is required for the web form designer.</p> <p><System.diagnostics.debuggerstepthrough ()> _ _</p> <p>Private subinitializeComponent ()</p> <p>End Sub</p> <p>'Note: The following placeholders are declared</p> <p>The 'Web Form Designer is required.</p> <p>'Do not delete or change its location.</p> <p>Private DesignerPlaceHolderDeclaration as System.Object</p> <p>Private sub page_init (byval sender as system.object, _</p> <p>Byval e as system.eventargs) Handles mybase.init</p> <p>'Codegen: This method call is required for the web form designer.</p> <p>'Do not modify it using the code editor.</p> <p>InitializeComponent ()</p> <p>End Sub</p> <p>#End region</p> <p>Private sub page_load (byval sender as system.Object, _</p> <p>BYVAL E as system.eventargs) Handles mybase.load</p> <p>'Place the user code used to initialize this page</p> <p>End Sub</p> <p>END CLASS</p> <p>Visual Studio .NET whidbey default.aspx: <% @ page language = "VB" compilewith = "default.aspx.vb"</p> <p>ClassName = "asp.default_aspx"%></p> <p><html></p> <p><head runat = "server"></p> <p><title> No title page </ Title></p> <p></ hEAD></p> <p><body></p> <p><form runat = "server"></p> <p></ form></p> <p></ body></p> <p></ html></p> <p>Default.aspx.vb: imports Microsoft.visualBasicNamespace ASP</p> <p>Expands Class Default_ASPX</p> <p>END CLASS</p> <p>End Namespace</p> <p>From the above example, you can clearly see that the code generated by Visual Studio .Net Whidbey is more clear and easy to read. This goal does not need to sacrifice drag and drop function or IntelliSense. / Code directory ASP.NET Whidbey Another very cool and practical new feature is to increase / code directory. / Code directory is similar to the / bin directory, is a special directory for ASP.NET, but it is different from / bin directory: / bin directory is used to store the precompiled assembly used by the application, and / code directory Used to store class files to be dynamically compiled during runtime. This allows you to store the business logic components, data access components, and classes of other components in a location in the application and use these classes from any page. Because these classes are dynamically compiled during runtime, they are automatically referenced by the application containing / code directory, so they do not need to generate items before deploying projects, nor does it need to be explicitly adding class references. You can make changes to the components in peace of mind and then deploy using simple XCOPY or drag and drop operations. In addition to simplifying components deployment and reference, / code directory also greatly simplifies the creation and access process of resource files (.resx) used in the localization process, and automatically generates and compiles the Agent class for WSDL files (.wsdl). process. In order to better explain the implementation of the above operation, let us first see a few examples. In the first example, we will see how to create a simple business component and how to access it from the web form page. Interest Calculator First, we open Visual Studio .Net Whidbey, create a new Web site called Compilation. After creating a Web site, the IDE should be similar to Figure 1. Figure 1: Visual Studio .Net Whidbey Web Site, then add / code folder to the Web site, add the method to right click on the item, then select New Folder (New Folder). This folder must be named CODE, but the name is not case sensitive. After adding a folder, we can add a new class file: Right-click the / code folder, click Add New Item ... (add new item ...), then in the Add New Item dialog Select the Class (Class) item in the Templates pane. Name the class CalculateINTEREST.VB. Then add the code used to calculate interest (add it to the Class and End Class statements): Public Function Calcbalance (Byval Prencpl As INTEGER, _</p> <p>Byval rate as double, _</p> <p>Byval year as integer, _</p> <p>BYVAL Period As Integer AS String</p> <p>DIM Basenum as double = (1 rate / period)</p> <p>Calcbalance = _</p> <p>Format (PrNCPL * System.math.Pow (Basenum, _</p> <p>(Years * period), "#, ###, ## 0.00"). Tostring</p> <p>END FUNCTION</p> <p>After creating component classes, we need to modify the DEFAULT.ASPX page to provide a field for entering data, requiring the CalcBalance method of the component. For the sake of simplicity, the complete list of Default.aspx displays the following (please note that default.aspx uses a single file code model). Default.aspx: <% @ page language = "VB"%> <script runat = "server"></p> <p>Sub Button1_Click (Byval Sender As Object, _</p> <p>ByVal e as system.eventargs)</p> <p>DIM CALC AS New CalculateInterest</p> <p>Label6.Text = "$" & _</p> <p>Calc.calcbalance (Convert.Toint32 (TextBox1.text), _</p> <p>(Convert.Toint32 (TextBox2.text) / 100), _</p> <p>Convert.TOINT32 (TextBox3.text), _</p> <p>Convert.TOINT16 (DropDownList1.SelectedValue))</p> <p>Label6.visible = true</p> <p>End Sub</p> <p></ script></p> <p><html></p> <p><head runat = "server"></p> <p><Title> Interest Calculator </ Title></p> <p></ hEAD></p> <p><body></p> <p><form runat = "server"></p> <p><asp: label id = "label1"</p> <p>Runat = "Server"> P this gold ($): </ asp: label></p> <p><asp: textbox id = "textbox1" runat = "server"></p> <p></ asp: textbox></p> <p><br /></p> <p><asp: label id = "label2"</p> <p>Runat = "Server"> Interest rate (%): </ asp: label></p> <p><asp: textbox id = "textbox2" runat = "server"></p> <p></ asp: textbox></p> <p><br /></p> <p><asp: label id = "label3" runat = "server"> Number: </ asp: label></p> <p><ask: textbox id = "textbox3" runat = "server"></p> <p></ asp: textbox></p> <p><br /></p> <p><asp: label id = "label4"</p> <p>Runat = "Server"> Deli frequency: </ asp: label></p> <p><ask: DropDownList ID = "DropDownList1" runat = "server"></p> <p><asp: listitem value = "1"> Every year </ asp: listItem></p> <p><asp: listitem value = "4"> Each season </ asp: listitem> <asp: listitem value = "12"> monthly </ asp: listitem></p> <p><asp: listitem value = "365"> Daily </ asp: listItem></p> <p></ ask: DropDownList></p> <p><br /></p> <p><asp: label id = "label5"</p> <p>Runat = "server"> balance: </ asp: label></p> <p><asp: label id = "label6"</p> <p>Visible = "false" runat = "server"> </ asp: label></p> <p><br /></p> <p><asp: button id = "button1"</p> <p>Runat = "server" text = "calculate" οnclick = "button1_click" /></p> <p></ form></p> <p></ body></p> <p></ html></p> <p>In the design view, the modified Default.aspx should be similar to Figure 2. Figure 2: DEFAULT.ASPX in the design view requires that when you type the code in the <Script> block used to invoke the component class, the complete IntelliSense statement is completed (including the component class), as shown in Figure 3 . This is a major improvement on the Visual Studio .NET 2003, Visual Studio .NET 2003 does not support IntelliSense in the server-side <script> block. Figure 3: IntelliSense in the source view browsing DEFAULT.ASPX generates the output shown in Figure 4. Fill in the principal, interest rates, and number of years, then click Calculate, the output should be similar to Figure 5. Figure 4: Initial output of DEFAULT.ASPX Figure 5: Calculated Output Resource File If you have used a web application in Visual Studio .NET 2002 or 2003, you must have noticed that every time you create a new web form page. Visual Studio also creates a match file (ie Webform1.aspx.resx) with a .resx extension. Like most web developers, you may also ignore or try to delete these files because their uses and / or usage are not very intuitive. Briefly, these .resx files are called "resource files", primarily to store all versions of resources, such as text strings for different languages ​​for localization. In Visual Studio .NET 2002 and 2003, the resource file needs to be added to the project assembly as part of the generation project process, and you need to import two namespaces, create a resourceManager object, and call its getString method to access the resource string. With the help of / code directory, the resource access process in Visual Studio .NET Whidbey is very simple, as shown in the example below. Let's start with the creation resource file or use the items in the previous example. First, right-click the Compilation Web site you just created, then click Add New Item ... (add new items ...). In the Add New Item dialog box, select the Assembly Resource File template, name the resource file Strings.resx, and then click Open. The default view of the Strings.resx file should be similar to Figure 6. Figure 6: Editing the resource file in the XML editor Add the following to the data table (you can reserve the "comment", "Type", and "MIMETYPE" column is empty):</p> <p>Name Value TXTColorPrompt Please select a color: txtcolorresponsered you selected red! TXTCOLORRESPONSEGREEN You have chosen green! TXTCOLORRESPONSEBLUE You have chosen blue! Repeat the above process now, add a new resource file called strings.en-gb.resx, and add the following to its data table, then save the file (because we didn't add TXTCOLORRESPONSE *, all clients The value of these items in Strings.resx will be used): Name value txtColorPrompt Please select a color: Now, in order to take advantage of the magic effect of the Code directory, we need to drag these two .resx files from the root of the Web site to In the Code directory. After completing the above operation, the results similar to Fig. 7 will be obtained. Figure 7: The .resx file in the code directory is to illustrate how easy to use the resource file created now. We add a web form to the project. The method is as follows: Right-click on the Web site node, and then click Add New Item .. (Add new items ...). In the Add New Item dialog box, select the web form, name the page to ColorPicker.aspx, and then click Open. Modify this page to match the following list. ColorPicker.aspx: <% @ Page Uicle = "EN-GB" Language = "VB"%></p> <p><script runat = "server"></p> <p>Sub Page_Load (Byval E AS ISTEM.EventArgs)</p> <p>Label1.text = Resources.strings.txtColorPrompt</p> <p>End Sub</p> <p>Sub submit_click (Byval Sender as Object, _</p> <p>ByVal e as system.eventargs)</p> <p>Label1.Forecolor = _</p> <p>System.drawing.color.fromname (DropdownList1.SelectedValue)</p> <p>Select Case DropdownList1.SelectedValue</p> <p>Case "red"</p> <p>Label1.text = resources.strings.txtColorResponsered</p> <p>Case "green"</p> <p>Label1.text = Resources.strings.txtColorResponsegreen</p> <p>Case "Blue"</p> <p>Label1.text = resources.strings.txtColorResponseblue</p> <p>End SELECT</p> <p>DropDownList1.visible = false</p> <p>Submit.visible = false</p> <p>End Sub</p> <p></ script></p> <p><html></p> <p><head runat = "server"></p> <p><Title> Color Pickup </ Title></p> <p></ hEAD></p> <p><body></p> <p><form runat = "server"></p> <p><ask: label id = "label1" runat = "server"> label </ ask: label> <ask: DropdownList ID = "DropDownList1" runat = "server"></p> <p><asp: listitem value = "red"> red </ asp: listItem></p> <p><asp: listitem value = "green"> Green </ asp: listitem></p> <p><asp: listitem value = "blue"> Blue </ asp: listitem></p> <p></ ask: DropDownList></p> <p><asp: button id = "submit"</p> <p>Text = "Submit" runat = "server" οnclick = "submit_click" /></p> <p></ form></p> <p></ body></p> <p></ html></p> <p>When browsing colorPicker.aspx from your browser, the default output is similar to Figure 8. If you browse this page from the system set for British users (you can simulate this situation by setting the UICURE property to "EN-GB" and save the page), the output will be similar to Figure 9 (please note that we are already U) is added "COLOUR". Figure 8: The default output of ColorPicker.aspx Figure 9: COLORPICKER.ASPX Output of the British system, please note that only one line of code is required in ASP.NET Whidbey. This resource file can be automatically embedded and referenced to the resource file to the Code directory, so you don't need to reference any namespace or assembly, nor does it need to create an object for accessing the resource string. And ASP.NET can also determine which resource file (based on user browser settings), so we do not need to judge and respond to this at runtime. ASP.NET can help us complete all this. Pre-compiling ASP.NET Web Forms The advantages of ASP.NET Web Forms are to increase dynamic compilation, you can easily change .aspx pages, save changes when saving changes, without recompilation (as long as you do not use modular code) . But dynamic compilation is not suitable for each application, and when accessing an application first, dynamic compilation will result in a decrease in the initial performance of the browser. In addition, many times you might want to deploy an application without source code. If you are in the above situation, you would prefer that ASP.NET Whidbey has a function of supporting the precompiled Web site. ASP.NET Whidbey supports two precompiled modes: pre-compiling and deploy preparatory preparation. In the pre-compilation, you can compile all the pages in the Web site to all pages in the Web site. This is also the first time that the user occurs after clicking a page in your application (except for the latter case mentioned above), users only need to sit down and wait for the batch compilation. Use two main reasons in the precompilation: First, it avoids the performance of the compilation when the first request page is decreasing; secondly, it allows you to "prior" users find compilation errors. It is also easy to implement in the pre-compilation, just browse to the root directory of the Web site, add a specific handler name precompile.axd (user familiar with the ASP.NET trace "will find that the name is similar to the name of the trace.axd handler : Http://localhost/mywebsitename/Precompile.axd</p> <p>Where myWebsitename is the name of your Web site. After the precompilation site, the request for the page within the site should be completed, and there will be no compilation lag. Deploying the second precompilation mode allows you to create an executable version of the entire Web site, deploying this version does not require any source code (including HTML and other static files). Therefore, deployment pre-compilation prevents others from accessing the intellectual property information indicated by the code. The generated assembly and STUB file set can be deployed on the production server via XCOPY, FTP, Windows Explorer, and the like. For the pre-compilation site for deployment, ASP.NET Whidbey provides a command-line utility called ASPNET_COMPILER.EXE. To call the ASP.NET Precorder on the File System Web site, you need to open a command window, browse to the .NET Framework installation location (<Windows> / Microsoft.Net/framework/ <version>), then enter the following command: ASPNET_COMPILER / V / <Websitename> -p <Source> <Destination> Where <Websitename> is the name of the web site (ie, the name entered in the browser), <source> and <destination> for two file system paths, respectively Point to the location of the compilation site and the selected version should be output. Take our web site as an example, the input command is as follows (Note the following is a command): ASPNET_COMPILER / V / COMPILATION</p> <p>-p: / Websites / CompiLATION C: / Websites / CompiLation_Compiled If you want to view all available options for the ASP.NET Precipcherator, simply enter the following command: aspnet_compiler /?</p> <p>Note that some command line options require a Web site to work for a valid Microsoft® Internet Information Services (IIS) application. If you browse to the target directory in the Microsoft® Windows Explorer, you will see a site that contains the bin directory after the precompiled Web site, and the bin directory contains some assemblies and descriptive files, as well as the same name with the original page. The stub file, but does not contain code (including HTML and executable code). If you browse this site, the output is the same as the original site. Please note that you cannot use in the pre-compiled site on a pre-compiled site, because it has been precompiled. IntelliSense is everywhere! For Visual Studio .NET 2002 and 2003, one of the most powerful issues (I believe that many developers have the same feeling) is inconsistent with IntelliSense and other functions used to increase productivity. Want to drag the control from the toolbox to the page in the HTML view? I can't do it. In fact, I can't see the web form panel of the toolbox at all in the HTML view! To write embedded code on the .aspx page instead of using modular code? It can be done, but you must give up IntelliSense, drag and drop function, and other more features. Finally, as I recently mentioned in the article published on the MSDN ASP.NET Developer Center, supports the design of custom controls in Visual Studio .NET 2002 or 2003, supports the need to cross the layer barriers, including a bit rough but work. XSL modification. It is gratifying that ASP.NET WHIDBEY implements unity of compilation models, all of which are all solved. In Visual Studio .NET Whidbey, you can write embedded code or use a new modular code model, and you can get control drag and drop, IntelliSense statement completion, and all previously you want to use but cannot be used due to coding methods. Improve productivity. In addition, there is a big improvement in the design of custom server controls and web controls, including custom controls in the source view (HTML view in Visual Studio .NET WHIDBEY) adds the IntelliSense statement completed . Summary ASP.NET WHIDBEY changes to compilation models, and the improvement of corresponding functions in Visual Studio .Net Whidbey is undoubtedly a huge leap, not only provide the developer's flexibility, but also allows them to make full use of IDE Can improve productivity. A greatly simplified modular code model will make this feature more useful, more simple, and more complete support for embedded code is clearly welcomed by developers who want all code to be in one .aspx file. I believe that the / Code Catalog will greatly increase productivity, which is especially true for developers who are engaged in the development of fast-growing small and medium-sized projects, as well as developers who do not work hard because the compilation process is too complicated. It also provides a more direct, simple way to access business logic components, resource files, WSDL files, and other resources: with automatic compilation, embedding or creation of these resources and automatically quote them, only small code You can access these resources. The precompiled function enables developers to easily increase the initial performance of its site, and can also add protection to important intellectual property information by providing a functional web application (excluding source or html).</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-5350.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="5350" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.035</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = 'gOtc0Qo9VlOYOaKFYHjyWXgftqg_2B6TXiklC4G_2FRorOhJxkHbgJjl8PkQ812HJuap8n5opZn8DRoPA_2F6i9Azjag_3D_3D'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>