From: moodler Date: Sun, 20 Jul 2003 13:53:31 +0000 (+0000) Subject: New feature - "Web link" resources can now specify a popup window X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=86aa7ccfdf100bc028f7d22a80dfb3a724f04b6b;p=moodle.git New feature - "Web link" resources can now specify a popup window fullscreen is currently the only feature left out of this .. I had trouble getting it to work consistently so I've left it out as being more troubles than it's worth. --- diff --git a/course/lib.php b/course/lib.php index f8c02c938b..02e39144c7 100644 --- a/course/lib.php +++ b/course/lib.php @@ -438,6 +438,7 @@ function get_array_of_activities($courseid) { // section - the number of the section (eg week or topic) // name - the name of the instance // visible - is the instance visible or not +// extra - contains extra string to include in any link $mod = array(); @@ -458,6 +459,19 @@ function get_array_of_activities($courseid) { $mod[$seq]->section = $section->section; $mod[$seq]->name = urlencode(get_field($rawmods[$seq]->modname, "name", "id", $rawmods[$seq]->instance)); $mod[$seq]->visible = $rawmods[$seq]->visible; + $mod[$seq]->extra = ""; + + // This part is an ugly hack that doesn't belong here// + if ($mod[$seq]->mod == "resource") { + if ($resource = get_record("resource", "id", $rawmods[$seq]->instance)) { + if ($resource->type == 5 and $resource->alltext) { + $mod[$seq]->extra = urlencode("onClick=\"return ". + "openpopup('/mod/resource/view.php?id=". + $mod[$seq]->cm. + "','resource','$resource->alltext');\""); + } + } + } } } } @@ -650,10 +664,15 @@ function print_section($course, $section, $mods, $modnamesused, $absolute=false, " href=\"mod.php?moveto=$mod->id\">$strmovehere
\n"; } $instancename = urldecode($modinfo[$modnumber]->name); + if (!empty($modinfo[$modnumber]->extra)) { + $extra = urldecode($modinfo[$modnumber]->extra); + } else { + $extra = ""; + } $link_css = $mod->visible ? "" : " class=\"dimmed\" "; echo "wwwroot/mod/$mod->modname/icon.gif\"". " height=16 width=16 alt=\"$mod->modfullname\">". - " modfullname\" $link_css ". + " modfullname\" $link_css $extra". " href=\"$CFG->wwwroot/mod/$mod->modname/view.php?id=$mod->id\">$instancename"; } if (isediting($course->id)) { diff --git a/lib/javascript.php b/lib/javascript.php index 1577dfc792..74a51cb7d0 100644 --- a/lib/javascript.php +++ b/lib/javascript.php @@ -15,11 +15,15 @@ function fillmessagebox(text) { document.form.message.value = text; } -function openpopup(url,name,height,width) { +function openpopup(url,name,options,fullscreen) { fullurl = "wwwroot ?>" + url; - options = "menubar=0,location=0,scrollbars,resizable,width="+width+",height="+height; - windowobj = window.open(fullurl,name, options); + windowobj = window.open(fullurl,name,options); + if (fullscreen) { + windowobj.moveTo(0,0); + windowobj.resizeTo(screen.availWidth,screen.availHeight); + } windowobj.focus(); + return false; } function copyrichtext(textname) { @@ -43,15 +47,40 @@ function inserttext(text) { } echo " text = ' ' + text + ' ';\n"; echo " if ( $insertfield.createTextRange && $insertfield.caretPos) {\n"; - echo " var caretPos = $insertfield.caretPos;\n"; - echo " caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;\n"; + echo " var caretPos = $insertfield.caretPos;\n"; + echo " caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;\n"; echo " } else {\n"; - echo " $insertfield.value += text;\n"; + echo " $insertfield.value += text;\n"; echo " }\n"; echo " $insertfield.focus();\n"; ?> } +function lockoptions(form, master, subitems) { + // subitems is an array of names of sub items + // requires that each item in subitems has a + // companion hidden item in the form with the + // same name but prefixed by "h" + if (eval("document."+form+"."+master+".checked")) { + for (i=0; i // done hiding --> diff --git a/lib/weblib.php b/lib/weblib.php index 2c4f9adf50..1e847c9507 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -247,7 +247,8 @@ function frmchecked(&$var, $true_value = "checked", $false_value = "") { } -function link_to_popup_window ($url, $name="popup", $linkname="click here", $height=400, $width=500, $title="Popup window") { +function link_to_popup_window ($url, $name="popup", $linkname="click here", + $height=400, $width=500, $title="Popup window") { /// This will create a HTML link that will work on both /// Javascript and non-javascript browsers. /// Relies on the Javascript function openpopup in javascript.php @@ -255,21 +256,29 @@ function link_to_popup_window ($url, $name="popup", $linkname="click here", $hei global $CFG; - echo "\n"; - echo "\n\n"; + $options = "menubar=0,location=0,scrollbars,resizable,width=$width,height=$height"; + $fullscreen = 0; + echo "wwwroot/$url\" ". + "onClick=\"return openpopup('$url', '$name', '$options', $fullscreen);\">$linkname\n"; } + function close_window_button() { /// Prints a simple button to close a window - echo "
"; - echo ""; - echo "
"; + echo "
\n"; + echo "\n"; + echo "\n"; + echo "
\n"; } diff --git a/mod/resource/details.php b/mod/resource/details.php index 41d4a7686f..c044979f57 100644 --- a/mod/resource/details.php +++ b/mod/resource/details.php @@ -73,8 +73,6 @@ break; case WEBPAGE: - case WEBLINK: - case PROGRAM: $strexampleurl = get_string("exampleurl", "resource"); ?> @@ -85,12 +83,117 @@ + +   + + +

+ + + + $optionname = ""; + $jsoption[] = "\"$optionname\""; + } + $alljsoptions = implode(",", $jsoption); + + if ($form->instance) { // Re-editing + if (!$form->alltext) { + $newwindow = ""; + } else { + $newwindow = "checked"; + $rawoptions = explode(',', $form->alltext); + foreach ($rawoptions as $rawoption) { + $option = explode('=', trim($rawoption)); + $optionname = $option[0]; + $optionvalue = $option[1]; + if ($optionname == "height" or $optionname == "width") { + $window->$optionname = $optionvalue; + } else if ($optionvalue) { + $window->$optionname = "checked"; + } + } + } + } else { + $newwindow = "checked"; + $window->resizable = "checked"; + $window->scrollbars = "checked"; + $window->status = "checked"; + $window->location = "checked"; + $window->width = 620; + $window->height = 450; + } + + echo $alloptions; + + ?> + -

()

+

:

+ + + + + + +   + + +

+ + + + +

-

+ + + + onclick="return lockoptions('theform','newwindow', subitems)"> + +

    + $value) { + if ($name == "height" or $name == "width") { + continue; + } + echo ""; + echo "$name.">"; + $stringname = "str$name"; + echo $$stringname."
    "; + } + ?> + + + +
    + + + +
    + "; + echo "lockoptions('theform','newwindow', subitems);"; + echo ""; + } + ?> +

@@ -98,6 +201,28 @@ + + +

:

+ + + + + + +   + + +

+ + + + get_string("resourcetype1", "resource"), $RESOURCE_FRAME_SIZE = 130; +$RESOURCE_WINDOW_OPTIONS = array("resizable", "scrollbars", "directories", "location", + "menubar", "toolbar", "status", "height", "width"); function resource_add_instance($resource) { // Given an object containing all the necessary data, @@ -27,8 +29,20 @@ function resource_add_instance($resource) { // will create a new instance and return the id number // of the new instance. + global $RESOURCE_WINDOW_OPTIONS; + $resource->timemodified = time(); + if (isset($resource->setnewwindow)) { + $optionlist = array(); + foreach ($RESOURCE_WINDOW_OPTIONS as $option) { + if (isset($resource->$option)) { + $optionlist[] = $option."=".$resource->$option; + } + } + $resource->alltext = implode(',', $optionlist); + } + return insert_record("resource", $resource); } @@ -38,9 +52,21 @@ function resource_update_instance($resource) { // (defined by the form in mod.html) this function // will update an existing instance with new data. + global $RESOURCE_WINDOW_OPTIONS; + $resource->id = $resource->instance; $resource->timemodified = time(); + if (isset($resource->setnewwindow)) { + $optionlist = array(); + foreach ($RESOURCE_WINDOW_OPTIONS as $option) { + if (isset($resource->$option)) { + $optionlist[] = $option."=".$resource->$option; + } + } + $resource->alltext = implode(',', $optionlist); + } + return update_record("resource", $resource); } diff --git a/mod/resource/version.php b/mod/resource/version.php index a843367188..a3b4241f86 100644 --- a/mod/resource/version.php +++ b/mod/resource/version.php @@ -5,7 +5,7 @@ // This fragment is called by /admin/index.php //////////////////////////////////////////////////////////////////////////////// -$module->version = 2002122300; +$module->version = 2003072000; $module->cron = 0; ?>