
{"id":862,"date":"2016-02-24T11:10:43","date_gmt":"2016-02-24T11:10:43","guid":{"rendered":"http:\/\/blogs.plymouth.ac.uk\/telmed\/?p=862"},"modified":"2016-02-24T11:10:43","modified_gmt":"2016-02-24T11:10:43","slug":"added-jquery-to-your-lectora-project-to-create-an-image-slider","status":"publish","type":"post","link":"https:\/\/blogs.plymouth.ac.uk\/digital-education\/added-jquery-to-your-lectora-project-to-create-an-image-slider\/","title":{"rendered":"Added jQuery to your Lectora project, to create an image slider."},"content":{"rendered":"<p><strong>Added jQuery to your Lectora project, to create an image slider.<\/strong><\/p>\n<p>I have created this blog entry to help anyone who is struggling to create an image slider in Lectora.<br \/>\nOpen and save a new Lectora project.<\/p>\n<p>Within the folder structure create a new folder called Script.<\/p>\n<p>You will need to download the following two files and place them in your Script folder (if the files don\u2019t download correctly you will need to copy and paste the content into a DW file and save.)<\/p>\n<p><span style=\"color: #3366ff\">https:\/\/code.jquery.com\/jquery-1.11.1.min.js<br \/>\n<\/span><span style=\"color: #3366ff\">http:\/\/code.jquery.com\/ui\/1.11.1\/jquery-ui.min.js<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-864 \" src=\"http:\/\/blogs.plymouth.ac.uk\/digital-education\/wp-content\/uploads\/sites\/96\/2016\/02\/Script_file.png\" alt=\"Script_file\" width=\"401\" height=\"234\" \/><\/p>\n<p>Once you have your .js files we need to create a \u2018my_functions.js\u2019 file, this where the code for the slider will be held.<br \/>\nCreating the \u2018my_functions.js\u2019 file in DW<br \/>\nIn Dreamweaver copy and paste the following code and save as a .js file, save the file to your Script folder.<\/p>\n<p><span style=\"color: #0000ff\">\/\/ this function is executed on Page Show in Lectora, when the page is opened.<\/span><br \/>\n<span style=\"color: #0000ff\">function init_drag_slider() {<\/span><br \/>\n<span style=\"color: #0000ff\">\/\/the minimum \u2018x\u2019 coordinate of the dragger.<\/span><br \/>\n<span style=\"color: #0000ff\">minimumPosition = $(&#8216;.base&#8217;).position().left;<\/span><br \/>\n<span style=\"color: #0000ff\">\/\/the maximum \u2018x\u2019 coordinate of the dragger.<\/span><br \/>\n<span style=\"color: #0000ff\">maximumPosition = $(&#8216;.base&#8217;).width() &#8211; $(&#8216;.dragger&#8217;).width();<\/span><\/p>\n<p><span style=\"color: #0000ff\">\/\/making the &#8220;dragger&#8221; image drag-able<\/span><br \/>\n<span style=\"color: #0000ff\">\u00a0\u00a0\u00a0 $(&#8216;.dragger&#8217;).drag-able({<\/span><br \/>\n<span style=\"color: #0000ff\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 axis: &#8220;x&#8221;,\u00a0\u00a0\u00a0 \/\/only horizontal movement<\/span><br \/>\n<span style=\"color: #0000ff\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 containment: &#8220;.base&#8221;, \/\/contained with the region of the &#8220;base&#8221; image<\/span><br \/>\n<span style=\"color: #0000ff\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 drag: function( event, dragger ) {\u00a0\u00a0 \/\/this function will fired every time the dragger moves<\/span><br \/>\n<span style=\"color: #0000ff\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/calculate the dragger position between 0 and 1<\/span><br \/>\n<span style=\"color: #0000ff\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 position = (dragger.position.left &#8211; minimumPosition) \/ maximumPosition;<\/span><\/p>\n<p><span style=\"color: #0000ff\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/converts it into amount of images you have, where the 100 is, is the amount of \/\/images you have change as required<\/span><br \/>\n<span style=\"color: #0000ff\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 result = Math.round(position*100);<\/span><br \/>\n<span style=\"color: #0000ff\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 $(&#8216;.counter span&#8217;).text(result);<\/span><\/p>\n<p><span style=\"color: #0000ff\">$(&#8216;.imgslider&#8217;).hide();<\/span><br \/>\n<span style=\"color: #0000ff\"> \/\/targets all instances of .imgslider (included in css classes under appearance in Lectora for \/\/each image.)<\/span><\/p>\n<p><span style=\"color: #0000ff\">$(&#8216;.img&#8217;+result).show();<\/span><br \/>\n<span style=\"color: #0000ff\"> \/\/target .img + result which is the number from the slider &#8211; you to add e.g. imgslider \/\/img1\/imgslider img2 etc. to each image for the slider to work.<\/span><\/p>\n<p><span style=\"color: #0000ff\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }<\/span><\/p>\n<p><span style=\"color: #0000ff\">\u00a0\u00a0\u00a0 });<\/span><\/p>\n<p><span style=\"color: #0000ff\">}<br \/>\n<\/span><br \/>\nAdding the jQuery<\/p>\n<p>Once you have set up your folder and files, add an HTML External object to you project, which is in the insert tab, HTML External.<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-865 \" src=\"http:\/\/blogs.plymouth.ac.uk\/digital-education\/wp-content\/uploads\/sites\/96\/2016\/02\/insert_html.png\" alt=\"insert_html\" width=\"501\" height=\"328\" \/><br \/>\nSelect the HTML External object and within properties and under \u2018Type\u2019 select Meta tags.<a href=\"http:\/\/blogs.plymouth.ac.uk\/digital-education\/wp-content\/uploads\/sites\/96\/2016\/02\/HTML-External-object.png\"><br \/>\n<\/a><a href=\"http:\/\/blogs.plymouth.ac.uk\/digital-education\/wp-content\/uploads\/sites\/96\/2016\/02\/HTML-External-object.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-866 \" src=\"http:\/\/blogs.plymouth.ac.uk\/digital-education\/wp-content\/uploads\/sites\/96\/2016\/02\/HTML-External-object.png\" alt=\"HTML External object\" width=\"503\" height=\"323\" \/><br \/>\n<\/a>Click on the Edit and add the following lines, this will call in the files.<br \/>\nIf you wish to run the scripts from an external server all you need to do is add the external code shown below.<strong><a href=\"http:\/\/blogs.plymouth.ac.uk\/digital-education\/wp-content\/uploads\/sites\/96\/2016\/02\/Edit.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-867 \" src=\"http:\/\/blogs.plymouth.ac.uk\/digital-education\/wp-content\/uploads\/sites\/96\/2016\/02\/Edit.png\" alt=\"Edit\" width=\"503\" height=\"199\" \/><\/a><\/strong><\/p>\n<p><strong>For external code use:<\/strong><\/p>\n<p><span style=\"color: #0000ff\">&lt;script src=\u201dhttps:\/\/code.jquery.com\/jquery-1.11.1.min.js\u201d&gt;&lt;\/script&gt;<\/span><br \/>\n<span style=\"color: #0000ff\">&lt;script src=\u201dhttp:\/\/code.jquery.com\/ui\/1.11.1\/jquery-ui.min.js\u201d&gt;&lt;\/script&gt;<\/span><br \/>\n<span style=\"color: #0000ff\">&lt;script src=&#8221;my_functions.js&#8221;&gt;&lt;\/script&gt;<\/span><\/p>\n<p><strong>For internal \u2013 these file should be in your Script folder.<\/strong><\/p>\n<p><span style=\"color: #0000ff\">&lt;script src=&#8221;jquery-1.11.1.min.js&#8221;&gt;&lt;\/script&gt;<\/span><br \/>\n<span style=\"color: #0000ff\">&lt;script src=&#8221;jquery-ui.min.js&#8221;&gt;&lt;\/script&gt;<\/span><br \/>\n<span style=\"color: #0000ff\">&lt;script src=&#8221;my_functions.js&#8221;&gt;&lt;\/script&gt;<\/span><\/p>\n<p>The same files will to be added to the \u2018additional files\u2019, which directly next to the edit.<br \/>\nOnce the pop up appears, you can either add each file from your Script folder or add the whole folder.<a href=\"http:\/\/blogs.plymouth.ac.uk\/digital-education\/wp-content\/uploads\/sites\/96\/2016\/02\/additional-files.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-868 \" src=\"http:\/\/blogs.plymouth.ac.uk\/digital-education\/wp-content\/uploads\/sites\/96\/2016\/02\/additional-files.png\" alt=\"additional files\" width=\"501\" height=\"330\" \/><br \/>\n<\/a>On the page you have your slider, add an action, on \u2018show\u2019 \u2018runJS\u2019 in the JavaScript box type: init_drag_slider();<img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-869 \" src=\"http:\/\/blogs.plymouth.ac.uk\/digital-education\/wp-content\/uploads\/sites\/96\/2016\/02\/runJS.png\" alt=\"runJS\" width=\"508\" height=\"298\" \/><br \/>\nMake your slider\/counter\/and bar seen.<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-870 \" src=\"http:\/\/blogs.plymouth.ac.uk\/digital-education\/wp-content\/uploads\/sites\/96\/2016\/02\/Make-your-slider.png\" alt=\"Make your slider\" width=\"505\" height=\"227\" \/><br \/>\n\u2018Click On\u2019 the appearance arrow and the CSS class will pop up. Enter the name of your object. For this example I have chosen the counter, therefore I named it counter. All the objects such as the slider and images will need to be named.<img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-871 \" src=\"http:\/\/blogs.plymouth.ac.uk\/digital-education\/wp-content\/uploads\/sites\/96\/2016\/02\/CSS-class.png\" alt=\"CSS class\" width=\"505\" height=\"278\" \/><br \/>\nEach image will require a name within the class, as shown above. I haven\u2019t found a quick way of doing this part yet so having 70 images is somewhat slow going.<br \/>\n<a href=\"http:\/\/blogs.plymouth.ac.uk\/digital-education\/wp-content\/uploads\/sites\/96\/2016\/02\/name_images.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-872 \" src=\"http:\/\/blogs.plymouth.ac.uk\/digital-education\/wp-content\/uploads\/sites\/96\/2016\/02\/name_images.png\" alt=\"name_images\" width=\"511\" height=\"226\" \/><\/a><\/p>\n<p>Now test your Lectora project and see the magic work.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Trouble shooting:<\/strong><\/p>\n<p>Check that you are pointing to the correct folder and are using the correct files<br \/>\nCheck you have all 3 in you edit HTML Extension<br \/>\nCheck you have added all 3 files to the \u2018additional files\u2019 area<\/p>\n<p>**Note When updating the function file.. Saving isn\u2019t good enough you need to add the function file again to the additional files and remove the old version, by clicking replace when promoted.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Added jQuery to your Lectora project, to create an image slider. I have created this blog entry to help anyone who is struggling to create an image slider in Lectora. Open and save a new Lectora project. Within the folder structure create a new folder called Script. You will need to download the following two [&hellip;]<\/p>\n","protected":false},"author":110,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"enabled":false},"version":2}},"categories":[337],"tags":[],"class_list":["post-862","post","type-post","status-publish","format-standard","hentry","category-lectora"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/pdVSkC-dU","_links":{"self":[{"href":"https:\/\/blogs.plymouth.ac.uk\/digital-education\/wp-json\/wp\/v2\/posts\/862","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.plymouth.ac.uk\/digital-education\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.plymouth.ac.uk\/digital-education\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.plymouth.ac.uk\/digital-education\/wp-json\/wp\/v2\/users\/110"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.plymouth.ac.uk\/digital-education\/wp-json\/wp\/v2\/comments?post=862"}],"version-history":[{"count":0,"href":"https:\/\/blogs.plymouth.ac.uk\/digital-education\/wp-json\/wp\/v2\/posts\/862\/revisions"}],"wp:attachment":[{"href":"https:\/\/blogs.plymouth.ac.uk\/digital-education\/wp-json\/wp\/v2\/media?parent=862"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.plymouth.ac.uk\/digital-education\/wp-json\/wp\/v2\/categories?post=862"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.plymouth.ac.uk\/digital-education\/wp-json\/wp\/v2\/tags?post=862"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}